:root {
  --bg: #080b11;
  --surface: #0e131c;
  --surface-2: #131a25;
  --surface-3: #192231;
  --border: #232d3c;
  --text: #edf3fa;
  --muted: #8794a6;
  --faint: #596678;
  --green: #48d7a4;
  --green-strong: #24b984;
  --blue: #6d8cff;
  --red: #f1727b;
  --amber: #e8b75c;
  --radius: 16px;
  --shadow: 0 24px 70px rgba(0, 0, 0, .34);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 75% -10%, rgba(69, 104, 255, .11), transparent 32rem),
    radial-gradient(circle at 10% 100%, rgba(72, 215, 164, .06), transparent 28rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}
button, input { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
svg { display: block; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  width: 246px;
  padding: 28px 18px 22px;
  display: flex;
  flex-direction: column;
  background: rgba(10, 14, 21, .92);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 10px 34px; color: var(--text); text-decoration: none; }
.brand-mark {
  width: 40px; height: 40px; border: 1px solid rgba(72, 215, 164, .42); border-radius: 11px;
  display: grid; place-items: center; color: var(--green); background: rgba(72, 215, 164, .08);
  font: 700 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .05em;
}
.brand-mark.large { width: 52px; height: 52px; border-radius: 14px; font-size: 16px; }
.brand-copy { display: grid; gap: 2px; }
.brand-copy strong { font-size: 17px; letter-spacing: .02em; }
.brand-copy small { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; }
.nav { display: grid; gap: 6px; }
.nav-item, .logout-button, .docs-link {
  width: 100%; min-height: 44px; padding: 0 13px; border: 0; border-radius: 10px;
  display: flex; align-items: center; gap: 12px; color: var(--muted); background: transparent;
  text-decoration: none; cursor: pointer; transition: .18s ease;
}
.nav-item:hover, .logout-button:hover, .docs-link:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { color: var(--text); background: linear-gradient(90deg, rgba(72, 215, 164, .15), rgba(72, 215, 164, .04)); box-shadow: inset 3px 0 var(--green); }
.nav-item svg, .logout-button svg, .docs-link svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-item svg { fill: currentColor; stroke: none; }
.sidebar-footer { margin-top: auto; display: grid; gap: 4px; border-top: 1px solid var(--border); padding-top: 14px; }

.main { margin-left: 246px; min-height: 100vh; padding: 0 34px 48px; }
.topbar {
  min-height: 112px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid rgba(35, 45, 60, .65); margin-bottom: 28px;
}
.topbar h1 { margin: 3px 0 0; font-size: 25px; line-height: 1.2; letter-spacing: -.03em; }
.eyebrow, .panel-kicker { margin: 0; color: var(--green); font-size: 10px; font-weight: 700; letter-spacing: .17em; }
.topbar-status { display: grid; grid-template-columns: auto auto; align-items: center; gap: 3px 8px; color: var(--muted); font-size: 13px; }
.topbar-status small { grid-column: 2; color: var(--faint); font-size: 11px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 5px rgba(232, 183, 92, .08); }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 5px rgba(72, 215, 164, .08); }
.status-dot.offline { background: var(--red); box-shadow: 0 0 0 5px rgba(241, 114, 123, .08); }
.mobile-menu { display: none; border: 0; background: none; padding: 8px; }
.mobile-menu svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.8; fill: none; }

