/* =====================================================
   VALENS CRM — STYLE (Phase 3 visual pass)
   shadcn-inspired token system in plain CSS. Semantic
   surface/foreground pairs, one radius scale, restrained
   near-black palette, white as the single accent used
   sparingly. Legacy variable names are aliased onto the
   tokens so every existing selector keeps working.
   Motion: 150ms, hover/state only. Focus visible always.
   ===================================================== */

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

:root {
  /* ---- shadcn-style semantic tokens (dark) ---- */
  --background: #09090b;
  --foreground: #e4e4e7;
  --card: #101012;
  --card-foreground: #e4e4e7;
  --popover: #141416;
  --popover-foreground: #e4e4e7;
  --muted: #1b1b1f;
  --muted-foreground: #77777e;
  --primary: #fafafa;
  --primary-foreground: #09090b;
  --secondary: #202024;
  --secondary-foreground: #d4d4d8;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.16);
  --input: #17171a;
  --ring: rgba(250,250,250,0.55);
  --destructive: #f26d6d;
  --destructive-soft: rgba(242,109,109,0.12);
  --success: #4ade80;
  --warning: #fbbf24;
  --warning-soft: rgba(251,191,36,0.1);

  --radius: 8px;
  --radius-sm: calc(var(--radius) - 2px);
  --radius-md: calc(var(--radius) + 4px);
  --radius-full: 999px;

  /* spacing scale */
  --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem;
  --sp-4: 1rem; --sp-5: 1.5rem; --sp-6: 2rem;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  --sidebar-w: 232px;
  --transition: 0.15s ease;

  /* ---- legacy aliases (existing selectors keep working) ---- */
  --black: var(--background);
  --surface-1: #0d0d0f;
  --surface-2: var(--card);
  --surface-3: var(--input);
  --surface-4: var(--secondary);
  --white: var(--primary);
  --grey-1: #d4d4d8;
  --grey-2: #9d9da4;
  --grey-3: var(--muted-foreground);
  --grey-4: #2b2b30;
  --danger: var(--destructive);
  --ok: var(--success);
}

html { font-size: 15px; }
body {
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: inherit; text-decoration: none; }
button { font-family: var(--font); cursor: pointer; color: inherit; }
input, select, textarea { font-family: var(--font); }

/* Visible focus everywhere interactive — accessibility is part of finished. */
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }

.mono-sm { font-family: var(--mono); font-size: 0.75rem; }

/* ---------- App shell ---------- */
.app { display: flex; height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 1.25rem 0.9rem;
}
.acct-badge {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.7rem 0.75rem; margin-bottom: 1.5rem;
  background: var(--muted); border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.acct-avatar {
  width: 32px; height: 32px; border-radius: var(--radius); flex-shrink: 0;
  background: linear-gradient(180deg, #ffffff 0%, #8a8a8a 100%);
  color: var(--primary-foreground); font-weight: 800; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
}
.acct-name { font-size: 0.85rem; font-weight: 700; color: var(--primary); line-height: 1.2; }
.acct-loc { font-size: 0.7rem; color: var(--muted-foreground); }

.nav-section-label { font-size: 0.62rem; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted-foreground); padding: 0 0.75rem; margin: 0.9rem 0 0.4rem; }
.nav-item {
  display: flex; align-items: center; gap: 0.7rem;
  width: 100%; padding: 0.6rem 0.75rem; margin-bottom: 2px;
  background: none; border: none; border-radius: var(--radius-sm);
  color: var(--grey-2); font-size: 0.85rem; font-weight: 500; text-align: left;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--muted); color: var(--primary); }
.nav-item.active { background: var(--secondary); color: var(--primary); }
.nav-icon { width: 17px; text-align: center; font-weight: 600; opacity: 0.85; }

.sidebar-footer { margin-top: auto; padding: 0.75rem; font-size: 0.68rem; color: var(--muted-foreground); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}
.topbar h1 { font-size: 1.05rem; font-weight: 700; color: var(--primary); letter-spacing: -0.01em; }
.topbar-actions { display: flex; gap: 0.6rem; }

.content { flex: 1; overflow-y: auto; padding: 1.75rem; }

