/* ===================== KALITRACK UI ===================== */
:root {
  --bg: #f4f5f7;
  --bg-2: #ffffff;
  --bg-3: #f0f1f4;
  --text: #15171c;
  --text-2: #5b616e;
  --text-3: #8a90a0;
  --border: #e3e5ea;
  --border-2: #d2d5dc;
  --primary: #111318;
  --primary-text: #ffffff;
  --accent: #2f6bff;
  --accent-soft: rgba(47,107,255,.12);
  --success: #17a36a;
  --success-soft: rgba(23,163,106,.13);
  --warning: #d98a00;
  --warning-soft: rgba(217,138,0,.14);
  --danger: #d93a3a;
  --danger-soft: rgba(217,58,58,.13);
  --info: #2f6bff;
  --info-soft: rgba(47,107,255,.12);
  --meta: #1877f2;
  --kwai: #ff5e00;
  --shadow: 0 1px 2px rgba(16,20,30,.05), 0 4px 14px rgba(16,20,30,.05);
  --radius: 12px;
  --sidebar-w: 248px;
  --font: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", Consolas, "Courier New", monospace;
}
[data-theme="dark"] {
  --bg: #0d0f13;
  --bg-2: #15181e;
  --bg-3: #1c2027;
  --text: #f1f3f7;
  --text-2: #a7adba;
  --text-3: #6e7585;
  --border: #262b35;
  --border-2: #333945;
  --primary: #ffffff;
  --primary-text: #0d0f13;
  --accent: #5b8cff;
  --accent-soft: rgba(91,140,255,.16);
  --success: #2ecc8a;
  --success-soft: rgba(46,204,138,.16);
  --warning: #f2a93b;
  --warning-soft: rgba(242,169,59,.16);
  --danger: #ff5f5f;
  --danger-soft: rgba(255,95,95,.16);
  --info: #5b8cff;
  --info-soft: rgba(91,140,255,.16);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.muted { color: var(--text-2); } .small { font-size: 12px; } .tiny { font-size: 11px; }
.text-right { text-align: right; } .text-center { text-align: center; }
.mt-1{margin-top:8px}.mt-2{margin-top:16px}.mt-3{margin-top:24px}.mb-1{margin-bottom:8px}.mb-2{margin-bottom:16px}.mb-3{margin-bottom:24px}
.flex { display: flex; align-items: center; gap: 10px; } .flex-wrap { flex-wrap: wrap; } .between { justify-content: space-between; } .grow { flex: 1; }
.hide { display: none !important; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--bg-2); border-right: 1px solid var(--border); position: fixed; top: 0; bottom: 0; left: 0; display: flex; flex-direction: column; z-index: 40; transition: transform .2s; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 14px; font-weight: 800; font-size: 18px; letter-spacing: -.02em; color: var(--text); }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--primary); color: var(--primary-text); display: grid; place-items: center; font-size: 15px; font-weight: 800; }
.brand small { display: block; font-size: 10px; font-weight: 600; color: var(--text-3); letter-spacing: .08em; text-transform: uppercase; }
.nav { padding: 6px 12px; flex: 1; overflow-y: auto; }
.nav-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-3); padding: 14px 10px 6px; font-weight: 700; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 9px; color: var(--text-2); font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--bg-3); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary); color: var(--primary-text); }
.nav a svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.user-card { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.user-card .name { font-weight: 600; font-size: 13px; line-height: 1.2; }
.user-card .mail { font-size: 11px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 28px; background: var(--bg-2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
.topbar .title { font-weight: 650; font-size: 15px; }
.topbar .crumbs { color: var(--text-3); font-size: 12.5px; }
.content { padding: 28px; flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { color: var(--text-2); margin: 0; }

.burger { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; color: var(--text); cursor: pointer; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 35; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 15px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--bg-2); color: var(--text); font-weight: 600; font-size: 13px; cursor: pointer; font-family: inherit; line-height: 1.2; transition: .15s; white-space: nowrap; }
.btn:hover { background: var(--bg-3); text-decoration: none; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn-primary:hover { opacity: .88; background: var(--primary); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { opacity: .9; background: var(--accent); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn-xs { padding: 3px 8px; font-size: 11.5px; border-radius: 6px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-icon { padding: 7px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---------- Cards / Stats ---------- */
.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 20px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); } .grid-main { grid-template-columns: 2fr 1fr; } .grid-side { grid-template-columns: 1.4fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } .grid-4 { grid-template-columns: repeat(4, 1fr); }
.stat { padding: 18px 20px; }
.stat .label { font-size: 12px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; align-items: center; }
.stat .value { font-size: 26px; font-weight: 750; letter-spacing: -.02em; margin-top: 6px; line-height: 1.1; }
.stat .sub { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.stat .icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.stat .icon svg { width: 16px; height: 16px; }
.stat .icon.success { background: var(--success-soft); color: var(--success); }
.stat .icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat .icon.danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; line-height: 1.4; white-space: nowrap; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--bg-3); color: var(--text-2); }
.badge-meta { background: rgba(24,119,242,.14); color: var(--meta); }
.badge-kwai { background: rgba(255,94,0,.14); color: var(--kwai); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- Forms ---------- */
label.lbl, .lbl { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.input, select.input, textarea.input { width: 100%; padding: 9px 12px; border: 1px solid var(--border-2); border-radius: 9px; background: var(--bg-2); color: var(--text); font-family: inherit; font-size: 13.5px; outline: none; transition: .15s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 90px; resize: vertical; }
.field { margin-bottom: 14px; }
.help { font-size: 12px; color: var(--text-3); margin-top: 5px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; }
.copy-box { display: flex; align-items: center; gap: 8px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px; font-family: var(--mono); font-size: 12.5px; word-break: break-all; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); font-weight: 700; padding: 11px 14px; border-bottom: 1px solid var(--border); background: var(--bg-3); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--bg-3); }
.table .actions { white-space: nowrap; text-align: right; }
.empty { padding: 40px 20px; text-align: center; color: var(--text-3); }
.empty svg { width: 36px; height: 36px; opacity: .4; margin-bottom: 8px; }

/* ---------- Alerts ---------- */
.alert { padding: 11px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 14px; border: 1px solid transparent; display: flex; gap: 10px; align-items: flex-start; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-info { background: var(--info-soft); color: var(--info); }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.seg { display: inline-flex; background: var(--bg-3); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.seg a, .seg button { padding: 6px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--text-2); border: 0; background: transparent; cursor: pointer; font-family: inherit; }
.seg a.active, .seg button.active { background: var(--bg-2); color: var(--text); box-shadow: var(--shadow); }
.seg a:hover { text-decoration: none; color: var(--text); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; font-weight: 600; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--text); border-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; z-index: 100; align-items: center; justify-content: center; padding: 20px; }
.modal-bg.open { display: flex; }
.modal { background: var(--bg-2); border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; box-shadow: var(--shadow); border: 1px solid var(--border); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
pre.json { background: var(--bg-3); border: 1px solid var(--border); border-radius: 9px; padding: 12px; font-size: 12px; overflow: auto; max-height: 320px; margin: 0; font-family: var(--mono); white-space: pre-wrap; word-break: break-all; }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: #0d0f13; color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-side::before { content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%; background: radial-gradient(circle, rgba(91,140,255,.35), transparent 65%); top: -140px; right: -140px; }
.auth-side::after { content: ""; position: absolute; width: 420px; height: 420px; border-radius: 50%; background: radial-gradient(circle, rgba(255,94,0,.28), transparent 65%); bottom: -160px; left: -120px; }
.auth-side > * { position: relative; }
.auth-side h2 { font-size: 30px; line-height: 1.2; margin-bottom: 12px; }
.auth-side p { color: rgba(255,255,255,.7); max-width: 420px; font-size: 15px; }
.auth-side .feat { display: flex; gap: 10px; margin-top: 12px; color: rgba(255,255,255,.85); }
.auth-side .feat svg { width: 18px; height: 18px; color: #5b8cff; flex-shrink: 0; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-box { width: 100%; max-width: 400px; }
.auth-box h1 { font-size: 24px; margin-bottom: 4px; }
.auth-box .sub { color: var(--text-2); margin-bottom: 24px; }

/* ---------- Plans ---------- */
.plan { padding: 24px; display: flex; flex-direction: column; gap: 10px; position: relative; }
.plan.current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.plan .pname { font-weight: 700; font-size: 15px; }
.plan .price { font-size: 30px; font-weight: 800; letter-spacing: -.03em; }
.plan .price small { font-size: 13px; color: var(--text-3); font-weight: 500; }
.plan ul { list-style: none; padding: 0; margin: 4px 0 8px; color: var(--text-2); font-size: 13px; }
.plan ul li { padding: 4px 0; display: flex; gap: 8px; }
.plan ul li::before { content: "✓"; color: var(--success); font-weight: 700; }
.progress { height: 8px; background: var(--bg-3); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.progress > span.warn { background: var(--warning); } .progress > span.full { background: var(--danger); }

/* ---------- Theme switch ---------- */
.theme-toggle { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 4px; background: var(--bg-3); cursor: pointer; }
.theme-toggle span { width: 28px; height: 24px; display: grid; place-items: center; border-radius: 999px; color: var(--text-3); }
.theme-toggle span.active { background: var(--bg-2); color: var(--text); box-shadow: var(--shadow); }
.theme-toggle svg { width: 14px; height: 14px; }

.chart-box { position: relative; height: 280px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); font-weight: 600; } .kv dd { margin: 0; word-break: break-all; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--primary); color: var(--primary-text); padding: 10px 16px; border-radius: 9px; font-size: 13px; z-index: 200; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }

.pagination { display: flex; gap: 4px; flex-wrap: wrap; }
.pagination a { padding: 6px 11px; border-radius: 7px; border: 1px solid var(--border); font-size: 12.5px; color: var(--text-2); }
.pagination a.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  body.nav-open .sidebar { transform: none; } body.nav-open .overlay { display: block; }
  .main { margin-left: 0; } .burger { display: inline-flex; }
  .content { padding: 16px; } .topbar { padding: 0 16px; }
  .auth { grid-template-columns: 1fr; } .auth-side { display: none; }
  .grid-2, .grid-3, .grid-4, .grid-main, .grid-side { grid-template-columns: 1fr; } .form-row { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
