:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --line: #d9d6cc;
  --ink: #1d2522;
  --muted: #68736f;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --amber: #b7791f;
  --red: #b42318;
  --green: #28734c;
  --shadow: 0 10px 30px rgba(29, 37, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--teal-dark);
}

button,
.button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 14px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button:hover {
  border-color: var(--teal);
}

.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
  font: inherit;
}

label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 700;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

code,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.site-header,
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
}

.brand {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

nav a {
  border-radius: 6px;
  color: var(--muted);
  padding: 7px 10px;
  text-decoration: none;
}

nav a.active,
nav a:hover {
  background: #e6f2ef;
  color: var(--teal-dark);
}

.public-shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 34px 0 60px;
}

.public-shell.narrow {
  width: min(720px, calc(100vw - 32px));
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 28px;
  align-items: end;
  min-height: 420px;
  padding: clamp(26px, 5vw, 56px) 0;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.12;
}

.hero h1 {
  max-width: 760px;
  font-size: clamp(38px, 7vw, 82px);
}

.lead {
  max-width: 620px;
  color: var(--muted);
  font-size: 18px;
}

.actions,
.inline-form,
.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.inline-form input {
  flex: 1 1 220px;
}

.quick-search,
.form-panel,
.result-panel,
.panel,
.metric,
.public-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.quick-search,
.form-panel,
.result-panel,
.panel {
  padding: 22px;
}

.public-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.public-grid article {
  padding: 18px;
}

.public-grid h2 {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
}

.public-grid strong {
  display: block;
  margin-top: 12px;
  font-size: 30px;
}

.public-grid span {
  color: var(--muted);
}

.notice {
  margin: 14px 0;
  border-radius: 6px;
  padding: 12px 14px;
  font-weight: 700;
}

.notice.success {
  background: #e8f5ee;
  color: var(--green);
}

.notice.warning {
  background: #fff4df;
  color: #805400;
}

.notice.error,
.sql-error {
  background: #fff0ed;
  color: var(--red);
}

.sql-error {
  overflow: auto;
  border: 1px solid #f3b5ad;
  border-radius: 8px;
  padding: 14px;
}

.form-panel + .result-panel,
.notice + .result-panel,
.sql-error + .result-panel {
  margin-top: 18px;
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 2;
}

.admin-header h1 {
  font-size: 24px;
}

.dashboard {
  width: min(1440px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 54px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.dashboard-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.45fr);
  gap: 12px;
  margin-top: 12px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-heading h2 {
  font-size: 18px;
}

.timeline {
  display: grid;
  grid-template-columns: repeat(24, minmax(12px, 1fr));
  gap: 6px;
  height: 180px;
  align-items: end;
}

.bar {
  display: flex;
  min-width: 0;
  height: 100%;
  flex-direction: column;
  justify-content: end;
  gap: 4px;
}

.bar span {
  display: block;
  min-height: 6px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(#0f766e, #b7791f);
}

.bar em {
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
  text-align: center;
}

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

.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 44px;
  gap: 10px;
  align-items: center;
}

.rank-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

meter {
  width: 100%;
}

.events-panel {
  margin-top: 12px;
}

.event-tools input {
  max-width: 360px;
}

.event-table-wrap {
  overflow-x: auto;
}

.event-table {
  min-width: 980px;
}

.event-table tbody tr {
  cursor: pointer;
}

.event-table tbody tr:hover {
  background: #f0ebe1;
}

.event-table code {
  white-space: nowrap;
}

.sev-critical td:first-child {
  border-left: 4px solid var(--red);
}

.sev-high td:first-child {
  border-left: 4px solid var(--amber);
}

.sev-medium td:first-child {
  border-left: 4px solid var(--teal);
}

.empty {
  color: var(--muted);
  text-align: center;
}

dialog {
  width: min(920px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

#eventDetail {
  max-height: 70vh;
  margin: 0;
  overflow: auto;
  padding: 16px;
  background: #111713;
  color: #e8f5ee;
}

@media (max-width: 980px) {
  .hero,
  .dashboard-row {
    grid-template-columns: 1fr;
  }

  .metric-grid,
  .public-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .site-header,
  .admin-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero {
    min-height: auto;
  }

  .hero h1 {
    font-size: 38px;
  }

  .metric-grid,
  .public-grid {
    grid-template-columns: 1fr;
  }

  .timeline {
    gap: 3px;
  }

  .rank-row {
    grid-template-columns: minmax(0, 1fr) 70px 34px;
  }
}
