@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@500;700&display=swap');

:root{
  --bg: #14161a;
  --panel: #1b1e25;
  --panel-2: #21252e;
  --line: #2b2f39;
  --text: #e9ebef;
  --text-dim: #9298a6;
  --text-faint: #656b7a;
  --amber: #e8a33d;
  --amber-dim: #4a3a1e;
  --teal: #3ecf8e;
  --teal-dim: #1c3a2c;
  --red: #e5484d;
  --red-dim: #3d2226;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
}

*{ box-sizing: border-box; }
html,body{ margin:0; padding:0; }
body{
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
}

.mono{ font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }

/* ---------- App shell ---------- */
.app{
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar{
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
}
.brand{
  display:flex; align-items:center; gap:10px;
  padding: 4px 6px 22px 6px;
}
.brand-mark{
  width: 34px; height: 34px; border-radius: 8px;
  background: conic-gradient(from 210deg, var(--amber), #7a5620, var(--amber));
  display:flex; align-items:center; justify-content:center;
  font-family:'Rajdhani'; font-weight:700; color:#14161a; font-size:15px;
}
.brand-name{ font-family:'Rajdhani'; font-weight:700; font-size:19px; letter-spacing:0.5px; }
.brand-sub{ font-size:11px; color: var(--text-faint); margin-top:-2px; letter-spacing: 0.3px;}

.nav{ display:flex; flex-direction:column; gap:2px; margin-top: 6px;}
.nav a{
  display:flex; align-items:center; gap:10px;
  color: var(--text-dim); text-decoration:none;
  padding: 10px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 500;
  border: 1px solid transparent;
}
.nav a:hover{ background: var(--panel-2); color: var(--text); }
.nav a.active{
  background: var(--amber-dim); color: var(--amber);
  border-color: rgba(232,163,61,0.25);
}
.nav-icon{ width:16px; text-align:center; opacity:0.9; }

.sidebar-foot{ margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.sidebar-foot .email{ font-size: 12px; color: var(--text-faint); word-break: break-all; margin-bottom: 10px;}
.btn-logout{
  width:100%; padding: 9px; border-radius: 8px; border:1px solid var(--line);
  background: transparent; color: var(--text-dim); cursor:pointer; font-size:13px;
}
.btn-logout:hover{ border-color: var(--red); color: var(--red); }
.version{ text-align:center; font-size:11px; color: var(--text-faint); margin-top:10px; }

.main{ padding: 28px 34px; max-width: 1400px; }
.page-title{ font-family:'Rajdhani'; font-size: 28px; font-weight:700; margin:0; letter-spacing:0.3px; }
.page-sub{ color: var(--text-dim); margin: 4px 0 24px 0; font-size: 14px; }

/* ---------- Cards / panels ---------- */
.card{
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.grid{ display:grid; gap: 16px; }
.grid-4{ grid-template-columns: repeat(4, 1fr); }
.grid-3{ grid-template-columns: repeat(3, 1fr); }
.grid-2{ grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px){ .grid-4{grid-template-columns: repeat(2,1fr);} .grid-3{grid-template-columns: repeat(1,1fr);} }

.stat-label{ display:flex; align-items:center; justify-content:space-between; color:var(--text-dim); font-size:13px; }
.stat-badge{
  width:22px; height:22px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  font-size:11px; font-weight:700;
}
.badge-teal{ background: var(--teal-dim); color: var(--teal); }
.badge-red{ background: var(--red-dim); color: var(--red); }
.badge-amber{ background: var(--amber-dim); color: var(--amber); }
.stat-value{ font-family:'JetBrains Mono'; font-size: 26px; font-weight:700; margin-top: 8px; }
.stat-value.pos{ color: var(--teal); }
.stat-value.neg{ color: var(--red); }

/* ---------- Filters bar ---------- */
.filters{ display:flex; gap:10px; flex-wrap:wrap; margin-bottom: 20px; }
select, input[type=date], input[type=text], input[type=number], input[type=email], input[type=password]{
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
select:focus, input:focus{ outline: none; border-color: var(--amber); }
label{ font-size: 13px; color: var(--text-dim); display:block; margin-bottom:6px; }
.field{ margin-bottom: 16px; }

/* ---------- Buttons ---------- */
.btn{
  padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); cursor:pointer; font-size: 14px; font-weight:500;
}
.btn:hover{ border-color: #3a3f4b; }
.btn-primary{ background: var(--teal); border-color: var(--teal); color: #0e1f16; font-weight:600; }
.btn-primary:hover{ filter: brightness(1.08); }
.btn-danger{ background: var(--red-dim); border-color: rgba(229,72,77,0.3); color: var(--red); }
.btn-danger:hover{ background: var(--red); color: #fff; }
.btn-block{ width: 100%; }
.btn-sm{ padding: 6px 12px; font-size: 13px; }

/* ---------- Tabs ---------- */
.tabs{ display:flex; gap:6px; margin-bottom:20px; border-bottom:1px solid var(--line); }
.tab{
  padding: 10px 16px; cursor:pointer; color: var(--text-dim); font-size:14px; font-weight:500;
  border-bottom: 2px solid transparent; margin-bottom:-1px;
}
.tab.active{ color: var(--amber); border-color: var(--amber); }

/* ---------- Table ---------- */
table{ width:100%; border-collapse: collapse; }
th{ text-align:left; font-size:12px; text-transform:uppercase; letter-spacing:0.4px; color: var(--text-faint); padding: 10px 12px; border-bottom: 1px solid var(--line);}
td{ padding: 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
tr:last-child td{ border-bottom:none; }
.table-wrap{ overflow-x:auto; }

.pill{ display:inline-flex; align-items:center; gap:6px; padding: 4px 10px; border-radius:20px; font-size:12px; font-weight:600; }
.pill-dot{ width:6px; height:6px; border-radius:50%; }
.pill-active{ background: var(--teal-dim); color: var(--teal); }
.pill-active .pill-dot{ background: var(--teal); }
.pill-paused{ background: var(--amber-dim); color: var(--amber); }
.pill-paused .pill-dot{ background: var(--amber); }
.pill-disabled{ background: var(--red-dim); color: var(--red); }
.pill-disabled .pill-dot{ background: var(--red); }

/* ---------- Login ---------- */
.login-wrap{
  min-height: 100vh; display:flex; align-items:center; justify-content:center;
  background: radial-gradient(circle at 50% 20%, #1e222b 0%, #14161a 60%);
}
.login-card{
  width: 380px; background: var(--panel); border:1px solid var(--line);
  border-radius: 14px; padding: 32px; box-shadow: var(--shadow);
}
.login-logo{
  width: 52px; height:52px; border-radius: 12px; margin: 0 auto 16px auto;
  background: conic-gradient(from 210deg, var(--amber), #7a5620, var(--amber));
  display:flex; align-items:center; justify-content:center;
  font-family:'Rajdhani'; font-weight:700; color:#14161a; font-size:22px;
}
.login-title{ text-align:center; font-family:'Rajdhani'; font-size:24px; font-weight:700; margin: 0 0 2px 0;}
.login-sub{ text-align:center; color:var(--text-dim); font-size:13px; margin-bottom:26px; }
.login-error{ color: var(--red); font-size:13px; margin-top:10px; min-height:16px; }

/* ---------- Gauge (signature element) ---------- */
.gauge-wrap{ display:flex; align-items:center; gap:22px; }
.gauge-num{ font-family:'JetBrains Mono'; font-size:34px; font-weight:700; }
.gauge-caption{ color: var(--text-dim); font-size:13px; margin-top:4px; }

/* ---------- Misc ---------- */
.hint{ font-size:12px; color: var(--text-faint); margin-top: 10px; line-height:1.5;}
.section-title{ font-family:'Rajdhani'; font-weight:700; font-size:17px; margin: 28px 0 14px 0; }
.checkbox-row{ display:flex; align-items:center; gap:8px; margin: 4px 0 16px 0; }
.checkbox-row input{ width:16px; height:16px; }
.checkbox-row label{ margin:0; color: var(--text); font-size:14px; }
.two-col{ display:grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.right-panel{ display:flex; flex-direction:column; gap:16px; }
.empty{ text-align:center; color: var(--text-faint); padding: 30px 0; font-size:14px; }
.loader{ text-align:center; color:var(--text-faint); padding:20px; font-size:13px;}
a.link{ color: var(--amber); text-decoration:none; }
a.link:hover{ text-decoration:underline; }

/* ---------- Page loader (blocks clicks until auth+data ready) ---------- */
.page-loader{
  position:fixed; inset:0; background: var(--bg);
  display:flex; align-items:center; justify-content:center;
  z-index: 200; flex-direction:column; gap:14px;
}
.page-loader.hidden{ display:none; }
.spinner{
  width: 34px; height:34px; border-radius:50%;
  border: 3px solid var(--line); border-top-color: var(--amber);
  animation: spin 0.8s linear infinite;
}
.spinner-sm{ width:14px; height:14px; border-width:2px; display:inline-block; vertical-align:middle; margin-right:6px; }
@keyframes spin{ to{ transform: rotate(360deg); } }
.loader-caption{ color: var(--text-dim); font-size:13px; }

/* ---------- Toasts ---------- */
#toastRoot{ position:fixed; bottom:22px; right:22px; z-index:300; display:flex; flex-direction:column; gap:10px; }
.toast{
  min-width: 220px; max-width: 340px; padding: 12px 16px; border-radius: 9px;
  background: var(--panel-2); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 13.5px; display:flex; align-items:center; gap:10px;
  animation: toast-in 0.18s ease-out;
}
@keyframes toast-in{ from{ opacity:0; transform: translateY(8px); } to{ opacity:1; transform:none; } }
.toast.success{ border-color: rgba(62,207,142,0.35); }
.toast.error{ border-color: rgba(229,72,77,0.4); }
.toast-dot{ width:8px; height:8px; border-radius:50%; flex:none; }
.toast.success .toast-dot{ background: var(--teal); }
.toast.error .toast-dot{ background: var(--red); }

/* ---------- Button loading state ---------- */
button:disabled{ opacity:0.65; cursor:not-allowed; }

/* ---------- Sortable table headers ---------- */
th.sortable{ cursor:pointer; user-select:none; }
th.sortable:hover{ color: var(--text); }
th.sort-active{ color: var(--amber); }
.row-best{ color: var(--teal); }
.row-worst{ color: var(--red); }

/* ---------- Chart card ---------- */
.chart-card{ background: var(--panel); border:1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.chart-card canvas{ max-height: 280px; }

/* ---------- Sidebar submenu (Analytics group) ---------- */
.nav-group-toggle{
  display:flex; align-items:center; justify-content:space-between; width:100%;
  background:none; border:1px solid transparent; color: var(--text-dim);
  padding: 10px 12px; border-radius: 8px; font-size:14px; font-weight:500; cursor:pointer;
  font-family: inherit;
}
.nav-group-toggle:hover{ background: var(--panel-2); color: var(--text); }
.nav-group-toggle .chevron{ transition: transform 0.15s; font-size:11px; }
.nav-group-toggle.open .chevron{ transform: rotate(90deg); }
.nav-group-toggle.has-active{ color: var(--amber); }
.nav-submenu{
  max-height:0; overflow:hidden; transition: max-height 0.18s ease;
  display:flex; flex-direction:column; gap:2px;
  padding-left: 14px; border-left: 1px solid var(--line); margin-left: 22px;
}
.nav-submenu.open{ max-height: 200px; }
.nav-submenu a{
  display:flex; align-items:center; gap:8px; color: var(--text-dim); text-decoration:none;
  padding: 8px 10px; border-radius: 7px; font-size: 13px; font-weight:500;
}
.nav-submenu a:hover{ background: var(--panel-2); color: var(--text); }
.nav-submenu a.active{ background: var(--amber-dim); color: var(--amber); }

/* ---------- Colorful dashboard KPI cards ---------- */
.kpi-card{ border-top: 3px solid transparent; }
.kpi-income{ border-top-color: var(--teal); }
.kpi-expense{ border-top-color: var(--red); }
.kpi-net{ border-top-color: #6ea8fe; }
.kpi-turnover{ border-top-color: var(--amber); }
.badge-blue{ background: rgba(110,168,254,0.15); color: #6ea8fe; }

.view{ animation: view-in 0.12s ease; }
@keyframes view-in{ from{ opacity:0.4; } to{ opacity:1; } }

/* ---------- Generic show/hide utility (used across the whole app) ---------- */
.hidden{ display: none !important; }

/* ---------- Modal (History edit dialog) ---------- */
.modal-backdrop{
  position:fixed; inset:0; background:rgba(0,0,0,0.55);
  display:flex; align-items:center; justify-content:center; z-index:250;
}
.modal-card{
  width:380px; background: var(--panel); border:1px solid var(--line);
  border-radius:12px; padding:22px;
}

/* ---------- Gauge smooth transition (Profit margin) ---------- */
#db-gaugeArc{ transition: stroke-dashoffset 0.4s ease, stroke 0.4s ease; }
