:root {
  --bg: #f4f6f8; --panel: #ffffff; --panel-2: #f8fafb; --line: #e3e8ee; --line-2: #eef1f4;
  --text: #1c2733; --muted: #66768a; --faint: #93a1b2;
  --primary: #0f766e; --primary-2: #0d9488; --primary-soft: #e6f4f2; --primary-ink: #0b5a54;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf3e3; --bad: #b91c1c; --bad-soft: #fdecec;
  --info: #1d4ed8; --info-soft: #e8efff; --gray-soft: #eef1f4;
  --k-l: #15803d; --k-dpk: #a16207; --k-kl: #c2410c; --k-drg: #b91c1c; --k-m: #7f1d1d;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --side: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --panel: #161d24; --panel-2: #1b232b; --line: #27313b; --line-2: #212a33;
    --text: #e4e9ee; --muted: #9aa8b6; --faint: #6d7c8b;
    --primary: #2bb3a6; --primary-2: #34c3b5; --primary-soft: #133430; --primary-ink: #7fe0d6;
    --ok: #4ade80; --ok-soft: #12301e; --warn: #fbbf24; --warn-soft: #33270f; --bad: #f87171; --bad-soft: #3a1717;
    --info: #93b4ff; --info-soft: #172443; --gray-soft: #222b34;
    --k-l: #4ade80; --k-dpk: #facc15; --k-kl: #fb923c; --k-drg: #f87171; --k-m: #fca5a5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --panel: #161d24; --panel-2: #1b232b; --line: #27313b; --line-2: #212a33;
  --text: #e4e9ee; --muted: #9aa8b6; --faint: #6d7c8b;
  --primary: #2bb3a6; --primary-2: #34c3b5; --primary-soft: #133430; --primary-ink: #7fe0d6;
  --ok: #4ade80; --ok-soft: #12301e; --warn: #fbbf24; --warn-soft: #33270f; --bad: #f87171; --bad-soft: #3a1717;
  --info: #93b4ff; --info-soft: #172443; --gray-soft: #222b34;
  --k-l: #4ade80; --k-dpk: #facc15; --k-kl: #fb923c; --k-drg: #f87171; --k-m: #fca5a5;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* layout */
.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; display: grid; place-items: center; font-weight: 800; }
.brand b { display: block; font-size: 15px; } .brand span { font-size: 12px; color: var(--muted); }
.nav { padding: 6px 10px 16px; flex: 1; }
.nav .sec { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--panel-2); }
.nav a.on { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.side-foot { border-top: 1px solid var(--line); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-ink); display: grid; place-items: center; font-weight: 700; flex: none; }
.side-foot .who { flex: 1; min-width: 0; } .side-foot .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main { min-width: 0; }
.topbar { display: none; }
.page { padding: 24px 28px 48px; max-width: 1480px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.card-b { padding: 16px; }
.grid { display: grid; gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .l { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stat .v { font-size: 21px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat.ok .v { color: var(--ok); } .stat.warn .v { color: var(--warn); } .stat.bad .v { color: var(--bad); }
.bar { height: 8px; background: var(--gray-soft); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar.ok > i { background: var(--ok); } .bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }

/* controls */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 9px; height: 36px; padding: 0 10px; min-width: 0; }
textarea { height: auto; padding: 8px 10px; min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
input[type=checkbox] { height: auto; width: 16px; height: 16px; accent-color: var(--primary); }
.search { min-width: 220px; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 550; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { color: var(--text); font-weight: 400; font-size: 14px; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.form h4 { grid-column: 1 / -1; margin-top: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line-2); font-size: 13px; color: var(--primary-ink); }
.chk { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; cursor: pointer; user-select: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: transparent; padding: 0 12px; height: 34px; font: inherit; font-weight: 550; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--primary-soft); color: var(--primary-ink); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; font: inherit; font-weight: 550; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--primary-ink); border-bottom-color: var(--primary); }

/* table */
.tbl-wrap { overflow: auto; border-radius: 0 0 var(--radius) var(--radius); }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; }
table.t th { position: sticky; top: 0; z-index: 2; background: var(--panel-2); color: var(--muted); font-size: 12px; font-weight: 650; text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.t tbody tr:hover td { background: var(--panel-2); }
table.t tr.click { cursor: pointer; }
table.t tfoot td { font-weight: 700; background: var(--panel-2); border-top: 1px solid var(--line); position: sticky; bottom: 0; }
table.t .sub { font-size: 12px; color: var(--muted); }
table.t th.num, table.t td.num { text-align: right; }
.full-tbl { max-height: calc(100vh - 260px); }
.full-tbl table.t td, .full-tbl table.t th { padding: 6px 10px; font-size: 12.5px; white-space: nowrap; }
.full-tbl table.t th .col { display: block; font-size: 10.5px; color: var(--faint); font-weight: 600; }
.full-tbl table.t .grp th { top: 0; text-align: center; color: var(--primary-ink); background: var(--primary-soft); border-right: 1px solid var(--panel); }
.full-tbl table.t thead tr:nth-child(2) th { top: 31px; }
.full-tbl table.t .stick { position: sticky; left: 0; z-index: 1; background: var(--panel); box-shadow: 1px 0 0 var(--line); }
.full-tbl table.t th.stick { z-index: 3; background: var(--panel-2); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--gray-soft); color: var(--muted); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.pri { background: var(--primary-soft); color: var(--primary-ink); }
.kol { display: inline-block; min-width: 38px; text-align: center; padding: 1px 7px; border-radius: 6px; font-size: 12px; font-weight: 700; border: 1px solid currentColor; }
.kol.L { color: var(--k-l); } .kol.DPK { color: var(--k-dpk); } .kol.KL { color: var(--k-kl); } .kol.Drg { color: var(--k-drg); } .kol.M { color: var(--k-m); background: var(--bad-soft); }

/* drawer & modal */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 32, .45); z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 5vh 16px; overflow-y: auto; animation: fade .15s; }
.modal { background: var(--panel); border-radius: 14px; width: min(760px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(1040px, 100%); }
.modal-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.modal-b { padding: 18px 20px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line-2); }
.drawer-o { justify-content: flex-end; padding: 0; align-items: stretch; }
.drawer { background: var(--bg); width: min(760px, 100%); height: 100vh; overflow-y: auto; box-shadow: -10px 0 40px rgba(0,0,0,.2); animation: slide .2s; }
.drawer-h { position: sticky; top: 0; z-index: 2; background: var(--panel); border-bottom: 1px solid var(--line); padding: 16px 20px; }
.drawer-b { padding: 16px 20px 40px; display: grid; gap: 14px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0; }
.kv > div { padding: 9px 14px; border-bottom: 1px solid var(--line-2); }
.kv dt { font-size: 11.5px; color: var(--muted); } .kv dd { margin: 2px 0 0; font-weight: 550; word-break: break-word; }
.kv .col { color: var(--faint); font-size: 10.5px; margin-left: 4px; }
.x { border: 0; background: none; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.x:hover { background: var(--panel-2); }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(30px); opacity: .5; } }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1c2733; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: 90vw; }
.toast.err { background: #b91c1c; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.note { background: var(--info-soft); color: var(--text); border-radius: 10px; padding: 10px 14px; font-size: 13px; }
.note.warn { background: var(--warn-soft); }
.pw-box { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px; background: var(--panel-2); border: 1px dashed var(--line); border-radius: 10px; padding: 12px; text-align: center; letter-spacing: .03em; user-select: all; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 500px at 10% -10%, var(--primary-soft), transparent), var(--bg); }
.login .card { width: min(400px, 100%); padding: 28px; }
.login h1 { margin: 14px 0 4px; }
.login form { display: grid; gap: 14px; margin-top: 20px; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.list-plain { margin: 0; padding: 0; list-style: none; }
.list-plain li { padding: 9px 0; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; gap: 10px; }
.list-plain li:last-child { border-bottom: 0; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; }
.pre { white-space: pre-wrap; }

@media (max-width: 1000px) {
  .two, .three { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 60; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
  .page { padding: 16px 16px 40px; }
  .search { min-width: 0; flex: 1 1 100%; }
  .toolbar > select, .toolbar > input { flex: 1 1 140px; }
  .hide-m { display: none; }
}
@media print {
  .side, .topbar, .toolbar, .no-print, .pager, .tabs { display: none !important; }
  .app { display: block; } .page { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; }
  body { background: #fff; color: #000; font-size: 11px; }
  .tbl-wrap, .full-tbl { max-height: none !important; overflow: visible !important; }
  table.t th { position: static; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
.btn.danger-bg { background: var(--bad); border-color: var(--bad); color: #fff; }
