:root {
  --bg: #0b1220;
  --bg-grad-start: #08101d;
  --bg-grad-end: #0b1220;
  --panel-grad-start: rgba(17, 26, 46, 0.95);
  --panel-grad-end: rgba(15, 23, 40, 0.98);
  --sidebar-bg: rgba(7, 12, 24, 0.78);
  --panel-border: rgba(255,255,255,0.06);
  --line: #23314d;
  --text: #e8eefc;
  --muted: #9cb0d0;
  --accent: #f48120;
  --good: #3ddc97;
  --bad: #ff6b6b;
  --eyebrow: #ffbf80;
  --card-sub: #bfd0ee;
  --code-bg: rgba(255,255,255,0.08);
  --button-ghost-bg: rgba(255,255,255,0.05);
  --button-ghost-border: rgba(255,255,255,0.08);
  --table-row-bg: rgba(255,255,255,0.02);
  --table-row-border: rgba(255,255,255,0.05);
  --chart-axis-color: rgba(255,255,255,0.12);
  --chart-grid-color: rgba(255,255,255,0.08);
  --event-border: rgba(255,255,255,0.06);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] {
  --bg: #f4f1e8;
  --bg-grad-start: #f7f2e7;
  --bg-grad-end: #efe6d3;
  --panel-grad-start: rgba(255, 252, 246, 0.96);
  --panel-grad-end: rgba(248, 242, 231, 0.98);
  --sidebar-bg: rgba(255, 247, 235, 0.88);
  --panel-border: rgba(123, 92, 54, 0.14);
  --line: #d9c7a9;
  --text: #2f2517;
  --muted: #78664c;
  --accent: #c96d16;
  --good: #168d62;
  --bad: #c94b43;
  --eyebrow: #a85b12;
  --card-sub: #5f4d37;
  --code-bg: rgba(109, 79, 42, 0.08);
  --button-ghost-bg: rgba(120, 86, 45, 0.06);
  --button-ghost-border: rgba(123, 92, 54, 0.18);
  --table-row-bg: rgba(120, 86, 45, 0.04);
  --table-row-border: rgba(123, 92, 54, 0.1);
  --chart-axis-color: rgba(120, 86, 45, 0.18);
  --chart-grid-color: rgba(120, 86, 45, 0.12);
  --event-border: rgba(123, 92, 54, 0.12);
  --shadow: 0 18px 44px rgba(115, 82, 44, 0.12);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; background: linear-gradient(180deg, var(--bg-grad-start) 0%, var(--bg-grad-end) 100%); color: var(--text); font-family: "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif; transition: background 0.25s ease, color 0.25s ease; }
body { min-width: 320px; overflow-x: hidden; }
code { background: var(--code-bg); padding: 0.1rem 0.35rem; border-radius: 0.4rem; }

.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px;
  min-width: 0;
  border-right: 1px solid var(--panel-border);
  background: var(--sidebar-bg);
  backdrop-filter: blur(8px);
}

.content {
  padding: 28px;
  min-width: 0;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand h1 { margin: 0; font-size: 1.15rem; }
.brand p { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.92rem; }
.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #ffb15e, #f48120);
  color: #1d1507;
  font-weight: 800;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--eyebrow);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  margin-bottom: 0.5rem;
}

.hero h2 { margin: 0; font-size: 2rem; }
.muted { color: var(--muted); }

