/* ─────────────────────────────────────────────────────────────────────────
   Tahlil — Yagona oyna. Analytics workspace UI (restrained, data-first).
   ───────────────────────────────────────────────────────────────────────── */
:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --bg:        #f8fafc;
  --surface:   #ffffff;
  --ink:       #0f172a;
  --ink-soft:  #475569;
  --line:      #e2e8f0;

  --accent:    #2563eb;
  --accent-ink:#1e40af;
  --accent-bg: #eff6ff;

  --region:    #16a34a;
  --up:        #16a34a;
  --down:      #dc2626;

  --r:         12px;
  --r-sm:      8px;
  --shadow:    0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
  --shadow-hi: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  line-height: 1.5;
  background: var(--bg);
  font-size: 15px;
}

/* ── Header / nav ───────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: .5rem 1.25rem;
  position: sticky; top: 0; z-index: 50;
}
.nav-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}
nav { display: flex; gap: .25rem; align-items: center; }
nav a {
  text-decoration: none; color: var(--ink-soft); font-weight: 500; font-size: .9rem;
  padding: .35rem .55rem; border-radius: 6px; transition: background .12s, color .12s;
}
nav a:hover { background: var(--accent-bg); color: var(--accent-ink); }
.brand {
  font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; color: var(--accent); margin-right: .4rem;
  text-decoration: none; display: inline-block;
}
.menu-toggle {
  display: none !important;
  background: transparent !important;
  border: none !important;
  color: var(--ink-soft) !important;
  padding: 0.35rem !important;
  cursor: pointer;
  box-shadow: none !important;
  transform: none !important;
}
.menu-toggle:hover {
  color: var(--accent) !important;
}

/* ── Nav dropdown menus ─────────────────────────────────────────────────── */
.nav-dropdown { position: relative; display: inline-flex; }
.nav-drop-trigger {
  text-decoration: none; color: var(--ink-soft); font-weight: 500; font-size: .9rem;
  padding: .35rem .55rem; border-radius: 6px; cursor: pointer; user-select: none;
  transition: background .12s, color .12s; white-space: nowrap;
}
.nav-drop-trigger:hover { background: var(--accent-bg); color: var(--accent-ink); }
.nav-drop-menu {
  display: none; position: absolute; top: 100%; left: 0; min-width: 210px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--shadow-hi); z-index: 100; padding: .3rem 0; margin-top: 2px;
}
.nav-dropdown:hover .nav-drop-menu,
.nav-dropdown.open .nav-drop-menu { display: block; }
.nav-drop-menu a {
  display: block; padding: .45rem .85rem; font-size: .85rem; color: var(--ink);
  text-decoration: none; border-radius: 0; transition: background .1s;
}
.nav-drop-menu a:hover { background: #eef4fb; color: var(--accent); }

/* ── Layout ─────────────────────────────────────────────────────────────── */
main { max-width: 1200px; margin: 1.25rem auto 3rem; padding: 0 1.25rem; }
h1 { margin: .2rem 0 .35rem; font-size: 1.5rem; font-weight: 650; letter-spacing: -.01em; line-height: 1.2; }
h2 {
  font-size: 1.02rem; font-weight: 600; letter-spacing: 0; margin: 1.5rem 0 .75rem;
  padding-bottom: .3rem; position: relative; color: var(--ink);
}
h2::after { content: ""; position: absolute; left: 0; bottom: 0; width: 26px; height: 2px; border-radius: 2px; background: var(--accent); }
section { margin: 1.3rem 0; }
p { margin: .35rem 0 .85rem; }
small, .muted { color: var(--ink-soft); }
.muted { font-size: .88rem; }

/* ── Context strip (role/scope) ─────────────────────────────────────────── */
.ctx {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--accent-bg); border: 1px solid #d7e6f7;
  padding: .25rem .7rem !important; border-radius: 6px !important;
  font-size: .85rem !important; color: var(--ink-soft) !important; margin: .15rem 0 .55rem !important;
  box-shadow: none;
}
.ctx b { color: var(--accent-ink); font-weight: 600; }

