/* Nautical-luxury theme — obsidian ink + champagne gold + serif display.
   "Vela" = the sails; the whole app is dressed like a yacht-club night sky. */
:root {
  --bg-base: #0A0A0F;
  --bg-panel: #121219;
  --bg-hover: #1B1B24;
  --accent: #D9B46A;          /* champagne — links / active / focus */
  --accent-gold: #E6BF76;     /* brighter champagne highlight */
  --on-accent: #201907;       /* ink for text sitting on a gold fill (WCAG) */
  --danger: #DE6460;
  --success: #57B391;
  --text-primary: #E9E7E0;    /* warm ivory */
  --text-muted: #8C8A97;
  --border: #262631;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 34px rgba(0,0,0,0.55);
  --hair: rgba(255,255,255,0.05);      /* top-highlight on cards + hairline row dividers */
  --accent-wash: rgba(230,191,118,0.06); /* soft gold hover/feature wash */
  --font-display: 'Fraunces', 'Cormorant Garamond', ui-serif, Georgia, 'Times New Roman', serif;
}

/* C-1 — light theme (token overrides only; layout/radius stay in :root).
   Warm ivory "paper" with deep brass — a private-dashboard feel. */
body.light {
  --bg-base: #F6F3EC;
  --bg-panel: #FFFFFF;
  --bg-hover: #EFE8D8;
  --accent: #7F5F17;          /* deep brass — ≥4.5:1 as link on ivory AND under white button text */
  --accent-gold: #8A6A1E;
  --on-accent: #FFFFFF;
  --danger: #C2453F;
  --success: #2E9E68;
  --text-primary: #211D14;
  --text-muted: #6E6656;
  --border: #E5DDCB;
  --shadow: 0 8px 30px rgba(60,50,20,0.12);
  --hair: rgba(0,0,0,0.045);
  --accent-wash: rgba(127,95,23,0.06);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  overflow: hidden;
}

body { display: flex; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2b2b36; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
body.light ::-webkit-scrollbar-thumb { background: #d3ccb9; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 220px;
  min-width: 220px;
  height: 100vh;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 0;
}

#vela-logo {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 22px 22px;
  font-weight: 600;
}
#vela-logo .logo-mark { color: var(--accent-gold); display: inline-flex; transform: translateY(-1px); }
#vela-logo .logo-mark svg { display: block; filter: drop-shadow(0 1px 4px rgba(230,191,118,.28)); }
#vela-logo .logo-word { font-family: var(--font-display); font-size: 20px; font-weight: 600; letter-spacing: 5px; color: var(--text-primary); }

#nav { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  font-weight: 500;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg-hover); color: var(--accent); }
.nav-item.active i { color: var(--accent); }
.nav-item i { width: 18px; height: 18px; }

#sidebar-footer { padding: 14px 22px 4px; border-top: 1px solid var(--border); margin-top: 6px; }
.sf-name { font-weight: 600; font-size: 13px; }
.sf-email { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* ---------- Main ---------- */
#main { flex: 1; display: flex; flex-direction: column; height: 100vh; min-width: 0; }
#topbar {
  height: 60px;
  min-height: 60px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 20px;
}
#module-title { font-family: var(--font-display); font-size: 19px; font-weight: 600; letter-spacing: .2px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.ccp-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 500; padding: 7px 12px; border-radius: 20px; background: var(--bg-panel); border: 1px solid var(--border); cursor: pointer; white-space: nowrap; }
.ccp-pill:hover { background: var(--bg-hover); }
.ccp-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.ccp-pill.live .ccp-dot { background: var(--success); box-shadow: 0 0 0 3px rgba(76,175,130,.18); }
.ccp-pill.error .ccp-dot { background: var(--danger); }
#global-search {
  width: 320px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 9px 14px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
#global-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }

#content { flex: 1; overflow: auto; padding: 24px; }