/* Admin context bar (6.5) — unmissable. */
.admin-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.45rem 1.75rem;
  background: var(--warning-soft);
  border-bottom: 1px solid rgba(251,191,36,0.35);
  color: var(--warning);
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.04em;
}
.admin-bar b { color: #fde68a; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1.1rem; border-radius: var(--radius-sm);
  font-size: 0.82rem; font-weight: 600; border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--grey-1); }
.btn-ghost { background: transparent; color: var(--grey-2); border-color: var(--grey-4); }
.btn-ghost:hover:not(:disabled) { border-color: var(--grey-2); color: var(--primary); }
.btn-danger { background: transparent; color: var(--destructive); border-color: rgba(242,109,109,0.3); }
.btn-danger:hover:not(:disabled) { border-color: var(--destructive); background: var(--destructive-soft); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.75rem; }
.btn-icon { padding: 0.35rem 0.55rem; background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--muted-foreground); font-size: 0.8rem; transition: color var(--transition), border-color var(--transition); }
.btn-icon:hover { color: var(--primary); border-color: var(--grey-2); }

/* ---------- Cards / tables ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); }
.card-pad { padding: 1.5rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th {
  text-align: left; padding: 0.75rem 1rem;
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted-foreground); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); color: var(--foreground); vertical-align: middle; }
tbody tr { transition: background var(--transition); cursor: pointer; }
tbody tr:hover { background: var(--muted); }
tbody tr:last-child td { border-bottom: none; }
tr.row-sel { background: rgba(250,250,250,0.045); }
.th-check, .td-check { width: 34px; padding-right: 0 !important; }
.cell-clip { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 0.4rem; justify-content: flex-end; }
.muted-count { font-size: 0.78rem; color: var(--muted-foreground); }
.panel-title { font-size: 0.9rem; font-weight: 700; color: var(--primary); }
.panel-sub { font-size: 0.78rem; color: var(--muted-foreground); max-width: 60ch; }

.empty-state { padding: 3.5rem 1.5rem; text-align: center; color: var(--muted-foreground); font-size: 0.9rem; }
.empty-state strong { display: block; color: var(--grey-2); font-size: 1rem; margin-bottom: 0.3rem; }

/* Tags */
.tag {
  display: inline-block; padding: 0.15rem 0.6rem; margin: 0 0.25rem 0.25rem 0;
  background: var(--secondary); border: 1px solid var(--border-strong);
  border-radius: var(--radius-full); font-size: 0.7rem; font-weight: 600; color: var(--foreground);
  white-space: nowrap;
}
.tag.selectable { cursor: pointer; color: var(--muted-foreground); border-color: var(--border); }
.tag.selectable:hover { color: var(--foreground); }
.tag.selected { color: var(--primary-foreground); background: var(--primary); border-color: var(--primary); }

/* Inputs */
.search-input, .form-input, .form-select, .form-textarea {
  width: 100%; padding: 0.6rem 0.85rem;
  background: var(--input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--primary); font-size: 0.85rem;
  outline: none; transition: border-color var(--transition);
}
.search-input:focus, .form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--ring); }
.form-input[readonly] { color: var(--grey-2); }
.form-textarea { min-height: 90px; resize: vertical; }
.form-select { appearance: none; }
.search-input { max-width: 300px; }

.form-group { margin-bottom: 1.1rem; }
.form-label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--foreground); margin-bottom: 0.4rem; }
.form-label .req { color: var(--destructive); margin-left: 2px; }
.form-hint { font-size: 0.72rem; color: var(--muted-foreground); margin-top: 0.3rem; }
.field-error { font-size: 0.74rem; color: var(--destructive); margin-top: 0.3rem; display: none; }
.form-group.has-error .field-error { display: block; }
.form-group.has-error .form-input, .form-group.has-error .form-select { border-color: var(--destructive); }
.filter-row { display: flex; gap: 0.5rem; }
.filter-row .form-select { flex: 1; }
.filter-row .form-input { flex: 1; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; padding: 1.5rem;
}
.modal-overlay.open { display: flex; }
.modal {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--popover); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); padding: 1.75rem;
}
.modal-lg { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.modal-head h2 { font-size: 1.05rem; font-weight: 700; color: var(--primary); }
.modal-close { background: none; border: none; color: var(--muted-foreground); font-size: 1.3rem; line-height: 1; transition: color var(--transition); }
.modal-close:hover { color: var(--primary); }
.modal-foot { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }

/* ---------- Detail drawer ---------- */
.drawer-overlay { position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,0.5); display: none; }
.drawer-overlay.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 160;
  width: min(480px, 94vw);
  background: var(--surface-1); border-left: 1px solid var(--border-strong);
  transform: translateX(100%); transition: transform 0.15s ease-out;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 1.5rem 1.75rem 1rem; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; justify-content: space-between; }
