*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #f5f5f5;
  --surface: #fff;
  --surface-alt: #f0f0f0;
  --border: #e0e0e0;
  --text: #222;
  --text-muted: #666;
  --nav-bg: #1a1a2e;
  --nav-text: #e0e0ff;
  --input-border: #ccc;
  --shadow: rgba(0,0,0,.08);
  --accent: #1a1a2e;
  --link: #1a1a2e;
}

/* Variables on html so they cascade from the root immediately */
html.dark {
  --bg: #0f0f1a;
  --surface: #1c1c2e;
  --surface-alt: #252538;
  --border: #2e2e48;
  --text: #e0e0f0;
  --text-muted: #8080a0;
  --nav-bg: #0a0a14;
  --nav-text: #c0c0e0;
  --input-border: #3a3a5a;
  --shadow: rgba(0,0,0,.4);
  --accent: #5050a0;
  --link: #9ea8e8;
}

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--link); }
a:visited { color: var(--link); }
a:hover { opacity: 0.75; }

/* ── Nav ── */
nav {
  background: var(--nav-bg);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.nav-brand {
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
  text-decoration: none;
}
.nav-spacer { flex: 1; }
nav a:not(.nav-brand) { color: var(--nav-text); text-decoration: none; font-size: 0.95rem; }
nav a:not(.nav-brand):hover { color: #fff; }
#dark-toggle {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: var(--nav-text);
  border-radius: 4px;
  padding: 0.2rem 0.55rem;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.4;
}
#dark-toggle:hover { background: rgba(255,255,255,0.1); }

/* ── Layout ── */
main { max-width: 1100px; margin: 2rem auto; padding: 0 1rem; }

/* ── Auth ── */
.auth-form {
  max-width: 380px; margin: 4rem auto;
  background: var(--surface); padding: 2rem;
  border-radius: 8px; box-shadow: 0 2px 8px var(--shadow);
}
.auth-form h1 { margin-top: 0; }
.auth-form label { display: block; margin-bottom: 1rem; font-size: 0.9rem; }
.auth-form input {
  display: block; width: 100%; padding: 0.5rem; margin-top: 0.25rem;
  border: 1px solid var(--input-border); border-radius: 4px;
  background: var(--bg); color: var(--text);
}
.auth-form button {
  width: 100%; padding: 0.6rem;
  background: var(--nav-bg); color: #fff;
  border: none; border-radius: 4px; cursor: pointer; font-size: 1rem;
}

/* ── Alerts ── */
.error { color: #e74c3c; font-size: 0.9rem; }
.flash { padding: 0.75rem 1rem; border-radius: 4px; margin-bottom: 1rem; }
.flash-success { background: #d4edda; color: #155724; }
.flash-error { background: #f8d7da; color: #721c24; }

/* ── Cards ── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.card {
  background: var(--surface); padding: 1.25rem;
  border-radius: 8px; box-shadow: 0 1px 4px var(--shadow);
}
.card h3 { margin: 0 0 0.5rem; }
.card h3 a { color: var(--text); text-decoration: none; }
.card h3 a:hover { text-decoration: underline; }

/* ── Status badges ── */
.status-pending  { background: #fff3cd; color: #856404; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.8rem; }
.status-success  { background: #d4edda; color: #155724; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.8rem; }
.status-failed   { background: #f8d7da; color: #721c24; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.8rem; }

/* ── Tables ── */
table { background: var(--surface); border-radius: 8px; border-collapse: collapse; }
th { padding: 0.75rem; background: var(--surface-alt); color: var(--text); }
td { color: var(--text); }
tr + tr { border-top: 1px solid var(--border); }

/* Override inline background/color styles on table rows in dark mode */
html.dark thead tr,
html.dark tfoot tr { background: var(--surface-alt) !important; }
html.dark tbody tr { background: var(--surface) !important; }
html.dark tbody tr:nth-child(even) { background: var(--surface-alt) !important; }
html.dark td,
html.dark th { color: var(--text) !important; border-color: var(--border) !important; }

/* Override inline muted text colors in dark mode */
html.dark [style*="color:#888"],
html.dark [style*="color:#666"],
html.dark [style*="color:#aaa"] { color: var(--text-muted) !important; }

/* Override inline white/light backgrounds in dark mode */
html.dark [style*="background:#fff"],
html.dark [style*="background: #fff"] { background: var(--surface) !important; }
html.dark [style*="background:#f9f9f9"],
html.dark [style*="background:#f0f0f0"] { background: var(--surface-alt) !important; }

/* ── Forms ── */
input, select, textarea {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 4px; padding: 0.5rem;
}

/* ── Page header ── */
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.5rem; flex-wrap: wrap; gap: 0.75rem;
}
.page-header h1 { margin: 0; }

/* ── Buttons ── */
.btn { display: inline-block; padding: 0.5rem 1rem; border-radius: 4px; text-decoration: none; border: none; cursor: pointer; font-size: 0.95rem; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.85; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 3rem; }
.empty-state p { margin: 0 0 1.25rem; }

/* ── Dashboard cards ── */
.dash-card { display: flex; flex-direction: column; min-height: 240px; }

.dash-header { margin-bottom: 1rem; }
.dash-title { margin: 0 0 0.2rem; font-size: 1.05rem; }
.dash-title a { color: var(--text); text-decoration: none; }
.dash-title a:hover { text-decoration: underline; }
.dash-address { margin: 0; font-size: 0.82rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dash-metrics {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem;
  background: var(--surface-alt); border-radius: 6px;
  padding: 0.75rem 0.5rem; margin-bottom: 0.75rem;
}
.dash-metric { text-align: center; }
.dash-value { font-size: 1.3rem; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.1rem; text-transform: uppercase; letter-spacing: 0.04em; }

.dash-period { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.dash-trend { font-size: 0.85rem; color: var(--text-muted); min-height: 1.4em; }
.trend-up   { color: #c0392b; font-weight: 600; }
.trend-down { color: #27ae60; font-weight: 600; }
.trend-neutral { color: var(--text-muted); }

.dash-empty { flex: 1; display: flex; align-items: center; }
.dash-empty p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

.dash-actions { display: flex; gap: 1rem; margin-top: auto; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.dash-link { font-size: 0.84rem; color: var(--text-muted); text-decoration: none; }
.dash-link:hover { color: var(--text); }
.dash-link-green { color: #27ae60; }
.dash-link-green:hover { color: #1e8449; }

/* ── Misc ── */
details summary { color: var(--text-muted); cursor: pointer; }
details pre {
  background: var(--surface-alt); color: var(--text);
  padding: 0.8rem; border-radius: 6px; margin-top: 0.5rem;
  font-size: 0.82rem; white-space: pre-wrap; word-break: break-all;
}
