/* ==========================================================================
   Omni-Nerd — design tokens + shell styles
   Theme is controlled by  <html data-theme="light|dark" data-accent="…">
   ========================================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --gap: 12px;
  --widget-h: 384px;   /* uniform widget tile height */

  /* severity ramps (mode-agnostic mid tones) */
  --sev-critical: #E24B4A;
  --sev-warning:  #EF9F27;
  --sev-info:     #378ADD;
  --sev-ok:       #1D9E75;
}

/* ---- accent options ---- */
[data-accent="blue"]   { --accent: #378ADD; --accent-strong:#185FA5; }
[data-accent="teal"]   { --accent: #1D9E75; --accent-strong:#0F6E56; }
[data-accent="purple"] { --accent: #7F77DD; --accent-strong:#534AB7; }
[data-accent="amber"]  { --accent: #BA7517; --accent-strong:#854F0B; }
[data-accent="coral"]  { --accent: #D85A30; --accent-strong:#993C1D; }

/* ---- dark (default) ---- */
[data-theme="dark"] {
  --bg:          #0f1115;
  --surface:     #181b21;
  --surface-2:   #1f232b;
  --surface-hover:#242933;
  --border:      rgba(255,255,255,0.09);
  --border-2:    rgba(255,255,255,0.16);
  --text:        #e7e9ee;
  --text-2:      #a3a8b4;
  --text-3:      #6f7480;
  --chip-bg:     rgba(255,255,255,0.05);
}

/* ---- light ---- */
[data-theme="light"] {
  --bg:          #f4f5f7;
  --surface:     #ffffff;
  --surface-2:   #f1f2f5;
  --surface-hover:#f5f6f8;
  --border:      rgba(0,0,0,0.10);
  --border-2:    rgba(0,0,0,0.18);
  --text:        #1c1f25;
  --text-2:      #5a606c;
  --text-3:      #8b909b;
  --chip-bg:     rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: var(--radius-md);
}
.skip-link:focus { left: 12px; }

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: #fff; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.brand-mark img { display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 600; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--text-3); }

.search {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 0 10px; height: 34px;
  flex: 1 1 220px; min-width: 160px; max-width: 360px;
}
.search i { color: var(--text-3); font-size: 16px; }
.search input { border: none; background: transparent; color: var(--text); outline: none; width: 100%; font-size: 13px; }
.spacer { flex: 1 1 auto; }

.btn, .icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 11px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  font-size: 13px; font-family: inherit; cursor: pointer;
}
.icon-btn { width: 34px; padding: 0; justify-content: center; }
.btn:hover, .icon-btn:hover { background: var(--surface-hover); border-color: var(--border-2); }
.btn i, .icon-btn i { font-size: 16px; }

.accents { display: flex; align-items: center; gap: 5px; }
.swatch {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--sw); border: 1px solid var(--border-2); cursor: pointer; padding: 0;
}
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }

/* dropdown menu */
.client-picker { position: relative; }
.menu {
  position: absolute; top: 40px; left: 0; z-index: 40;
  list-style: none; margin: 0; padding: 6px;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-md); min-width: 200px;
  max-height: 320px; overflow: auto;
  box-shadow: 0 8px 28px rgba(0,0,0,0.28);
}
.menu li {
  padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.menu li:hover { background: var(--surface-2); }
.menu li[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.menu .count { color: var(--text-3); font-size: 11px; }

/* ===== Attention strip ===== */
.pulse {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 12px 16px 4px;
}
.pulse-chip {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; padding: 6px 11px;
  border-radius: 999px; cursor: pointer; border: 1px solid transparent;
}
.pulse-chip i { font-size: 14px; }
.pulse-chip.is-active { border-color: currentColor; }
.pulse-chip[data-sev="critical"] { color: var(--sev-critical); background: color-mix(in srgb, var(--sev-critical) 14%, transparent); }
.pulse-chip[data-sev="warning"]  { color: var(--sev-warning);  background: color-mix(in srgb, var(--sev-warning) 16%, transparent); }
.pulse-chip[data-sev="info"]     { color: var(--sev-info);     background: color-mix(in srgb, var(--sev-info) 14%, transparent); }

/* ===== Grid ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--gap);
  padding: 12px 16px 24px;
}

/* ===== Widget ===== */
/* Uniform fixed-height tiles → no gaps, clean drag swap. Content area scrolls. */
.widget {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 13px 13px 9px;
  height: var(--widget-h);
  display: flex; flex-direction: column; overflow: hidden;
}
.widget-head, .wmetrics, .wtool, .widget-foot { flex: 0 0 auto; }
.wlist { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.empty { flex: 1 1 auto; }

/* Custom scrollbars — transparent track, dark-grey thumb, no arrow buttons */
.wlist, .menu, .side-panel {
  scrollbar-width: thin;
  scrollbar-color: var(--text-3) transparent;
}
.wlist::-webkit-scrollbar, .menu::-webkit-scrollbar { width: 10px; height: 10px; }
.wlist::-webkit-scrollbar-track, .menu::-webkit-scrollbar-track { background: transparent; }
.wlist::-webkit-scrollbar-thumb, .menu::-webkit-scrollbar-thumb {
  background: var(--text-3); border-radius: 8px;
  border: 3px solid transparent; background-clip: padding-box;
}
.wlist::-webkit-scrollbar-thumb:hover, .menu::-webkit-scrollbar-thumb:hover {
  background: var(--text-2); background-clip: padding-box;
}
.wlist::-webkit-scrollbar-button, .menu::-webkit-scrollbar-button { display: none; height: 0; width: 0; }
.widget-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.widget-icon { color: var(--accent); font-size: 19px; flex: 0 0 auto; }
.widget-title { font-weight: 500; font-size: 14px; white-space: nowrap; }
.widget-badge {
  margin-left: auto; font-size: 10.5px; color: var(--text-3);
  background: var(--chip-bg); padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.widget-grip { color: var(--text-3); font-size: 17px; cursor: grab; display: none; flex: 0 0 auto; }

.wlist { list-style: none; margin: 0; padding: 0; }
.witem {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 5px; border-radius: var(--radius-md); cursor: pointer;
}
.witem:hover { background: var(--surface-2); }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.dot[data-sev="critical"] { background: var(--sev-critical); }
.dot[data-sev="warning"]  { background: var(--sev-warning); }
.dot[data-sev="info"]     { background: var(--sev-info); }
.dot[data-sev="ok"]       { background: var(--sev-ok); }
.witem-main { min-width: 0; flex: 1; }
.witem-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.witem-sub { font-size: 11px; color: var(--text-3); margin-top: 1px; }
.witem-client {
  font-size: 10px; color: var(--text-2); background: var(--chip-bg);
  padding: 1px 6px; border-radius: 999px; margin-right: 4px;
}
.src-tag {
  font-size: 9px; font-weight: 600; letter-spacing: 0.3px;
  padding: 1px 5px; border-radius: 4px; margin-right: 5px; vertical-align: 1px;
}
.src-bd  { background: color-mix(in srgb, #E24B4A 20%, transparent); color: #E24B4A; }
.src-mwb { background: color-mix(in srgb, #378ADD 22%, transparent); color: #378ADD; }
.src-uf  { background: color-mix(in srgb, #3B82F6 20%, transparent); color: #5AA0FF; }
.src-om  { background: color-mix(in srgb, #1D9E75 22%, transparent); color: #2BBE8E; }
.src-wg  { background: color-mix(in srgb, #D9342B 22%, transparent); color: #F0635A; }
.witem-go { color: var(--text-3); font-size: 15px; opacity: 0; flex: 0 0 auto; }
.witem:hover .witem-go { opacity: 1; }

.witem-actions { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.mini-btn {
  height: 24px; font-size: 11px; padding: 0 9px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
}
.mini-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.wmetrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 2px 2px 8px; }
.metric { background: var(--surface-2); border-radius: var(--radius-md); padding: 9px 4px; text-align: center; }
.metric-num { font-size: 20px; font-weight: 600; line-height: 1.1; }
.metric-lbl { font-size: 10.5px; color: var(--text-2); margin-top: 2px; }

.wtool { display: flex; gap: 6px; padding: 2px 2px 8px; }
.wtool select, .wtool input {
  height: 34px; font-size: 12px; background: var(--surface-2);
  color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.wtool select { flex: 0 0 96px; padding: 0 6px; }
.wtool input { flex: 1; min-width: 0; padding: 0 9px; }
.wtool button {
  height: 34px; width: 34px; flex: 0 0 auto; background: var(--surface-2);
  color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-md); cursor: pointer;
}
.wtool button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.widget-foot {
  width: 100%; margin-top: 5px; background: transparent; border: none;
  color: var(--accent); font-size: 12px; text-align: left; padding: 7px 5px;
  display: flex; align-items: center; gap: 5px; cursor: pointer; font-family: inherit;
}
.widget-foot:hover { text-decoration: underline; }
.widget-foot-multi { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 7px 5px; margin-top: 5px; }
.foot-link {
  background: none; border: none; padding: 0; cursor: pointer; font-family: inherit;
  color: var(--accent); font-size: 12px; display: inline-flex; align-items: center; gap: 4px;
}
.foot-link:hover { text-decoration: underline; }
.foot-link i { font-size: 13px; }
.empty { font-size: 12px; color: var(--text-3); padding: 10px 5px; }

/* add-widget tile */
.add-widget {
  border: 1px dashed var(--border-2); border-radius: var(--radius-lg);
  background: transparent; height: var(--widget-h); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: var(--text-3); font-size: 13px; font-family: inherit;
}
.add-widget:hover { color: var(--accent); border-color: var(--accent); }
.add-widget i { font-size: 22px; }

/* ===== Edit mode + drag ===== */
.editing .widget { border: 1px dashed var(--accent); cursor: grab; }
.editing .widget-grip { display: block; }
.editing .witem { pointer-events: none; }
.widget.dragging { opacity: 0.4; }

/* ===== Footer ===== */
.appfoot {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 16px 18px; font-size: 11px; color: var(--text-3);
  border-top: 1px solid var(--border);
}

/* ===== Live/demo status pill (PSA widget) ===== */
.live-pill {
  font-size: 10px; font-weight: 500; padding: 2px 8px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 5px; margin-left: 6px;
}
.live-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.live-pill.live  { color: var(--sev-ok);      background: color-mix(in srgb, var(--sev-ok) 16%, transparent); }
.live-pill.demo  { color: var(--text-3);      background: var(--chip-bg); }
.live-pill.error { color: var(--sev-critical); background: color-mix(in srgb, var(--sev-critical) 16%, transparent); }
.live-pill.loading { color: var(--sev-warning); background: color-mix(in srgb, var(--sev-warning) 14%, transparent); }
.live-pill.loading::before { animation: pillpulse 1s ease-in-out infinite; }
@keyframes pillpulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 440px; max-width: 100%; background: var(--surface);
  border: 1px solid var(--border-2); border-radius: var(--radius-lg);
  box-shadow: 0 18px 50px rgba(0,0,0,0.4); display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.modal-title { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 15px; }
.modal-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-note { margin: 0; font-size: 12px; color: var(--text-3); line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-2); }
.field input, .field select {
  height: 36px; padding: 0 10px; font-size: 13px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.test-result { font-size: 12px; padding: 8px 10px; border-radius: var(--radius-md); }
.test-result[hidden] { display: none; }
.test-result.ok  { color: var(--sev-ok);       background: color-mix(in srgb, var(--sev-ok) 14%, transparent); }
.test-result.bad { color: var(--sev-critical);  background: color-mix(in srgb, var(--sev-critical) 14%, transparent); }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-danger { color: var(--sev-critical); border-color: color-mix(in srgb, var(--sev-critical) 50%, var(--border)); }
.btn-danger:hover { background: color-mix(in srgb, var(--sev-critical) 12%, transparent); }

/* ===== Field Notes side panel ===== */
.side-panel {
  position: fixed; top: 0; right: 0; height: 100vh; width: 400px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 60; display: flex; flex-direction: column;
  box-shadow: -10px 0 34px rgba(0,0,0,0.28);
}
.side-panel[hidden] { display: none; }
.side-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.side-panel-title { display: flex; align-items: center; gap: 7px; font-weight: 500; font-size: 14px; }
.side-panel-actions { display: flex; gap: 6px; }
.side-panel-actions .icon-btn { text-decoration: none; }
.side-panel iframe { flex: 1; width: 100%; border: none; background: #fff; }
.side-panel-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 55; }
.side-panel-backdrop[hidden] { display: none; }

@media (max-width: 560px) {
  .search { order: 10; max-width: none; flex-basis: 100%; }
  .brand-sub { display: none; }
}