.drawer-title { font-size: 1.2rem; font-weight: 800; color: var(--primary); letter-spacing: -0.02em; }
.drawer-sub { font-size: 0.75rem; color: var(--muted-foreground); margin-top: 0.2rem; }
.drawer-tabs { padding: 0 1.75rem; margin-bottom: 0; border-bottom: 1px solid var(--border); }
.drawer-body { flex: 1; overflow-y: auto; padding: 1.5rem 1.75rem; }
.drawer-foot { padding: 1rem 1.75rem; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 0.6rem; }

.detail-section-label { font-size: 0.62rem; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted-foreground); margin: 1.4rem 0 0.6rem; }
.detail-section-label:first-child { margin-top: 0; }
.detail-field { padding: 0.65rem 0; border-bottom: 1px solid var(--border); }
.detail-field-name { font-size: 0.7rem; color: var(--muted-foreground); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.15rem; }
.detail-field-value { font-size: 0.9rem; color: var(--foreground); word-break: break-word; white-space: pre-wrap; }
.detail-field-value.empty { color: var(--grey-4); font-style: italic; }

/* Call card + audio (6.3) */
.call-card {
  background: var(--card); border: 1px solid var(--border);
  border-left: 2px solid var(--primary);
  border-radius: var(--radius-sm); padding: 0.9rem 1rem; margin-bottom: 1.1rem;
}
.call-summary { font-size: 0.85rem; color: var(--foreground); white-space: pre-wrap; margin-bottom: 0.6rem; }
.call-audio { width: 100%; height: 36px; margin-top: 0.35rem; }
.senti { display: inline-block; padding: 0.1rem 0.55rem; border-radius: var(--radius-full); font-size: 0.68rem; font-weight: 700; border: 1px solid var(--border-strong); }
.senti.pos { color: var(--success); border-color: rgba(74,222,128,0.4); }
.senti.neg { color: var(--destructive); border-color: rgba(242,109,109,0.4); }
.senti.neu { color: var(--grey-2); }

/* Activity timeline (6.3) */
.note-composer { display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-end; margin-bottom: 1.25rem; }
.note-composer .form-textarea { min-height: 56px; }
.tl-item { display: flex; gap: 0.75rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.tl-item:last-child { border-bottom: none; }
.tl-icon {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--secondary); border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; font-size: 0.75rem; color: var(--grey-2);
}
.tl-body { flex: 1; min-width: 0; }
.tl-head { display: flex; justify-content: space-between; gap: 0.6rem; align-items: baseline; }
.tl-label { font-size: 0.78rem; font-weight: 700; color: var(--foreground); }
.tl-ts { font-size: 0.68rem; color: var(--muted-foreground); white-space: nowrap; }
.tl-text { font-size: 0.82rem; color: var(--grey-2); white-space: pre-wrap; word-break: break-word; margin-top: 0.2rem; }
.tl-change { font-size: 0.76rem; color: var(--grey-2); margin-top: 0.25rem; }
.tl-from { color: var(--muted-foreground); text-decoration: line-through; }
.tl-to { color: var(--foreground); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.tab {
  padding: 0.6rem 1.1rem; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted-foreground); font-size: 0.85rem; font-weight: 600;
  transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--foreground); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Saved-view chips (6.9) ---------- */
.vchips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.9rem; }
.vchip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.28rem 0.75rem; border-radius: var(--radius-full);
  background: transparent; border: 1px solid var(--grey-4);
  color: var(--grey-2); font-size: 0.74rem; font-weight: 600;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.vchip:hover { border-color: var(--grey-2); color: var(--primary); }
.vchip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.vchip.add { border-style: dashed; }
.vchip-x { font-weight: 400; opacity: 0.7; padding: 0 0.1rem; }
.vchip-x:hover { opacity: 1; }

