/* ═══════════════════════════════════════════════════════════════════════
   Xonsaroy Qurilish — umumiy uslublar
   Inline style yo'q: server qat'iy CSP yuboradi (style-src 'self').
   ═══════════════════════════════════════════════════════════════════════ */

/* Palitra: Alabaster White · Metallic Brass · Steel Navy · Deep Sapphire */
:root {
  --paper:      #FBFAF8;   /* deyarli oq, iliq */
  --surface:    #FFFFFF;
  --cap:        #F4F2ED;
  --boxbg:      #17191B;   /* qora qutilar: Holding va yo'nalishlar */
  --ink:        #1C1E20;
  --ink-2:      #55585C;
  --ink-3:      #949089;
  --gold:       #B8912E;   /* antik oltin — urg'u */
  --gold-soft:  #E2D5B0;
  --wire:       #C9B588;
  --line:       #C7B183;
  --line-soft:  #E8E5DE;
  --brass:      #B8912E;
  --brass-deep: #8E6F1F;
  --olive:      #B8912E;
  --olive-deep: #8E6F1F;
  --olive-soft: #F3EEE1;
  --danger:     #A33B2A;
  --ok:         #2F6B4F;
  --info:       #4A5D75;
  --bar:        #17191B;
  --bar-ink:    #FFFFFF;
  --accent-bg:  #17191B;
  --accent-ink: #FFFFFF;
  /* ─── Harakat va chuqurlik ─── */
  --radius:     3px;
  --dur-fast:   .14s;
  --dur:        .24s;
  --ease:       cubic-bezier(.2, .7, .3, 1);
  --lift:       0 1px 2px rgba(42, 46, 34, .07), 0 1px 1px rgba(42, 46, 34, .04);
  --lift-hover: 0 10px 24px -12px rgba(42, 46, 34, .38), 0 3px 8px -3px rgba(42, 46, 34, .14);

  /* Eski nomlar — qolgan uslublar buzilmasligi uchun yangi palitraga bog'landi. */
  --hivis:      var(--olive);
  --steel:      var(--info);
  --steel-ink:  #FFFFFF;
  --steel-soft: var(--olive-soft);

  --font-d: "Avenir Next", "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  --font-m: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --gap: 24px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #101112; --surface: #1A1C1E; --cap: #232527;
    --boxbg: #0A0B0C;
    --ink: #F2F0EC; --ink-2: #B3AFA8; --ink-3: #837E76;
    --gold: #D4AF37; --gold-soft: #4A3F1E; --wire: #6B5C33;
    --line: #6B5C33; --line-soft: #2A2C2E;
    --brass: #D4AF37; --brass-deep: #E9C766;
    --olive: #D4AF37; --olive-deep: #E9C766; --olive-soft: #262218;
    --danger: #E08A76; --ok: #6FC49B; --info: #8FA6C0;
    --steel-ink: #101112;
    --bar: #0A0B0C; --bar-ink: #F2F0EC;
    --accent-bg: #0A0B0C; --accent-ink: #FFFFFF;
    --lift: 0 1px 2px rgba(0, 0, 0, .5);
    --lift-hover: 0 12px 28px -12px rgba(0, 0, 0, .85), 0 3px 10px -4px rgba(0, 0, 0, .6);
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   JONLI PALITRA — data-palette="vivid"
   Har yo'nalishga o'z rangi: chizmada qaysi yo'nalish ekanini rangdan
   bilib olasiz. Zaytun palitra o'z holicha qoladi, almashtirib ko'rish mumkin.
   ═══════════════════════════════════════════════════════════════════════ */

/* Palitra o'zgarmaydi — faqat yo'nalishlarga rang beriladi. Ranglar
   guruch/po'lat/safir bilan uyg'un tanlangan. */
:root[data-palette="vivid"] {
  --d1: #D4AF37;  --d1-ink: #0D1B2A;  /* 01 GP  — guruch */
  --d2: #2F6B4F;  --d2-ink: #F7F3E9;  /* 02 FIN — to'q yashil */
  --d3: #415A77;  --d3-ink: #F7F3E9;  /* 03 CC  — po'lat ko'k */
  --d4: #5D5279;  --d4-ink: #F7F3E9;  /* 04 DEV — bosiq binafsha */
  --d5: #A3583F;  --d5-ink: #F7F3E9;  /* 05 PI  — terrakota */
}

@media (prefers-color-scheme: dark) {
  :root[data-palette="vivid"] {
    --d1: #E9C766;  --d1-ink: #0D1B2A;
    --d2: #6FC49B;  --d2-ink: #0D1B2A;
    --d3: #8FB0D0;  --d3-ink: #0D1B2A;
    --d4: #A99BD0;  --d4-ink: #0D1B2A;
    --d5: #DE9679;  --d5-ink: #0D1B2A;
  }
}

/* Yo'nalish sarlavhasi — o'z rangida */
:root[data-palette="vivid"] .col[data-div="1"] .head .cap { background: var(--d1); color: var(--d1-ink); }
:root[data-palette="vivid"] .col[data-div="2"] .head .cap { background: var(--d2); color: var(--d2-ink); }
:root[data-palette="vivid"] .col[data-div="3"] .head .cap { background: var(--d3); color: var(--d3-ink); }
:root[data-palette="vivid"] .col[data-div="4"] .head .cap { background: var(--d4); color: var(--d4-ink); }
:root[data-palette="vivid"] .col[data-div="5"] .head .cap { background: var(--d5); color: var(--d5-ink); }
:root[data-palette="vivid"] .col[data-div] .head .cap .kind,
:root[data-palette="vivid"] .col[data-div] .head .cap .code { color: inherit; opacity: .95; }
:root[data-palette="vivid"] .col[data-div] .head .chev { border-color: currentColor; }

/* Bo'lim kartalari — o'z yo'nalishi rangida ost chizig'i */
:root[data-palette="vivid"] .col[data-div="1"] .head,
:root[data-palette="vivid"] .col[data-div="1"] .unit { border-bottom-color: var(--d1); }
:root[data-palette="vivid"] .col[data-div="2"] .head,
:root[data-palette="vivid"] .col[data-div="2"] .unit { border-bottom-color: var(--d2); }
:root[data-palette="vivid"] .col[data-div="3"] .head,
:root[data-palette="vivid"] .col[data-div="3"] .unit { border-bottom-color: var(--d3); }
:root[data-palette="vivid"] .col[data-div="4"] .head,
:root[data-palette="vivid"] .col[data-div="4"] .unit { border-bottom-color: var(--d4); }
:root[data-palette="vivid"] .col[data-div="5"] .head,
:root[data-palette="vivid"] .col[data-div="5"] .unit { border-bottom-color: var(--d5); }

:root[data-palette="vivid"] .col[data-div="1"] .unit:hover { border-color: var(--d1); }
:root[data-palette="vivid"] .col[data-div="2"] .unit:hover { border-color: var(--d2); }
:root[data-palette="vivid"] .col[data-div="3"] .unit:hover { border-color: var(--d3); }
:root[data-palette="vivid"] .col[data-div="4"] .unit:hover { border-color: var(--d4); }
:root[data-palette="vivid"] .col[data-div="5"] .unit:hover { border-color: var(--d5); }
:root[data-palette="vivid"] .col[data-div] .unit:hover .cap { background: var(--cap); }

.chart-title .meta b { color: var(--brass-deep); }

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-d);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ─── Umumiy o'tishlar ──────────────────────────────────────────────────
   Bitta joyda belgilanadi — barcha bosiladigan narsa bir xil his beradi. */