/* ---------- Generic UI ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-head h2 { font-family: var(--font-display); font-size: 18px; font-weight: 600; letter-spacing: .2px; }
.muted { color: var(--text-muted); }
.row-gap { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-primary);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover { background: var(--bg-hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.gold { background: var(--accent-gold); border-color: var(--accent-gold); color: #1a1300; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: rgba(224,92,92,.12); }
button.ghost { background: transparent; }
button.sm { padding: 6px 10px; font-size: 12px; }

select, input[type="text"], input[type="number"], input[type="date"], textarea {
  font-family: inherit;
  font-size: 13px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 9px 12px;
  outline: none;
  width: 100%;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 var(--hair);
}

/* Tables */
.table-wrap { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: inset 0 1px 0 var(--hair); }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
tbody td { padding: 13px 18px; border-bottom: 1px solid var(--hair); font-size: 13px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background .12s; }
tbody tr:hover { background: var(--accent-wash); }
tbody tr:hover td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 11px;
  border-radius: 20px;
  margin: 2px 4px 2px 0;
  white-space: nowrap;
}

/* Summary metric cards */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric { position: relative; background: linear-gradient(180deg, var(--bg-panel), var(--bg-base)); border: 1px solid var(--border); border-radius: var(--radius); padding: 17px 18px 16px; box-shadow: inset 0 1px 0 var(--hair); }
.metric .m-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .6px; }
.metric .m-value { font-family: var(--font-display); font-size: 27px; font-weight: 600; margin-top: 8px; letter-spacing: .3px; }
.metric .m-sub { font-size: 12px; margin-top: 6px; }
.pos { color: var(--success); }
.neg { color: var(--danger); }

/* Slide-in detail panel */
#detail-panel {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: 420px;
  max-width: 92vw;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform .22s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
#detail-panel.open { transform: translateX(0); }
/* Tap-to-dismiss backdrop behind the panel (primary "back out" on mobile). */
#detail-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); z-index: 49; opacity: 0; pointer-events: none; transition: opacity .22s ease; }
#detail-backdrop.open { opacity: 1; pointer-events: auto; }
.dp-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 22px 22px 14px; border-bottom: 1px solid var(--border); }
.dp-title { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.dp-sub { color: var(--text-muted); font-size: 13px; margin-top: 3px; }
.dp-body { padding: 20px 22px; overflow: auto; flex: 1; }
.dp-close { background: transparent; border: none; color: var(--text-muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 6px 10px; margin: -6px -6px 0 0; border-radius: var(--radius-sm); }
.dp-close:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Mobile: full-screen panel with a comfortable close tap target. */
@media (max-width: 640px) {
  #detail-panel { width: 100vw; max-width: 100vw; border-left: none; }
  .dp-close { font-size: 30px; padding: 8px 14px; }
}
.dp-row { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.dp-row .k { color: var(--text-muted); width: 100px; min-width: 100px; }
.dp-row .v { flex: 1; word-break: break-word; }
/* Tappable phone number — dials via the OS handler (desktop) / dialer (phone). */
.dp-tel { display: inline-flex; align-items: center; gap: 6px; background: transparent; border: none; padding: 0; color: var(--accent); font-size: 13px; cursor: pointer; }
.dp-tel:hover { text-decoration: underline; }
.dp-tel i { width: 14px; height: 14px; }
.dp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }

/* Modal */
#modal-root { position: fixed; inset: 0; z-index: 100; display: none; }
#modal-root.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.modal {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 480px;
  max-width: 92vw;
  max-height: 88vh;
  overflow: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
}
.modal h3 { font-family: var(--font-display); font-size: 18px; font-weight: 600; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* Toast */
#toast-root { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: slideIn .2s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Empty state */
.empty { text-align: center; color: var(--text-muted); padding: 60px 20px; }
.empty i { width: 40px; height: 40px; opacity: .5; margin-bottom: 12px; }

/* Kanban */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.kan-col { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); width: 260px; min-width: 260px; display: flex; flex-direction: column; box-shadow: inset 0 1px 0 var(--hair); }
.kan-col-head { padding: 13px 15px; font-family: var(--font-display); font-weight: 600; font-size: 14px; letter-spacing: .2px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.kan-col-head .count { color: var(--text-muted); font-size: 12px; font-weight: 500; }
.kan-cards { padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 60px; }
.kan-cards.drag-over { background: var(--bg-hover); }
.deal-card { position: relative; background: var(--bg-base); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; cursor: grab; touch-action: pan-y; }
.deal-card:hover { border-color: var(--accent); }
.deal-card .dc-name { font-weight: 600; font-size: 13px; padding-right: 22px; }
.deal-card .dc-meta { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.deal-card .dc-value { font-family: var(--font-display); color: var(--accent-gold); font-weight: 600; font-size: 15px; margin-top: 8px; }
.deal-card.rotting { border-left: 3px solid var(--danger); }
/* C-4 — close-date urgency borders */
.deal-card.due-soon { border-left: 3px solid var(--accent-gold); }
.deal-card.due-overdue { border-left: 3px solid var(--danger); }
.rotten-badge { font-size: 10px; }
/* B-5 — one-click stage advance button (reveals on card hover) */
.adv-btn { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; padding: 0; line-height: 1; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-panel); color: var(--text-muted); cursor: pointer; opacity: 0; transition: opacity .12s, color .12s, border-color .12s; font-size: 14px; }
.deal-card:hover .adv-btn { opacity: 1; }
.adv-btn:hover { color: var(--success); border-color: var(--success); }
button.danger.on { background: rgba(224,92,92,.18); }
.stage-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
/* C-5 — initials avatars */
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--border); font-weight: 600; flex: none; line-height: 1; }
.cell-name { display: inline-flex; align-items: center; gap: 9px; }
.dp-avatar { display: flex; justify-content: center; margin: 4px 0 16px; }