/* ---------- Bulk action bar (6.7) ---------- */
.bulk-bar {
  position: sticky; bottom: 0.75rem; z-index: 50;
  display: flex; align-items: center; gap: 0.5rem;
  margin-top: 0.9rem; padding: 0.6rem 0.9rem;
  background: var(--popover); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  width: fit-content;
}
.bulk-count { font-size: 0.78rem; font-weight: 700; color: var(--primary); margin-right: 0.4rem; }

/* ---------- Alert banners (6.9) ---------- */
.alert-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.7rem 1rem; margin-bottom: 1.1rem;
  background: var(--destructive-soft);
  border: 1px solid rgba(242,109,109,0.35);
  border-radius: var(--radius-sm);
  font-size: 0.8rem; color: var(--foreground);
}
.alert-banner b { color: var(--destructive); }
.alert-banner.warn { background: var(--warning-soft); border-color: rgba(251,191,36,0.35); }
.alert-banner.warn b { color: var(--warning); }

/* ---------- Toast (undo) ---------- */
#toastHost { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 400; }
.toast {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--popover); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); padding: 0.7rem 1.1rem;
  font-size: 0.82rem; color: var(--foreground);
  box-shadow: 0 8px 30px rgba(0,0,0,0.55);
}
.toast-act {
  background: none; border: none; color: var(--primary);
  font-weight: 700; font-size: 0.82rem; text-decoration: underline; padding: 0;
}

/* ---------- Glossary tooltips (6.9) ---------- */
.help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin-left: 0.35rem;
  border-radius: 50%; border: 1px solid var(--border-strong);
  color: var(--muted-foreground); font-size: 0.62rem; font-weight: 700;
  cursor: help; position: relative; vertical-align: middle;
}
.help:hover, .help:focus-visible { color: var(--primary); border-color: var(--grey-2); }
.help::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  width: 230px; padding: 0.55rem 0.7rem;
  background: var(--popover); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); color: var(--foreground);
  font-size: 0.72rem; font-weight: 400; line-height: 1.45; text-transform: none; letter-spacing: 0;
  opacity: 0; pointer-events: none; transition: opacity var(--transition);
  z-index: 300; box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.help:hover::after, .help:focus-visible::after { opacity: 1; }