/* ── Cards grid (sectors / districts) ───────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.card {
  position: relative; display: block; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r); padding: .85rem .95rem;
  text-decoration: none; color: inherit; box-shadow: var(--shadow);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
a.card:hover { border-color: #b9d3f1; box-shadow: var(--shadow-hi); transform: translateY(-3px) scale(1.01); }
.card h3 { margin: 0 0 .25rem; font-size: .98rem; font-weight: 600; color: var(--accent-ink); letter-spacing: 0; }
.card .muted { font-size: .82rem; }

/* ── KPI tiles (district / indicator dashboards) ────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: .7rem; }
.kpi {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: .8rem .9rem .75rem; text-decoration: none; color: inherit;
  display: block; box-shadow: var(--shadow); transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
a.kpi:hover { border-color: #b9d3f1; box-shadow: var(--shadow-hi); transform: translateY(-3px) scale(1.01); }
.kpi .kpi-name { font-size: .84rem; color: var(--ink-soft); font-weight: 500; min-height: 2.4em; }
.kpi .big { font-size: 1.55rem; font-weight: 650; line-height: 1.15; letter-spacing: -.01em; margin-top: .1rem; color: var(--ink); }
.kpi .unit { font-size: .8rem; color: var(--ink-soft); font-weight: 400; }
.kpi .meta { font-size: .79rem; color: var(--ink-soft); margin-top: .4rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* badges */
.rank { background: var(--accent-bg); color: var(--accent-ink); border-radius: 5px; padding: .08rem .42rem; font-weight: 600; font-size: .77rem; }
.pending-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.15rem; height: 1.15rem; padding: 0 .22rem;
  background: #c92a2a; color: #fff; border-radius: 50%;
  font-size: .62rem; font-weight: 700; line-height: 1;
  margin-left: .25rem; vertical-align: middle;
  animation: pulse-badge 2s ease-in-out infinite;
}
@keyframes pulse-badge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}
.delta-up { color: var(--up); font-weight: 600; }
.delta-down { color: var(--down); font-weight: 600; }

