/* Wick Monitor design system.
   Dark is the default; [data-theme="light"] on <html> switches palettes
   (set by public/js/theme.js from the viewer's saved choice).
   Pages should style with the --wm-* tokens. The short legacy names
   (--bg, --card, --primary...) are kept as aliases so older page CSS
   follows the theme too. */

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --wm-bg: #0B0E17;
  --wm-surface: #131826;
  --wm-surface-2: #0F1320;      /* inset panels inside a card */
  --wm-surface-3: #1C2232;      /* tracks, hover rows */
  --wm-border: #1E2536;
  --wm-border-strong: #262E42;
  --wm-text: #F2F4F8;
  --wm-text-2: #C9CFDC;
  --wm-muted: #8D96AB;
  --wm-accent: #3358F0;
  --wm-accent-hover: #4669FF;
  --wm-on-accent: #FFFFFF;
  --wm-accent-soft: rgba(51, 88, 240, 0.18);
  --wm-accent-text: #9DB2FF;    /* accent used as text/links on surfaces */
  --wm-attention: #FF7A63;      /* coral: problems, the second accent */
  --wm-on-attention: #0B0E17;
  --wm-good: #3DD68C;
  --wm-ok: #F5B841;
  --wm-bad: #FF6B6B;
  --wm-good-soft: rgba(61, 214, 140, 0.14);
  --wm-ok-soft: rgba(245, 184, 65, 0.14);
  --wm-bad-soft: rgba(255, 107, 107, 0.14);
  --wm-neutral-bar: #5B6B8C;
  --wm-overlay: rgba(5, 7, 12, 0.72);
  --wm-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

[data-theme="light"] {
  color-scheme: light;
  --wm-bg: #F3F5FA;
  --wm-surface: #FFFFFF;
  --wm-surface-2: #F1F4F9;
  --wm-surface-3: #E4E9F2;
  --wm-border: #E3E8F0;
  --wm-border-strong: #CCD4E2;
  --wm-text: #0E1424;
  --wm-text-2: #334057;
  --wm-muted: #5D6980;
  --wm-accent: #3358F0;
  --wm-accent-hover: #2647D6;
  --wm-on-accent: #FFFFFF;
  --wm-accent-soft: rgba(51, 88, 240, 0.10);
  --wm-accent-text: #2A4BD8;
  --wm-attention: #F0654D;
  --wm-on-attention: #0E1424;
  --wm-good: #14804F;
  --wm-ok: #9A6200;
  --wm-bad: #C9353B;
  --wm-good-soft: rgba(20, 128, 79, 0.10);
  --wm-ok-soft: rgba(154, 98, 0, 0.10);
  --wm-bad-soft: rgba(201, 53, 59, 0.10);
  --wm-neutral-bar: #8A97B1;
  --wm-overlay: rgba(14, 20, 36, 0.45);
  --wm-shadow: 0 16px 48px rgba(14, 20, 36, 0.14);
}

:root {
  --wm-radius-lg: 24px;
  --wm-radius: 16px;
  --wm-radius-sm: 10px;
  --wm-gutter: clamp(16px, 2.5vw, 32px);
  --wm-font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --wm-font-display: 'Averia Serif Libre', Georgia, 'Times New Roman', serif; /* page headlines and big numbers */

  /* Legacy aliases (page CSS written before the redesign) */
  --bg: var(--wm-bg);
  --card: var(--wm-surface);
  --border: var(--wm-border);
  --text: var(--wm-text);
  --muted: var(--wm-muted);
  --primary: var(--wm-accent);
  --success: var(--wm-good);
  --warning: var(--wm-ok);
  --error: var(--wm-bad);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* App Bridge reads <s-app-nav> into the admin sidebar; never paint it in the page. */
s-app-nav { display: none; }

html { background: var(--wm-bg); }

body {
  font-family: var(--wm-font);
  background: var(--wm-bg);
  color: var(--wm-text);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--wm-accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--wm-text); letter-spacing: -0.01em; }
