:root {
  --bg: #0b1220;
  --bg-2: #0f172a;
  --card: #111c33;
  --card-2: #16233f;
  --line: #22304f;
  --text: #e6edf7;
  --muted: #8ea2c0;
  --accent: #34d399;
  --accent-2: #38bdf8;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ════════ LOGIN ════════ */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1000px 500px at 20% -10%, #12304d 0%, var(--bg) 55%);
  padding: 24px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.login-logo { font-size: 44px; text-align: center; }
.login-title { text-align: center; font-size: 24px; margin-top: 8px; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 24px; }
.field-label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.field-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 13px;
  font-size: 14px;
  outline: none;
}
.field-input:focus { border-color: var(--accent-2); }
.login-error {
  background: rgba(248, 113, 113, .12);
  border: 1px solid rgba(248, 113, 113, .4);
  color: var(--danger);
  font-size: 13px;
  border-radius: 10px;
  padding: 9px 12px;
  margin-top: 14px;
}
.login-foot { text-align: center; color: var(--muted); font-size: 11px; margin-top: 22px; }

/* ════════ LAYOUT ════════ */
.dash { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid var(--line);
}
.side-logo { font-size: 20px; }
.side-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: rgba(52, 211, 153, .12); color: var(--accent); font-weight: 600; }
.side-foot { padding: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }

.main { flex: 1; padding: 24px 28px 60px; max-width: 1500px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 22px; font-weight: 700; }
.page-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.switch-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.switch-row input { display: none; }
.switch {
  width: 38px; height: 20px;
  background: var(--line);
  border-radius: 999px;
  position: relative;
  transition: background .2s;
}
.switch::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 2px; left: 2px;
  transition: left .2s;
}
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { left: 20px; }

/* ════════ VIEWS / CARDS ════════ */
.view { display: none; }
.view.active { display: block; }
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi .k-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.kpi .k-value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.kpi.good .k-value { color: var(--accent); }
.kpi.bad .k-value { color: var(--danger); }
.kpi.warn .k-value { color: var(--warn); }
.kpi.accent .k-value { color: var(--accent-2); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 18px; margin-top: 18px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card-head h3 { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 14px; }
.chart-wrap { position: relative; height: 260px; }
.chart-tall { height: 320px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: .5px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 9px 10px; border-bottom: 1px solid rgba(34, 48, 79, .5); font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.green { background: rgba(52, 211, 153, .15); color: var(--accent); }
.badge.red { background: rgba(248, 113, 113, .15); color: var(--danger); }
.badge.amber { background: rgba(251, 191, 36, .15); color: var(--warn); }
.badge.blue { background: rgba(56, 189, 248, .15); color: var(--accent-2); }
.badge.gray { background: rgba(142, 162, 192, .15); color: var(--muted); }

/* ════════ FUNNEL ════════ */
.funnel { display: flex; flex-direction: column; gap: 10px; padding: 4px 0; }
.funnel-row { display: flex; align-items: center; gap: 12px; }
.funnel-label { width: 110px; font-size: 12.5px; color: var(--muted); flex-shrink: 0; }
.funnel-track { flex: 1; height: 26px; background: var(--bg-2); border-radius: 7px; overflow: hidden; position: relative; }
.funnel-fill { height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 7px; min-width: 2px; transition: width .4s; }
.funnel-val { width: 84px; text-align: right; font-size: 13px; font-weight: 600; flex-shrink: 0; font-variant-numeric: tabular-nums; }

/* ════════ EVENT LIST ════════ */
.event-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid rgba(34, 48, 79, .5); font-size: 13px; }
.event-row:last-child { border-bottom: none; }
.event-name { flex: 1; color: var(--text); }
.event-count { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ════════ MONEY FLOW ════════ */
.money-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }
.money-cell { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.money-cell .m-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.money-cell .m-value { font-size: 20px; font-weight: 700; margin-top: 5px; }
.money-note { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* ════════ BESTSELLERS ════════ */
.bestseller-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.bestseller-card h4 { font-size: 13.5px; margin-bottom: 10px; }
.bestseller-card ul { list-style: none; }
.bestseller-card li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid rgba(34, 48, 79, .5); font-size: 12.5px; }
.bestseller-card li:last-child { border-bottom: none; }
.bestseller-card .bs-qty { color: var(--muted); }
.bestseller-mini { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }

/* ════════ GAPS / ABOUT ════════ */
.gap-row { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid rgba(34, 48, 79, .5); font-size: 13px; }
.gap-row:last-child { border-bottom: none; }
.gap-metric { width: 240px; font-weight: 600; flex-shrink: 0; color: var(--warn); }
.gap-reason { color: var(--muted); }
.about-text { font-size: 13px; color: var(--muted); line-height: 1.7; }

/* ════════ BUTTONS / TOAST ════════ */
.btn-primary {
  background: var(--accent);
  color: #06251a;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-ghost:hover { background: var(--card); color: var(--text); }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 99;
}
.toast.error { border-color: rgba(248, 113, 113, .5); color: var(--danger); }

/* ════════ RESPONSIVE ════════ */
@media (max-width: 900px) {
  .dash { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; }
  .side-brand { border-bottom: none; padding: 12px 14px; }
  .side-nav { flex-direction: row; padding: 8px; }
  .side-foot { flex-direction: row; padding: 8px; }
  .nav-item { white-space: nowrap; }
  .main { padding: 16px; }
  .card-grid { grid-template-columns: 1fr; }
}