/* Desk Engine 2 — design system */
:root {
  --accent: #2563EB; --accent-ink: #fff; --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --bg: #F6F7F9; --panel: #FFFFFF; --panel-2: #F9FAFB; --line: #E5E7EB; --line-2: #EEF0F3;
  --ink: #111827; --ink-2: #374151; --muted: #6B7280; --faint: #9CA3AF;
  --ok: #059669; --ok-soft: #ECFDF5; --warn: #D97706; --warn-soft: #FFFBEB; --bad: #DC2626; --bad-soft: #FEF2F2; --info-soft: #EFF6FF;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 20px 50px rgba(16,24,40,.18), 0 4px 12px rgba(16,24,40,.08);
  --r: 10px; --r-sm: 7px; --side: 244px; --row: 44px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Inter", Roboto, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", ui-monospace, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0E1116; --panel: #161A21; --panel-2: #1B2029; --line: #262C36; --line-2: #1F242D;
  --ink: #E9EDF3; --ink-2: #C9D1DC; --muted: #8E99A8; --faint: #677284;
  --ok-soft: rgba(5,150,105,.14); --warn-soft: rgba(217,119,6,.14); --bad-soft: rgba(220,38,38,.14); --info-soft: rgba(37,99,235,.14);
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 20px 50px rgba(0,0,0,.55);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12.5px; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.hidden { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--side) 1fr; height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 4px 10px color-mix(in srgb, var(--accent) 35%, transparent); }
.brand .logo svg { width: 20px; height: 20px; }
.brand b { display: block; font-size: 14.5px; letter-spacing: -.01em; line-height: 1.2; }
.brand span { font-size: 11.5px; color: var(--muted); }
.nav { flex: 1; overflow: auto; padding: 6px 10px; }
.nav .sec { font-size: 11px; font-weight: 600; 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(--ink-2); text-decoration: none; font-weight: 500; margin: 1px 0; }
.nav a:hover { background: var(--panel-2); color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav a .cnt { margin-left: auto; font-size: 11.5px; color: var(--muted); background: var(--panel-2); border-radius: 20px; padding: 0 7px; }
.side-foot { border-top: 1px solid var(--line); padding: 10px; }
.company-btn { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; }
.company-btn:hover { background: var(--panel-2); }
.company-btn .av { width: 28px; height: 28px; border-radius: 7px; background: var(--panel-2); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.company-btn b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.company-btn span { font-size: 11.5px; color: var(--muted); }
.edition { margin: 8px 10px 4px; font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.edition i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); display: inline-block; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { height: 60px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 24px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 85%, transparent); backdrop-filter: blur(8px); }
.top h1 { font-size: 17px; margin: 0; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .crumb { color: var(--muted); font-weight: 500; }
.top .grow { flex: 1; }
.search-btn { display: flex; align-items: center; gap: 8px; height: 36px; min-width: 240px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); color: var(--muted); cursor: pointer; }
.search-btn kbd { margin-left: auto; }
kbd { font: 11px var(--font); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; color: var(--muted); background: var(--panel); }
.menu-btn { display: none; }
.content { flex: 1; overflow: auto; padding: 24px; min-height: 0; }
.content.flush { padding: 0; overflow: hidden; display: flex; }
.page { max-width: 1280px; margin: 0 auto; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-weight: 600; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow); transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { background: var(--panel-2); border-color: color-mix(in srgb, var(--line) 50%, var(--muted)); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { background: none; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 30px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.input, select.input, textarea.input { width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); outline: none; transition: border-color .12s, box-shadow .12s; }
textarea.input { height: auto; min-height: 80px; padding: 9px 11px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[readonly] { background: var(--panel-2); }
.input.num { text-align: right; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.field.err .input { border-color: var(--bad); }
.field .errmsg { font-size: 12px; color: var(--bad); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- cards, stats, badges ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card > .hd { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card > .hd h3 { margin: 0; font-size: 14.5px; }
.card > .hd .grow { flex: 1; }
.card > .bd { padding: 18px; }
.card > .bd.tight { padding: 0; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stat { padding: 16px 18px; }
.stat .lbl { font-size: 12.5px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat .val { font-size: clamp(18px, 1.9vw, 24px); overflow-wrap: anywhere; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat.accent { border-top: 3px solid var(--accent); }
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--accent); border-color: transparent; }
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 9px; background: var(--info-soft); color: var(--ink-2); margin-bottom: 16px; }
.banner.warn { background: var(--warn-soft); } .banner.bad { background: var(--bad-soft); } .banner.ok { background: var(--ok-soft); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty > svg.i { width: 40px; height: 40px; stroke-width: 1.4; color: var(--faint); }
.empty h3 { color: var(--ink); margin: 10px 0 4px; font-size: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 500; }
.progress { height: 8px; border-radius: 8px; background: var(--line-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 8px; }
.progress.ok > i { background: var(--ok); } .progress.bad > i { background: var(--bad); }

/* ---------- tables ---------- */
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--panel-2); }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
table.t td.act { width: 1%; white-space: nowrap; }
table.t th.num { text-align: right; }
table.t td.nowrap { white-space: nowrap; }
table.edit td { padding: 4px 6px; }
table.edit .input { height: 32px; border-color: transparent; background: transparent; }
table.edit .input:hover { border-color: var(--line); }
table.edit .input:focus { border-color: var(--accent); background: var(--panel); }

/* virtual list */
.list-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; flex: 1; background: var(--panel); }
.list-tools { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list-tools .search { position: relative; flex: 1; min-width: 180px; max-width: 360px; }
.list-tools .search svg { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.list-tools .search input { padding-left: 34px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 16px; border-bottom: 1px solid var(--line-2); }
.chip { height: 28px; padding: 0 11px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .n { font-weight: 500; opacity: .75; }
.vt { flex: 1; overflow: auto; position: relative; min-height: 0; }
.vt-head, .vt-row { display: grid; align-items: center; min-width: 100%; }
.vt-head { position: sticky; top: 0; z-index: 2; background: var(--panel-2); border-bottom: 1px solid var(--line); height: 38px; }
.vt-head div { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 12px; cursor: pointer; user-select: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vt-head div:hover { color: var(--ink); }
.vt-head div.sorted { color: var(--accent); }
.vt-row { height: var(--row); border-bottom: 1px solid var(--line-2); cursor: pointer; position: absolute; left: 0; right: 0; }
.vt-row:hover { background: var(--panel-2); }
.vt-row.sel { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.vt-row > div { padding: 0 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vt-row > div.num { font-variant-numeric: tabular-nums; }
.vt-foot { display: flex; gap: 16px; padding: 8px 16px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); background: var(--panel); }
.vt-foot b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* split view */
.split.full { grid-template-columns: 1fr; }
.split.full > .list-wrap { display: none; }
.split.full .detail-inner { max-width: 1280px; margin: 0 auto; }
.split { display: grid; grid-template-columns: minmax(380px, 44%) 1fr; flex: 1; min-height: 0; min-width: 0; }
.split > .list-wrap { border-right: 1px solid var(--line); }
.split .detail { overflow: auto; min-width: 0; background: var(--bg); }
.detail-inner { padding: 22px 26px; max-width: 980px; }
.detail-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 18px; flex-wrap: wrap; }
.detail-head h2 { margin: 0; font-size: 20px; letter-spacing: -.015em; }
.detail-head .grow { flex: 1; min-width: 200px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { border: 0; background: none; padding: 9px 12px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--accent); border-color: var(--accent); }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,18,24,.45); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 50; padding: 20px; animation: fade .12s ease-out; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; animation: pop .14s ease-out; }
.modal.wide { width: min(880px, 100%); } .modal.xwide { width: min(1100px, 100%); }
.modal > .hd { padding: 18px 22px 8px; display: flex; align-items: center; gap: 10px; }
.modal > .hd h3 { margin: 0; font-size: 17px; flex: 1; }
.modal > .bd { padding: 8px 22px 18px; overflow: auto; }
.modal > .ft { padding: 14px 22px; border-top: 1px solid var(--line-2); display: flex; gap: 8px; justify-content: flex-end; }
.palette { position: fixed; inset: 0; z-index: 60; background: rgba(15,18,24,.35); display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; animation: fade .1s; }
.palette .box { width: min(640px, 92vw); background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; border: 1px solid var(--line); }
.palette input { width: 100%; height: 54px; border: 0; border-bottom: 1px solid var(--line); padding: 0 18px; font-size: 16px; outline: none; background: none; }
.palette .res { max-height: 52vh; overflow: auto; padding: 6px; }
.palette .it { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.palette .it.on { background: var(--accent-soft); color: var(--accent); }
.palette .it small { margin-left: auto; color: var(--muted); }
.palette .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 8px 12px 4px; font-weight: 600; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 70; }
.toast { display: flex; gap: 10px; align-items: center; background: #111827; color: #fff; padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 260px; max-width: 420px; animation: up .16s ease-out; }
.toast.bad { background: var(--bad); }
.toast button { margin-left: auto; background: none; border: 0; color: #93C5FD; font-weight: 700; cursor: pointer; }
.combo { position: relative; }
.combo-list { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow-lg); max-height: 260px; overflow: auto; z-index: 40; padding: 4px; }
.combo-list div { padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.combo-list div.on, .combo-list div:hover { background: var(--accent-soft); }
.combo-list .add { color: var(--accent); font-weight: 600; }
.lockscreen { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 80; }
.lockscreen .card { width: 340px; padding: 28px; text-align: center; }
.pin { font-size: 24px; letter-spacing: .4em; text-align: center; height: 50px; }
.dropzone { border: 2px dashed var(--line); border-radius: 12px; padding: 28px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

/* charts */
.chart { width: 100%; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid line { stroke: var(--line-2); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(6px); } }
@keyframes up { from { opacity: 0; transform: translateY(10px); } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .split.has-detail > .list-wrap { display: none; }
  .split:not(.has-detail) > .detail { display: none; }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 45; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow-lg); }
  .app.nav-open .side { transform: none; }
  .menu-btn { display: inline-flex; }
  .search-btn { min-width: 0; } .search-btn span, .search-btn kbd { display: none; }
  .top { padding: 0 12px; } .content { padding: 14px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .detail-inner { padding: 16px; }
  .top .hide-sm { display: none; }
}
@media print {
  body { overflow: visible; background: #fff; }
  .side, .top, .list-tools, .chips, .btns { display: none !important; }
  .app { display: block; } .content { overflow: visible; }
}