strong { color: var(--wm-text); }
:focus-visible { outline: 2px solid var(--wm-accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.display-num { font-family: var(--wm-font-display); font-weight: 300; letter-spacing: -0.01em; }

/* ---------- App shell (edge to edge) ---------- */
.wm-app { min-height: 100vh; padding: 24px var(--wm-gutter) 64px; display: flex; flex-direction: column; gap: 24px; }
.container { width: 100%; }

.wm-topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.wm-brand { display: flex; align-items: center; gap: 14px; color: var(--wm-text); }
.wm-brand:hover { text-decoration: none; }
.wm-mark { width: 44px; height: 44px; border-radius: 14px; background: var(--wm-accent); color: var(--wm-on-accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 20px; flex: none; }
.wm-brand-text { display: flex; flex-direction: column; gap: 1px; }
.wm-brand-name { font-size: 18px; font-weight: 600; }
.wm-brand-store { font-size: 13px; color: var(--wm-muted); }
.wm-topbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.wm-tabs { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.wm-tabs::-webkit-scrollbar { display: none; }
.wm-tab { flex: none; min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--wm-border-strong); color: var(--wm-text-2); font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; white-space: nowrap; }
.wm-tab:hover { text-decoration: none; color: var(--wm-text); border-color: var(--wm-muted); }
.wm-tab[aria-current="page"] { background: var(--wm-text); border-color: var(--wm-text); color: var(--wm-bg); font-weight: 600; }

.wm-theme-toggle { width: 44px; height: 44px; border-radius: 999px; border: 1px solid var(--wm-border-strong); background: var(--wm-surface); color: var(--wm-text); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.wm-theme-toggle:hover { border-color: var(--wm-muted); }
.wm-theme-toggle .wm-icon-sun { display: none; }
[data-theme="light"] .wm-theme-toggle .wm-icon-sun { display: block; }
[data-theme="light"] .wm-theme-toggle .wm-icon-moon { display: none; }

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 4px; }
.page-header h1 { font-family: var(--wm-font-display); font-size: clamp(30px, 3.2vw, 44px); font-weight: 400; letter-spacing: -0.01em; line-height: 1.1; }
.page-header p, .page-subtitle { color: var(--wm-muted); font-size: 15px; margin-top: 6px; }
.header-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--wm-muted); font-size: 14px; font-weight: 500; margin-bottom: 8px; }
.back-link:hover { color: var(--wm-text); text-decoration: none; }

/* ---------- Buttons (pills) ---------- */
.btn { min-height: 44px; padding: 0 20px; border-radius: 999px; border: 1px solid transparent; background: var(--wm-accent); color: var(--wm-on-accent); font: 600 14px/1 var(--wm-font); display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, color .15s; }
.btn:hover { background: var(--wm-accent-hover); text-decoration: none; }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: transparent; color: var(--wm-text); border-color: var(--wm-border-strong); }
.btn-secondary:hover { background: var(--wm-surface-3); border-color: var(--wm-muted); }
.btn-inverse { background: var(--wm-text); color: var(--wm-bg); }
.btn-inverse:hover { background: var(--wm-text-2); }
.btn-danger { background: transparent; color: var(--wm-bad); border-color: var(--wm-bad); }
.btn-danger:hover { background: var(--wm-bad-soft); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 13px; }
.btn-lg { min-height: 52px; padding: 0 26px; font-size: 16px; }

/* ---------- Cards and tiles ---------- */
.card { background: var(--wm-surface); border: 1px solid var(--wm-border); border-radius: var(--wm-radius-lg); overflow: hidden; }
.card-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding: 24px 28px 0; }
.card-header h2, .card-title { font-size: 20px; font-weight: 600; }
.card-header p, .card-subtitle { font-size: 14px; color: var(--wm-muted); }
.card-body { padding: 24px 28px 28px; }
.panel { background: var(--wm-surface-2); border-radius: var(--wm-radius); padding: 16px 18px; }

