:root {
  --bg: #f3f5f7; --panel: #ffffff; --text: #18202b; --muted: #667085; --line: #e4e7ec; --soft: #f7f8fa;
  --accent: #2f7d4f; --accent-soft: #e6f2eb; --accent-ink: #ffffff;
  --warn: #b42318; --warn-soft: #fef3f2; --amber: #b54708; --amber-soft: #fffaeb; --blue: #175cd3; --blue-soft: #eff8ff;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1318; --panel: #171c23; --text: #e6e9ee; --muted: #98a2b3; --line: #262d37; --soft: #1c222b;
    --accent: #4aa774; --accent-soft: #19301f; --accent-ink: #0b130e;
    --warn: #f97066; --warn-soft: #3a1714; --amber: #fdb022; --amber-soft: #36270a; --blue: #84caff; --blue-soft: #102a44; --shadow: none; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.app { display: flex; min-height: 100vh; }
.mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-weight: 800; flex: none; }

.side { width: 232px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; gap: 10px; align-items: center; padding: 16px; border-bottom: 1px solid var(--line); }
.logo small { display: block; color: var(--muted); font-size: 12px; }
.nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--soft); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav .ico { width: 20px; text-align: center; }
.nav .badge { margin-left: auto; background: var(--warn); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.me { padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; }
.me .r { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }

.body { flex: 1; min-width: 0; }
.bar { display: none; }
.main { max-width: 1180px; margin: 0 auto; padding: 24px; }
h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head .row > * { flex: none; }
.back { display: inline-block; margin-bottom: 10px; color: var(--muted); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: block; color: inherit; }
a.kpi:hover { border-color: var(--accent); text-decoration: none; }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); margin-top: 4px; }
.kpi.warn .v { color: var(--warn); } .kpi.ok .v { color: var(--accent); }
.facts { list-style: none; margin: 0; padding: 0; }
.facts li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.facts li:last-child { border: 0; }
.bars .b { display: grid; grid-template-columns: 120px 1fr 90px; gap: 10px; align-items: center; margin: 7px 0; }
.bars .t { height: 10px; background: var(--soft); border-radius: 6px; overflow: hidden; position: relative; }
.bars .t i { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 6px; }
.bars .t b { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 6px; }
.bars .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.tools .grow { flex: 1 1 240px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
textarea { width: 100%; min-height: 150px; resize: vertical; }
.seg { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 9px; padding: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; font: inherit; color: var(--muted); padding: 6px 10px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn.ghost { background: var(--panel); color: var(--text); border-color: var(--line); font-weight: 500; }
.btn.danger { background: var(--warn-soft); color: var(--warn); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--text); padding: 0 4px; }

.tbl-wrap { overflow: auto; max-height: calc(100vh - 220px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; z-index: 1; background: var(--soft); color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; cursor: pointer; user-select: none; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
th .ar { opacity: .7; margin-left: 4px; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--soft); }
td .s { color: var(--muted); font-size: 12px; }
.dense th, .dense td { padding: 6px 8px; font-size: 13px; }
.dense td b { font-variant-numeric: tabular-nums; }
.dense tbody tr:nth-child(even) { background: color-mix(in srgb, var(--soft) 60%, transparent); }
tfoot td { position: sticky; bottom: 0; background: var(--accent-soft); border-top: 2px solid var(--line); font-weight: 600; }
.count { color: var(--muted); font-size: 13px; margin: 8px 2px; }

.chip { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 12px; background: var(--soft); border: 1px solid var(--line); margin: 1px 2px 1px 0; white-space: nowrap; }
.chip.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.amber { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.chip.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.muted { color: var(--muted); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; user-select: all; }

.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.toggles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.toggles label { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-weight: 500; }
.form label > span { color: var(--muted); font-size: 12px; font-weight: 500; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.check { display: flex !important; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; }
.preview { background: var(--soft); border: 1px solid var(--line); border-radius: 12px; padding: 12px; white-space: pre-wrap; word-break: break-word; }
.preview img { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 8px; }

.chat { display: grid; gap: 10px; max-height: 58vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 78%; padding: 10px 12px; border-radius: 12px; background: var(--soft); border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }
.msg.out { margin-left: auto; background: var(--accent-soft); border-color: transparent; }
.msg .m { color: var(--muted); font-size: 11px; margin-top: 4px; }
.msg img { max-width: 100%; max-height: 320px; border-radius: 8px; display: block; margin-top: 6px; }

.login { max-width: 400px; margin: 10vh auto; }
.login .mark { width: 44px; height: 44px; font-size: 22px; margin-bottom: 12px; }

.modal { position: fixed; inset: 0; background: rgba(15, 19, 24, .45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.sheet { background: var(--panel); border-radius: 14px; width: min(560px, 100%); max-height: 90vh; overflow-y: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.sheet h3 { margin: 0 0 12px; font-size: 17px; }
.sheet .acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: calc(100% - 32px); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }

@media (max-width: 860px) {
  .app { display: block; }
  .side { position: fixed; inset: 0 auto 0 0; z-index: 15; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .bar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 10; background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .bar .icon { margin-left: auto; }
  .main { padding: 16px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dt { margin-top: 8px; }
  .hide-sm { display: none; }
  .msg { max-width: 92%; }
  .tbl-wrap { max-height: none; }
  .bars .b { grid-template-columns: 90px 1fr 70px; }
}
