:root {
  --bg: #f3f5fa; --card: #ffffff; --text: #1a2233; --muted: #6a7488; --line: #e5e8f0;
  --primary: #2f6bff; --primary-soft: #e8efff; --primary-text: #ffffff;
  --ok: #16a34a; --ok-soft: #e3f6ea; --warn: #c27803; --warn-soft: #fdf1d9;
  --bad: #dc2626; --bad-soft: #fde8e8; --gray-soft: #eceef4;
  --shadow: 0 1px 2px rgba(20, 30, 55, .06), 0 4px 16px rgba(20, 30, 55, .05);
  --radius: 14px; --side: 236px;
  --c1: #2f6bff; --c2: #16a34a; --c3: #f59e0b; --c4: #8b5cf6; --c5: #ef4444;
}
[data-theme="dark"] {
  --bg: #0e131f; --card: #161d2c; --text: #e7ebf4; --muted: #8b96ac; --line: #242d42;
  --primary: #5b8bff; --primary-soft: #1b2850; --primary-text: #0b1020;
  --ok: #34d17a; --ok-soft: #12301f; --warn: #f2b13d; --warn-soft: #3a2c0f;
  --bad: #ff6b6b; --bad-soft: #3b1819; --gray-soft: #202839;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --c1: #5b8bff; --c2: #34d17a; --c3: #f2b13d; --c4: #a78bfa; --c5: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.right { text-align: right; } .nowrap { white-space: nowrap; } .grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: var(--card); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 700; font-size: 16px; }
.brand i { width: 30px; height: 30px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; }
.brand svg { width: 18px; height: 18px; fill: #fff; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--gray-soft); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav .ico { width: 20px; text-align: center; }
.nav .count { margin-left: auto; background: var(--primary); color: var(--primary-text); border-radius: 20px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; }
.main { min-width: 0; padding: 22px 26px 60px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card > h2 { margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12.5px; display: flex; gap: 6px; align-items: center; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.3px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .sub b { color: var(--ok); font-weight: 600; }
.chart { width: 100%; min-height: 200px; position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 8px; padding: 6px 9px; font-size: 12px; z-index: 5; white-space: nowrap; box-shadow: var(--shadow); transform: translate(-50%, -100%); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--gray-soft); white-space: nowrap; position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; } th.sortable:hover { color: var(--text); }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover td { background: var(--primary-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-user b { display: block; font-weight: 600; } .cell-user span { color: var(--muted); font-size: 12px; }
.ellipsis { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 2px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; line-height: 1.2; }
.btn:hover { background: var(--gray-soft); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); } .btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); background: var(--bad-soft); }
.btn.ok { color: var(--ok); border-color: var(--ok-soft); background: var(--ok-soft); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.input, select, textarea { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; outline: none; max-width: 100%; }
.input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { width: 100%; min-height: 120px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 5px; } .field label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters .input { min-width: 220px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 6px 0 14px; overflow-x: auto; }
.tab { padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; white-space: nowrap; background: none; border-top: 0; border-left: 0; border-right: 0; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--gray-soft); color: var(--muted); }
.badge.running { background: var(--primary-soft); color: var(--primary); } .badge.done, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.partial, .badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.failed, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.progress { height: 8px; background: var(--gray-soft); border-radius: 8px; overflow: hidden; min-width: 90px; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: 8px; transition: width .4s; }
.progress.done > i { background: var(--ok); } .progress.warn > i { background: var(--warn); } .progress.bad > i { background: var(--bad); }
.switch { width: 38px; height: 22px; border-radius: 22px; background: var(--line); position: relative; border: 0; cursor: pointer; padding: 0; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch.on { background: var(--ok); } .switch.on::after { transform: translateX(16px); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; font-size: 15px; color: var(--text); margin-bottom: 4px; }
.skeleton { height: 90px; border-radius: var(--radius); background: linear-gradient(90deg, var(--gray-soft), var(--card), var(--gray-soft)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }
.profile { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.avatar { width: 54px; height: 54px; border-radius: 16px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.live-card { display: flex; flex-direction: column; gap: 10px; }
.live-card .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.live-card .nums { display: flex; gap: 16px; font-size: 13px; flex-wrap: wrap; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 7px 18px; }
.dl dt { color: var(--muted); } .dl dd { margin: 0; word-break: break-word; }

/* ---------- modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 12, 24, .5); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .15s; }
.modal { background: var(--card); border-radius: 16px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.modal.wide { max-width: 640px; }
.modal h2 { margin-bottom: 14px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); animation: fade .2s; max-width: 340px; }
.toast.bad { background: var(--bad); color: #fff; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 8px 10px; overflow-x: auto; gap: 4px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 8px 0 4px; } .brand span, .side-foot { display: none; }
  .nav { display: flex; gap: 2px; } .nav a { white-space: nowrap; padding: 8px 10px; }
  .main { padding: 16px 14px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  h1 { font-size: 19px; } .kpi .value { font-size: 20px; } .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters .input { min-width: 0; flex: 1 1 100%; }
  .nav .lbl { display: none; } .nav a.active .lbl { display: inline; }
}