/* Solid accent tile: one per row at most, for the headline number */
.tile { border-radius: var(--wm-radius-lg); padding: 28px; display: flex; flex-direction: column; gap: 18px; min-height: 196px; }
.tile-accent { background: var(--wm-accent); color: var(--wm-on-accent); }
.tile-accent * { color: var(--wm-on-accent); }
.tile-attention { background: var(--wm-attention); color: var(--wm-on-attention); }
.tile-attention * { color: var(--wm-on-attention); }
.tile-plain { background: var(--wm-surface); border: 1px solid var(--wm-border); }
.tile-label { font-size: 14px; font-weight: 500; color: var(--wm-muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile-accent .tile-label, .tile-attention .tile-label { opacity: .92; }
.tile-chip { font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,.18); }
.tile-note { font-size: 14px; color: var(--wm-muted); line-height: 1.5; }
.tile-accent .tile-note, .tile-accent .tile-label { color: var(--wm-on-accent); opacity: .92; }
.tile-attention .tile-note, .tile-attention .tile-label { color: var(--wm-on-attention); opacity: .92; }
.tile-accent .tile-note a, .tile-attention .tile-note a { color: inherit; text-decoration: underline; }

.big-number { font-family: var(--wm-font-display); font-size: clamp(44px, 5vw, 64px); font-weight: 300; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.big-number .unit { font-family: var(--wm-font); font-size: .4em; letter-spacing: 0; color: var(--wm-muted); margin-left: 4px; }
.tile-accent .big-number .unit, .tile-attention .big-number .unit { opacity: .85; }

.grid-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.split { display: flex; flex-wrap: wrap; gap: 16px; }
.split > .main { flex: 999 1 560px; min-width: 0; }
.split > .side { flex: 1 1 340px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* Legacy stat cards adopt the tile look */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--wm-surface); border: 1px solid var(--wm-border); border-radius: var(--wm-radius-lg); padding: 24px; display: flex; flex-direction: column-reverse; gap: 12px; }
.stat-value { font-family: var(--wm-font-display); font-size: clamp(36px, 4vw, 52px); font-weight: 300; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; color: var(--wm-text); }
.stat-label { font-size: 14px; font-weight: 500; color: var(--wm-muted); }

/* ---------- Period comparison chips ---------- */
.delta { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--wm-muted); white-space: nowrap; }
.delta .arrow { font-size: 10px; }
.delta.up { color: var(--wm-good); }
.delta.down { color: var(--wm-bad); }
.delta .vs { font-weight: 500; color: var(--wm-muted); }
.tile-accent .delta, .tile-accent .delta .vs { color: var(--wm-on-accent); }
.tile-accent .delta { background: rgba(255,255,255,.16); padding: 4px 10px; border-radius: 999px; align-self: flex-start; }
.compare-picker { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.compare-picker select { width: auto; border-radius: 999px; padding-right: 36px; }

/* ---------- Progress / meters ---------- */
.meter { height: 8px; border-radius: 999px; background: var(--wm-surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--wm-accent); transition: width .3s ease; }
.progress-bar { height: 8px; border-radius: 999px; background: var(--wm-surface-3); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--wm-accent); transition: width .3s ease; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--wm-muted); padding: 12px 16px; border-bottom: 1px solid var(--wm-border); white-space: nowrap; }
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--wm-border); color: var(--wm-text-2); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--wm-surface-2); }
.data-table a { color: var(--wm-text); font-weight: 500; }
.data-table a:hover { color: var(--wm-accent-text); }
.view-link { color: var(--wm-accent-text); font-weight: 600; font-size: 13px; }

/* ---------- Badges & scores ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.4; background: var(--wm-surface-3); color: var(--wm-text-2); }
.badge.high, .badge-bad { background: var(--wm-bad-soft); color: var(--wm-bad); }
.badge.medium, .badge-ok { background: var(--wm-ok-soft); color: var(--wm-ok); }
.badge.low, .badge-info { background: var(--wm-accent-soft); color: var(--wm-accent-text); }
.badge-good { background: var(--wm-good-soft); color: var(--wm-good); }

.score-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--wm-surface-3); color: var(--wm-text-2); }
.score-badge.excellent, .score-badge.good { background: var(--wm-good-soft); color: var(--wm-good); }
.score-badge.needs-work, .score-badge.warning, .score-badge.medium { background: var(--wm-ok-soft); color: var(--wm-ok); }
.score-badge.poor { background: var(--wm-bad-soft); color: var(--wm-bad); }
.score-badge.none { background: var(--wm-surface-3); color: var(--wm-muted); }
.score-good { color: var(--wm-good); }
.score-ok { color: var(--wm-ok); }
.score-bad { color: var(--wm-bad); }
.dot { flex: none; width: 10px; height: 10px; border-radius: 999px; background: var(--wm-accent); }
.dot-attention { background: var(--wm-attention); }

/* ---------- Lists ---------- */
.issue-item { display: flex; align-items: flex-start; gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--wm-border); color: var(--wm-text-2); font-size: 14px; }
.issue-item:last-child { border-bottom: none; }
.issue-item p { color: var(--wm-muted); font-size: 13px; margin-top: 4px; }
.issue-item .rec { color: var(--wm-accent-text); font-size: 13px; margin-top: 6px; }
.finding { display: flex; gap: 14px; padding: 16px; border-radius: var(--wm-radius); background: var(--wm-surface-2); }
.finding .dot { margin-top: 5px; }
.finding-tag { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--wm-muted); }
.finding-title { font-size: 15px; font-weight: 600; line-height: 1.35; color: var(--wm-text); }
.finding-body { font-size: 14px; line-height: 1.5; color: var(--wm-text-2); }
.alert-item { padding: 16px 18px; border-radius: var(--wm-radius); background: var(--wm-surface-2); margin-bottom: 10px; }
.alert-item.unread { box-shadow: inset 0 0 0 1px var(--wm-accent); }
.alert-item p { color: var(--wm-text-2); font-size: 14px; margin-top: 4px; }
.alert-item small { color: var(--wm-muted); }
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--wm-border); color: var(--wm-text-2); }
.history-item:last-child { border-bottom: none; }
.empty, .empty-state { color: var(--wm-muted); text-align: center; padding: 32px 16px; font-size: 14px; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; color: var(--wm-text); margin-bottom: 8px; }
input[type="text"], input[type="email"], input[type="url"], input[type="number"], input[type="date"], input[type="search"], input[type="password"], select, textarea, .search-input {
  width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--wm-border-strong); background: var(--wm-surface-2); color: var(--wm-text); font: 400 14px/1.4 var(--wm-font);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, .search-input:focus { outline: none; border-color: var(--wm-accent); box-shadow: 0 0 0 3px var(--wm-accent-soft); }