.btn, .unit, .head, .staff, .holding, .agent, .role, .panel,
.ai-badge, .chip, .pill, .tag, .agent-from, .crumbs button, .drawer-close,
.field input, .field select, .search input, .topbar nav a, .sw {
  transition:
    background-color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    box-shadow var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}

/* Yumshoq burchaklar — chizma uslubini buzmaydigan darajada */
.btn, .field input, .field select, .search input, .zval,
.holding, .staff, .head, .unit, .panel, .agent, .ai-stats, .facts, .caution,
.chip, .pill, .tag, .ai-badge, .agent-from, .drawer-close, .auth-card {
  border-radius: var(--radius);
}
/* Karta shapkasi yuqori burchaklarni takrorlaydi */
.holding .cap, .staff .cap, .head .cap, .unit .cap {
  border-radius: var(--radius) var(--radius) 0 0;
}

/* ─── Yuqori panel ──────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bar);
  color: var(--bar-ink);
  border-bottom: 3px solid var(--olive);
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 8px 22px;
  padding: 12px 24px;
}
.topbar .brand {
  font-size: 17px; font-weight: 800; letter-spacing: -.02em;
  margin-right: 6px;
}
.topbar .brand span {
  display: block; font-family: var(--font-m); font-size: 8.5px;
  letter-spacing: .2em; color: color-mix(in srgb, var(--bar-ink) 66%, transparent); font-weight: 400; margin-top: 2px;
}
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: var(--bar-ink); text-decoration: none;
  font-family: var(--font-m); font-size: 10.5px; letter-spacing: .14em;
  text-transform: uppercase; padding: 8px 12px;
  border: 1.5px solid transparent;
}
.topbar nav a:hover { border-color: color-mix(in srgb, var(--bar-ink) 34%, transparent); }
.topbar nav a.active { border-color: var(--bar-ink); }
.topbar nav a:focus-visible { outline: 2px solid var(--bar-ink); outline-offset: 2px; }
.topbar .who {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  font-size: 13px;
}
.topbar .who .nm { font-weight: 600; }
.chip {
  font-family: var(--font-m); font-size: 9px; letter-spacing: .16em;
  text-transform: uppercase; padding: 3px 8px;
  border: 1.5px solid currentColor;
}
.chip.admin { color: var(--bar-ink); }
.topbar .who { color: var(--bar-ink); }
.topbar .btn { background: transparent; color: var(--bar-ink); border-color: color-mix(in srgb, var(--bar-ink) 38%, transparent); }

/* ─── Boshqaruv elementlari ─────────────────────────────────────────── */

