:root {
  --canvas: #f8fafc;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-light: #eef2ff;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --input-bg: #ffffff;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(79, 70, 229, .08), transparent 30rem),
    linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 276px minmax(0, 1fr); }
.sidebar {
  margin: 16px 0 16px 16px;
  height: calc(100vh - 32px);
  position: sticky;
  top: 16px;
  padding: 18px;
  border: 1px solid rgba(226, 232, 240, .85);
  border-radius: 28px;
  background: rgba(255, 255, 255, .78);
  box-shadow: 0 20px 45px rgba(15, 23, 42, .08);
  backdrop-filter: blur(18px);
}
.brand { display: flex; gap: 12px; align-items: center; padding: 6px 6px 20px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.brand-icon {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  letter-spacing: -.03em;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  box-shadow: 0 12px 24px rgba(79, 70, 229, .22);
}
h1, h2, h3, p { margin: 0; }
.brand h1 { font-size: 17px; letter-spacing: -.03em; }
.brand p, .topbar p, .card p { color: var(--muted); margin-top: 5px; font-size: 13px; }
.side-nav { display: grid; gap: 8px; }
.nav-item {
  width: 100%;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: #475569;
  padding: 12px 14px;
  text-align: left;
  font-size: 14px;
  font-weight: 700;
}
.nav-item:hover { background: #f1f5f9; color: var(--accent); }
.nav-item.active { background: var(--accent-light); color: var(--accent-strong); box-shadow: inset 0 0 0 1px rgba(79, 70, 229, .1); }
.content { padding: 24px; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 18px 20px;
  border: 1px solid rgba(226, 232, 240, .85);
  border-radius: 26px;
  background: rgba(255, 255, 255, .75);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
  backdrop-filter: blur(18px);
}
.topbar h2 { font-size: 26px; letter-spacing: -.04em; }
.top-actions, .form-actions, .toolbar, .card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar, .card-head, .form-title { justify-content: space-between; margin-bottom: 14px; }
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
  transition: box-shadow .2s ease, border-color .2s ease, transform .2s ease;
}
.metric:hover, .card:hover { border-color: #dbe2ee; box-shadow: 0 18px 40px rgba(15, 23, 42, .08); }
.metric { padding: 16px; color: var(--muted); font-size: 13px; font-weight: 700; }
.metric b { display: block; margin-top: 8px; color: var(--text); font-size: 26px; letter-spacing: -.04em; }
.page { display: none; }
.page.active { display: block; animation: panel-fade-up .18s ease both; margin-bottom: 18px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.wide { grid-column: 1 / -1; }
.card { padding: 18px; margin-bottom: 16px; }
.card h3, .toolbar h3 { font-size: 17px; letter-spacing: -.02em; }
.form-panel.hidden { display: none; }
.form-title { display: flex; align-items: center; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin: 16px 0; }
.form-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { display: grid; gap: 7px; color: #374151; font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, .1); }
textarea { min-height: 110px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; resize: vertical; }
button {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
  color: #374151;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 800;
  font-size: 13px;
  transition: background .15s ease, color .15s ease, transform .15s ease, box-shadow .15s ease;
}
button:hover { color: var(--accent); background: var(--accent-light); transform: translateY(-1px); }
button.primary { border-color: var(--accent); background: var(--accent); color: #fff; box-shadow: 0 10px 22px rgba(79, 70, 229, .22); }
button.primary:hover { background: var(--accent-strong); color: #fff; }
button.danger { border-color: #fecaca; background: #fef2f2; color: var(--danger); }
button.danger:hover { background: #fee2e2; color: #991b1b; }
code { display: block; padding: 12px; background: #f8fafc; border: 1px solid var(--line); border-radius: 14px; color: #475569; word-break: break-all; margin-top: 12px; font-size: 13px; }
.table-wrap { overflow-x: auto; border: 1px solid #eef2f7; border-radius: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; overflow: hidden; }
th, td { border-bottom: 1px solid #eef2f7; padding: 11px 12px; text-align: left; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th { color: #64748b; background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 800; }
td select { min-width: 120px; }
.badge { display: inline-flex; align-items: center; border: 1px solid #c7d2fe; background: var(--accent-light); color: var(--accent-strong); border-radius: 999px; padding: 3px 8px; margin: 2px; font-size: 12px; font-weight: 800; }
.ok { color: var(--success); font-weight: 800; }
.warn { color: var(--warning); font-weight: 800; }
.danger { color: var(--danger); font-weight: 800; }
.muted { color: var(--muted); }
.traffic-meter { position: relative; min-width: 230px; height: 42px; overflow: hidden; border: 1px solid #cbd5e1; border-radius: 8px; background: #f8fafc; box-shadow: inset 0 1px 2px rgba(15, 23, 42, .05); }
.traffic-meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 7px; transition: width .25s ease; }
.traffic-meter.ok .traffic-meter-fill { background: linear-gradient(90deg, #bbf7d0, #86efac); }
.traffic-meter.warn .traffic-meter-fill { background: linear-gradient(90deg, #fde68a, #fbbf24); }
.traffic-meter.danger .traffic-meter-fill { background: linear-gradient(90deg, #fecaca, #f87171); }
.traffic-meter-text { position: relative; z-index: 1; display: grid; place-items: center; height: 100%; padding: 0 10px; color: #0f172a; font-size: 13px; font-weight: 800; text-align: center; }
.traffic-meter-caption { margin-top: 4px; color: var(--muted); font-size: 12px; text-align: center; }
.log-summary { margin-top: 10px; color: var(--muted); font-size: 13px; text-align: right; }
.ordered-list { margin: 0; padding-left: 22px; }
.ordered-list li { margin: 8px 0; }
.empty { color: var(--muted); padding: 14px; background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 16px; }
.toast { position: fixed; right: 22px; top: 22px; z-index: 50; max-width: 360px; padding: 12px 14px; border-radius: 14px; background: #111827; color: #fff; box-shadow: 0 18px 45px rgba(15, 23, 42, .22); font-size: 14px; font-weight: 700; animation: panel-fade-up .16s ease both; }
.toast.hidden { display: none; }
.toast.ok { background: #065f46; color: #ecfdf5; }
.toast.error { background: #991b1b; color: #fef2f2; }
.login-gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(248, 250, 252, .82); backdrop-filter: blur(18px); }
.login-gate.hidden { display: none; }
.login-card { width: min(440px, 100%); display: grid; gap: 14px; padding: 28px; border: 1px solid var(--line); border-radius: 28px; background: var(--panel); box-shadow: 0 24px 60px rgba(15, 23, 42, .16); animation: panel-fade-up .18s ease both; }
.login-card .brand-icon { margin-bottom: 2px; }
.login-card h2 { letter-spacing: -.04em; }

@keyframes panel-fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #0f172a;
    --panel: #1e293b;
    --line: #334155;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --accent: #818cf8;
    --accent-strong: #6366f1;
    --accent-light: #312e81;
    --input-bg: #1e293b;
  }
  body { background: radial-gradient(circle at top left, rgba(129, 140, 248, .16), transparent 28rem), #0f172a; }
  .sidebar, .topbar { background: rgba(30, 41, 59, .76); border-color: rgba(51, 65, 85, .82); }
  .nav-item { color: #cbd5e1; }
  .nav-item:hover { background: #334155; }
  button { background: #1e293b; color: #e2e8f0; border-color: #334155; }
  button:hover { background: #334155; }
  input, select, textarea, code, .empty, th { background: #1e293b; border-color: #334155; color: var(--text); }
  .table-wrap, th, td { border-color: #334155; }
  .traffic-meter { background: #0f172a; border-color: #475569; }
  .traffic-meter-text { color: #0f172a; }
}

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; margin: 12px; }
  .content { padding: 12px; }
  .side-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid, .summary, .form-grid, .form-grid.compact { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
}