/* ---------- Sites grid ---------- */
.sites-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.site-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; transition: border-color var(--transition); }
.site-card:hover { border-color: var(--grey-3); }
.site-thumb {
  height: 130px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 800;
  background: linear-gradient(180deg, #101012 0%, #060607 100%);
}
.site-thumb span { background: linear-gradient(180deg, #ffffff 0%, #6a6a6a 100%); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.site-body { padding: 1rem 1.1rem; }
.site-name { font-size: 0.92rem; font-weight: 700; color: var(--primary); margin-bottom: 0.2rem; }
.site-url { font-size: 0.73rem; color: var(--muted-foreground); word-break: break-all; margin-bottom: 0.75rem; }
.site-meta { font-size: 0.68rem; color: var(--grey-4); margin-bottom: 0.75rem; }
.site-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Automation ---------- */
.auto-row {
  display: flex; align-items: center; gap: 1rem;
  padding: 1.1rem 1.25rem; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 0.75rem;
  transition: border-color var(--transition);
}
.auto-row:hover { border-color: var(--grey-3); }
.auto-flow { flex: 1; min-width: 0; }
.auto-name { font-size: 0.9rem; font-weight: 700; color: var(--primary); margin-bottom: 0.3rem; }
.auto-sentence { font-size: 0.78rem; color: var(--grey-2); margin-bottom: 0.45rem; }
.auto-chips { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.auto-chip { padding: 0.2rem 0.65rem; background: var(--secondary); border: 1px solid var(--border-strong); border-radius: var(--radius-full); font-size: 0.7rem; font-weight: 600; color: var(--foreground); }
.auto-arrow { color: var(--muted-foreground); font-size: 0.8rem; }
.auto-status { font-size: 0.7rem; font-weight: 700; }
.auto-status.on { color: var(--success); }
.auto-status.off { color: var(--muted-foreground); }
.auto-warn {
  margin-top: 0.45rem; font-size: 0.72rem; color: var(--warning);
  background: var(--warning-soft); border: 1px solid rgba(251,191,36,0.3);
  border-radius: var(--radius-sm); padding: 0.3rem 0.6rem; display: inline-block;
}

/* Toggle */
.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; background: var(--grey-4); border: none; border-radius: var(--radius-full); transition: background var(--transition); }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--grey-2); transition: transform var(--transition), background var(--transition); }
.toggle.on { background: var(--primary); }
.toggle.on::after { transform: translateX(16px); background: var(--primary-foreground); }

.check { width: 16px; height: 16px; accent-color: #fafafa; cursor: pointer; }

/* ---------- Dashboard ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { padding: 1.4rem 1.5rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); }
.stat-num { font-size: 2rem; font-weight: 800; color: var(--primary); letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.72rem; color: var(--muted-foreground); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; margin-top: 0.3rem; }

.section-title { font-size: 0.95rem; font-weight: 700; color: var(--primary); margin: 1.75rem 0 0.9rem; }
.section-title:first-child { margin-top: 0; }
.page-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }

.int-row { display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.5rem 0; }
.int-row .sdot { margin-top: 0.45rem; }
.int-label { font-size: 0.85rem; font-weight: 600; color: var(--foreground); }

.pick-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.2rem; border-bottom: 1px solid var(--border); }
.pick-row:last-of-type { border-bottom: none; }

.option-pill-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }

/* Scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--grey-4); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--grey-3); }

.menu-btn { display: none; }

/* ===================== AUTH SCREEN ===================== */
.auth-screen {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: var(--background);
  align-items: center; justify-content: center;
}
.auth-screen.open { display: flex; }
.auth-box {
  width: 100%; max-width: 380px;
  padding: 2.5rem 2rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.auth-logo {
  font-size: 1.15rem; font-weight: 800; color: var(--primary);
  letter-spacing: -0.02em; margin-bottom: 1.75rem; text-align: center;
}
.auth-error {
  font-size: 0.8rem; color: var(--destructive);
  background: var(--destructive-soft);
  border: 1px solid rgba(242,109,109,0.25);
  border-radius: var(--radius-sm); padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
}
.auth-msg { font-size: 0.85rem; color: var(--grey-2); line-height: 1.6; }
.auth-msg strong { display: block; color: var(--primary); margin-bottom: 0.35rem; font-size: 0.95rem; }
.auth-uid {
  margin-top: 0.75rem; padding: 0.6rem 0.75rem;
  background: var(--input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 0.78rem; color: var(--foreground);
  word-break: break-all; font-family: var(--mono);
}
.auth-acct-pick {
  display: block; width: 100%; text-align: left;
  padding: 0.85rem 1rem; margin-bottom: 0.6rem;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  transition: border-color var(--transition);
}
.auth-acct-pick:hover { border-color: var(--grey-3); }
.auth-acct-name { font-size: 0.92rem; font-weight: 600; color: var(--primary); }
.auth-acct-loc { font-size: 0.78rem; color: var(--muted-foreground); margin-top: 0.15rem; text-transform: capitalize; }

/* ---- Sites: deploy modal ---- */
.deploy-url a { font-size: 0.85rem; word-break: break-all; color: var(--primary); }
.deploy-cname { background: var(--background); border: 1px solid var(--grey-4); padding: 0.7rem 0.85rem; display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.85rem; word-break: break-all; }
.deploy-cname .ck { display: inline-block; min-width: 54px; color: var(--grey-2); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; }
.form-err { color: var(--destructive); font-size: 0.8rem; margin: 0.4rem 0 0; }

/* ================= Sites — Netlify deploy ================= */
.sites-sub { color: var(--grey-2); font-size: 0.85rem; margin: 0 0 1.25rem; }
.sgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0.85rem; }
.scard { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1.1rem 1.15rem; display: flex; flex-direction: column; }
.scard-top { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.7rem; }
.scard-top h3 { font-size: 0.95rem; font-weight: 600; color: var(--primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sbadge { flex: none; font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--grey-2); border: 1px solid var(--border-strong); border-radius: var(--radius-full); padding: 0.15rem 0.5rem; }
.scard-url { display: block; color: var(--foreground); font-size: 0.8rem; word-break: break-all; margin-bottom: 0.25rem; }
.scard-url:hover { color: var(--primary); text-decoration: underline; }
.scard-url.sub { color: var(--muted-foreground); font-size: 0.74rem; }
.scard-url.muted { color: var(--muted-foreground); }
.scard-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-top: 0.9rem; flex-wrap: wrap; }
.sstatus { font-size: 0.72rem; color: var(--grey-2); display: inline-flex; align-items: center; }
.sdot { width: 7px; height: 7px; border-radius: 50%; margin-right: 0.4rem; display: inline-block; flex: none; }
.sdot.live { background: var(--success); }
.sdot.pending { background: var(--muted-foreground); }
.scard-actions { display: inline-flex; gap: 0.75rem; }
.slink { background: none; border: none; color: var(--grey-2); font-size: 0.74rem; padding: 0; transition: color var(--transition); }
.slink:hover { color: var(--primary); }
.slink.danger:hover { color: var(--destructive); }
.sempty { border: 1px dashed var(--border-strong); border-radius: var(--radius-md); padding: 2.75rem; text-align: center; color: var(--grey-2); font-size: 0.85rem; }
.sempty b { color: var(--primary); font-weight: 600; }
select.form-input { -webkit-appearance: none; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239a9a9a' d='M6 8L2 4h8z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2rem; }
.sdrop { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 1.35rem; text-align: center; color: var(--grey-2); font-size: 0.82rem; cursor: pointer; transition: border-color var(--transition), background var(--transition); }
.sdrop:hover { border-color: var(--grey-2); }
.sdrop.over { border-color: var(--primary); background: var(--card); }
.sdrop b { color: var(--primary); font-weight: 500; }
.sdrop-hint { font-size: 0.7rem; color: var(--muted-foreground); }
.sfilelist { font-size: 0.72rem; color: var(--foreground); margin-top: 0.5rem; }
.sfilelist div { padding: 0.1rem 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt { color: var(--muted-foreground); font-weight: 400; }
.skv { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.65rem 0.8rem; margin-top: 0.6rem; }
.skv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 0.6rem; }
.skv-grid .skv { margin-top: 0; }
.sk { font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--grey-2); margin-bottom: 0.25rem; }
.sv { font-size: 0.8rem; color: var(--primary); word-break: break-all; display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.sv a { color: var(--primary); }
.sv a:hover { text-decoration: underline; }
.scopy { flex: none; background: transparent; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); color: var(--foreground); font-size: 0.66rem; padding: 0.2rem 0.5rem; transition: border-color var(--transition), color var(--transition); }
.scopy:hover { border-color: var(--primary); color: var(--primary); }
.snote { font-size: 0.72rem; color: var(--grey-2); line-height: 1.5; margin-top: 0.75rem; }
.snote.strong { color: var(--primary); font-weight: 500; margin-top: 1rem; }

/* ---------- Automation builder ---------- */
.step-card { background: var(--input); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.9rem 1rem; margin-bottom: 0.7rem; }
.step-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.step-num { width: 22px; height: 22px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--secondary); border: 1px solid var(--border-strong); font-size: 0.72rem; font-weight: 700; color: var(--foreground); }
.step-head .step-type { flex: 1; }
.step-tools { display: flex; gap: 0.25rem; }
.step-body { display: block; }
.step-sentence { font-size: 0.76rem; color: var(--grey-2); font-style: italic; margin: 0 0 0.5rem 1.9rem; }
.input-with-picker { display: flex; gap: 0.4rem; }
.input-with-picker .form-input { flex: 1; }
.insert-field { flex: none; width: 150px; font-size: 0.72rem; padding: 0.45rem 0.5rem; color: var(--grey-2); }
textarea + .insert-field { margin-top: 0.4rem; width: 100%; }

.map-editor { display: block; }
.map-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.map-to { flex: 0 0 34%; font-size: 0.78rem; color: var(--foreground); font-weight: 600; display: flex; flex-direction: column; gap: 0.15rem; line-height: 1.25; }
.map-arrow { color: var(--muted-foreground); font-size: 0.8rem; }
.map-src { flex: 1; }
code { background: var(--secondary); border: 1px solid var(--border); border-radius: 4px; padding: 0.05rem 0.3rem; font-size: 0.85em; font-family: var(--mono); }

/* ---------- Run log ---------- */
.run-steps { margin-top: 0.4rem; display: flex; flex-direction: column; gap: 0.25rem; }
.run-step { font-size: 0.78rem; color: var(--foreground); }
.run-card { background: var(--input); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.9rem 1rem; margin-bottom: 0.7rem; }

/* ---------- Field transparency ---------- */
.key-pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem; color: var(--foreground);
  background: var(--secondary); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 0.1rem 0.45rem;
  letter-spacing: 0.01em; white-space: nowrap;
}
.key-copy {
  background: none; border: none; color: var(--muted-foreground);
  font-size: 0.85rem; line-height: 1; padding: 0.1rem 0.35rem; margin-left: 0.3rem;
  border-radius: var(--radius-sm); vertical-align: middle;
  transition: color var(--transition);
}
.key-copy:hover { color: var(--primary); }
.info-note {
  display: flex; align-items: flex-start; gap: 0.65rem;
  background: var(--card); border: 1px solid var(--border);
  border-left: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem; margin-bottom: 1.1rem;
  font-size: 0.78rem; color: var(--grey-2); line-height: 1.5;
}
.info-note b { color: var(--primary); font-weight: 600; }
.info-note code { font-size: 0.9em; }
.info-note-icon { color: var(--primary); font-size: 0.8rem; margin-top: 0.1rem; flex: none; }
.key-preview {
  margin-top: 0.5rem; font-size: 0.74rem; color: var(--muted-foreground);
  display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;
}
.key-preview-hint { color: var(--muted-foreground); }
.key-preview-hint code {
  color: var(--foreground); background: var(--secondary);
  border: 1px solid var(--border); border-radius: 4px; padding: 0.05rem 0.3rem;
  font-size: 0.92em;
}
.map-key {
  font-family: var(--mono);
  font-size: 0.66rem; color: var(--muted-foreground); font-weight: 500; letter-spacing: 0.01em;
}
.map-foot {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 0.75rem; margin-top: 0.55rem; flex-wrap: wrap;
}
.map-foot .form-hint { margin-top: 0; flex: 1; min-width: 200px; }
.map-foot .btn { flex: none; }