.btn {
  font-family: var(--font-m); font-size: 10.5px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line);
  padding: 11px 16px; cursor: pointer; border-radius: 0;
}
.btn:hover { border-color: var(--olive); background: var(--cap); transform: translateY(-1px); box-shadow: var(--lift); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn:focus-visible { outline: 2px solid var(--hivis); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: var(--olive); border-color: var(--olive); color: #FFFFFF; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 10px; font-size: 9.5px; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: var(--surface); }
.topbar .btn:hover { border-color: var(--bar-ink); background: rgba(255, 255, 255, .08); }

/* Palitra tugmasi — yonida joriy palitraning rangli nuqtasi */
.palette-btn::before {
  content: ""; display: inline-block; vertical-align: -1px;
  width: 8px; height: 8px; margin-right: 7px; border-radius: 50%;
  background: var(--brass);
}
:root[data-palette="vivid"] .palette-btn::before {
  background: linear-gradient(135deg, #D4AF37 0 50%, #A3583F 50% 100%);
}

.field { display: flex; flex-direction: column; gap: 7px; }
.field label {
  font-family: var(--font-m); font-size: 9.5px; letter-spacing: .2em;
  text-transform: uppercase; color: var(--ink-3);
}
.field input, .field select {
  font-family: var(--font-d); font-size: 15px; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line);
  padding: 11px 13px; border-radius: 0; outline: none;
  -webkit-appearance: none; appearance: none; width: 100%;
}
.field select {
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
.field input:focus-visible, .field select:focus-visible {
  border-color: var(--hivis); box-shadow: inset 0 0 0 2px var(--hivis);
}
.hint { font-size: 11.5px; color: var(--ink-3); }

.alert {
  border: 1.5px solid var(--danger); border-left-width: 4px;
  color: var(--danger); background: var(--surface);
  padding: 11px 13px; font-size: 13.5px;
}
.alert.ok { border-color: var(--ok); color: var(--ok); }
.alert[hidden] { display: none; }

/* ─── Kirish / parol sahifalari ─────────────────────────────────────── */

.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 32px 20px;
}
.auth-card {
  width: 100%; max-width: 430px;
  background: var(--surface); border: 1.5px solid var(--ink);
  box-shadow: var(--lift);
}
.auth-head { padding: 30px 30px 24px; border-bottom: 1.5px solid var(--line-soft); }
.auth-head h1 {
  margin: 0; font-size: 44px; font-weight: 800; letter-spacing: -.045em; line-height: .9;
}
.auth-head .sub {
  font-family: var(--font-m); font-size: 10px; letter-spacing: .2em;
  text-transform: uppercase; color: var(--ink-2); margin-top: 12px;
}
.auth-rule { height: 5px; background: var(--hivis); width: 96px; margin-top: 18px; }
.auth-body { padding: 26px 30px 30px; display: flex; flex-direction: column; gap: 18px; }
.auth-foot {
  padding: 14px 30px; border-top: 1.5px solid var(--line-soft);
  font-family: var(--font-m); font-size: 9.5px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-3);
}

/* ─── Sahifa qobig'i ────────────────────────────────────────────────── */

.sheet { max-width: 1400px; margin: 0 auto; padding: 36px 24px 80px; }

.page-head { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 16px; margin-bottom: 26px; }
.page-head h1 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -.035em; }
.page-head .sub { font-family: var(--font-m); font-size: 10px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-3); margin-top: 6px; }
.page-head .spacer { margin-left: auto; }

/* ─── Chizma sarlavhasi ─────────────────────────────────────────────── */

/* Markazda, ostida ingichka oltin chiziq va romb */
.chart-title { text-align: center; padding: 6px 0 24px; }
.chart-title h1 {
  margin: 0;
  font-size: clamp(19px, 2.3vw, 28px);
  font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink); line-height: 1.25; text-wrap: balance;
}
.title-rule {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 12px auto 0; max-width: 620px;
}
.title-rule span { flex: 1 1 auto; height: 1px; background: var(--gold); opacity: .55; }
.title-rule i { width: 6px; height: 6px; background: var(--gold); transform: rotate(45deg); }
.chart-title .meta {
  margin: 11px 0 0;
  font-family: var(--font-d); font-size: 12px;
  letter-spacing: .01em; text-transform: none; color: var(--ink-3);
}
.chart-title .meta b { color: var(--ink-2); font-weight: 600; }

