:root {
  --bg: #0b0f17;
  --bg-2: #111827;
  --panel: #151d2b;
  --panel-2: #1b2536;
  --border: #263247;
  --text: #e8eef8;
  --muted: #8b9bb4;
  --accent: #5b8cff;
  --accent-2: #22d3ee;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #fb7185;
  --shadow: 0 18px 50px rgba(0, 0, 0, .35);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 85% -10%, rgba(91, 140, 255, .18), transparent 60%),
    radial-gradient(900px 600px at 0% 100%, rgba(34, 211, 238, .10), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px;
  flex: 0 0 250px;
  border-right: 1px solid var(--border);
  background: rgba(12, 18, 29, .72);
  backdrop-filter: blur(14px);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-stacked { flex-direction: column; align-items: flex-start; gap: 6px; }
.brand-logo { display: block; width: 210px; max-width: 100%; height: auto; }
.login-card .brand-stacked { align-items: center; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #041020; font-weight: 800;
}
.brand-name { font-weight: 700; letter-spacing: .02em; }
.brand-sub { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav button {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; color: var(--muted);
  padding: 10px 12px; border-radius: 10px; cursor: pointer; text-align: left;
}
.nav button:hover { background: rgba(91, 140, 255, .10); color: var(--text); }
.nav button.active { background: rgba(91, 140, 255, .16); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav .icon { width: 18px; text-align: center; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot .who { color: var(--muted); font-size: 12px; padding: 0 8px; word-break: break-all; }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.topbar .sub { color: var(--muted); margin-top: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  background: linear-gradient(180deg, rgba(255,255,255,.025), transparent), var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card.tight { padding: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 8px; }
.stat-value.small { font-size: 20px; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 6px; }
.stat-accent { color: var(--accent); }
.stat-green { color: var(--green); }
.stat-yellow { color: var(--yellow); }
.stat-red { color: var(--red); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #3b4f70; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #7c5cff); border-color: transparent; color: white; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(251, 113, 133, .12); border-color: rgba(251, 113, 133, .35); color: #fecdd3; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { color: var(--muted); font-size: 12px; }
.field input, .field select, .field textarea {
  width: 100%; background: #0e1521; border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 9px 11px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,.12); }
.field textarea { min-height: 74px; resize: vertical; }
.field .hint { color: var(--muted); font-size: 11px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid rgba(38, 50, 71, .7); vertical-align: middle; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; background: rgba(255,255,255,.02); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(91, 140, 255, .05); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px;
  font-size: 11px; border: 1px solid var(--border); color: var(--muted); background: rgba(255,255,255,.02);
}
.badge.green { color: #a7f3d0; border-color: rgba(52, 211, 153, .35); background: rgba(52, 211, 153, .10); }
.badge.yellow { color: #fde68a; border-color: rgba(251, 191, 36, .35); background: rgba(251, 191, 36, .10); }
.badge.red { color: #fecdd3; border-color: rgba(251, 113, 133, .35); background: rgba(251, 113, 133, .10); }
.badge.blue { color: #bfdbfe; border-color: rgba(91, 140, 255, .35); background: rgba(91, 140, 255, .10); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 160px; }
.search { position: relative; }
.search input { width: 100%; padding-left: 34px; }
.search::before { content: "⌕"; position: absolute; left: 12px; top: 8px; color: var(--muted); }

.empty { color: var(--muted); text-align: center; padding: 34px 10px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { background: transparent; border: 0; color: var(--muted); padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.chart { width: 100%; height: 190px; display: block; }
.chart-legend { display: flex; gap: 16px; color: var(--muted); font-size: 12px; margin-top: 8px; }
.chart-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 10px; }
.bar { flex: 1; background: linear-gradient(180deg, var(--accent), rgba(91,140,255,.18)); border-radius: 4px 4px 2px 2px; min-height: 2px; position: relative; }
.bar:hover { filter: brightness(1.2); }
.bar span { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; opacity: 0; }
.bar:hover span { opacity: 1; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(3, 7, 14, .72); backdrop-filter: blur(4px);
  display: none; align-items: flex-start; justify-content: center; padding: 34px 16px; z-index: 50; overflow: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(980px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 30px 90px rgba(0,0,0,.6); overflow: hidden;
}
.modal.small { width: min(520px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: rgba(0,0,0,.12); }
.icon-btn { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 20px; line-height: 1; }
.icon-btn:hover { color: var(--text); }

.toast {
  position: fixed; right: 22px; bottom: 22px; z-index: 80;
  background: #182234; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 16px; box-shadow: var(--shadow); max-width: 420px; display: none;
}
.toast.show { display: block; animation: slide .18s ease-out; }
.toast.error { border-color: rgba(251,113,133,.55); }
.toast.success { border-color: rgba(52,211,153,.55); }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); }
.login-card .brand { justify-content: center; margin-bottom: 18px; }
.login-tabs { display: flex; gap: 6px; background: #0e1521; padding: 4px; border-radius: 10px; margin: 16px 0; }
.login-tabs button { flex: 1; background: transparent; border: 0; color: var(--muted); padding: 8px; border-radius: 8px; cursor: pointer; }
.login-tabs button.active { background: var(--panel-2); color: var(--text); }
.login-note { color: var(--muted); font-size: 12px; text-align: center; margin-top: 14px; }

.code {
  background: #0a111c; border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; overflow: auto; color: #c7d5ef; font-size: 12px; line-height: 1.6;
}
.code .k { color: #93c5fd; }
.code .s { color: #86efac; }
.code .c { color: #6b7c96; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row .mono { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.split { display: grid; grid-template-columns: 1.15fr .85fr; gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: rgba(255,255,255,.015); }
.list-item .meta { color: var(--muted); font-size: 12px; }

.loading { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1080px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; padding: 12px; }
  .sidebar .nav { flex-direction: row; }
  .sidebar-foot { display: none; }
  .brand-sub { display: none; }
  .brand-logo { width: 150px; }
  .main { padding: 18px 14px 50px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2, .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
  .kv { grid-template-columns: 1fr; }
}

/* ============================ mobile touch targets ============================ */

@media (max-width: 760px) {
  .btn { min-height: 44px; padding: 11px 14px; }
  .btn.small { min-height: 38px; padding: 8px 10px; font-size: 12px; }
  .sidebar { flex-wrap: wrap; overflow-x: visible; }
  .sidebar .nav {
    flex: 1 1 100%;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }
  .sidebar .nav button {
    justify-content: center;
    min-height: 44px;
    padding: 8px 4px;
    font-size: 10px;
    gap: 4px;
    white-space: nowrap;
  }
  .sidebar .nav .icon { width: auto; }
  .tabs button { min-height: 44px; padding: 10px 12px; }
  .icon-btn { min-width: 44px; min-height: 44px; }
  .field input, .field select, .field textarea { min-height: 44px; }
  .modal-head { padding: 16px; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px; }
}