/* Memory module */
.memory-layout { display: grid; grid-template-columns: 220px 1fr; gap: 22px; align-items: start; }
.mem-nav { position: sticky; top: 0; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; max-height: calc(100vh - 130px); overflow: auto; }
.mem-nav a { display: block; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--text-muted); cursor: pointer; font-size: 12px; }
.mem-nav a:hover { background: var(--bg-hover); color: var(--text-primary); }
.markdown { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 34px; line-height: 1.6; box-shadow: inset 0 1px 0 var(--hair); }
.markdown h1 { font-family: var(--font-display); font-size: 25px; margin: 8px 0 16px; }
.markdown h2 { font-size: 18px; margin: 28px 0 12px; padding-top: 10px; border-top: 1px solid var(--border); color: var(--accent); scroll-margin-top: 20px; }
.markdown h3 { font-size: 15px; margin: 18px 0 8px; }
.markdown p, .markdown li { color: var(--text-primary); }
.markdown ul, .markdown ol { padding-left: 22px; margin: 8px 0; }
.markdown code { background: var(--bg-base); padding: 2px 6px; border-radius: 4px; font-size: 12px; color: var(--accent-gold); }
.markdown table { margin: 12px 0; border: 1px solid var(--border); }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 8px 10px; font-size: 12px; }
.markdown a { color: var(--accent); }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
mark { background: var(--accent-gold); color: #1a1300; padding: 0 2px; border-radius: 2px; }
body.light mark { background: #f6e3ad; color: #3a2e0a; }

/* Sparkline cell */
.spark { width: 90px; height: 28px; }

#map { height: calc(100vh - 200px); min-height: 420px; border-radius: var(--radius); border: 1px solid var(--border); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--bg-panel); color: var(--text-primary); }
.leaflet-popup-content { font-family: 'Inter', sans-serif; font-size: 13px; }
.leaflet-popup-content b { color: var(--text-primary); }

.delta-up { color: var(--success); }
.delta-down { color: var(--danger); }
.delta-flat { color: var(--text-muted); }

.chart-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; margin-top: 22px; }
.rpt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.rpt-head { font-size: 13px; font-weight: 600; color: var(--text-muted); margin: 24px 0 12px; letter-spacing: .5px; }
.due-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.due-row:last-child { border-bottom: none; }
.seq-step { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 10px; background: var(--bg-base); }
.attach-sec { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 14px; }
.dp-sub-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 8px; }
.attach-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; }
/* Notification bell + dropdown */
.notif-bell { position: relative; background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm); width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); cursor: pointer; }
.notif-bell:hover { color: var(--text); border-color: var(--accent); }
.notif-bell i { width: 17px; height: 17px; }
.notif-badge { position: absolute; top: -6px; right: -6px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.notif-panel { position: fixed; width: 340px; max-height: 70vh; overflow: auto; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0,0,0,.45); z-index: 200; }
.notif-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.notif-item { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-hover); }
.notif-item i { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
/* Duplicate detection */
.dupe-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: rgba(244,167,50,.10); border: 1px solid rgba(244,167,50,.4); border-radius: var(--radius-sm); padding: 10px 14px; margin: 4px 0 14px; font-size: 13px; }
.dupe-group { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 12px; background: var(--bg-base); }
.chart-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: inset 0 1px 0 var(--hair); }
.chart-card h3 { font-family: var(--font-display); font-size: 14.5px; font-weight: 600; color: var(--text-primary); letter-spacing: .4px; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.chart-card h3::before { content: ""; width: 3px; height: 15px; border-radius: 2px; background: linear-gradient(var(--accent-gold), var(--accent)); flex: none; }
.chart-card h3 .muted { font-family: 'Inter', system-ui, sans-serif; font-weight: 500; font-size: 12px; letter-spacing: 0; }
.chart-card canvas { max-height: 260px; }

.toolbar-btn { padding: 6px 9px; font-size: 12px; }
.email-layout { display: grid; grid-template-columns: 1fr 300px; gap: 22px; align-items: start; }
.autocomplete { position: relative; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 4px; max-height: 220px; overflow: auto; z-index: 10; display: none; }
.ac-list.open { display: block; }
.ac-item { padding: 9px 12px; cursor: pointer; font-size: 13px; }
.ac-item:hover, .ac-item.sel { background: var(--bg-hover); }
.ac-item .ac-sub { color: var(--text-muted); font-size: 11px; }
.recent-draft { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 12px; }
.recent-draft:last-child { border-bottom: none; }
.recent-draft .rd-to { color: var(--text-muted); }
/* B-2 — email open status badge */
.email-status { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; padding: 2px 7px; border-radius: 10px; white-space: nowrap; background: var(--bg-hover); color: var(--text-muted); }
.email-status.opened { background: rgba(76,175,130,.15); color: var(--success); }

/* Dashboard */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.dash-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.dash-row:last-child { border-bottom: none; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 110px; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 12px; }
.bar-label { color: var(--text-primary); white-space: nowrap; }
.bar-track { background: var(--bg-base); border-radius: 20px; height: 9px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,.35); }
.bar-fill { height: 100%; border-radius: 20px; transition: width .4s ease; min-width: 2px; }
.bar-val { text-align: right; color: var(--text-muted); white-space: nowrap; }
@media (max-width: 1100px) { .dash-grid, .chart-grid, .rpt-grid, .email-layout { grid-template-columns: 1fr; } }