/* ─── AI agentlar hisobi — ingichka bitta qator ─────────────────────── */

.ai-stats {
  margin-top: 18px;
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 6px 20px;
  padding: 10px 16px 12px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--lift);
  position: relative;
}
.ai-label {
  font-family: var(--font-m); font-size: 9.5px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink-3);
  padding-right: 4px;
}
.ai-stats .st {
  display: inline-flex; align-items: baseline; gap: 5px;
  font-size: 12.5px; color: var(--ink-2);
}
.ai-stats .st b {
  font-size: 17px; font-weight: 800; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; color: var(--ink);
}
.ai-stats .st.ok b   { color: var(--ok); }
.ai-stats .st.soon b { color: var(--info); }
.ai-stats .st.no  b  { color: var(--danger); }

.ai-cap {
  margin-left: auto;
  font-family: var(--font-m); font-size: 9.5px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3);
}

/* Nisbat chizig'i — panelning eng pastki chekkasida, ingichka */
.ai-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 1px; height: 3px;
  background: var(--line-soft);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}
.ai-bar .seg { display: block; flex-basis: 0; }
.ai-bar .seg.ok { background: var(--ok); }
.ai-bar .seg.soon { background: var(--info); }
.ai-bar .seg.no { background: var(--danger); }

@media (max-width: 759px) {
  .ai-stats { gap: 6px 14px; padding: 10px 12px 12px; }
  .ai-cap { margin-left: 0; width: 100%; }
}

/* ─── Chizma boshqaruvi ─────────────────────────────────────────────── */

.controls { margin-top: 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.search { position: relative; flex: 1 1 260px; max-width: 380px; }
.search input {
  width: 100%; font-family: var(--font-d); font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line);
  padding: 11px 13px 11px 38px; border-radius: 0; outline: none;
  -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus-visible { border-color: var(--hivis); box-shadow: inset 0 0 0 2px var(--hivis); }
.search input::-webkit-search-decoration,
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; stroke: var(--ink-3); fill: none; stroke-width: 2;
}
.tally {
  font-family: var(--font-m); font-size: 11px; letter-spacing: .1em;
  color: var(--ink-3); font-variant-numeric: tabular-nums; margin-left: auto;
}

/* ─── Masshtab ──────────────────────────────────────────────────────── */

.zoom { display: flex; align-items: stretch; }
.zoom .btn { border-left-width: 0; }
.zoom .btn:first-child { border-left-width: 1.5px; }
.zbtn {
  font-size: 15px; line-height: 1; padding: 0 14px; min-width: 40px;
  font-family: var(--font-d); letter-spacing: 0;
}
.zval {
  display: flex; align-items: center; justify-content: center;
  min-width: 62px; padding: 0 4px;
  border: 1.5px solid var(--line); border-left-width: 0; border-right-width: 0;
  background: var(--surface);
  font-family: var(--font-m); font-size: 11px; letter-spacing: .06em;
  color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.zfit { white-space: nowrap; }

/* ─── Chizma maydoni (gorizontal siljish + masshtab) ────────────────── */

.canvas {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  padding-bottom: 4px;
}
.canvas-inner {
  zoom: var(--zoom, 1);
  min-width: 1060px;
}

/* ─── Orgstruktura ──────────────────────────────────────────────────── */

/* ═══ Kartalar: qora sarlavhalar, oltin urg'u, oq bo'lim kartalari ═══ */

/* Holding — eng ustki, qora quti */
.holding {
  background: var(--boxbg);
  border: 1px solid var(--boxbg);
  box-shadow: 0 0 0 1px var(--gold-soft), var(--lift-hover);
  min-width: 250px;
  padding: 20px 40px;
  display: flex; align-items: center; justify-content: center;
}
.holding .hname {
  color: #FFFFFF; font-size: 23px; font-weight: 800;
  letter-spacing: .1em; text-transform: uppercase;
}

/* Shtab birliklari — oq karta, oltin ramka, chapda ikonka */
.staff {
  background: var(--surface);
  border: 1px solid var(--gold-soft);
  box-shadow: var(--lift);
  padding: 13px 20px;
  display: flex; align-items: center; gap: 12px;
  min-width: 210px;
}
.staff .sname {
  font-size: 12px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink);
}
.staff .ico { flex: none; width: 22px; height: 22px; stroke: var(--gold); }

