/* ---------- Tokens ---------- */
:root {
  --bg: #f1f4fa;
  --card: #ffffff;
  --text: #1a2230;
  --muted: #64748b;
  --border: #e3e8f1;
  --accent: #d97706;          /* chart/series color — 3.2:1 on white */
  --accent-soft: rgba(217, 119, 6, 0.14);
  --grid: #edf0f6;
  --danger: #dc2626;
  --ok-bg: #ecfdf3;
  --ok-text: #166534;
  --err-bg: #fef2f2;
  --err-text: #b91c1c;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
}

[data-theme="dark"] {
  --bg: #0f1420;
  --card: #171e2b;
  --text: #e6ebf4;
  --muted: #8b96a8;
  --border: #263042;
  --accent: #f59e0b;          /* 7.8:1 on dark card */
  --accent-soft: rgba(245, 158, 11, 0.16);
  --grid: #202a3b;
  --danger: #f87171;
  --ok-bg: #12291c;
  --ok-text: #6ee7a0;
  --err-bg: #2c1517;
  --err-text: #fca5a5;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: var(--accent-soft);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { color: var(--muted); font-size: 0.9rem; padding: 0.6rem 0; }

/* ---------- Layout ---------- */
.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}
.brand:hover { text-decoration: none; }

.topnav { display: flex; align-items: center; gap: 1rem; }
.topnav a { color: var(--muted); font-size: 0.92rem; }
.topnav a:hover { color: var(--text); text-decoration: none; }

.topnav .add-site-btn { margin-top: 0; white-space: nowrap; }

/* ---------- Modal ---------- */
.modal {
  width: min(440px, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.modal::backdrop { background: rgba(10, 14, 22, 0.55); }
.modal form { padding: 1.25rem; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0.35rem;
  border-radius: 7px;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal .alert { margin: 0.75rem 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

.theme-toggle {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 8px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
}
[data-theme="light"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: none; }

.footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  gap: 1rem;
}
.footer-link { color: var(--muted); }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}

/* ---------- Landing ---------- */
.hero { text-align: center; padding: 2.5rem 0 1.5rem; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 0.75rem; }
.lede { max-width: 640px; margin: 0 auto; color: var(--muted); font-size: 1.05rem; }
.hero-foot { text-align: center; color: var(--muted); font-size: 0.9rem; padding: 1.5rem 0; }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.feature h3 { margin: 0.4rem 0 0.35rem; font-size: 1.02rem; }
.feature p { margin: 0; color: var(--muted); font-size: 0.92rem; }
.feature-icon { font-size: 1.5rem; }

/* ---------- Auth ---------- */
.auth-card {
  max-width: 420px;
  margin: 3rem auto;
  padding: 1.75rem;
}
.auth-card h1 { margin: 0 0 0.5rem; font-size: 1.4rem; }
.auth-card p { color: var(--muted); margin-top: 0; }

/* ---------- Forms ---------- */
label { display: block; font-size: 0.88rem; color: var(--muted); margin: 0.75rem 0 0.25rem; }

input[type="text"], input[type="password"], input[type="date"], select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
textarea { display: block; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  cursor: pointer;
  margin-top: 0.75rem;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }

.alert { padding: 0.6rem 0.9rem; border-radius: 9px; font-size: 0.92rem; }
.alert.error { background: var(--err-bg); color: var(--err-text); }
.alert.ok { background: var(--ok-bg); color: var(--ok-text); }

.inline-form label { margin-top: 0.5rem; }

/* ---------- Sites list ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; }
.page-head h1 { margin: 0; font-size: 1.5rem; }

.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.site-card h2 { margin: 0; font-size: 1.1rem; }
.site-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; }
.site-card-head .btn { margin-top: 0; }
.site-mini-stats { margin: 0.6rem 0; font-size: 0.9rem; color: var(--muted); }
.site-mini-stats b { color: var(--text); }

.site-tools { border-top: 1px solid var(--border); padding-top: 0.5rem; margin-top: 0.5rem; }
.site-tools summary { cursor: pointer; font-size: 0.88rem; color: var(--muted); }
.site-tools summary:hover { color: var(--text); }
.danger-zone summary:hover { color: var(--danger); }
.share-on { color: var(--accent); font-size: 0.8rem; }

.embed-row { display: flex; gap: 0.5rem; align-items: flex-start; margin-top: 0.4rem; }
.embed-code {
  flex: 1;
  display: block;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  word-break: break-all;
  font-size: 0.78rem;
}
.copy-btn { margin-top: 0; flex-shrink: 0; }

.empty-state { text-align: center; padding: 2rem 1.25rem; }
.empty-state h2 { margin: 0 0 0.25rem; font-size: 1.1rem; }
.empty-state p { margin: 0; }

/* View toggle (cards / list) */
.view-toggle { display: flex; gap: 0.25rem; }
.view-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 0.85rem;
  font-family: inherit;
  padding: 0.3rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
}
.view-btn:hover { color: var(--text); }
.view-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* List view: same markup, compact rows */
.site-grid.list-view { display: flex; flex-direction: column; gap: 0.6rem; }
.list-view .site-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 1rem;
  padding: 0.7rem 1.1rem;
}
.list-view .site-card-head {
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
}
.list-view .site-card-head .btn { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.list-view .site-mini-stats { font-size: 0.85rem; }
.list-view .site-card-head > div { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.list-view .site-card-head h2 { font-size: 1rem; }
.list-view .site-card-head .btn { order: 2; }
.list-view .site-mini-stats { margin: 0; white-space: nowrap; }
.list-view .site-tools { border-top: 0; padding-top: 0; margin-top: 0; }
.list-view .site-tools[open] { flex-basis: 100%; }
@media (max-width: 640px) {
  .list-view .site-card-head { flex-wrap: wrap; }
}
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 480px)); gap: 1rem; align-items: start; }
.settings-card > p { margin: 0.25rem 0 0; }
.settings-card form p { margin: 0.3rem 0 0; }
.settings-card .btn + .btn, .site-tools .btn + .btn { margin-left: 0.4rem; }
.site-tools textarea { margin-top: 0.4rem; }
input[type="file"] { width: 100%; font-size: 0.88rem; color: var(--text); font-family: inherit; }
input[type="color"] { display: block; width: 3.5rem; height: 2.2rem; padding: 0.15rem; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); cursor: pointer; }
.logo-preview { display: flex; align-items: center; gap: 1rem; margin-top: 0.5rem; }
.logo-preview img { max-height: 48px; max-width: 200px; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 0.35rem; }
label.check { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; }
.settings-card h2 { margin: 0 0 0.25rem; font-size: 1.1rem; }