.page { display: none; animation: page-in .2s ease; }
.page.active { display: block; }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.metric-card {
  min-height: 126px; padding: 22px; display: flex; align-items: center; gap: 16px;
  background: linear-gradient(145deg, rgba(19, 26, 37, .94), rgba(13, 18, 27, .94));
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 34px rgba(0, 0, 0, .12);
}
.metric-card > div:last-child { min-width: 0; display: grid; gap: 5px; }
.metric-card span { color: var(--muted); font-size: 12px; }
.metric-card strong { font-size: clamp(22px, 2.1vw, 30px); letter-spacing: -.045em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-card small { color: var(--faint); font-size: 11px; }
.metric-icon { flex: 0 0 42px; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: var(--green); background: rgba(72, 215, 164, .09); }
.metric-icon.upload { color: var(--green); }
.metric-icon.download { color: var(--blue); background: rgba(109, 140, 255, .1); }
.metric-icon.health { color: var(--amber); background: rgba(232, 183, 92, .08); }
.metric-icon svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(270px, .9fr); gap: 18px; margin-bottom: 18px; }
.panel { background: rgba(14, 19, 28, .9); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 16px 42px rgba(0, 0, 0, .12); overflow: hidden; }
.panel-header { min-height: 76px; padding: 0 22px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--border); }
.panel-header h2 { margin: 5px 0 0; font-size: 16px; letter-spacing: -.01em; }
.chart-legend { display: flex; gap: 15px; color: var(--muted); font-size: 11px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 8px; height: 8px; border-radius: 50%; }
.legend-upload { background: var(--green); }
.legend-download { background: var(--blue); }
.chart-wrap { position: relative; height: 310px; padding: 22px 18px 28px; }
#trafficChart { width: 100%; height: 245px; overflow: visible; }
.chart-grid path { fill: none; stroke: #222b39; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-area { stroke: none; }
.upload-line { stroke: var(--green); }
.download-line { stroke: var(--blue); }
.upload-area { fill: url(#uploadFill); }
.download-area { fill: url(#downloadFill); }
.chart-scale { position: absolute; inset: 18px 18px auto; display: flex; justify-content: space-between; color: var(--faint); font-size: 10px; pointer-events: none; }
.system-list { margin: 0; padding: 8px 22px 14px; }
.system-list div { min-height: 48px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(35, 45, 60, .64); }
.system-list div:last-child { border-bottom: 0; }
.system-list dt { color: var(--muted); }
.system-list dd { margin: 0; font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.text-action { border: 0; color: var(--green); background: none; cursor: pointer; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 22px; text-align: left; border-bottom: 1px solid rgba(35, 45, 60, .65); white-space: nowrap; }
th { color: var(--faint); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; font-weight: 600; }
td { color: var(--muted); font-size: 12px; }
td strong { color: var(--text); display: block; font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
.empty-cell { padding: 36px; text-align: center; color: var(--faint); }
.state-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; color: var(--green); background: rgba(72, 215, 164, .08); font-size: 10px; font-weight: 700; letter-spacing: .05em; }
.state-badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.state-badge.off { color: var(--faint); background: rgba(89, 102, 120, .1); }
.state-badge.error { color: var(--red); background: rgba(241, 114, 123, .08); }

.section-toolbar { margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.section-toolbar p { margin: 0; color: var(--muted); line-height: 1.7; }
.primary-button, .secondary-button, .danger-button {
  min-height: 42px; padding: 0 17px; border-radius: 10px; border: 1px solid transparent;
  display: inline-flex; justify-content: center; align-items: center; gap: 8px; font-weight: 650; font-size: 12px; cursor: pointer; transition: .18s ease;
}
.primary-button { color: #07110d; background: var(--green); }
.primary-button:hover { background: #67e2b7; transform: translateY(-1px); }
.secondary-button { color: var(--text); border-color: var(--border); background: var(--surface-2); }
.danger-button { color: var(--red); border-color: rgba(241, 114, 123, .2); background: rgba(241, 114, 123, .06); }
.primary-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.wide { width: 100%; }
.rule-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.rule-card { padding: 22px; background: rgba(14, 19, 28, .92); border: 1px solid var(--border); border-radius: var(--radius); }
.rule-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 24px; }
.rule-card h2 { margin: 0 0 5px; font-size: 16px; }
.rule-card-id { color: var(--faint); font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.rule-route { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: rgba(8, 11, 17, .42); }
.route-node { min-width: 0; }
.route-node span { color: var(--faint); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.route-node strong { display: block; margin-top: 5px; overflow: hidden; color: var(--text); font: 600 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; }
.route-arrow { color: var(--green); }
.route-arrow svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.rule-metrics { margin: 18px 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.rule-metrics div { padding: 12px; border-radius: 10px; background: var(--surface-2); }
.rule-metrics span { color: var(--faint); font-size: 10px; }
.rule-metrics strong { display: block; margin-top: 5px; font-size: 14px; }
.rule-actions { display: flex; gap: 8px; justify-content: flex-end; }
.rule-actions button { min-height: 36px; padding: 0 12px; }

.settings-panel { max-width: 940px; }
.form-grid { padding: 24px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 21px; }
.form-grid.compact { padding: 0; }
.form-grid label { display: grid; gap: 8px; color: var(--muted); font-size: 12px; }
.form-grid label > span { color: var(--text); font-weight: 600; }
.form-grid label small { color: var(--faint); line-height: 1.45; font-size: 10px; }
input {
  width: 100%; height: 43px; padding: 0 12px; color: var(--text); background: #0a0f16;
  border: 1px solid var(--border); border-radius: 9px; outline: 0; transition: .16s ease;
}
input:focus { border-color: rgba(72, 215, 164, .7); box-shadow: 0 0 0 3px rgba(72, 215, 164, .08); }
input:disabled { color: var(--faint); cursor: not-allowed; }
.input-unit { position: relative; }
.input-unit input { padding-right: 64px; }
.input-unit b { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }
.toggle-field { grid-template-columns: 1fr auto !important; align-items: center; min-height: 67px; padding: 13px 15px; border: 1px solid var(--border); border-radius: 10px; background: rgba(8, 11, 17, .34); cursor: pointer; }
.toggle-field span { display: grid; gap: 5px; }
.toggle-field input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-field i { position: relative; width: 38px; height: 22px; border-radius: 999px; background: var(--surface-3); transition: .18s; }
.toggle-field i::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: var(--muted); transition: .18s; }
.toggle-field input:checked + i { background: rgba(72, 215, 164, .3); }
.toggle-field input:checked + i::after { left: 19px; background: var(--green); }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; padding-top: 5px; }
.full { grid-column: 1 / -1 !important; }

.modal-backdrop { position: fixed; z-index: 80; inset: 0; padding: 24px; display: grid; place-items: center; background: rgba(3, 5, 8, .76); backdrop-filter: blur(8px); }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(680px, 100%); max-height: calc(100vh - 48px); overflow-y: auto; padding: 24px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.modal-header { margin-bottom: 25px; display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { margin: 5px 0 0; }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 9px; color: var(--muted); background: var(--surface-2); cursor: pointer; }
.icon-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; }

.auth-screen { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at 50% 5%, rgba(72, 215, 164, .08), transparent 26rem), #080b11; }
.auth-screen.hidden { display: none; }
.auth-card { width: min(430px, 100%); padding: 34px; border: 1px solid var(--border); border-radius: 20px; background: rgba(14, 19, 28, .96); box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 15px; }
.auth-brand p { margin: 0 0 3px; color: var(--green); font-size: 10px; font-weight: 700; letter-spacing: .17em; }
.auth-brand h1 { margin: 0; font-size: 23px; }
.auth-copy { margin: 24px 0; color: var(--muted); line-height: 1.75; }
.auth-card form label { display: grid; gap: 8px; color: var(--muted); font-size: 12px; }
.auth-card form button { margin-top: 15px; }
.form-error { min-height: 17px; margin: 8px 0 0; color: var(--red); font-size: 11px; }
.auth-host { display: block; margin-top: 24px; color: var(--faint); text-align: center; font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.toast-stack { position: fixed; z-index: 120; right: 22px; bottom: 22px; display: grid; gap: 9px; }
.toast { min-width: 240px; max-width: 390px; padding: 13px 15px; color: var(--text); border: 1px solid var(--border); border-left: 3px solid var(--green); border-radius: 10px; background: var(--surface-2); box-shadow: var(--shadow); animation: toast-in .2s ease; }
.toast.error { border-left-color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .system-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 26px; }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 0 18px 36px; }
  .topbar { min-height: 92px; margin-bottom: 20px; }
  .mobile-menu { display: block; margin-right: 10px; }
  .topbar > div:nth-child(2) { margin-right: auto; }
  .topbar h1 { font-size: 21px; }
  .rule-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 104px; }
  .topbar-status { font-size: 0; }
  .topbar-status small { display: none; }
  .status-dot { margin-right: 3px; }
  .chart-wrap { height: 260px; padding-inline: 10px; }
  #trafficChart { height: 205px; }
  .system-list { display: block; }
  .panel-header { padding-inline: 16px; }
  th, td { padding-inline: 16px; }
  .section-toolbar { align-items: stretch; flex-direction: column; }
  .section-toolbar .primary-button { align-self: flex-start; }
  .form-grid { grid-template-columns: 1fr; padding: 18px; }
  .form-grid label, .toggle-field, .full, .form-actions { grid-column: 1 !important; }
  .rule-route { grid-template-columns: 1fr; }
  .route-arrow { transform: rotate(90deg); justify-self: center; }
  .rule-metrics { grid-template-columns: 1fr 1fr; }
  .auth-card { padding: 26px 22px; }
}