.ico { fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* Yo'nalish sarlavhasi — qora quti, ikonka, oltin kod */
.head {
  position: relative;
  background: var(--boxbg);
  border: 1px solid var(--boxbg);
  border-bottom: 3px solid var(--gold);
  box-shadow: var(--lift);
  padding: 15px 34px 15px 16px;
  display: flex; align-items: center; gap: 11px;
  min-height: 62px;
}
.head .ico { flex: none; width: 24px; height: 24px; stroke: #FFFFFF; opacity: .92; }
.head .hname {
  flex: 1 1 auto;
  color: #FFFFFF; font-size: 12.5px; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; line-height: 1.3;
}
.head .hcode {
  position: absolute; right: 32px; top: 7px;
  font-family: var(--font-m); font-size: 8.5px; letter-spacing: .14em;
  color: var(--gold); opacity: .85;
}
.head .chev {
  position: absolute; right: 13px; top: 50%; margin-top: -4px;
  width: 8px; height: 8px;
  border-right: 1.5px solid var(--gold); border-bottom: 1.5px solid var(--gold);
  transform: rotate(45deg); transition: transform .18s ease;
}
.col:not([open]) .head .chev { transform: rotate(-45deg); }

/* Bo'lim — oq karta, chapda oltin chiziq */
.unit {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--gold);
  box-shadow: var(--lift);
  padding: 11px 34px 11px 13px;
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
/* Ustun: nom, ostida AI belgisi — belgi matn ichiga kirib qolmasin */
.unit { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.unit .uname { font-size: 13px; font-weight: 500; color: var(--ink); line-height: 1.35; }
.unit .ai-badge { margin-top: 0; }
.unit .idx {
  position: absolute; right: 11px; top: 11px;
  font-family: var(--font-m); font-size: 8.5px; letter-spacing: .1em; color: var(--ink-3);
}
.unit:hover { transform: translateY(-2px); box-shadow: var(--lift-hover); border-color: var(--gold); }
.unit:active { transform: translateY(0); }
.unit.is-off { display: none; }
.col.is-off { opacity: .3; transition: opacity var(--dur) var(--ease); }

/* ─── Ulanishlar: ingichka oltin chiziqlar, tugunlarda halqacha ─── */

.top {
  margin-top: 34px;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
}
.tie { flex: 0 0 64px; height: 0; border-top: 1px solid var(--wire); align-self: center; }

.bus { position: relative; height: 52px; }
.bus::before { content: ""; position: absolute; top: 0; left: 50%; width: 1px; height: 26px; background: var(--wire); }
.bus::after {
  content: ""; position: absolute; top: 25px;
  left: calc((100% - 4 * var(--gap)) / 10);
  right: calc((100% - 4 * var(--gap)) / 10);
  height: 1px; background: var(--wire);
}

.divisions { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--gap); align-items: start; }

.col { position: relative; }
/* Shinadan sarlavhaga tushuvchi chiziq */
.col::before { content: ""; position: absolute; top: -27px; left: 50%; width: 1px; height: 27px; background: var(--wire); }
/* Shina bilan tutashgan joydagi halqacha */
.col::after {
  content: ""; position: absolute; top: -30px; left: 50%; margin-left: -3px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--paper); border: 1px solid var(--wire);
}
.col > summary { display: block; list-style: none; cursor: pointer; }
.col > summary::-webkit-details-marker { display: none; }
.col > summary:focus-visible .head { outline: 2px solid var(--gold); outline-offset: 2px; }

/* Bo'limlar — chapdagi umumiy o'q va har biriga qisqa tarmoq */
.stack { display: flex; flex-direction: column; gap: 12px; padding: 14px 0 0 20px; }
.unit::before {
  content: ""; position: absolute; left: -14px; top: 19px;
  width: 14px; height: 1px; background: var(--wire);
}
.unit::after {
  content: ""; position: absolute; left: -14px; top: -13px;
  bottom: calc(100% - 19px); width: 1px; background: var(--wire);
}
.unit:first-child::after { top: -15px; }


.legend {
  margin-top: 56px; border-top: 1.5px solid var(--olive); padding-top: 18px;
  display: flex; flex-wrap: wrap; gap: 12px 30px; font-size: 12px; color: var(--ink-2);
}
.legend .item { display: flex; align-items: center; gap: 9px; }
.sw { width: 24px; height: 14px; flex: none; border: 1px solid var(--line-soft); border-left: 3px solid var(--gold); background: var(--surface); }
.sw.h { background: var(--boxbg); border-color: var(--boxbg); border-bottom: 3px solid var(--gold); }
.sw.d { background: var(--olive-soft); }
.sw.s { height: 0; border: 0; border-top: 1.5px solid var(--line); align-self: center; }
.sw.ai { background: transparent; border: 1px dashed var(--gold); }

@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.top, .col { animation: rise .55s var(--ease) both; }
.col:nth-child(1) { animation-delay: .08s; }
.col:nth-child(2) { animation-delay: .15s; }
.col:nth-child(3) { animation-delay: .22s; }
.col:nth-child(4) { animation-delay: .29s; }
.col:nth-child(5) { animation-delay: .36s; }
.ai-stats { animation: rise .5s var(--ease) both; animation-delay: .04s; }

/* ─── Foydalanuvchilar jadvali ──────────────────────────────────────── */

.panel { background: var(--surface); border: 1.5px solid var(--ink); }
.panel > h2 {
  margin: 0; padding: 11px 14px; border-bottom: 1px solid var(--line-soft);
  font-family: var(--font-m); font-size: 9.5px; letter-spacing: .16em; text-transform: uppercase;
  font-weight: 600; color: var(--ink-2);
}
.panel .body { padding: 14px; }

.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; align-items: end; }