/* ── N/A (not applicable) indicator styling ─────────────────────────────── */
.kpi.na {
  border-style: dashed; border-color: #d0d7e2; background: #fafbfc;
  opacity: .72; cursor: default; box-shadow: none;
}
.kpi.na:hover { border-color: #d0d7e2; box-shadow: none; }
.na-val { color: #9aa6b6; font-weight: 400; }
.na-tag {
  display: inline-block; background: #eef1f6; color: #8a94a3;
  border-radius: 4px; padding: .04rem .35rem; font-size: .62rem;
  font-weight: 600; letter-spacing: .04em; vertical-align: middle;
}
.na-notice {
  margin: .1rem 0 .75rem; padding: .5rem .75rem;
  border-radius: var(--r-sm); border: 1px solid #f3d9a4;
  background: #fef9ee; color: #8a6d14; font-size: .88rem;
}

/* ── Phase 2: Forecast & Anomaly tiles ─────────────────────────────────── */
.forecast-tile {
  margin: .3rem 0 .8rem; padding: .55rem .8rem;
  border-radius: var(--r); border: 1px solid #c8e0d4;
  background: #f2faf6; display: flex; gap: .8rem; align-items: center;
  flex-wrap: wrap;
}
.fc-label { font-size: .8rem; font-weight: 600; color: #2d6a4f; }
.fc-value { font-size: 1.3rem; font-weight: 650; color: #1b4332; }
.fc-meta { font-size: .72rem; color: #6b9080; margin-left: auto; }
.anomaly-warn {
  margin: .2rem 0 .7rem; padding: .45rem .75rem;
  border-radius: var(--r-sm); border: 1px solid #f3c8c8;
  background: #fef5f5; color: #a61b1b; font-size: .84rem; font-weight: 500;
}

/* ── Period picker container (unified, clean — same as import page) ────── */
.period-row {
  display: inline-flex; align-items: center; gap: .5rem;
  font-size: .85rem; vertical-align: middle;
}

/* ── Inline edit ───────────────────────────────────────────────────────── */
.inline-edit {
  cursor: text; border-bottom: 1px dashed transparent;
  transition: border-color .12s, background .12s;
  padding: 0 .15rem; border-radius: 2px;
}
.inline-edit:hover { border-bottom-color: #a0b8d0; background: #f8faff; }
.inline-edit.editing { border-bottom-color: transparent; background: transparent; }
.inline-edit input {
  font: inherit; font-weight: inherit; color: inherit;
  border: 1px solid var(--accent); border-radius: 4px;
  padding: .08rem .3rem; width: 100px; outline: none;
  background: #fff; box-shadow: 0 0 0 2px rgba(37,99,235,.12);
}
.inline-edit input:focus { border-color: #1d4ed8; box-shadow: 0 0 0 3px rgba(37,99,235,.18); }
.edit-hint {
  font-size: .65rem; color: #999; margin-left: .25rem;
  opacity: 0; transition: opacity .15s;
}
.inline-edit:hover .edit-hint { opacity: 1; }

/* ── Compact dashboard (redesign) ───────────────────────────────────────── */
.kpi-grid.compact { 
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .4rem; 
  align-items: start;
}
.kpi-grid.compact .kpi, .kpi-grid.compact a.kpi { 
  padding: .4rem .55rem .35rem; min-height: auto; 
}
.kpi-grid.compact .kpi .kpi-name { font-size: .74rem; min-height: auto; line-height: 1.2; }
.kpi-grid.compact .kpi .big { font-size: 1.15rem; margin-top: .05rem; }
.kpi-grid.compact .kpi .unit { font-size: .66rem; }
.kpi-grid.compact .kpi .meta { font-size: .68rem; margin-top: .15rem; gap: .2rem; }

.chart-card.compact { padding: .5rem .65rem; margin: .4rem 0; }
.chart-card.compact h3 { font-size: .88rem; }
.chart-card.compact .sub { font-size: .74rem; margin-bottom: .35rem; }

section.compact { margin: .6rem 0; }
section.compact h2 { font-size: .92rem; margin: .6rem 0 .35rem; }

/* ── District dashboard data-table (redesign) ───────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.data-table th { 
  background: #f6f8fb; font-weight: 600; color: #444; font-size: .76rem;
  padding: .35rem .5rem; text-align: left; border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
.data-table td {
  padding: .3rem .5rem; border-bottom: 1px solid #eef1f5;
  vertical-align: middle;
}
.data-table tbody tr:hover { background: #f9fbfe; }
.data-table .td-name { font-weight: 500; max-width: 200px; }
.data-table .td-value { font-weight: 650; text-align: right; white-space: nowrap; }
.data-table .td-rank { font-size: .78rem; text-align: center; }
.data-table .td-delta { font-size: .78rem; text-align: right; white-space: nowrap; }
.data-table .td-period { font-size: .76rem; color: #888; }

/* ── Hybrid dashboard: indicator strips (not tables) ────────────────────── */
.dash-strip {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: .45rem; margin: .35rem 0 .65rem; align-items: start;
}
.dash-item {
  display: flex; align-items: center; gap: .55rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: .45rem .55rem;
  box-shadow: var(--shadow); transition: border-color .12s;
  text-decoration: none; color: inherit;
}
.dash-item:hover { border-color: #b9d3f1; box-shadow: var(--shadow-hi); }
.dash-item .di-left { flex: 1; min-width: 0; }
.dash-item .di-name {
  display: block;
  font-size: .8rem; font-weight: 500; color: var(--accent); line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-decoration: none;
}
a.di-name:hover { text-decoration: underline; color: #0d4a8a; }
.dash-item .di-value {
  font-size: 1.15rem; font-weight: 650; color: var(--ink);
  letter-spacing: -.01em; line-height: 1.15;
  white-space: nowrap;
}
.dash-item .di-unit { font-size: .7rem; color: var(--ink-soft); font-weight: 400; white-space: nowrap; }
.dash-item .di-right { text-align: right; flex-shrink: 0; }
.dash-item .di-rank {
  font-size: .72rem; font-weight: 600; background: var(--accent-bg);
  color: var(--accent-ink); border-radius: 4px; padding: .06rem .35rem;
  white-space: nowrap;
}
.dash-item .di-delta { font-size: .72rem; font-weight: 600; white-space: nowrap; }
.dash-item .di-period { font-size: .68rem; color: #999; margin-top: .1rem; }
.dash-item .di-right > * { display: block; line-height: 1.3; }

.dash-item.na-item {
  border-style: dashed; border-color: #dbe0e8; background: #fafbfc;
  opacity: .65; cursor: default;
}
.dash-item.na-item .di-value { color: #9aa6b6; font-weight: 400; }
.dash-item.na-item .di-name { color: #999; }

/* Sector section header */
.sect-head {
  display: flex; align-items: baseline; gap: .5rem;
  margin: 1rem 0 .3rem;
}
.sect-head h2 {
  font-size: .95rem; font-weight: 600; letter-spacing: 0; margin: 0;
  padding-bottom: 0; color: var(--ink);
}
.sect-head h2::after { display: none; }
.sect-head .sect-badge {
  font-size: .7rem; font-weight: 600; color: var(--accent);
  background: var(--accent-bg); border-radius: 5px; padding: .08rem .4rem;
}
.sect-head .sect-na {
  font-size: .7rem; color: #999; background: #f5f5f5;
  border-radius: 5px; padding: .08rem .4rem;
}
.sect-accent {
  width: 3px; border-radius: 2px; background: var(--accent);
  margin-right: .5rem; align-self: stretch;
}

/* ── Chart cards ────────────────────────────────────────────────────────── */
.chart-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: .95rem 1.05rem; margin: 1rem 0; box-shadow: var(--shadow);
}
.chart-card h3 { margin: 0 0 .15rem; font-size: 1rem; font-weight: 600; letter-spacing: 0; }
.chart-card h3 a { color: var(--accent-ink); text-decoration: none; }
.chart-card h3 a:hover { text-decoration: underline; }
.chart-card .sub { color: var(--ink-soft); font-size: .84rem; margin: 0 0 .65rem; }

svg.chart { width: 100%; height: auto; display: block; }
.chart .bar-label { font-size: 11px; fill: var(--ink); font-weight: 400; }
.chart .bar-value { font-size: 10.5px; fill: var(--ink); font-weight: 600; }
.chart .bar-row { transition: opacity .12s; }
.chart .bar-row:hover { opacity: .85; }
.chart .bar-row.sel .bar-label { font-weight: 600; fill: var(--down); }
.chart .bar-track { fill: #f1f4f9; }
.chart .axis { font-size: 10px; fill: #9aa6b6; }
.chart .pt-label { font-size: 10px; font-weight: 500; }
.chart .ref-label { font-size: 10px; font-weight: 600; }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .45rem; font-size: .84rem; color: var(--ink-soft); }
.legend .leg { display: inline-flex; align-items: center; gap: .4rem; }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ── Auto-analysis (NLG) insight strip ──────────────────────────────────── */
.insight {
  position: relative; margin: .1rem 0 1.1rem; padding: .7rem .95rem .75rem 1rem;
  border-radius: var(--r); border: 1px solid #d8e8f6; background: var(--accent-bg);
}
.insight::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); border-radius: var(--r) 0 0 var(--r); }
.insight-label { display: block; font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin-bottom: .2rem; }
.insight-text { color: var(--ink); font-size: .94rem; line-height: 1.55; }

/* ── Breadcrumbs ────────────────────────────────────────────────────────── */
.crumbs { font-size: .84rem; color: var(--ink-soft); margin-bottom: .35rem; }
.crumbs a { color: var(--accent); text-decoration: none; font-weight: 500; }
.crumbs a:hover { text-decoration: underline; }

/* ── Tables / forms ─────────────────────────────────────────────────────── */
table { border-collapse: separate; border-spacing: 0; width: 100%; background: var(--surface);
  font-size: .92rem; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; box-shadow: var(--shadow); }
th, td { padding: .5rem .65rem; text-align: left; border-bottom: 1px solid var(--line); }
th { background: #f6f8fb; font-weight: 600; color: var(--ink); font-size: .85rem; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #f9fbfe; }

input, select, button, textarea {
  font: inherit; padding: .4rem .55rem; border: 1px solid #cdd7e4; border-radius: 7px;
  background: #fff; color: var(--ink); transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23,105,196,.14); }
button {
  background: var(--accent); color: #fff; border: 1px solid var(--accent); cursor: pointer; font-weight: 600;
  padding: .42rem .85rem; box-shadow: none; transition: background .12s;
}
button:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
button:active { transform: translateY(1px); }

pre { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: .65rem; overflow: auto; font-size: .85rem; }
code { background: #eef2f7; padding: .05rem .3rem; border-radius: 4px; font-size: .9em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem 1rem; max-width: 720px; }
label { display: flex; flex-direction: column; font-size: .88rem; gap: .22rem; color: var(--ink-soft); font-weight: 500; }

@media (max-width: 768px) {
  .menu-toggle {
    display: block !important;
  }
  header {
    padding: 0.75rem 1.25rem;
  }
  nav {
    display: none;
    flex-direction: column;
    width: 100%;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 1rem;
    box-shadow: var(--shadow-hi);
    z-index: 1000;
    align-items: stretch !important;
    gap: 0.6rem !important;
  }
  nav.open {
    display: flex;
  }
  nav a {
    width: 100%;
    padding: 0.55rem 0.75rem;
    font-size: 0.92rem;
  }
  .nav-dropdown {
    display: flex;
    flex-direction: column;
    width: 100%;
  }
  .nav-drop-trigger {
    width: 100%;
    padding: 0.55rem 0.75rem;
    font-size: 0.92rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .nav-drop-menu {
    position: static;
    display: none;
    width: 100%;
    border: none;
    box-shadow: none;
    background: #f8fafc;
    margin-top: 0.2rem;
    padding: 0.4rem 0.4rem 0.4rem 1.2rem;
    border-left: 2px solid var(--line);
    border-radius: 0;
  }
  .nav-dropdown.open .nav-drop-menu {
    display: block;
  }
  .user-badge {
    margin-left: 0 !important;
    width: 100%;
    margin-top: 0.4rem;
    padding: 0.6rem 0.75rem;
    border-top: 1px solid var(--line);
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.55rem !important;
    display: flex !important;
  }
  .user-badge .badge-divider {
    display: none;
  }
}

@media (max-width: 560px) {
  h1 { font-size: 1.35rem; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* ── Print / PDF (T3.2) — hisobotni chop etish ──────────────────────────── */
@media print {
  @page {
    size: A4 portrait;
    margin: 1.5cm 1.2cm 1.8cm 1.2cm;
  }

  /* Chrome print background colours */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: #fff !important;
    font-size: 12px;
    color: #1a1a1a;
  }

  /* Hide navigation, breadcrumbs, and the print button */
  header,
  .crumbs,
  .print-btn-wrap,
  .no-print {
    display: none !important;
  }

  main {
    max-width: 100%;
    margin: 0;
    padding: 0;
  }

  /* ── Print report header ─────────────────────────────────────────── */
  .print-header {
    display: block !important;
    border-bottom: 2px solid #1769c4;
    padding-bottom: .35rem;
    margin-bottom: .85rem;
  }
  .print-header .ph-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #1769c4;
    letter-spacing: -.01em;
  }
  .print-header .ph-meta {
    font-size: .75rem;
    color: #555;
    margin-top: .15rem;
  }
  .print-footer {
    display: block !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    font-size: .65rem;
    color: #999;
    padding: .4rem 0;
    border-top: 1px solid #ddd;
  }

  h1 {
    font-size: 1.15rem;
    margin-bottom: .3rem;
  }
  h2 {
    font-size: .88rem;
    margin: .8rem 0 .4rem;
    color: #333;
  }
  h2::after { display: none; }
  section { margin: .6rem 0; page-break-inside: avoid; }
  p, .muted { font-size: .72rem; }

  /* KPI tiles: compact 3-col grid */
  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: .35rem;
  }
  .kpi, a.kpi {
    border: 1px solid #d0d7e2;
    border-radius: 6px;
    padding: .4rem .5rem;
    box-shadow: none;
    background: #fff;
    page-break-inside: avoid;
  }
  .kpi .kpi-name { font-size: .7rem; min-height: auto; }
  .kpi .big { font-size: 1.15rem; }
  .kpi .unit { font-size: .65rem; }
  .kpi .meta { font-size: .65rem; margin-top: .2rem; gap: .25rem; }
  .rank {
    background: #eef5fc;
    font-size: .62rem;
    padding: .04rem .3rem;
  }
  .delta-up { color: #16a34a; }
  .delta-down { color: #c92a2a; }

  /* Chart cards */
  .chart-card {
    border: 1px solid #d0d7e2;
    border-radius: 6px;
    padding: .5rem .6rem;
    margin: .5rem 0;
    box-shadow: none;
    background: #fff;
    page-break-inside: avoid;
  }
  .chart-card h3 { font-size: .82rem; }
  .chart-card .sub { font-size: .68rem; margin-bottom: .35rem; }

  svg.chart {
    max-width: 100%;
    height: auto;
  }

  /* NLG insight */
  .insight {
    border: 1px solid #c0d8f0;
    padding: .35rem .5rem;
    margin: .1rem 0 .6rem;
    background: #f6fafe;
    page-break-inside: avoid;
  }
  .insight-text { font-size: .78rem; }
  .insight-label { font-size: .58rem; }

  /* Legend */
  .legend { font-size: .7rem; gap: .6rem; }

  /* Make links not look like links */
  .kpi a, a.kpi { text-decoration: none; color: inherit; }

  .ctx {
    border: 1px solid #d0d7e2;
    background: #f8fafd;
    font-size: .7rem !important;
    padding: .15rem .4rem !important;
  }
}

/* ── Period picker (calendar-like widget) ────────────────────────────────── */
.perpick {
  position: relative; display: inline-block;
}
.perpick-trigger {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--surface); border: 1px solid #cdd7e4;
  border-radius: var(--r-sm); padding: .45rem .65rem;
  font-size: .85rem; cursor: pointer; user-select: none;
  min-width: 150px; justify-content: space-between;
  transition: border-color .12s;
}
.perpick-trigger:hover { border-color: var(--accent); }
.perpick-trigger .pp-arrow { font-size: .6rem; color: #999; margin-left: .3rem; }
.perpick-drop {
  position: absolute; top: 100%; left: 0; z-index: 100;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: 0 4px 18px rgba(0,0,0,.12);
  padding: .6rem; display: none; min-width: 250px;
  margin-top: 3px;
}
.perpick-drop.open { display: block; }
.perpick-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  margin-bottom: .5rem;
  gap: 2px;
}
.pp-tab {
  flex: 1;
  background: none !important;
  border: none !important;
  border-bottom: 2px solid transparent !important;
  border-radius: 0 !important;
  color: var(--ink-soft) !important;
  padding: .25rem 0 !important;
  font-size: .78rem !important;
  font-weight: 600 !important;
  cursor: pointer;
  text-align: center;
  transition: all .12s;
  box-shadow: none !important;
  transform: none !important;
}
.pp-tab:hover {
  color: var(--accent) !important;
  background: var(--accent-bg) !important;
}
.pp-tab.active {
  color: var(--accent) !important;
  border-bottom-color: var(--accent) !important;
}
.perpick-years {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px;
  margin-bottom: .45rem;
}
.perpick-years button {
  background: #f6f8fb; border: 1px solid transparent; border-radius: 5px;
  padding: .28rem .15rem; font-size: .73rem; cursor: pointer;
  color: #555; transition: all .1s;
}
.perpick-years button:hover { background: var(--accent-bg); color: var(--accent); border-color: #b9d3f1; }
.perpick-years button.sel { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.pp-nav-label {
  font-weight: 700; font-size: .88rem; color: var(--ink);
}
.perpick-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .4rem; gap: .3rem;
}
.perpick-nav button {
  background: none; border: 1px solid var(--line); color: var(--ink);
  border-radius: 5px; padding: .18rem .5rem; cursor: pointer;
  font-size: .85rem; font-weight: 600;
}
.perpick-nav button:hover { background: var(--accent-bg); color: var(--accent); }
.perpick-nav .pp-year { font-weight: 700; font-size: .95rem; color: var(--ink); }
.perpick-months {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px;
  margin-bottom: .45rem;
}
.perpick-months button {
  background: #f6f8fb; border: 1px solid transparent; border-radius: 5px;
  padding: .28rem .15rem; font-size: .73rem; cursor: pointer;
  color: #555; transition: all .1s;
}
.perpick-months button:hover { background: var(--accent-bg); color: var(--accent); border-color: #b9d3f1; }
.perpick-months button.sel { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.perpick-quarters {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px;
  margin-bottom: .45rem;
}
.perpick-quarters button {
  background: #eef4fb; border: 1px solid #d0dff2; border-radius: 5px;
  padding: .28rem .15rem; font-size: .72rem; cursor: pointer;
  color: var(--accent-ink); transition: all .1s; font-weight: 500;
}
.perpick-quarters button:hover { background: var(--accent); color: #fff; }
.perpick-quarters button.sel { background: var(--accent); color: #fff; font-weight: 600; }
.perpick-year-btn {
  display: block; width: 100%; margin-top: 2px;
  background: #f0f4f8; border: 1px solid #d0d7e2; border-radius: 5px;
  padding: .28rem; font-size: .76rem; cursor: pointer;
  color: #555; font-weight: 500;
}
.perpick-year-btn:hover { background: var(--accent); color: #fff; }
.perpick-year-btn.sel { background: var(--accent); color: #fff; font-weight: 600; }
.perpick-back-btn {
  display: block; width: 100%; margin-top: 4px;
  background: none; border: 1px solid #d0d7e2; border-radius: 5px;
  padding: .22rem; font-size: .7rem; cursor: pointer;
  color: #888;
}
.perpick-back-btn:hover { background: #f0f4f8; color: #555; }
.perpick-days {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
  margin-bottom: .4rem;
}
.perpick-days span { 
  text-align: center; font-size: .62rem; color: #aaa; padding: .1rem 0; 
}
.perpick-days .pp-dow { font-weight: 600; color: #888; }
.perpick-days button {
  background: #f6f8fb; border: 1px solid transparent; border-radius: 4px;
  padding: .2rem 0; font-size: .7rem; cursor: pointer; color: #555;
  transition: all .1s;
}
.perpick-days button:hover { background: var(--accent-bg); color: var(--accent); border-color: #b9d3f1; }
.perpick-days button.sel { background: var(--accent); color: #fff; font-weight: 600; }

/* ── Infographic/Chart Type Selector ────────────────────────────────────── */
.chart-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.chart-type-selector {
  display: inline-flex;
  gap: 0.2rem;
  background: #eaeff6;
  padding: 3px;
  border-radius: 6px;
  border: 1px solid var(--line);
}
.chart-type-btn {
  background: transparent;
  border: none;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  color: #4a5568;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.chart-type-btn:hover {
  background: rgba(0,0,0,0.04);
}
.chart-type-btn.active {
  background: #ffffff;
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.chart-card.compact .chart-type-selector {
  transform: scale(0.9);
  transform-origin: right center;
}
.pie-slice {
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.pie-slice:hover {
  opacity: 0.9;
  transform: scale(1.02);
  transform-origin: center;
}
.pt-label {
  font-size: 9px;
  font-weight: 600;
}

/* ── Export and Action Buttons styles ─────────────────────────────────── */
.dl-sub-btn:hover {
  opacity: 0.9;
  filter: brightness(1.05);
}
.dl-sub-btn:active {
  transform: scale(0.97);
}
#print-btn:hover {
  background: var(--accent-bg) !important;
  color: var(--accent) !important;
  border-color: var(--accent) !important;
}
.action-btn-row button, .print-btn-wrap button {
  border-radius: var(--r-sm);
  transition: background-color 0.12s, border-color 0.12s, color 0.12s, transform 0.1s;
}


