/* =====================================================================
   Дархан-Уул аймгийн нээлттэй өгөгдлийн самбар
   Өнгөний слотууд нь dataviz шалгуурыг (CVD ΔE, тод/бүдэг зурвас,
   тодролт) хар болон цайвар хоёуланд нь давсан утгууд.
   ===================================================================== */

:root {
  color-scheme: dark;

  --bg:          #0b1420;
  --surface:     #131c2b;
  --surface-2:   #18243a;
  --surface-3:   #1e2c44;
  --border:      #22314a;

  --text:        #e8edf4;
  --text-2:      #94a7bf;
  --muted:       #6b7f99;

  --series-1:    #199e70;   /* ногоон  — Дархан-Уул / үндсэн */
  --series-2:    #d95926;   /* улбар   */
  --series-3:    #3987e5;   /* цэнхэр  */
  --series-4:    #c98500;   /* шар     */
  --series-5:    #d55181;   /* ягаан   */

  --pos:         #199e70;
  --neg:         #d95926;

  --grid:        rgba(148,167,191,.16);
  --shadow:      0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.22);

  --header-1:    #0d2a1c;
  --header-2:    #1c6a44;

  --radius:      12px;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg:          #eef1f6;
  --surface:     #ffffff;
  --surface-2:   #f5f7fa;
  --surface-3:   #eaeff6;
  --border:      #d9e0ea;

  --text:        #0f1b2a;
  --text-2:      #4a5c71;
  --muted:       #7b8b9e;

  --series-1:    #1baf7a;
  --series-2:    #eb6834;
  --series-3:    #2a78d6;
  --series-4:    #eda100;
  --series-5:    #e87ba4;

  --pos:         #14875f;
  --neg:         #c9491c;

  --grid:        rgba(15,27,42,.10);
  --shadow:      0 1px 2px rgba(15,27,42,.06), 0 8px 24px rgba(15,27,42,.07);

  --header-1:    #14653f;
  --header-2:    #2fa06a;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", "Noto Sans", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------ бүтэц ------------------------------ */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px 40px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.brand { display: flex; gap: 11px; align-items: center; padding: 6px 8px 22px; }