.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 720px; }
table.users th {
  text-align: left; font-family: var(--font-m); font-size: 9.5px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--ink-3); font-weight: 600;
  padding: 12px 14px; border-bottom: 1.5px solid var(--line);
}
table.users td { padding: 13px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.users tr:last-child td { border-bottom: 0; }
table.users tr.off td { opacity: .5; }
table.users .u { font-weight: 700; }
table.users .meta { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
table.users .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
table.users td.right { text-align: right; }

.tag {
  font-family: var(--font-m); font-size: 9px; letter-spacing: .14em; text-transform: uppercase;
  padding: 3px 7px; border: 1.5px solid var(--line); color: var(--ink-2); white-space: nowrap;
}
.tag.admin { border-color: var(--hivis); color: var(--hivis); }
.tag.blocked { border-color: var(--danger); color: var(--danger); }
.tag.pending { border-color: var(--steel); color: var(--steel); }

/* ─── Bosiladigan kartalar ──────────────────────────────────────────── */

.openable { cursor: pointer; }
.openable:focus-visible { outline: 2px solid var(--hivis); outline-offset: 3px; }
.unit.openable:hover .n { text-decoration: underline; text-decoration-color: var(--olive); text-underline-offset: 3px; }
.staff.openable:hover, .holding.openable:hover {
  border-color: var(--olive); transform: translateY(-3px); box-shadow: var(--lift-hover);
}
.staff.openable:active, .holding.openable:active { transform: translateY(-1px); }

.ai-badge {
  display: inline-block; margin-top: 8px;
  font-family: var(--font-m); font-size: 9px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-3);
  border: 1px solid var(--line-soft); padding: 2px 6px;
}
.unit:hover .ai-badge { border-color: var(--ink-3); color: var(--ink-2); }
.sw.ai { background: transparent; border-color: var(--hivis); }

/* ─── O'ng panel (chizma joyida qoladi) ─────────────────────────────── */

#scrim {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(18, 21, 13, .5);
  animation: fade .18s ease both;
  cursor: pointer;
}
#scrim[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

#detail {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: min(520px, 100vw);
  background: var(--paper);
  border-left: 3px solid var(--olive);
  box-shadow: -16px 0 44px -24px rgba(0, 0, 0, .55);
  overflow-y: auto; overscroll-behavior: contain;
  animation: slide-in .22s cubic-bezier(.2, .7, .3, 1) both;
}
#detail[hidden] { display: none; }

.drawer-head {
  position: sticky; top: 0; z-index: 2;
  background: var(--paper);
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px 10px 16px;
}
.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 7px;
  font-family: var(--font-m); font-size: 10px; letter-spacing: .12em;
  text-transform: uppercase; line-height: 1.5;
}
.crumbs button {
  background: none; border: 0; padding: 0; margin: 0; cursor: pointer;
  font: inherit; color: var(--olive);
  text-decoration: underline; text-underline-offset: 3px;
}
.crumbs button:hover { color: var(--ink); }
.crumbs button:focus-visible { outline: 2px solid var(--olive); outline-offset: 2px; }
.crumbs .sep, .crumbs .cur { color: var(--ink-3); }

.drawer-close {
  margin-left: auto; flex: none;
  width: 34px; height: 34px; line-height: 1;
  background: transparent; border: 1.5px solid var(--line-soft);
  color: var(--ink-2); font-size: 17px; cursor: pointer;
}
.drawer-close:hover { border-color: var(--olive); color: var(--ink); }
.drawer-close:focus-visible { outline: 2px solid var(--olive); outline-offset: 2px; }

.drawer-body { padding: 18px 16px 34px; }

.crumb-parent {
  margin: 0 0 9px; font-family: var(--font-m); font-size: 9px;
  letter-spacing: .18em; text-transform: uppercase; color: var(--ink-3);
}
.back-btn { margin-bottom: 13px; }

@media (prefers-reduced-motion: reduce) {
  #scrim, #detail { animation: none; }
}