input:disabled, select:disabled { opacity: .6; }
.hint { font-size: 13px; color: var(--wm-muted); margin-top: 6px; line-height: 1.5; }
.settings-section { padding: 24px 0; border-bottom: 1px solid var(--wm-border); }
.settings-section:first-child { padding-top: 0; }
.settings-section:last-child { border-bottom: none; }
.settings-section h3 { font-size: 18px; font-weight: 600; margin-bottom: 14px; }
.inline-input { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--wm-text-2); }
.inline-input input { width: 96px; }

/* Segmented control */
.segmented { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--wm-surface-2); gap: 2px; }
.segmented button { min-height: 36px; padding: 0 14px; border-radius: 999px; border: none; background: transparent; color: var(--wm-muted); font: 500 13px/1 var(--wm-font); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--wm-border-strong); color: var(--wm-text); font-weight: 600; }

/* ---------- Scores (detail pages) ---------- */
.score-section { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.big-score { font-family: var(--wm-font-display); font-size: clamp(56px, 7vw, 88px); font-weight: 300; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }

/* ---------- Charts ---------- */
.charts-row, .two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); gap: 16px; }
.chart-card .card-body { height: 240px; position: relative; }
.chart-empty { height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--wm-muted); font-size: 14px; }
.chart-empty small { color: var(--wm-muted); }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--wm-muted); }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- Modals, toasts, progress widget ---------- */
.modal, .sync-modal { display: none; position: fixed; inset: 0; background: var(--wm-overlay); z-index: 1000; align-items: center; justify-content: center; padding: 16px; }
.modal.active, .sync-modal.active { display: flex; }
.modal-content, .sync-content { background: var(--wm-surface); border: 1px solid var(--wm-border); border-radius: var(--wm-radius-lg); padding: 28px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--wm-shadow); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 { font-size: 20px; font-weight: 600; }
.modal-close { width: 40px; height: 40px; border-radius: 999px; border: none; background: transparent; color: var(--wm-muted); font-size: 24px; cursor: pointer; line-height: 1; }
.modal-close:hover { background: var(--wm-surface-3); color: var(--wm-text); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); min-width: 260px; max-width: calc(100vw - 32px); padding: 14px 20px; border-radius: 999px; background: var(--wm-text); color: var(--wm-bg); font-size: 14px; font-weight: 600; text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10000; box-shadow: var(--wm-shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { background: var(--wm-good); color: #04120B; }
.toast.error { background: var(--wm-bad); color: #FFFFFF; }

.floating-progress { position: fixed; bottom: 20px; right: 20px; background: var(--wm-surface); border: 1px solid var(--wm-border); border-radius: var(--wm-radius); padding: 16px 20px; min-width: 280px; max-width: 350px; box-shadow: var(--wm-shadow); z-index: 9999; animation: wmSlideIn .3s ease; }
@keyframes wmSlideIn { from { transform: translateY(100px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.floating-progress.hiding { animation: wmSlideOut .3s ease forwards; }
@keyframes wmSlideOut { from { transform: translateY(0); opacity: 1; } to { transform: translateY(100px); opacity: 0; } }
.floating-progress-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.floating-progress-title { font-weight: 600; color: var(--wm-text); font-size: 14px; }
.floating-progress-close { background: none; border: none; color: var(--wm-muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 0; }
.floating-progress-close:hover { color: var(--wm-text); }
.floating-progress-bar { height: 6px; background: var(--wm-surface-3); border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.floating-progress-fill { height: 100%; background: var(--wm-accent); border-radius: 999px; transition: width .3s ease; }
.floating-progress-status { font-size: 12px; color: var(--wm-muted); }
.floating-progress-status.success { color: var(--wm-good); }
.floating-progress-status.error { color: var(--wm-bad); }

/* ---------- Standalone pages ---------- */
.landing, .error-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 32px 16px; gap: 16px; }
.hero h1, .error-page h1 { font-size: clamp(40px, 6vw, 72px); font-weight: 300; letter-spacing: -0.04em; }
.hero p, .error-page p { font-size: 18px; color: var(--wm-muted); }

/* Lucide icons */
[data-lucide], .icon { width: 18px; height: 18px; stroke-width: 2; }

@media (max-width: 640px) {
  .card-header { padding: 20px 20px 0; }
  .card-body { padding: 20px; }
  .tile { padding: 22px; min-height: 0; }
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; }
}