.brand .mark {
  width: 38px; height: 38px; flex: none; border-radius: 10px;
  background: linear-gradient(140deg, var(--series-1), #0d6b4a);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
}
.brand .txt { font-size: 12.5px; font-weight: 700; letter-spacing: .04em; line-height: 1.25; }
.brand .txt span { display: block; color: var(--text-2); font-weight: 500; letter-spacing: 0; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav button {
  all: unset; cursor: pointer; padding: 10px 13px; border-radius: 9px;
  font-size: 12.5px; font-weight: 600; letter-spacing: .03em; color: var(--text-2);
  text-transform: uppercase; transition: background .12s, color .12s;
}
.nav button:hover  { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--series-1); color: #ffffff; }
.nav button:focus-visible { outline: 2px solid var(--series-3); outline-offset: 2px; }

.main { min-width: 0; display: flex; flex-direction: column; }

/* ------------------------------ толгой ----------------------------- */
.topbar {
  background: linear-gradient(97deg, var(--header-1), var(--header-2));
  padding: 11px 22px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 30;
  border-bottom: 1px solid rgba(0,0,0,.25);
}
.topbar .field { display: flex; align-items: center; gap: 8px; }
.topbar label { font-size: 12px; font-style: italic; color: rgba(255,255,255,.86); }
.topbar select {
  background: rgba(255,255,255,.96); color: #10202f; border: 0; border-radius: 7px;
  padding: 6px 10px; font: inherit; font-size: 13px; min-width: 148px; cursor: pointer;
}
.topbar select:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.spacer { margin-left: auto; }

.switch { display: flex; align-items: center; gap: 9px; color: #fff; font-size: 12.5px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 40px; height: 21px; border-radius: 11px; background: rgba(255,255,255,.3);
  position: relative; transition: background .15s; cursor: pointer; display: inline-block;
}
.switch .track::after {
  content: ""; position: absolute; top: 2.5px; left: 2.5px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .15s;
}
.switch input:checked + .track { background: #0f3f28; }
.switch input:checked + .track::after { transform: translateX(19px); }
.switch input:focus-visible + .track { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------------------------- статус мөр --------------------------- */
.statusbar {
  display: flex; gap: 18px; flex-wrap: wrap; align-items: center;
  padding: 9px 22px; background: var(--surface); border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-2);
}
.statusbar b { color: var(--text); font-weight: 600; }
.statusbar a { color: var(--series-1); text-decoration: none; font-weight: 600; }
.statusbar a:hover { text-decoration: underline; }

/* ------------------------------ талбар ----------------------------- */
.content { padding: 18px 22px 60px; }
.section-title { margin: 0 0 14px; font-size: 17px; font-weight: 700; letter-spacing: .01em; }

.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; }

.card {
  grid-column: span 6;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px 12px; box-shadow: var(--shadow); min-width: 0;
  display: flex; flex-direction: column;
}
.card.w3  { grid-column: span 3; }
.card.w4  { grid-column: span 4; }
.card.w6  { grid-column: span 6; }
.card.w8  { grid-column: span 8; }
.card.w12 { grid-column: span 12; }

.card-head { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.card-title { font-size: 13px; font-weight: 650; line-height: 1.35; flex: 1; min-width: 0; }
.card-tools { display: flex; gap: 4px; flex: none; }
.icon-btn {
  all: unset; cursor: pointer; width: 22px; height: 22px; border-radius: 6px;
  display: grid; place-items: center; color: var(--muted); font-size: 12px;
  border: 1px solid transparent;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--series-3); outline-offset: 1px; }

.card-foot {
  margin-top: 9px; display: flex; justify-content: space-between; gap: 10px;
  font-size: 10.5px; font-style: italic; color: var(--muted);
}

.chart-box { position: relative; flex: 1; min-height: 190px; }
.chart-box.tall { min-height: 260px; }
.chart-box canvas { position: absolute; inset: 0; }

/* ------------------------------- KPI ------------------------------- */
.kpi { grid-column: span 3; align-self: start; }
.kpi .kpi-value { font-size: 27px; font-weight: 750; letter-spacing: -.01em; line-height: 1.1; }
.kpi .kpi-unit  { font-size: 12px; font-weight: 500; color: var(--text-2); margin-left: 5px; }
.kpi .kpi-meta  { display: flex; align-items: center; gap: 8px; margin-top: 7px; flex-wrap: wrap; }
.chip {
  font-size: 11px; font-weight: 700; padding: 2.5px 8px; border-radius: 20px;
  display: inline-flex; align-items: center; gap: 4px;
}
.chip.up   { background: color-mix(in srgb, var(--pos) 20%, transparent); color: var(--pos); }
.chip.down { background: color-mix(in srgb, var(--neg) 20%, transparent); color: var(--neg); }
.chip.flat { background: var(--surface-3); color: var(--text-2); }
.kpi .kpi-period { font-size: 11px; color: var(--muted); }

/* ---------------------------- хүснэгт ------------------------------ */
.tablewrap { overflow-x: auto; max-height: 300px; overflow-y: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 12px; }
table.data th, table.data td { padding: 5px 9px; text-align: right; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
table.data thead th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--text-2);
  font-weight: 600; border-bottom: 1px solid var(--border); z-index: 1;
}
table.data tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
table.data tbody tr:nth-child(even) td:first-child { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }

/* ----------------------------- бусад ------------------------------- */
.legend { display: flex; flex-wrap: wrap; gap: 10px 15px; margin: 2px 0 8px; font-size: 11.5px; color: var(--text-2); }
.legend .li { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .li.off { opacity: .38; text-decoration: line-through; }

.empty {
  display: grid; place-items: center; min-height: 150px; text-align: center;
  color: var(--muted); font-size: 12.5px; padding: 16px; line-height: 1.6;
}

.tip {
  position: fixed; z-index: 90; max-width: 320px; background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px;
  font-size: 12px; line-height: 1.55; color: var(--text); box-shadow: var(--shadow);
}
.tip b { display: block; margin-bottom: 4px; }
.tip .src { color: var(--text-2); font-size: 11px; margin-top: 6px; display: block; }

.banner {
  margin: 0 0 16px; padding: 13px 16px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--series-4) 15%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--series-4) 45%, var(--border));
  font-size: 13px;
}
.banner a { color: var(--series-1); font-weight: 600; }

.loading { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 1180px) {
  .card.w3 { grid-column: span 6; }
  .card.w4 { grid-column: span 6; }
  .kpi     { grid-column: span 6; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .card, .card.w3, .card.w4, .card.w6, .card.w8, .kpi { grid-column: span 12; }
}

@media print {
  .sidebar, .topbar, .card-tools { display: none; }
  .card { break-inside: avoid; }
}