.detail-title { display: flex; align-items: baseline; gap: 11px; flex-wrap: wrap; }
.detail-title h1 {
  margin: 0; font-size: clamp(19px, 2.1vw, 25px); font-weight: 800;
  letter-spacing: -.03em; line-height: 1.15; text-wrap: balance;
}
.detail-code {
  font-family: var(--font-m); font-size: 10px; letter-spacing: .12em;
  color: var(--hivis); border: 1px solid var(--hivis); padding: 3px 7px;
  font-variant-numeric: tabular-nums;
}
.detail-fn {
  margin: 11px 0 0; max-width: 60ch; font-size: 13.5px; color: var(--ink-2);
  border-top: 3px solid var(--hivis); padding-top: 10px; display: inline-block;
}

/* Panel tor bo'lgani uchun bo'limlar bir ustunda ketma-ket keladi. */
.detail-grid { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.detail-grid .stackv { gap: 14px; }

.role {
  display: flex; align-items: baseline; gap: 10px;
  padding: 8px 10px 8px 11px;
  border-bottom: 1px solid var(--line-soft);
  border-left: 4px solid var(--olive-soft);
  transition: border-left-color .15s ease, background .15s ease;
}
.role:last-of-type { border-bottom: 0; }
.role.openable:hover { border-left-color: var(--olive); background: var(--cap); }
.role.openable:hover .role-title { text-decoration: underline; text-underline-offset: 3px; }
.role-head {
  background: var(--cap); border-left-color: var(--olive);
  margin-bottom: 8px; padding-top: 10px; padding-bottom: 10px;
}
.role-head .role-title { font-size: 14px; font-weight: 700; }
.role-title { font-size: 13px; font-weight: 600; flex: 1 1 auto; }
.role-count {
  font-family: var(--font-m); font-size: 10.5px; letter-spacing: .08em;
  color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.role-go { color: var(--ink-3); font-size: 13px; line-height: 1; }
.role.openable:hover .role-go { color: var(--olive); }

.panel-hint {
  margin: 14px 0 0; font-family: var(--font-m); font-size: 9.5px;
  letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3);
}

/* ─── Lavozim sahifasi ──────────────────────────────────────────────── */

.facts {
  margin-top: 16px; display: flex; flex-wrap: wrap;
  border: 1px solid var(--line-soft);
  background: var(--surface);
}
.facts .fact {
  flex: 1 1 150px; padding: 9px 13px 10px;
  border-left: 1px solid var(--line-soft);
  display: flex; flex-direction: column; gap: 4px;
}
.facts .fact:first-child { border-left: 0; }
.facts .k {
  font-family: var(--font-m); font-size: 9.5px; letter-spacing: .17em;
  text-transform: uppercase; color: var(--ink-3);
}
.facts .v { font-size: 13px; font-weight: 600; }

ul.bullets { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
ul.bullets li {
  position: relative; padding: 7px 0 7px 17px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px; line-height: 1.45;
}
ul.bullets li:last-child { border-bottom: 0; }
ul.bullets li::before {
  content: ""; position: absolute; left: 0; top: 13px;
  width: 6px; height: 6px; background: var(--olive);
}

.agent-list { display: flex; flex-direction: column; gap: 10px; }
.agent {
  border: 1px solid var(--line-soft); border-left-width: 3px;
  padding: 10px 12px; background: var(--surface);
}
.agent.ok { border-left-color: var(--ok); }
.agent.soon { border-left-color: var(--steel); }
.agent.no { border-left-color: var(--danger); }
.agent:hover { box-shadow: var(--lift-hover); transform: translateY(-2px); border-color: var(--line); }
.agent.ok:hover { border-left-color: var(--ok); }
.agent.soon:hover { border-left-color: var(--steel); }
.agent.no:hover { border-left-color: var(--danger); }
.agent-top { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.agent-top h3 { margin: 0; font-size: 13.5px; font-weight: 700; letter-spacing: -.015em; }
.agent-from {
  display: inline-block; margin-top: 9px;
  background: transparent; border: 1.5px solid var(--line-soft);
  padding: 3px 8px; cursor: pointer;
  font-family: var(--font-m); font-size: 9px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-3);
}
.agent-from:hover { border-color: var(--olive); color: var(--ink); }
.agent-from:focus-visible { outline: 2px solid var(--olive); outline-offset: 2px; }

.agent-does { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); line-height: 1.45; max-width: 62ch; }
.agent-note {
  margin: 7px 0 0; font-size: 11.5px; line-height: 1.45; color: var(--ink-2);
  border-left: 2px solid var(--line-soft); padding-left: 9px; max-width: 62ch;
}
.agent.no .agent-note { color: var(--danger); border-left-color: var(--danger); }

.pill {
  font-family: var(--font-m); font-size: 9px; letter-spacing: .14em;
  text-transform: uppercase; padding: 3px 8px; white-space: nowrap;
  border: 1.5px solid currentColor;
}
.pill.ok { color: var(--ok); }
.pill.soon { color: var(--steel); }
.pill.no { color: var(--danger); }

.caution {
  margin-top: 16px; border: 1px solid var(--hivis); border-left-width: 3px;
  background: var(--surface); padding: 11px 14px; max-width: 88ch;
}
.caution-label {
  display: block; font-family: var(--font-m); font-size: 9.5px;
  letter-spacing: .2em; text-transform: uppercase; color: var(--hivis); margin-bottom: 7px;
}
.caution p { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); }