/* ---------- Dashboard ---------- */
.dash-head { flex-wrap: wrap; }
.dash-controls { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.dash-controls .btn { margin-top: 0; }
.range-form { display: flex; align-items: center; gap: 0.5rem; }
.range-form select { width: auto; }
.custom-dates { display: inline-flex; gap: 0.4rem; align-items: center; }
.custom-dates[hidden] { display: none; }
.custom-dates input { width: auto; }
.custom-dates .btn { margin-top: 0; }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.stat-card { position: relative; padding: 1.1rem 1.25rem 1rem; }
.stat-card-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-card-value { display: block; font-size: 1.9rem; font-weight: 700; line-height: 1.2; margin-top: 0.15rem; }
.stat-card-sub { display: block; font-size: 0.8rem; color: var(--muted); }
.stat-card-icon {
  position: absolute;
  top: 1rem; right: 1.1rem;
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft);
  border-radius: 50%;
  font-size: 1.15rem;
}
.rt-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22c55e;
  margin-left: 0.25rem;
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.chart-card { position: relative; margin-bottom: 1rem; padding: 1.25rem 1rem 0.75rem; }
#chart { width: 100%; display: block; }
.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 0.4rem 0.65rem;
  font-size: 0.82rem;
  white-space: nowrap;
  z-index: 10;
}
.chart-tip b { display: block; }

/* ---------- Panels ---------- */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.panel { padding-bottom: 0.75rem; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.panel-head h3 { margin: 0; font-size: 1rem; }

.tabs { display: flex; gap: 0.15rem; }
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: inherit;
  padding: 0.25rem 0.5rem;
  border-radius: 7px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); font-weight: 600; background: var(--accent-soft); }

.pane { display: none; }
.pane.active { display: block; }

.stat-list { list-style: none; margin: 0; padding: 0; }
.stat-row { padding: 0.45rem 0 0.2rem; }
.stat-row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; }
.stat-label {
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.row-icon { margin-right: 0.35rem; }
.stat-nums { flex-shrink: 0; font-size: 0.9rem; }
.stat-nums b { font-weight: 600; }
.stat-pct { color: var(--muted); font-size: 0.8rem; margin-left: 0.5rem; display: inline-block; min-width: 3.2em; text-align: right; }

.bar {
  height: 5px;
  border-radius: 4px;
  background: var(--grid);
  margin-top: 0.3rem;
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 4px; background: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; row-gap: 0.4rem; }
  .topnav { gap: 0.75rem; flex-wrap: wrap; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .stat-card-value { font-size: 1.6rem; }
}
