:root {
  --bg: #f6f6fb;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-solid: #ffffff;
  --line: #e7e6f0;
  --text: #1d1b2e;
  --muted: #6e6b85;
  --faint: #a19fb5;
  --accent: #6d5df5;
  --accent-soft: #efedfe;
  --green: #1f9d6b;
  --green-soft: #e6f6ef;
  --red: #d64545;
  --red-soft: #fcecec;
  --amber: #b7791f;
  --amber-soft: #fbf3e2;
  --blue: #2f6fdb;
  --blue-soft: #e8f0fd;
  --shadow: 0 1px 2px rgba(29, 27, 46, 0.04), 0 8px 24px rgba(29, 27, 46, 0.05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111019;
    --panel: rgba(29, 27, 43, 0.72);
    --panel-solid: #1b1a27;
    --line: #2b2939;
    --text: #ecebf5;
    --muted: #a3a0b8;
    --faint: #6f6c85;
    --accent: #8b7dff;
    --accent-soft: #26223f;
    --green: #4cc895;
    --green-soft: #17302a;
    --red: #f07272;
    --red-soft: #351d22;
    --amber: #e0a94a;
    --amber-soft: #33291a;
    --blue: #6d9cf0;
    --blue-soft: #1a2638;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(1200px 500px at 85% -10%, var(--accent-soft), transparent 60%);
  color: var(--text);
  font: 400 13px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px;
  border-right: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(14px);
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; font-weight: 500; font-size: 13px; }
.brand .name { font-weight: 500; font-size: 14px; }
.brand .sub { color: var(--muted); font-size: 11px; }
.nav button {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; color: var(--muted); text-align: left;
}
.nav button:hover { background: var(--accent-soft); color: var(--text); }
.nav button.on { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 16px; height: 16px; flex: none; }
.nav .count { margin-left: auto; font-size: 11px; color: var(--faint); }
.side .foot { margin-top: auto; color: var(--faint); font-size: 11px; padding: 8px; }
.side .foot button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; }

.main { min-width: 0; padding: 22px 28px 60px; }
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.top h1 { font-size: 18px; font-weight: 500; margin: 0; letter-spacing: -0.01em; }
.top .spacer { flex: 1; }
.select, .search {
  height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-solid); padding: 0 10px; outline: none;
}
.select:focus, .search:focus { border-color: var(--accent); }
.search { width: 240px; }
.btn {
  height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-solid); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; color: var(--muted);
}
.btn:hover { color: var(--text); border-color: var(--faint); }
.updated { color: var(--faint); font-size: 11px; }

/* cards */
.card { background: var(--panel); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .k { color: var(--muted); font-size: 11.5px; }
.kpi .v { font-size: 22px; font-weight: 500; margin-top: 4px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .s { color: var(--faint); font-size: 11px; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.block { padding: 16px 18px; }
.block h3 { margin: 0 0 12px; font-size: 13px; font-weight: 500; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 11.5px; margin-bottom: 8px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.chart svg { width: 100%; height: 200px; display: block; }
.chart .axis { fill: var(--faint); font-size: 10px; }
.chart .grid { stroke: var(--line); }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; color: var(--muted); }
.meta b { font-weight: 400; color: var(--text); text-align: right; }

.camps { margin-top: 12px; }

/* tables */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-weight: 400; color: var(--muted); font-size: 11.5px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel-solid); white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--accent-soft); }
.lead .n { color: var(--text); }
.lead .e, .dim { color: var(--muted); font-size: 12px; }
.ellipsis { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; white-space: nowrap; background: var(--accent-soft); color: var(--accent); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.grey { background: var(--line); color: var(--muted); }
.tbar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tbar .chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 3px 10px; cursor: pointer; color: var(--muted); font-size: 12px; }
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 14px; color: var(--muted); font-size: 12px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(15, 14, 25, 0.25); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; }
.scrim.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(640px, 100vw); background: var(--panel-solid); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .22s ease; z-index: 11; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer.on { transform: none; }
.drawer header { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.drawer header .who { flex: 1; min-width: 0; }
.drawer header .who .n { font-size: 15px; font-weight: 500; }
.drawer header .x { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; }
.drawer .body { overflow: auto; padding: 16px 20px 40px; display: flex; flex-direction: column; gap: 12px; }
.msg { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.msg.in { background: var(--accent-soft); border-color: transparent; }
.msg .h { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.msg .h .when { margin-left: auto; }
.msg .subj { font-weight: 500; margin-bottom: 6px; }
.msg pre { margin: 0; white-space: pre-wrap; word-wrap: break-word; font: inherit; }
.spin { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: s 0.8s linear infinite; margin: 40px auto; }
@keyframes s { to { transform: rotate(360deg); } }
.err { color: var(--red); padding: 14px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 16px; font-weight: 500; margin: 0; }
.login p { margin: 0; color: var(--muted); }
.login input { height: 38px; border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; background: var(--panel-solid); outline: none; }
.login input:focus { border-color: var(--accent); }
.login button { height: 38px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; }
.login .bad { color: var(--red); font-size: 12px; min-height: 16px; }

@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 8px 0 0; }
  .nav { display: flex; gap: 4px; flex-wrap: wrap; }
  .nav button { width: auto; }
  .nav .count, .side .foot { display: none; }
  .main { padding: 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search { width: 100%; }
}