@media (max-width: 620px) {
  .facts .fact { flex-basis: 100%; border-left: 0; border-top: 1px solid var(--line-soft); }
  .facts .fact:first-child { border-top: 0; }
  .drawer-body { padding: 20px 14px 40px; }
  .drawer-head { padding-left: 14px; }
}

.audit { font-family: var(--font-m); font-size: 11.5px; line-height: 1.9; }
.audit div { display: flex; gap: 14px; flex-wrap: wrap; border-bottom: 1px solid var(--line-soft); padding: 5px 0; }
.audit .t { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.audit .a { font-weight: 600; min-width: 150px; }

.stackv { display: flex; flex-direction: column; gap: 22px; }

/* ─── Moslashuvchanlik ──────────────────────────────────────────────── */

/* Harakatni kamaytirish so'ralsa — hamma narsa darhol, siljishsiz.
   Rang o'zgarishi qoladi: u holatni bildiradi, chalg'itmaydi. */
@media (prefers-reduced-motion: reduce) {
  .top, .col, .col[open] > .stack, #detail, #scrim { animation: none; }
  * { transition-duration: .01ms !important; }
  .unit:hover, .agent:hover, .btn:hover, .staff.openable:hover,
  .holding.openable:hover, .col > summary:hover .head { transform: none; }
}

@media (max-width: 1120px) {
  .chart-title h1 { letter-spacing: 0; }
}

/* ─── Telefon: ro'yxat rejimi ───────────────────────────────────────────
   Tor ekranda 5 ustunli daraxtni siqib ko'rsatishdan foyda yo'q — matn
   o'qib bo'lmas darajada kichrayadi. Shu sababli yo'nalishlar yopiq
   akkordeonga aylanadi: 5 ta sarlavha ko'rinadi, kerakligini bosasiz. */

@media (max-width: 759px) {
  .sheet { padding: 18px 12px 56px; }

  /* Ikki qator: brend + kim kirgani, ostida navigatsiya. */
  .topbar { padding: 9px 14px; gap: 6px 10px; }
  .topbar .brand { order: 1; margin-right: 0; font-size: 15px; }
  .topbar .who { order: 2; margin-left: auto; width: auto; font-size: 12px; gap: 8px; }
  .topbar .who .chip { display: none; }
  .topbar nav { order: 3; width: 100%; }
  .topbar nav a { padding: 6px 9px; font-size: 9.5px; letter-spacing: .1em; }

  .canvas { overflow-x: visible; }
  .canvas-inner { min-width: 0; }

  .divisions { grid-template-columns: 1fr; gap: 12px; }
  .col::before, .col::after, .bus::before, .bus::after,
  .unit::before, .unit::after { display: none; }
  .bus { height: 20px; }
  .stack { gap: 10px; padding-top: 12px; }
  .head .chev { top: 50%; margin-top: -5px; right: 14px; }

  .top { margin-top: 24px; flex-direction: column; gap: 10px; }
  .top .staff, .top .holding { width: 100%; }
  .top .holding { order: -1; }
  .tie { display: none; }

  .chart-title { padding: 4px 0 2px; }
  .chart-title .meta { margin-top: 10px; font-size: 9.5px; letter-spacing: .12em; }

  .controls { gap: 8px; }
  .search { flex: 1 1 100%; max-width: none; }
  #toggle { flex: 1 1 auto; }
  .zoom { flex: 0 0 auto; }
  .zfit, #printBtn { display: none; }
  .tally { margin-left: 0; width: 100%; }
  .legend { margin-top: 34px; gap: 10px 20px; }
  .auth-head h1 { font-size: 34px; }
  table.users { min-width: 620px; }
}

@media print {
  body { background: #fff; color: #000; }
  .topbar, .controls, .page-head .spacer { display: none; }
  .sheet { max-width: none; padding: 0; }
  .unit, .staff, .holding, .head, .panel { box-shadow: none; }
  .canvas { overflow: visible; }
  .canvas-inner { zoom: 1; min-width: 0; }
  .divisions { grid-template-columns: repeat(5, 1fr); }
  .top, .col { animation: none; }
}
