:root {
  --bg: #f7f7fa;
  --card: #ffffff;
  --ink: #11121a;
  --muted: #6a6d7a;
  --faint: #8b8d99;
  --line: #e3e4ec;
  --purple: #7b4dff;
  --purple-2: #9d83ff;
  --purple-soft: #f1eeff;
  --green: #177a55;
  --green-bg: #e3f6ee;
  --amber: #8a5300;
  --amber-bg: #fff4e0;
  --red: #c43d62;
  --red-bg: #fdeaef;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(20, 18, 40, .06);
  --ease: cubic-bezier(.22, .61, .36, 1);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.02em; }
a { color: var(--purple); text-decoration: none; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px clamp(16px, 3vw, 32px);
  background: rgba(247, 247, 250, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand .mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(140deg, #1b1b22, #3a2c66); color: #fff; font-size: 15px;
}
.brand small { display: block; font-weight: 500; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); }
.top .spacer { flex: 1; }
.top .chip { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: 13px; }
.top .chip b { font-weight: 600; }
.wrap { max-width: 1240px; margin: 0 auto; padding: clamp(20px, 3vw, 34px) clamp(16px, 3vw, 32px) 80px; }

/* ---------- auth ---------- */
.auth { display: grid; place-items: center; min-height: calc(100vh - 60px); padding: 32px 16px; }
.auth-card { width: 100%; max-width: 430px; padding: 30px; border: 1px solid var(--line); border-radius: 22px; background: var(--card); box-shadow: var(--shadow); }
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-card p.lead { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.tabs-lite { display: inline-flex; gap: 4px; margin-bottom: 20px; padding: 4px; border-radius: 12px; background: #efeef5; }
.tabs-lite button { height: 34px; padding: 0 14px; border: 0; border-radius: 9px; background: none; font: inherit; font-size: 13px; color: #4a4d5c; cursor: pointer; }
.tabs-lite button[aria-pressed="true"] { background: #fff; color: var(--purple); font-weight: 600; box-shadow: 0 2px 8px rgba(20, 18, 40, .08); }

/* ---------- forms ---------- */
label.field-label { display: grid; gap: 6px; margin-bottom: 12px; font-size: 12px; font-weight: 560; color: var(--muted); }
.field {
  width: 100%; height: 46px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  font: inherit; font-size: 14px; color: var(--ink); transition: border-color .2s, box-shadow .2s;
}
textarea.field { height: auto; min-height: 84px; padding: 12px 14px; resize: vertical; }
select.field { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236a6d7a' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 34px; }
.field:focus { outline: none; border-color: var(--purple-2); box-shadow: 0 0 0 4px rgba(123, 77, 255, .12); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px; border: 1px solid transparent; border-radius: 12px;
  background: var(--ink); color: #fff; font: inherit; font-size: 14px; font-weight: 560; cursor: pointer;
  transition: background-color .2s, border-color .2s, color .2s, transform .15s var(--ease);
}
.btn:hover { background: var(--purple); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--purple-2); color: var(--purple); }
.btn.danger { background: #fff; border-color: #f0c9d3; color: var(--red); }
.btn.danger:hover { background: var(--red); color: #fff; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn.full { width: 100%; }
.err { margin: 10px 0 0; color: var(--red); font-size: 13px; }
.note { margin: 10px 0 0; color: var(--faint); font-size: 13px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; margin: 0 0 20px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { position: relative; flex: none; padding: 12px 15px; border: 0; background: none; font: inherit; font-size: 14px; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--ink); font-weight: 600; }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--purple); }
.tabs .count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--purple-soft); font-size: 11px; color: var(--purple); }

/* ---------- cards & grids ---------- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: #efeef5; }
.seg button { height: 34px; padding: 0 13px; border: 0; border-radius: 9px; background: none; font: inherit; font-size: 13px; color: #4a4d5c; cursor: pointer; }
.seg button[aria-pressed="true"] { background: #fff; color: var(--purple); font-weight: 600; box-shadow: 0 2px 8px rgba(20, 18, 40, .08); }
.card { padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); min-width: 0; }
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { font-size: 16px; }
.grid { display: grid; gap: 18px; }
.grid.split { grid-template-columns: 1.7fr 1fr; align-items: start; }
.grid.forms { grid-template-columns: minmax(300px, .9fr) 1.6fr; align-items: start; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.kpi { padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.kpi span { display: block; font-size: 12px; color: var(--faint); }
.kpi b { display: block; margin-top: 6px; font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.small-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--line); margin-bottom: 18px; }
.small-grid div { padding: 12px 14px; background: #fff; }
.small-grid span { display: block; font-size: 11px; color: var(--faint); }
.small-grid b { font-size: 15px; font-weight: 600; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: separate; border-spacing: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
th { padding: 12px 14px; text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); background: #f7f6fb; white-space: nowrap; }
th:first-child { border-top-left-radius: var(--radius); }
th:last-child { border-top-right-radius: var(--radius); }
td { padding: 12px 14px; border-top: 1px solid #eeeef3; font-size: 14px; color: #33354a; vertical-align: middle; }
td small { display: block; color: var(--faint); font-size: 12px; }
td code, .code-inline { padding: 3px 7px; border-radius: 6px; background: var(--purple-soft); color: #5b3de0; font-size: 12px; }
tr.total td { background: #fbfaff; font-weight: 600; }
.empty { margin: 0; padding: 36px; text-align: center; color: var(--faint); background: #fff; border: 1px dashed #d7d8e1; border-radius: var(--radius); }

/* ---------- misc bits ---------- */
.tag { display: inline-block; padding: 3px 9px; border-radius: 999px; background: #f1f1f6; font-size: 12px; font-weight: 560; }
.tag.ok { background: var(--green-bg); color: var(--green); }
.tag.hold { background: var(--amber-bg); color: var(--amber); }
.tag.no { background: var(--red-bg); color: var(--red); }
.tag.purple { background: var(--purple-soft); color: var(--purple); }
.dot-status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dot-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.dot-status.off::before { background: #b5b7c3; }
.dot-status.warn::before { background: #e0a100; }
.code-box { position: relative; margin-top: 12px; padding: 14px 96px 14px 16px; border-radius: 12px; background: #171922; color: #e7e3ff; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; line-height: 1.6; word-break: break-all; }
.code-box button { position: absolute; top: 10px; right: 10px; height: 30px; padding: 0 12px; border: 0; border-radius: 8px; background: rgba(255, 255, 255, .14); color: #fff; font: inherit; font-size: 12px; cursor: pointer; }
.code-box button:hover { background: var(--purple); }
.list { display: grid; gap: 12px; }
.item { display: grid; gap: 10px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fcfcfe; }
.item-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.item small { color: var(--muted); font-size: 12.5px; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .track { height: 8px; border-radius: 999px; background: #f0eff6; overflow: hidden; }
.bar-row .track i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--purple-2), var(--purple)); }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-size: 11px; fill: var(--faint); font-family: inherit; }
.chart .grid-line { stroke: #eeeef3; }
.chart .line-a { fill: none; stroke: var(--purple); stroke-width: 2.4; stroke-linejoin: round; }
.chart .line-b { fill: none; stroke: #22242e; stroke-width: 1.6; stroke-dasharray: 5 4; stroke-linejoin: round; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 2px; margin-right: 6px; vertical-align: middle; background: var(--purple); }
.legend .b::before { background: #22242e; }
.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 60; transform: translate(-50%, 12px);
  padding: 12px 18px; border-radius: 12px; background: #171922; color: #fff; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s var(--ease);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .25);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.loading { padding: 60px; text-align: center; color: var(--faint); }

@media (max-width: 980px) {
  .grid.split, .grid.forms { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .small-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 560px) {
  .two, .three { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .small-grid { grid-template-columns: repeat(2, 1fr); }
  .wrap { padding-bottom: 60px; }
}