.panel,
.status,
.cards .card {
  background: linear-gradient(180deg, var(--panel-grad-start), var(--panel-grad-end));
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel.compact { display: grid; gap: 10px; }
.panel-title {
  font-size: 0.95rem;
  color: var(--card-sub);
  margin-bottom: 12px;
  font-weight: 700;
}

.status {
  padding: 14px 16px;
  margin-bottom: 16px;
  color: var(--muted);
}

.cards {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.card { padding: 18px; }
.card-label { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.6rem; }
.card-value { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.03em; }
.card-sub { margin-top: 0.4rem; color: var(--card-sub); font-size: 0.88rem; }

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.zone-list {
  display: grid;
  gap: 8px;
}

.zone-item {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--button-ghost-border);
  border-radius: 14px;
  background: var(--table-row-bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.zone-item small { display: block; color: var(--muted); margin-top: 0.25rem; }
.zone-item.active { border-color: rgba(244, 129, 32, 0.9); background: rgba(244, 129, 32, 0.1); }

.button {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.button.primary { background: linear-gradient(135deg, #ffb15e, #f48120); color: #1d1507; }
.button.ghost { background: var(--button-ghost-bg); color: var(--text); border: 1px solid var(--button-ghost-border); }
.button.ghost.active { border-color: rgba(244,129,32,0.85); color: #ffbf80; }

.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-toggle { min-width: 110px; }
.hint { color: var(--muted); margin: 0; font-size: 0.85rem; line-height: 1.5; }

.scroll-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  appearance: none;
  border: 1px solid rgba(244, 129, 32, 0.24);
  border-radius: 999px;
  padding: 0.8rem 1rem;
  background: linear-gradient(135deg, rgba(255, 177, 94, 0.96), rgba(244, 129, 32, 0.98));
  color: #1d1507;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.scroll-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.chart-panel { min-height: 320px; }
.chart svg { width: 100%; height: 280px; display: block; }
.chart-axis { stroke: var(--chart-axis-color); stroke-width: 1; }
.chart-grid { stroke: var(--chart-grid-color); stroke-width: 1; stroke-dasharray: 4 6; }
.chart-line { fill: none; stroke: #ff9e4a; stroke-width: 3; }
.chart-area { fill: rgba(244,129,32,0.16); }
.chart-dot { fill: #ffbf80; stroke: var(--bg-grad-start); stroke-width: 1.5; }
.chart-tick { fill: var(--muted); font-size: 11px; }
.chart-labels,
.table {
  color: var(--muted);
  font-size: 0.88rem;
}

.table {
  display: grid;
  gap: 8px;
}

.table-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--table-row-bg);
  border: 1px solid var(--table-row-border);
  border-radius: 14px;
}

.table-row-main {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-row-stats {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.table-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.36rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--button-ghost-border);
  background: var(--button-ghost-bg);
  color: var(--text);
  font-size: 0.82rem;
  white-space: nowrap;
}

.table-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.pager-pages {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pager-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
}

.pager-btn.active {
  border-color: rgba(244, 129, 32, 0.9);
  color: #ffbf80;
  background: rgba(244, 129, 32, 0.12);
}

.pager-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.event-wrap {
  overflow-x: auto;
  min-width: 0;
}

.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filter-bar-compact {
  align-items: center;
  flex-wrap: nowrap;
}

.filter-bar-compact .filter-grow {
  flex: 1 1 auto;
  min-width: 0;
}

.filter-bar-compact .filter-input {
  min-width: 0;
}

.filter-bar-compact .filter-select {
  flex: 0 0 160px;
  width: 160px;
  min-width: 0;
}

.filter-input,
.filter-select {
  appearance: none;
  border: 1px solid var(--button-ghost-border);
  border-radius: 12px;
  background: var(--button-ghost-bg);
  color: var(--text);
  padding: 9px 12px;
  font: inherit;
  width: 100%;
  max-width: 100%;
}

.filter-input {
  min-width: 200px;
}

.filter-select {
  min-width: 140px;
}

.filter-grow {
  flex: 1 1 280px;
}

.event-table {
  width: 100%;
  border-collapse: collapse;
}

.event-table th,
.event-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--event-border);
  font-size: 0.9rem;
  vertical-align: top;
}

.event-table th { color: var(--muted); font-weight: 600; }
.event-table td { color: var(--text); }
.badge {
  display: inline-block;
  padding: 0.22rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: rgba(244,129,32,0.16);
  color: #ffbf80;
}
.badge.block { background: rgba(255,107,107,0.12); color: #ff9a9a; }
.badge.allow { background: rgba(61,220,151,0.12); color: #8bf3c1; }
.empty { color: var(--muted); padding: 16px 0; }

@media (max-width: 1200px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--panel-border); }
  .content { padding: 22px; }
  .grid.two { grid-template-columns: 1fr; }
  .hero { flex-direction: column; align-items: flex-start; }
  .hero-actions { width: 100%; }
  .pager { align-items: flex-start; }
}

@media (max-width: 680px) {
  .sidebar,
  .content {
    padding: 16px;
  }

  .panel,
  .status,
  .cards .card {
    border-radius: 18px;
  }

  .hero {
    gap: 12px;
    margin-bottom: 14px;
  }

  .hero h2 {
    font-size: 1.55rem;
  }

  .hero-actions {
    width: 100%;
    gap: 8px;
  }

  .hero-actions .button {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }

  .theme-toggle {
    min-width: 0;
  }

  .scroll-top {
    right: 16px;
    bottom: 16px;
    padding: 0.72rem 0.92rem;
  }

  .cards {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card {
    padding: 16px;
  }

  .card-value {
    font-size: 1.35rem;
  }

  .chart-panel {
    min-height: 0;
  }

  .chart svg {
    height: 220px;
  }

  .chart-labels {
    line-height: 1.5;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar-compact {
    align-items: stretch;
  }

  .filter-input,
  .filter-select {
    min-width: 0;
  }

  .filter-grow {
    flex-basis: auto;
  }

  .filter-bar-compact .filter-select,
  .filter-bar-compact .filter-grow {
    flex: 1 1 auto;
    width: 100%;
  }

  .table-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .table-row-main {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .table-row-stats {
    justify-content: flex-start;
  }

  .pager-pages {
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    padding-bottom: 4px;
  }

  .event-wrap {
    overflow-x: visible;
  }

  .event-table,
  .event-table tbody,
  .event-table tr,
  .event-table td {
    display: block;
    width: 100%;
  }

  .event-table thead {
    display: none;
  }

  .event-table tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--event-border);
  }

  .event-table tr:last-child {
    border-bottom: 0;
  }

  .event-table td {
    padding: 6px 0;
    border-bottom: 0;
    word-break: break-word;
  }

  .event-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
  }
}
