:root {
  --bg: #f4f5f7; --panel: #ffffff; --line: #e5e7eb; --text: #111827; --muted: #6b7280;
  --brand: #c2410c; --brand-soft: #fff1e8; --ok: #15803d; --ok-soft: #e8f6ed; --warn: #b45309; --warn-soft: #fef5e4;
  --bad: #b91c1c; --bad-soft: #fdecec; --info: #1d4ed8; --info-soft: #e8efff; --side: #111827; --side-text: #d1d5db;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --panel: #171a21; --line: #272b35; --text: #e5e7eb; --muted: #9aa1ad; --brand-soft: #3a2116;
    --ok-soft: #12291b; --warn-soft: #33270f; --bad-soft: #3a1717; --info-soft: #172340; --side: #0b0d11; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, -apple-system, sans-serif; }
a { color: var(--brand); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.error { color: var(--bad); min-height: 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand.big { font-size: 20px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; }

.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 13px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }
textarea { min-height: 90px; resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.danger.solid { background: var(--bad); color: #fff; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 4px; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.icon { padding: 6px 10px; }

.app { display: flex; min-height: 100vh; }
.side { width: 240px; background: var(--side); color: var(--side-text); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.side .brand { color: #fff; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--side-text); padding: 9px 10px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
.side nav a.on, .side nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side .me { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.pill { background: var(--brand); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; }
.pill:empty { display: none; }
main { flex: 1; min-width: 0; }
.top { display: flex; align-items: center; gap: 10px; padding: 16px 24px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.top h1 { font-size: 18px; margin: 0; }
.spacer { flex: 1; }
.menu { display: none; }
.view { padding: 20px 24px 60px; max-width: 1300px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 500; }
.two { grid-template-columns: 1fr 1fr; }
.three { grid-template-columns: 1fr 1fr 1fr; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.section { margin-top: 18px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--brand-soft); }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); } .b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); } .b-info { background: var(--info-soft); color: var(--info); }
.b-mute { background: var(--line); color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { min-width: 240px; flex: 1; max-width: 420px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 11px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--text); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--brand); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.inbox { display: grid; grid-template-columns: 380px 1fr; gap: 14px; align-items: start; }
.tlist { display: flex; flex-direction: column; max-height: calc(100vh - 190px); overflow: auto; padding: 0; }
.titem { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.titem:hover, .titem.on { background: var(--brand-soft); }
.titem .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply { border-left: 3px solid var(--brand); padding: 6px 12px; margin: 8px 0; background: var(--brand-soft); border-radius: 0 8px 8px 0; }
pre.msg { font-family: inherit; }
pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; background: var(--bg); padding: 10px; border-radius: 8px; max-height: 260px; overflow: auto; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
.toast.on { opacity: 1; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal-card { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 12px; }
.modal-card .row { display: flex; gap: 8px; justify-content: flex-end; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 900px) {
  .side { position: fixed; left: -260px; z-index: 30; transition: left .2s; }
  .side.open { left: 0; }
  .menu { display: inline-block; }
  .two, .three { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: 1fr; }
  .view { padding: 16px; }
  .top { padding: 12px 16px; }
  .kv { grid-template-columns: 120px 1fr; }
  .toolbar input[type=search] { min-width: 0; width: 100%; max-width: none; }
}

a.tile { display: block; color: inherit; transition: border-color .15s, transform .15s; }
a.tile:hover { border-color: var(--brand); transform: translateY(-1px); }
a.tile .go { color: var(--brand); font-weight: 600; margin-top: 6px; opacity: 0; transition: opacity .15s; }
a.tile:hover .go, a.tile:focus .go { opacity: 1; }
@media (hover: none) { a.tile .go { opacity: 1; } }
a.statrow { display: flex; align-items: center; gap: 10px; margin: 2px -8px; padding: 6px 8px; border-radius: 8px; color: inherit; }
a.statrow:hover { background: var(--brand-soft); }
