:root {
  --bg: #f4f5f0; --panel: #ffffff; --panel2: #fafbf7; --line: #e2e4dc; --line2: #d3d6cb;
  --text: #1b1d18; --muted: #6d7166; --faint: #9a9e93;
  --accent: #c2df3e; --accent-2: #b0cd2b; --accent-soft: #eef6c8; --accent-ink: #1b1d18;
  --ok: #2f9e44; --warn: #e09c0b; --bad: #d9480f; --info: #3b6fd8;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 8px; --shadow: 0 8px 30px rgba(20, 24, 10, .12);
  --sidebar: 252px;
}
:root[data-theme="dark"] {
  --bg: #11130f; --panel: #181b15; --panel2: #1d2019; --line: #2a2e25; --line2: #363b30;
  --text: #e6e8e1; --muted: #9aa092; --faint: #6f7568;
  --accent-soft: #2a3313; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
body { -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.ico { display: inline-flex; width: 16px; height: 16px; flex: none; }
.ico svg { width: 100%; height: 100%; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
#app { display: flex; height: 100vh; height: 100dvh; }
.sidebar { width: var(--sidebar); flex: none; background: var(--panel2); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-family: var(--mono); font-size: 14px; }
.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 1px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 6px; text-decoration: none; color: var(--text); opacity: .86; }
.nav a:hover { background: var(--line); opacity: 1; }
.nav a.active { background: var(--accent); color: var(--accent-ink); opacity: 1; font-weight: 600; }
.nav a .kbd { margin-left: auto; opacity: 0; }
.nav a:hover .kbd { opacity: .7; }
.nav .sep { height: 1px; background: var(--line); margin: 6px 4px; }
.side-terms { padding: 4px 10px; overflow: auto; flex: 1; }
.side-terms .lbl { font: 600 10.5px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--faint); padding: 10px 10px 4px; }
.side-terms a { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 6px; text-decoration: none; font-size: 13px; }
.side-terms a:hover { background: var(--line); }
.side-terms a.active { background: var(--accent-soft); }
.side-terms a .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.side-foot { border-top: 1px solid var(--line); padding: 8px 10px; display: flex; flex-direction: column; gap: 1px; }
.side-foot button { all: unset; display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 13px; }
.side-foot button:hover { background: var(--line); color: var(--text); }
body.collapsed .sidebar { width: 58px; }
body.collapsed .sidebar .brand span:not(.logo), body.collapsed .nav a span:not(.ico), body.collapsed .side-terms,
body.collapsed .side-foot button span:not(.ico) { display: none; }
body.collapsed .nav a, body.collapsed .side-foot button { justify-content: center; }

main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 52px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel2); }
.topbar .crumb { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .burger { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 1px solid var(--line2); border-radius: 7px; background: var(--panel); cursor: pointer; font-size: 12.5px; white-space: nowrap; }
.chip:hover { border-color: var(--muted); }
.chip .dim { color: var(--faint); font-family: var(--mono); font-size: 11.5px; }
.search-btn { display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px; border: 1px solid var(--line2); border-radius: 7px; background: var(--panel); color: var(--muted); cursor: pointer; min-width: 190px; }
.search-btn .k { margin-left: auto; }
.kbd, .k { font: 500 10.5px var(--mono); padding: 1px 5px; border: 1px solid var(--line2); border-radius: 4px; color: var(--muted); background: var(--panel2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--line); display: grid; place-items: center; font: 600 11px var(--mono); cursor: pointer; flex: none; }
.icon-btn.bell { position: relative; overflow: visible; }
.bell .badge { position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--bad); color: #fff; font: 600 10px/16px var(--mono); text-align: center; }

.page { flex: 1; overflow: auto; padding: 32px 40px 60px; }
.page.full { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.page-inner { max-width: 1120px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 16px; padding-bottom: 18px; margin-bottom: 22px; border-bottom: 1px dashed var(--line2); flex-wrap: wrap; }
.page-head h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -.02em; }
.page-head p { margin: 0; color: var(--muted); max-width: 640px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 34px; padding: 0 14px; border-radius: 7px; border: 1px solid var(--line2); background: var(--panel); cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent-2); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { all: unset; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--line); color: var(--text); }
.input, select.input, textarea.input { width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--line2); border-radius: 7px; background: var(--panel); outline: none; }
textarea.input { height: auto; min-height: 90px; padding: 9px 11px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
.input:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > label { font-weight: 600; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 7px; overflow: hidden; background: var(--panel); flex-wrap: wrap; }
.seg button { all: unset; padding: 6px 12px; cursor: pointer; font-size: 13px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent-2); }
.toggle { position: relative; width: 38px; height: 22px; flex: none; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle span { position: absolute; inset: 0; border-radius: 6px; background: var(--line2); transition: .15s; }
.toggle span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 4px; background: var(--panel); transition: .15s; }
.toggle input:checked + span { background: var(--accent-2); }
.toggle input:checked + span::after { left: 19px; background: #1b1d18; }

/* ---------- cards & lists ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.card-head h3 { margin: 0; font-size: 15px; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 16px 18px; }
.card.pad { padding: 22px 26px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); margin-bottom: 22px; }
.stat { padding: 18px 22px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat .lbl { font: 600 11px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stat .val { font-size: 26px; font-weight: 700; margin: 6px 0 2px; letter-spacing: -.02em; }
.stat .sub { color: var(--muted); font-size: 12.5px; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line); min-height: 50px; }
.list-row:last-child { border-bottom: 0; }
.list-row.click { cursor: pointer; }
.list-row.click:hover { background: var(--panel2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok, .dot.busy { background: var(--ok); }
.dot.bad, .dot.limit { background: var(--bad); }
.dot.needs { background: var(--warn); box-shadow: 0 0 0 3px rgba(224, 156, 11, .2); animation: pulse 1.6s infinite; }
.dot.done { background: var(--info); }
.dot.unknown { background: var(--faint); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(224, 156, 11, 0); } }
.badge { display: inline-flex; align-items: center; gap: 4px; height: 21px; padding: 0 7px; border-radius: 5px; border: 1px solid var(--line2); font-size: 11.5px; white-space: nowrap; background: var(--panel); }
.badge.accent { background: var(--accent-soft); border-color: var(--accent-2); }
.badge.mono { font-family: var(--mono); }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 11px; font-size: 12px; background: var(--line); }
.pill.needs { background: rgba(224, 156, 11, .16); color: #9a6a00; }
.pill.done { background: rgba(59, 111, 216, .13); color: var(--info); }
.pill.limit { background: rgba(217, 72, 15, .13); color: var(--bad); }
.pill.busy { background: rgba(47, 158, 68, .13); color: var(--ok); }
:root[data-theme="dark"] .pill.needs { color: #f3c04b; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font: 600 11px var(--mono); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); padding: 10px 18px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 11px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--panel2); }
.empty { text-align: left; padding: 26px 30px; }
.empty h3 { margin: 0 0 6px; }
.empty p { margin: 0 0 16px; color: var(--muted); max-width: 520px; }
.banner { display: flex; gap: 10px; align-items: center; padding: 11px 15px; border-radius: 7px; background: #fff6dc; border: 1px solid #f2d68a; margin-bottom: 18px; color: #6d5410; }
:root[data-theme="dark"] .banner { background: #2c2510; border-color: #5a4a17; color: #ecd28a; }
.banner.info { background: var(--accent-soft); border-color: var(--accent-2); color: var(--text); }
.prov-ico { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; color: #fff; }
.term-card { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line); cursor: pointer; }
.term-card:hover { background: var(--panel2); }
.term-card:last-child { border-bottom: 0; }
.term-card .main { flex: 1; min-width: 0; }
.term-card .title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.term-card .meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.term-card .osc { color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 520px; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent-2); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; font-size: 13px; }
.kv .k2 { color: var(--muted); }
pre.code { background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 12px 14px; overflow: auto; font: 12.5px/1.5 var(--mono); margin: 0; white-space: pre-wrap; word-break: break-all; }
.copyline { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; }
.copyline code { flex: 1; padding: 8px 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; overflow: auto; white-space: nowrap; }

/* ---------- terminal view ---------- */
.tbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel2); flex: none; flex-wrap: wrap; }
.tbar .ttl { font-weight: 600; cursor: text; }
.tbar .osc { color: var(--faint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.xwrap { flex: 1; min-height: 0; position: relative; background: #11130f; padding: 6px 0 0 8px; }
.xwrap.light { background: #fff; }
.xwrap .xterm { height: 100%; }
.xwrap .overlay-msg { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 12, 8, .72); color: #eee; z-index: 5; text-align: center; }
.xwrap .overlay-msg .box { background: var(--panel); color: var(--text); padding: 22px 26px; border-radius: 10px; box-shadow: var(--shadow); max-width: 420px; }
.conn { font: 11px var(--mono); color: var(--faint); }
.conn.bad { color: var(--bad); }
.keybar { display: none; gap: 6px; padding: 7px 8px; overflow-x: auto; border-top: 1px solid var(--line); background: var(--panel2); flex: none; -webkit-overflow-scrolling: touch; }
.keybar.on { display: flex; }
.keybar button { flex: none; min-width: 42px; height: 36px; padding: 0 10px; border: 1px solid var(--line2); border-radius: 7px; background: var(--panel); font: 600 13px var(--mono); }
.keybar button:active { background: var(--accent); }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 17, 12, .45); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; z-index: 50; overflow: auto; }
.modal { width: 100%; max-width: 540px; background: var(--panel); border-radius: 11px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--line); }
.menu { position: fixed; z-index: 60; min-width: 200px; background: var(--panel); border: 1px solid var(--line2); border-radius: 9px; box-shadow: var(--shadow); padding: 5px; }
.menu button { all: unset; display: flex; align-items: center; gap: 9px; width: 100%; box-sizing: border-box; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.menu button:hover, .menu button.sel { background: var(--line); }
.menu button.danger { color: var(--bad); }
.menu .sep { height: 1px; background: var(--line); margin: 4px 2px; }
.menu .mh { font: 600 10.5px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--faint); padding: 6px 10px 3px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 70; }
.toast { background: var(--text); color: var(--bg); padding: 11px 15px; border-radius: 9px; box-shadow: var(--shadow); max-width: 380px; font-size: 13px; cursor: default; animation: tin .2s; }
.toast.click { cursor: pointer; }
.toast.err { background: var(--bad); color: #fff; }
.toast b { display: block; margin-bottom: 2px; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }
.palette { max-width: 600px; }
.palette input { border: 0; border-bottom: 1px solid var(--line); border-radius: 11px 11px 0 0; height: 50px; font-size: 15px; padding: 0 18px; box-shadow: none !important; }
.palette .items { max-height: 50vh; overflow: auto; padding: 6px; }
.palette .it { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 7px; cursor: pointer; }
.palette .it.sel { background: var(--accent-soft); }
.palette .it .ty { margin-left: auto; font: 11px var(--mono); color: var(--faint); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 30px; box-shadow: var(--shadow); }
.login h1 { font-size: 22px; margin: 18px 0 4px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.drawer .sidebar { transform: none; }
  body.collapsed .sidebar { width: var(--sidebar); }
  .topbar .burger { display: inline-grid; }
  .search-btn { min-width: 0; }
  .search-btn .txt, .search-btn .k, .chip .lbl { display: none; }
  .page { padding: 20px 14px 50px; }
  .page-head h1 { font-size: 22px; }
  .hide-m { display: none !important; }
  .tbar { gap: 6px; padding: 6px 8px; }
  .tbar .osc { display: none; }
  .stat { border-right: 0; border-bottom: 1px solid var(--line); }
  .kv { grid-template-columns: 110px 1fr; }
}