/* ---------- Layout builder (6.1/6.8) ---------- */
.layout-wrap { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 1.25rem; align-items: start; }
.layout-controls { display: flex; flex-direction: column; gap: 0.75rem; }
.lay-group { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.8rem 0.9rem; }
.lay-group-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.lay-name {
  flex: 1; background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--primary); font-size: 0.85rem; font-weight: 700; padding: 0.25rem 0.4rem;
  transition: border-color var(--transition), background var(--transition);
}
.lay-name:hover, .lay-name:focus { border-color: var(--border-strong); background: var(--input); outline: none; }
.drag-handle { cursor: grab; color: var(--muted-foreground); font-size: 0.8rem; flex: none; user-select: none; }
.lay-toggles { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 0.6rem; }
.lay-toggles label { font-size: 0.7rem; color: var(--grey-2); display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.lay-toggles .check { width: 13px; height: 13px; }
.lay-fields { display: flex; flex-direction: column; gap: 0.3rem; min-height: 26px; border-radius: var(--radius-sm); }
.lay-field {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 0.55rem; background: var(--input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.78rem; color: var(--foreground); cursor: grab;
}
.lay-field:active { cursor: grabbing; }
.lay-field .tag { margin: 0 0 0 auto; }
.lay-drop-hint { padding: 0.3rem 0.55rem; border: 1px dashed var(--border); border-radius: var(--radius-sm); margin-top: 0; }
.lay-add { display: flex; gap: 0.5rem; }
.layout-preview { position: sticky; top: 0; }

/* ---------- Responsive (6.9) ---------- */
@media (max-width: 900px) {
  .layout-wrap { grid-template-columns: 1fr; }
  .layout-preview { position: static; }
}
@media (max-width: 760px) {
  html { font-size: 14px; }
  .sidebar { position: fixed; z-index: 300; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform var(--transition); }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-flex !important; }
  .content { padding: 1rem; }
  .topbar { padding: 0 1rem; }
  .admin-bar { padding: 0.45rem 1rem; }
  .drawer { width: 100vw; border-left: none; }
  .drawer-head, .drawer-body, .drawer-foot { padding-left: 1.1rem; padding-right: 1.1rem; }
  .drawer-tabs { padding: 0 1.1rem; }
  .page-toolbar { flex-direction: column; align-items: stretch; }
  .search-input { max-width: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .bulk-bar { width: 100%; flex-wrap: wrap; }
  .modal { padding: 1.25rem; }
  .map-row { flex-wrap: wrap; }
  .map-to { flex: 1 1 100%; }
}

/* Caller role: belt-and-braces hiding of anything mutating. The real
   enforcement is RLS — this only keeps the UI honest if a write control
   ever renders by mistake. */
body.role-caller .btn-danger,
body.role-caller .toggle { display: none !important; }

/* =====================================================
   CALENDAR — booking month view
   Same restrained near-black system: card surfaces, 1px
   borders, white accent only where it earns it. Day-off
   cells get the hatch treatment from the booking page.
   ===================================================== */
.cal-card { padding: var(--sp-5); }
.cal-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap;
}
.cal-month { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }

.cal-dow {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  margin-bottom: 6px;
}
.cal-dow div {
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted-foreground);
  text-align: center; padding: 0.25rem 0;
}

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell {
  position: relative; min-height: 92px; padding: 0.4rem 0.45rem;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); display: flex; flex-direction: column; gap: 3px;
  cursor: pointer; transition: border-color var(--transition), background var(--transition);
}
.cal-cell:hover { border-color: var(--border-strong); background: var(--card); }
.cal-cell:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.cal-blank { background: transparent; border-color: transparent; cursor: default; min-height: 92px; }
.cal-past { opacity: 0.5; }
.cal-today { border-color: var(--border-strong); }
.cal-today .cal-daynum {
  background: var(--primary); color: var(--primary-foreground);
}
.cal-daynum {
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 600; border-radius: var(--radius-full);
  color: var(--grey-2);
}
.cal-off {
  background:
    repeating-linear-gradient(-45deg, transparent 0 6px, rgba(255,255,255,0.03) 6px 12px),
    var(--surface-1);
}
.cal-offlabel {
  font-size: 0.62rem; color: var(--muted-foreground);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-chip {
  display: flex; align-items: center; gap: 0.35rem; width: 100%;
  padding: 0.22rem 0.4rem; font-size: 0.7rem; font-family: var(--font);
  background: var(--secondary); color: var(--secondary-foreground);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; text-align: left;
  transition: background var(--transition), border-color var(--transition);
}
.cal-chip:hover { background: var(--input); border-color: var(--border-strong); color: var(--foreground); }
.cal-chip-time { font-weight: 600; white-space: nowrap; }
.cal-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-more { font-size: 0.64rem; color: var(--muted-foreground); padding-left: 0.15rem; }

/* Day drawer job rows */
.cal-job {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%;
  padding: 0.7rem 0.75rem; margin-bottom: 0.5rem;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; font-family: var(--font);
  color: var(--foreground); text-align: left;
  transition: border-color var(--transition), background var(--transition);
}
.cal-job:hover { border-color: var(--border-strong); background: var(--card); }
.cal-job-time { font-size: 0.78rem; font-weight: 700; min-width: 58px; }
.cal-job-mid { flex: 1; min-width: 0; }
.cal-job-name { font-size: 0.85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-job-sub { font-size: 0.72rem; color: var(--muted-foreground); }

/* Contact card */
.cal-back { margin-bottom: var(--sp-4); }
.cal-rows {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin-bottom: var(--sp-4);
}
.cal-row {
  display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3);
  padding: 0.6rem 0.75rem; background: var(--surface-1);
}
.cal-row + .cal-row { border-top: 1px solid var(--border); }
.cal-row-label { font-size: 0.72rem; color: var(--muted-foreground); white-space: nowrap; }
.cal-row-val { font-size: 0.82rem; text-align: right; overflow-wrap: anywhere; }
.cal-block { margin-bottom: var(--sp-4); }
.cal-block-label {
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted-foreground); margin-bottom: 0.35rem;
}
.cal-block-body {
  font-size: 0.82rem; line-height: 1.55; color: var(--grey-1);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.7rem 0.75rem; white-space: pre-wrap;
}

@media (max-width: 900px) {
  .cal-cell, .cal-blank { min-height: 64px; }
  .cal-chip-name { display: none; }
}
