:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6e9f0;
  --text: #1b2333;
  --muted: #6b7488;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --sidebar-bg: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 16px;
  --sidebar-w: 264px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 100% -10%, #e8ecff 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ================= Layout ================= */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ================= Sidebar ================= */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 19px; color: #fff;
  background: linear-gradient(135deg, #6366f1, #4f46e5 60%, #4338ca);
  box-shadow: 0 6px 16px rgba(79, 70, 229, .35);
  flex: none;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: -.01em; }
.brand-text span { font-size: 12px; color: var(--muted); }

/* ---------- Menu ---------- */
.menu { display: flex; flex-direction: column; gap: 4px; }

.menu-group { border-radius: 12px; }

.menu-main {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 14.5px;
  font-weight: 600;
  text-align: left;
  transition: background .15s;
}
.menu-main:hover { background: var(--surface-2); }

.menu-logo { width: 30px; height: 30px; flex: none; display: block; }
.menu-logo svg { width: 100%; height: 100%; display: block; border-radius: 8px; }

.menu-name { flex: 1; }

.chevron {
  width: 16px; height: 16px;
  color: var(--muted);
  transition: transform .22s ease;
}
.menu-group.open .chevron { transform: rotate(90deg); }

/* Submenu: hidden by default, expands when the group is open */
.submenu {
  overflow: hidden;
  max-height: 0;
  transition: max-height .24s ease;
}
.menu-group.open .submenu { max-height: 240px; }

.submenu-item {
  display: block;
  margin: 2px 0 2px 41px;
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.submenu-item:hover { background: var(--surface-2); color: var(--text); }
.submenu-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
}

/* ================= Main ================= */
.main {
  min-width: 0;
  padding: 26px 30px 64px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.page-title h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.page-title p { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; }

/* ---------- Shared filter bar ---------- */
.filterbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  margin-bottom: 22px;
}

.filter-head { display: flex; align-items: center; gap: 9px; }
.filter-icon { width: 18px; height: 18px; color: var(--accent); flex: none; }
.filter-title { font-weight: 700; font-size: 14px; letter-spacing: -.01em; }
.filter-hint { font-size: 12px; color: var(--muted); }

.filter-fields { display: flex; align-items: flex-end; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}

.period { display: flex; gap: 8px; }

select {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7488' stroke-width='2.5'><path d='M6 9l6 6 6-6'/></svg>") no-repeat right 12px center;
  padding: 10px 34px 10px 14px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
select:hover { border-color: #cfd5e4; }
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.refresh {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 11px;
  color: var(--muted);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: color .15s, border-color .15s, transform .15s;
}
.refresh:hover { color: var(--accent); border-color: #cfd5e4; }
.refresh:active { transform: scale(.94); }
.refresh svg { fill: currentColor; }
.refresh.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.download {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 11px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: color .15s, border-color .15s, transform .15s, opacity .15s;
}
.download:hover:not(:disabled) { color: var(--accent); border-color: #cfd5e4; }
.download:active:not(:disabled) { transform: scale(.97); }
.download:disabled { opacity: .45; cursor: not-allowed; }
.download svg { stroke: currentColor; }

/* ---------- KPI cards ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi::after {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--accent);
  opacity: .85;
}
.kpi.primary { background: linear-gradient(135deg, #4f46e5, #4338ca); border-color: transparent; color: #fff; }
.kpi.primary::after { display: none; }
.kpi.primary .kpi-label { color: rgba(255,255,255,.8); }
.kpi.primary .kpi-value { color: #fff; }

.kpi-label {
  font-size: 12px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted);
}
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; }
.kpi-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.kpi.primary .kpi-sub { color: rgba(255,255,255,.75); }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 22px;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.panel-head h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.muted { color: var(--muted); font-size: 13px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- Bar chart ---------- */
.chart { display: flex; flex-direction: column; gap: 14px; }

.bar-row { display: grid; grid-template-columns: 46px 1fr 160px; align-items: center; gap: 14px; }
.bar-country {
  font-weight: 700; font-size: 13px; text-align: center;
  color: var(--text);
}
.bar-track {
  position: relative;
  background: var(--surface-2);
  border-radius: 10px;
  height: 34px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 10px;
  width: 0;
  transition: width .7s cubic-bezier(.22,1,.36,1);
  min-width: 2px;
}
.bar-value {
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; font-size: 11.5px; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted);
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; background: var(--accent-soft); }
tr.total:hover td { background: var(--accent-soft); }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}

.share {
  display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end;
}
.share-bar { width: 60px; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.share-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- Placeholder view ---------- */
.placeholder { text-align: center; padding: 60px 24px; }
.placeholder-icon { width: 56px; height: 56px; margin: 0 auto 16px; }
.placeholder-icon svg { width: 100%; height: 100%; border-radius: 14px; }
.placeholder h2 { margin: 0 0 6px; font-size: 18px; }

/* ---------- States ---------- */
.state { text-align: center; color: var(--muted); padding: 8px; }
.state.error {
  background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca;
  border-radius: 12px; padding: 14px 18px; margin-top: 8px;
}
.hidden { display: none !important; }

.skeleton {
  height: 34px; border-radius: 10px;
  background: linear-gradient(90deg, #eef1f7 25%, #e3e8f2 37%, #eef1f7 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ================= Auth prompt ================= */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 40, .45);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(16, 24, 40, .25);
  padding: 26px 24px;
  text-align: center;
}

.auth-icon {
  width: 52px; height: 52px;
  margin: 0 auto;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
}
.auth-icon svg { width: 26px; height: 26px; }

.auth-card h2 { margin: 14px 0 6px; font-size: 18px; letter-spacing: -.01em; }
.auth-card p.muted { margin: 0 0 18px; }

.auth-field { display: block; text-align: left; margin-bottom: 12px; }
.auth-field span {
  display: block;
  font-size: 11.5px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted);
  margin-bottom: 6px;
}
.auth-field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #fff;
}

.auth-error { color: #b91c1c; font-size: 13px; margin: 4px 0 12px; }

.auth-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn-primary, .btn-ghost {
  flex: 1;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }

/* ================= Responsive ================= */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .main { padding: 20px 16px 48px; }
}

@media (max-width: 560px) {
  .kpi-value { font-size: 22px; }
  .bar-row { grid-template-columns: 40px 1fr 110px; gap: 10px; }
  .bar-value { font-size: 11.5px; }
}
