:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --border: #dfe2dc;
  --text: #1b1f1a;
  --muted: #6a7065;
  --accent: #3f6f3a;
  --accent-soft: #e8f0e6;
  --danger: #a33124;
  --danger-soft: #fbeae7;
  --warn: #8a6410;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151714;
    --surface: #1e211c;
    --border: #333830;
    --text: #e8ebe5;
    --muted: #9aa294;
    --accent: #8fc286;
    --accent-soft: #24301f;
    --danger: #e08275;
    --danger-soft: #35211e;
    --warn: #d4a747;
  }
}

:root[data-theme="dark"] {
  --bg: #151714;
  --surface: #1e211c;
  --border: #333830;
  --text: #e8ebe5;
  --muted: #9aa294;
  --accent: #8fc286;
  --accent-soft: #24301f;
  --danger: #e08275;
  --danger-soft: #35211e;
  --warn: #d4a747;
}

* { box-sizing: border-box; }

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

h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 20px; margin: 8px 0 0; font-size: 14px; }

button, input, select { font: inherit; color: inherit; }

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); color: #fff; }
button.link { background: none; color: var(--muted); padding: 4px; text-decoration: underline; }

input, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}

/* ===== Login ===== */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 360px;
}
.login-card label { display: block; margin: 16px 0 6px; font-size: 14px; color: var(--muted); }
.login-card button { width: 100%; margin-top: 20px; }

/* ===== Chrome ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tabs button {
  background: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
}
.tabs button.active { background: var(--accent-soft); color: var(--accent); }
.account { display: flex; align-items: center; gap: 12px; }
.badge {
  display: inline-block;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
  margin-left: 4px;
}

main { padding: 20px; max-width: 1200px; margin: 0 auto; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; }
.panel-head select { width: auto; }
.panel-note { margin: -8px 0 16px; font-size: 14px; }

/* ===== Stats ===== */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 4px; }
.stat .value.alert { color: var(--danger); }

/* ===== Chart ===== */
#chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend span::before {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  background: currentColor;
}

/* ===== Tables and cards ===== */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num { font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

.item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.item-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.item-meta { font-size: 13px; color: var(--muted); }
.item-text { margin: 8px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.item-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.item img { max-width: 220px; border-radius: 6px; display: block; margin: 8px 0; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--danger-soft); color: var(--warn); }

code, .mono { font-family: var(--mono); font-size: 13px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 180px; }
.inline-form select, .inline-form button { width: auto; }

.empty { color: var(--muted); padding: 16px 0; }

/* ===== Dialog ===== */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  max-width: 440px;
  width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog p { color: var(--muted); font-size: 14px; }
dialog label { display: block; margin: 16px 0 6px; font-size: 13px; color: var(--muted); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 20px 0 0; }
dialog menu button[value="cancel"] { background: transparent; color: var(--text); border: 1px solid var(--border); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 10;
  max-width: calc(100% - 32px);
}

@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
