:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11,11,11,0.10);
  --blue: #2a78d6;
  --series-green: #008300;
  --series-magenta: #e87ba4;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255,255,255,0.10);
    --blue: #3987e5;
    --series-green: #008300;
    --series-magenta: #d55181;
    --good: #0ca30c;
    --warning: #fab219;
    --serious: #ec835a;
    --critical: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255,255,255,0.10);
  --blue: #3987e5;
  --series-green: #008300;
  --series-magenta: #d55181;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #e66767;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
}

[hidden] { display: none !important; }

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--surface-1);
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { margin: 0 0 8px; font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--text-secondary); }
.login-card input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 1rem;
}
button {
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--blue);
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: filter 0.15s ease, transform 0.1s ease;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; filter: none; transform: none; }
button.ghost {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}
button.danger { background: var(--critical); }
.error { color: var(--critical); font-size: 0.85rem; margin: 0; }

html { scroll-behavior: smooth; }

.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px 14px;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 6px 10px 18px;
}
.sidebar-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent);
  flex-shrink: 0;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  padding: 9px 10px;
  border-radius: 8px;
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar-nav a:hover { background: var(--page); color: var(--text-primary); }
.sidebar-logout { align-self: stretch; margin-top: 8px; }

.main-content {
  flex: 1;
  min-width: 0;
  padding-bottom: 32px;
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: auto;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-logout { width: auto; margin-top: 0; margin-left: auto; }
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  padding: 24px 24px 20px;
  scroll-margin-top: 20px;
}
.tile {
  background: var(--surface-1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.tile .label { color: var(--text-secondary); font-size: 0.8rem; }
.tile .value { font-size: 1.6rem; font-weight: 600; font-variant-numeric: proportional-nums; margin-top: 4px; }
.tile .sub { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }

.meter-tile {
  background: var(--surface-1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.meter-tile .meter-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.meter-tile .label { color: var(--text-secondary); font-size: 0.8rem; }
.meter-tile .value { font-size: 1.3rem; font-weight: 600; font-variant-numeric: proportional-nums; }
.meter-track {
  height: 8px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--meter-color) 18%, transparent);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--meter-color);
  transition: width 0.4s ease;
}
.meter-tile .sub { color: var(--muted); font-size: 0.78rem; margin-top: 6px; }

.panel { padding: 8px 24px 24px; scroll-margin-top: 20px; }
.panel h2 { font-size: 1.02rem; font-weight: 600; color: var(--text-primary); margin: 20px 0 12px; letter-spacing: -0.01em; }
.panel h3.subheading { font-size: 0.85rem; color: var(--muted); margin: 16px 0 8px; }
.panel table + table { margin-top: 8px; }

table { width: 100%; border-collapse: collapse; background: var(--surface-1); box-shadow: 0 1px 2px rgba(0,0,0,0.04); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--gridline); font-size: 0.88rem; }
th { color: var(--muted); font-weight: 500; }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: var(--page); }
tr:last-child td { border-bottom: none; }
td.num { font-variant-numeric: tabular-nums; }

.account-form { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.account-form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--text-secondary); }
.account-form input[type="password"],
.account-form input[type="text"],
.account-form input[type="number"] {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 1rem;
}
.account-form button { align-self: flex-start; }

.pw-generator {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
}
.pw-generator-row { display: flex; gap: 12px; }
.pw-generator-row label { flex: 1; }
.pw-generator-row input[type="number"] { width: 100%; }
.pw-generator-checks { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.85rem; color: var(--text-primary); }
.pw-generator-checks label { flex-direction: row; align-items: center; gap: 6px; color: var(--text-primary); }
.pw-preview-row { display: flex; gap: 8px; }
.pw-preview {
  flex: 1;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}
.pw-preview-row button { align-self: stretch; white-space: nowrap; }
.password-result {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--good);
  border-radius: 8px;
  background: color-mix(in srgb, var(--good) 10%, transparent);
}
.password-result code { font-size: 1rem; font-weight: 600; user-select: all; }

.account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.account-card {
  background: var(--surface-1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}
.account-card h3 { margin: 0 0 4px; font-size: 0.95rem; }
.account-card > .muted { margin: 0 0 14px; font-size: 0.82rem; }
.account-card.danger-zone { border-color: color-mix(in srgb, var(--critical) 35%, var(--border)); }
.account-card.danger-zone h3 { color: var(--critical); }
.account-card .account-form button[type="submit"] { align-self: flex-start; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: modal-fade-in 0.15s ease;
}
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  animation: modal-pop-in 0.18s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes modal-pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-close {
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  padding: 4px 8px;
}
.modal-body { padding: 12px 20px 4px; color: var(--text-secondary); font-size: 0.92rem; line-height: 1.5; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 20px; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.good { background: var(--good); }
.status-dot.critical { background: var(--critical); }
.status-dot.muted { background: var(--muted); }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions button { font-size: 0.78rem; padding: 5px 8px; }
.row-actions button.danger { background: var(--critical); }

.panel-header { display: flex; justify-content: space-between; align-items: center; }
.range-picker { display: flex; gap: 4px; }
.range-picker button {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
}
.range-picker button.active { background: var(--blue); color: #fff; border-color: transparent; }

.chart-wrap {
  position: relative;
  background: var(--surface-1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.chart-wrap svg { width: 100%; height: 220px; display: block; }
.chart-gridline { stroke: var(--gridline); stroke-width: 1; }
.chart-axis-label { fill: var(--muted); font-size: 9px; }
.chart-crosshair { stroke: var(--muted); stroke-width: 1; pointer-events: none; }
.chart-tooltip {
  position: absolute;
  top: 8px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.78rem;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  white-space: nowrap;
}
.chart-tooltip .time { color: var(--muted); margin-bottom: 4px; }
.chart-tooltip .row { display: flex; align-items: center; gap: 6px; }
.chart-tooltip .swatch { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chart-legend { display: flex; gap: 16px; margin-top: 10px; font-size: 0.82rem; color: var(--text-secondary); flex-wrap: wrap; }
.chart-legend .item { display: flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.log-breakdown { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; font-size: 0.85rem; }
.log-breakdown .row { display: flex; justify-content: space-between; padding: 4px 8px; border-bottom: 1px solid var(--gridline); }

.cleanup-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.muted { color: var(--muted); font-size: 0.85rem; }