/* Relationship color legend (Contacts) */
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 5px 10px; border-radius: 20px; border: 1px solid transparent; background: var(--bg-panel); cursor: pointer; user-select: none; transition: background .12s; }
.legend-item:hover { background: var(--bg-hover); }
.legend-item.active { background: var(--bg-hover); }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }

/* Local / CCP-Live source toggle */
.src-toggle { display: inline-flex; background: var(--bg-base); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.src-btn { border: none; background: transparent; padding: 7px 12px; font-size: 12px; border-radius: 0; display: inline-flex; align-items: center; gap: 6px; }
.src-btn.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.src-btn:not(.on):hover { background: var(--bg-hover); }

/* AP Creative tag on an entity row (CCP is the unmarked default). */
.brand-badge { display: inline-block; font-size: 10px; font-weight: 600; letter-spacing: .3px; padding: 1px 6px; margin-left: 7px; border-radius: 10px; background: #7C5CFF22; color: #7C5CFF; border: 1px solid #7C5CFF55; vertical-align: middle; }

/* Global brand switcher in the topbar. */
.brand-switch { display: inline-flex; background: var(--bg-base); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.bs-btn { border: none; background: transparent; color: var(--text-muted); padding: 6px 11px; font-size: 12px; font-weight: 500; border-radius: 0; }
.bs-btn:not(.on):hover { background: var(--bg-hover); color: var(--text); }
.bs-btn.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.bs-btn[data-brand="AP Creative"].on { background: #7C5CFF; color: #fff; }

/* Tasks */
.task-row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.task-row:last-child { border-bottom: none; }
.task-row:hover { background: var(--accent-wash); box-shadow: inset 3px 0 0 var(--accent); }
.task-check { display: inline-flex; color: var(--text-muted); cursor: pointer; }
.task-check.on { color: var(--success); }
.task-check i { width: 18px; height: 18px; }
.task-main { flex: 1; min-width: 0; }
.task-title { font-size: 13px; font-weight: 500; }
.task-title.done { text-decoration: line-through; color: var(--text-muted); }

/* Activity timeline */
.activity-log { margin-top: 6px; }
.act-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.act-item:last-child { border-bottom: none; }
.act-kind { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; padding: 2px 7px; border-radius: 10px; height: fit-content; white-space: nowrap; }
.act-body { flex: 1; font-size: 13px; }
.act-meta { color: var(--text-muted); font-size: 11px; margin-top: 2px; }
.act-compose { display: flex; gap: 8px; margin: 10px 0 4px; }
.act-compose select { width: auto; }
/* B-6 — one-tap quick-log buttons */
.quick-log { display: flex; gap: 8px; margin: 8px 0 10px; }
.quick-log button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.quick-log button i { width: 14px; height: 14px; }

/* Outreach recipient list */
.recip-list { max-height: calc(100vh - 230px); overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.recip-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.recip-row:last-child { border-bottom: none; }
.recip-row:hover { background: var(--bg-hover); }
.recip-row.on { background: rgba(217,180,106,.12); }
.recip-check { display: inline-flex; color: var(--text-muted); }
.recip-row.on .recip-check { color: var(--accent); }
.recip-check i { width: 16px; height: 16px; }

/* Inbox */
.inbox-layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.inbox-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 180px); background: var(--bg-panel); }
.inbox-row { padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.inbox-row:last-child { border-bottom: none; }
.inbox-row:hover { background: var(--accent-wash); }
.inbox-row.sel { background: var(--accent-wash); box-shadow: inset 3px 0 0 var(--accent); }
.inbox-row.unread .ib-from { font-weight: 600; color: var(--text-primary); }
.ib-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.ib-from { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 6px; }
.ib-date { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.ib-subj { font-size: 13px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-read { min-height: 300px; max-height: calc(100vh - 180px); overflow: auto; }
.ib-read-head { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.ib-read-subj { font-size: 16px; font-weight: 600; }
.ib-read-body { padding: 18px 20px; font-size: 13px; line-height: 1.6; white-space: normal; word-break: break-word; }

/* Auto-update banner */
#update-bar { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; align-items: center; gap: 14px; background: var(--bg-panel); border: 1px solid var(--accent); border-radius: var(--radius); padding: 12px 18px; box-shadow: var(--shadow); font-size: 13px; }

/* C-6 — command palette (Ctrl/Cmd+K) */
.cmdk { position: fixed; top: 14vh; left: 50%; transform: translateX(-50%); width: 560px; max-width: 92vw; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; z-index: 400; }
.cmdk input { width: 100%; border: none; border-bottom: 1px solid var(--border); background: transparent; color: var(--text-primary); font-size: 15px; padding: 16px 18px; outline: none; border-radius: 0; }
.cmdk-results { max-height: 50vh; overflow: auto; }
.cmdk-item { display: flex; align-items: center; gap: 12px; padding: 11px 18px; cursor: pointer; }
.cmdk-item i { width: 16px; height: 16px; color: var(--text-muted); flex: none; }
.cmdk-item:hover, .cmdk-item.sel { background: var(--bg-hover); }
.cmdk-item.sel i { color: var(--accent); }
.cmdk-text { min-width: 0; }
.cmdk-text > div:first-child { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-sub { color: var(--text-muted); font-size: 11px; }
.cmdk-empty { padding: 16px 18px; font-size: 13px; }

/* ============================================================================
   Launch intro — a gilded schooner on a midnight sea, sails unfurling, then the
   VELA wordmark rises. Injected + driven by vela-intro.js; plays once per cold
   launch (sessionStorage), skippable, honours prefers-reduced-motion. Lives here
   so it mirrors to the desktop app AND the phone/PWA from one source.
   ========================================================================== */
#vela-intro {
  position: fixed; inset: 0; z-index: 9000;
  background: #0A0A0F;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  opacity: 1;
  transition: opacity .9s ease, transform .9s ease;
}
#vela-intro.vi-done { opacity: 0; transform: scale(1.04); pointer-events: none; }
#vela-intro .vi-scene { position: absolute; inset: 0; width: 100%; height: 100%; }
#vela-intro .vi-star { fill: #fff; animation: vi-tw 3s ease-in-out infinite; }
@keyframes vi-tw { 0%,100% { opacity: .28; } 50% { opacity: .9; } }
#vela-intro .vi-ship { transform-box: fill-box; transform-origin: center; animation: vi-bob 4.6s ease-in-out infinite 1.6s; }
@keyframes vi-bob { 0%,100% { transform: translateY(0) rotate(-.4deg); } 50% { transform: translateY(-6px) rotate(.4deg); } }
#vela-intro .vi-sail { transform-box: fill-box; transform-origin: top; transform: scaleY(0); opacity: 0; animation: vi-unfurl 1s cubic-bezier(.22,1,.36,1) forwards; }
#vela-intro .vi-s1 { animation-delay: .35s; }
#vela-intro .vi-s2 { animation-delay: .62s; }
#vela-intro .vi-s3 { animation-delay: .9s; }
@keyframes vi-unfurl { 0% { transform: scaleY(0); opacity: 0; } 60% { opacity: 1; } 100% { transform: scaleY(1); opacity: 1; } }
#vela-intro .vi-hull { opacity: 0; animation: vi-fade .7s ease forwards .1s; }
#vela-intro .vi-pennant { transform-box: fill-box; transform-origin: left; animation: vi-flag 2.2s ease-in-out infinite 1.4s; }
@keyframes vi-flag { 0%,100% { transform: scaleX(.7); } 50% { transform: scaleX(1) skewY(-6deg); } }
#vela-intro .vi-refl { animation: vi-shim 3.5s ease-in-out infinite 1.6s; }
@keyframes vi-shim { 0%,100% { opacity: .1; } 50% { opacity: .2; } }
#vela-intro .vi-glints line { animation: vi-glint 3s ease-in-out infinite; }
#vela-intro .vi-glints line:nth-child(2) { animation-delay: .6s; }
#vela-intro .vi-glints line:nth-child(3) { animation-delay: 1.1s; }
#vela-intro .vi-glints line:nth-child(4) { animation-delay: 1.6s; }
@keyframes vi-glint { 0%,100% { opacity: .2; } 50% { opacity: .6; } }
@keyframes vi-fade { to { opacity: 1; } }
#vela-intro .vi-word-wrap { position: absolute; left: 0; right: 0; bottom: 12vh; text-align: center; z-index: 2; }
#vela-intro .vi-word {
  font-family: var(--font-display);
  font-size: clamp(48px, 8vw, 76px); font-weight: 600; letter-spacing: 16px; padding-left: 16px;
  background: linear-gradient(180deg, #fbeecb, #e6bf76 55%, #b98a2c);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  opacity: 0; animation: vi-rise 1s ease forwards 1.5s;
}
#vela-intro .vi-tag { font-size: 10px; letter-spacing: 6px; color: #8C8A97; margin-top: 12px; opacity: 0; animation: vi-rise 1s ease forwards 1.85s; }
@keyframes vi-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

/* Reduced motion: no unfurl/bob — just a quiet gilded wordmark fade. */
@media (prefers-reduced-motion: reduce) {
  #vela-intro .vi-scene { display: none; }
  #vela-intro .vi-word, #vela-intro .vi-tag { animation: vi-rise .6s ease forwards; }
  #vela-intro .vi-tag { animation-delay: .15s; }
}

/* ============================================================================
   Sidebar customizer (nav-customize.js) — the "Customize" gear + the panel that
   toggles/reorders tabs and switches on optional modules.
   ========================================================================== */
.nav-tool {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-top: auto;            /* stick to the bottom of the nav */
  border-top: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; user-select: none;
  font-weight: 500; border-radius: var(--radius-sm);
}
.nav-tool:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-tool:hover i { color: var(--accent); }
.nav-tool i { width: 18px; height: 18px; }
/* Only the first bottom tool pushes to the bottom + carries the divider; the rest
   stack directly under it as one group (Theme + Customize). */
.nav-tool ~ .nav-tool { margin-top: 0; border-top: none; }

.nav-cust .nc-list { display: flex; flex-direction: column; gap: 6px; max-height: 52vh; overflow: auto; }
.nc-row { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-base); }
.nc-move { display: flex; flex-direction: column; gap: 3px; }
.nc-arrow { padding: 0; width: 22px; height: 15px; line-height: 1; font-size: 11px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-panel); color: var(--text-muted); cursor: pointer; }
.nc-arrow:disabled { opacity: .3; cursor: default; }
.nc-arrow:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.nc-ic { width: 17px; height: 17px; color: var(--text-muted); flex: none; }
.nc-label { flex: 1; font-size: 13.5px; }
.nc-opt { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--accent); border: 1px solid var(--accent); border-radius: 10px; padding: 1px 6px; margin-left: 6px; }
.nc-toggle { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; cursor: pointer; }
.nc-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.nc-slider { position: absolute; inset: 0; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 20px; transition: .15s; }
.nc-slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: var(--text-muted); transition: .15s; }
.nc-toggle input:checked + .nc-slider { background: var(--accent); border-color: var(--accent); }
.nc-toggle input:checked + .nc-slider::before { transform: translateX(16px); background: var(--on-accent); }

/* ============================================================================
   Fleet Tracker (modules/fleet.js) — live map + truck list.
   ========================================================================== */
.fleet-layout { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
#fleet-map { height: calc(100vh - 220px); min-height: 420px; border-radius: var(--radius); border: 1px solid var(--border); }
.fleet-list { padding: 0; overflow: hidden; max-height: calc(100vh - 220px); display: flex; flex-direction: column; }
.fleet-list-head { padding: 14px 16px; border-bottom: 1px solid var(--border); font-family: var(--font-display); font-size: 14px; font-weight: 600; letter-spacing: .2px; }
.fleet-list .fleet-row:first-of-type { }
.fleet-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 16px; border-bottom: 1px solid var(--hair); cursor: pointer; }
.fleet-row:last-child { border-bottom: none; }
.fleet-row:hover { background: var(--accent-wash); }
.fleet-row.sel { background: var(--accent-wash); box-shadow: inset 3px 0 0 var(--accent); }
.fleet-name { font-size: 13.5px; font-weight: 600; }
.fleet-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.fleet-row-meta { text-align: right; white-space: nowrap; }
.fleet-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.fleet-dot { width: 7px; height: 7px; border-radius: 50%; }
.fleet-speed { display: block; font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.chip.fleet-demo { background: var(--accent-wash); color: var(--accent); border: 1px solid var(--accent); }
.truck-pin { width: 30px; height: 30px; border-radius: 50%; background: var(--bg-panel); border: 2px solid; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
@media (max-width: 900px) { .fleet-layout { grid-template-columns: 1fr; } #fleet-map { height: 52vh; } .fleet-list { max-height: none; } }

/* ============================================================================
   Team Calendar (modules/calendar.js) — month grid of tasks colour-coded by person.
   ========================================================================== */
.cal-legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.cal-leg { display: inline-flex; align-items: center; gap: 7px; font-family: inherit; font-size: 12px; padding: 5px 11px; border-radius: 20px; border: 1px solid var(--border); background: var(--bg-panel); color: var(--text-muted); cursor: pointer; }
.cal-leg:hover { background: var(--bg-hover); }
.cal-leg.on { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent); }
.cal-leg-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.cal-leg-n { color: var(--text-muted); font-size: 11px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: inset 0 1px 0 var(--hair); }
.cal-dow { background: var(--bg-panel); padding: 9px 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .7px; color: var(--text-muted); font-weight: 600; }
.cal-cell { background: var(--bg-panel); min-height: 104px; padding: 7px 8px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; transition: background .12s; }
.cal-cell:hover { background: var(--accent-wash); }
.cal-cell.empty-cell, .cal-cell.empty-cell:hover { background: var(--bg-base); cursor: default; }
.cal-cell.today { background: var(--accent-wash); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-daynum { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.cal-cell.today .cal-daynum { color: var(--accent); }
.cal-chip { font-size: 11px; padding: 3px 7px; border-radius: 5px; background: var(--bg-hover); border-left: 3px solid var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-chip.done { opacity: .5; text-decoration: line-through; }
.cal-more { font-size: 11px; color: var(--text-muted); padding: 0 4px; }
.cal-day-list { display: flex; flex-direction: column; }
.cal-day-row { display: flex; align-items: center; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--hair); }
.cal-day-row:last-child { border-bottom: none; }
.cal-day-row.done { opacity: .55; }
@media (max-width: 760px) {
  .cal-legend { justify-content: flex-start; }
  .cal-cell { min-height: 72px; padding: 5px 5px; }
  .cal-chip { font-size: 10px; padding: 2px 4px; }
}
