:root {
  /* Emberly — graphite & silver (premium, metal; monochrome like Apple/Linear/Vercel) */
  --brand: #2a2d33;            /* graphite — primary actions */
  --brand-d: #3b4049;          /* slate-graphite — text/icons on light */
  --brand-tint: #f0f1f4;       /* light silver — chips, pills */
  --brand-tint-line: #e1e4e9;  /* silver hairline border */
  --bg: #f5f6f8;               /* cool platinum off-white */
  --card: #ffffff;
  --ink: #1b1d21;              /* graphite near-black */
  --muted: #72767e;            /* neutral gray */
  --line: #e6e8ec;             /* silver hairline */
  --danger: #dc2626;
  --radius: 14px;
  --maxw: 640px;
  /* legacy aliases — existing var(--teal*) usages now resolve to graphite */
  --teal: var(--brand);
  --teal-d: var(--brand-d);
  --accent: #b8a06a;          /* champagne — the one identity accent */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

/* Buttons don't inherit text colour by default (the UA paints them black), so in dark
   mode any button without an explicit colour showed black text. Make them follow the
   theme; the specific overrides below (white on brand, dark on the champagne accent) win. */
button { color: var(--ink); font-family: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--card); color: var(--ink);
  border-bottom: 1px solid var(--line);
  padding-top: max(14px, env(safe-area-inset-top));
}
/* The wordmark is an <a href="/"> on public pages (so a visitor is never stranded) and a
   plain <div> inside the app shell. Pin colour + decoration so both render identically. */
.brand { font-weight: 700; letter-spacing: .2px; font-size: 17px; color: var(--ink); display: flex; align-items: center; gap: 9px;
         text-decoration: none; }
a.brand:hover { opacity: .8; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: radial-gradient(circle at 35% 28%, #ecdcad, #b8a06a 60%, #8a7444); box-shadow: 0 1px 2px rgba(0,0,0,.2), inset 0 0 0 .5px rgba(255,255,255,.45); }
.ghost { background: var(--brand-tint); color: var(--brand-d); border: 0; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.ghost:active { transform: scale(.97); }

main { flex: 1; overflow-y: auto; width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 12px 12px 84px; }
.view { display: none; }
.view.active { display: block; }

/* chat */
.chat-log { display: flex; flex-direction: column; gap: 8px; min-height: 40vh; }
.msg { padding: 10px 13px; border-radius: var(--radius); max-width: 85%; line-height: 1.4; font-size: 15px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--teal); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.hint { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 2px 4px; }
.sug-label { grid-column: 1 / -1; color: var(--muted); font-size: 12px; letter-spacing: .02em; }
.sug-chip {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  width: 100%; text-align: left;
  border: 1px solid var(--brand-tint-line);
  background: linear-gradient(180deg, var(--card), var(--brand-tint));
  color: var(--ink); border-radius: 12px; padding: 9px 11px;
  font-size: 12.5px; line-height: 1.3;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
  cursor: pointer; transition: transform .08s ease, border-color .15s ease;
}
.sug-chip::before { content: "\2728"; margin-right: 7px; opacity: .65; }
.sug-chip:hover { border-color: var(--accent); }
.sug-chip:active { transform: scale(.99); }

.chat-input {
  position: fixed; left: 0; right: 0; bottom: 64px;
  display: flex; gap: 8px; padding: 10px 12px;
  background: var(--bg); border-top: 1px solid var(--line);
  max-width: var(--maxw); margin: 0 auto;
}
.chat-input input { flex: 1; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; font-size: 15px; background: var(--card); color: var(--ink); }
.chat-input button, .bucket-tabs button.active, form button[type=submit] { background: var(--teal); color: #fff; }
.chat-input button { border: 0; padding: 0 18px; border-radius: 12px; font-weight: 600; }
.chat-input .mic-btn { background: var(--card); color: var(--ink); border: 1px solid var(--line); padding: 0 13px; font-size: 18px; }
.chat-input .mic-btn.rec { background: #fee2e2; border-color: #fecaca; }
.cap-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 2px 10px; }
.msg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dup-banner { background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 13px; color: #92400e; }
.dup-banner .actions { margin-top: 8px; }
.more-fields { border: 0; background: transparent; color: var(--teal-d); font-size: 13px; font-weight: 600; padding: 8px 2px; margin-top: 2px; }
.del-contact { width: 100%; border: 1px solid var(--line); background: transparent; color: var(--danger); border-radius: 10px; padding: 10px; margin-top: 16px; font-size: 13px; }

/* lists */
.list { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; }
.card .body { font-size: 15px; font-weight: 600; }
.card .meta { color: var(--muted); font-size: 13px; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chip { background: var(--brand-tint); color: var(--brand-d); border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.card .who { background: var(--brand-tint); color: var(--brand-d); padding: 1px 8px; border-radius: 999px; font-size: 12px; }
.card .actions { display: flex; gap: 8px; margin-top: 10px; }
.card .actions button { border: 1px solid var(--line); background: var(--card); padding: 7px 12px; border-radius: 10px; font-size: 13px; color: var(--ink); }
.card .actions .done { border-color: var(--teal); color: var(--teal-d); font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 40px 12px; font-size: 14px; }

.bucket-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.bucket-tabs .bucket { flex: 1; padding: 9px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; font-size: 14px; color: var(--muted); }
.bucket-tabs .bucket.active { background: var(--accent); color: #1b1d21; border-color: var(--accent); }
.bucket-tabs .dkind { flex: 1; padding: 9px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; font-size: 14px; color: var(--muted); }
.bucket-tabs .dkind.active { background: var(--accent); color: #1b1d21; border-color: var(--accent); }
.deal-filter { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; background: var(--card); color: var(--ink); margin-bottom: 10px; }
.deal-contact { cursor: pointer; text-decoration: underline; }
#dealsSummary { margin: 0 2px 10px; }
.badge { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; margin-left: 4px; display: none; }
.badge.show { display: inline-block; }

.muted { color: var(--muted); } .small { font-size: 12.5px; }

/* tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  max-width: var(--maxw); margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; border: 0; background: none; padding: 8px 0 9px; font-size: 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tab span { font-size: 10.5px; }
.tab.active { color: var(--accent); }
.tab.active span { font-weight: 700; }
.tab .tab-badge { position: absolute; }

/* toasts */
.toasts { position: fixed; top: 64px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 20; pointer-events: none; }
.toast { background: #23262b; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: pop .25s ease; max-width: 90%; }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* contact detail overlay */
.hidden { display: none !important; }
.overlay { position: fixed; inset: 0; z-index: 10; background: var(--bg); display: flex; flex-direction: column; }
.cd-main { flex: 1; overflow-y: auto; width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 12px 12px 84px; }
.cd-contact { color: var(--muted); font-size: 14px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.cd-details { margin-bottom: 4px; }
.cd-h { font-size: 12px; color: var(--muted); margin: 16px 2px 8px; text-transform: uppercase; letter-spacing: .05em; }
.detail-row { display: flex; align-items: baseline; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.detail-row:last-child { border-bottom: 0; }
.detail-k { color: var(--muted); font-size: 13px; min-width: 120px; }
.detail-v { flex: 1; font-size: 14.5px; word-break: break-word; }
.detail-x { border: 0; background: none; color: var(--muted); font-size: 14px; padding: 2px 6px; cursor: pointer; }
.note-edit { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; font-size: 14.5px; resize: vertical; box-sizing: border-box; }
.field-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.field-row:last-child { border-bottom: 0; }
.field-k { color: var(--muted); font-size: 13px; min-width: 132px; flex-shrink: 0; }
.field-v { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-size: 14.5px; padding: 4px 2px; border-bottom: 1px solid transparent; }
.field-v:focus { outline: none; border-bottom-color: var(--accent); }
.field-v::placeholder { color: #c3c9d0; }
textarea.field-v { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; resize: vertical; }
.add-field { display: flex; gap: 8px; margin-top: 12px; }
.add-field input { min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font-size: 14px; }
.add-field .add-k { flex: 0 0 40%; }
.add-field .add-v { flex: 1; }
.add-field button { border: 0; background: var(--teal); color: #fff; border-radius: 10px; padding: 0 14px; font-weight: 600; white-space: nowrap; }
.money-card { background: var(--brand-tint); border-color: var(--brand-tint-line); margin-bottom: 10px; }
.money-h { font-weight: 700; font-size: 12.5px; color: var(--teal-d); margin-bottom: 4px; letter-spacing: .02em; }
.field-row.ro { border-bottom-color: var(--brand-tint-line); }
.ro-v { font-weight: 600; color: var(--ink); }
.cd-sub { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }
.opp-add { display: flex; gap: 8px; margin: 6px 0 4px; }
.opp-add .opp-title { flex: 1; min-width: 0; }
.opp-add .opp-amount { flex: 0 0 26%; min-width: 0; }
.opp-add input { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font-size: 14px; }
.opp-add button { border: 0; background: var(--teal); color: #fff; border-radius: 10px; padding: 0 14px; font-weight: 700; }
.card.opp .actions button { font-size: 12.5px; padding: 6px 10px; }
.opp-edit { display: flex; gap: 8px; }
.opp-edit input { min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 14px; }
.opp-edit .opp-title { flex: 1; }
.opp-edit .opp-amount { flex: 0 0 30%; }
.empty.small { padding: 12px; font-size: 13px; }
.opp-section { margin: 2px 0; }
.opp-section > summary { cursor: pointer; list-style: none; display: flex; align-items: center; }
.opp-section > summary::-webkit-details-marker { display: none; }
.opp-section > summary::after { content: "\25B8"; margin-left: auto; color: var(--muted); transition: transform .15s ease; }
.opp-section[open] > summary::after { transform: rotate(90deg); }
.sec-count { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.open-hint { margin-left: 8px; color: var(--muted); font-weight: 400; font-size: 11px; text-transform: none; letter-spacing: 0; }
.opp-section[open] .open-hint { display: none; }
#cdMoney { margin-top: 6px; }
.cd-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.act-btn { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; background: var(--card); border: 1px solid var(--line); color: var(--teal-d); border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 600; }
.act-btn:active { background: var(--brand-tint); }
.cd-msg { margin-top: 8px; }
.msg-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip-btn { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 7px 12px; font-size: 12.5px; min-height: 32px; }
.msg-box { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 14px; resize: vertical; box-sizing: border-box; }
.search-box { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 14px; margin-bottom: 10px; box-sizing: border-box; background: var(--card); color: var(--ink); }
.tag-filter { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tagf { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; color: var(--muted); }
.tagf.on { background: var(--accent); color: #1b1d21; border-color: var(--accent); }
.cd-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.tagchip { display: inline-flex; align-items: center; gap: 4px; background: var(--brand-tint); color: var(--brand-d); border: 1px solid var(--brand-tint-line); border-radius: 999px; padding: 3px 9px; font-size: 12px; }
.tagx { border: 0; background: transparent; color: var(--teal-d); font-size: 14px; line-height: 1; padding: 0 0 0 2px; }
.tagadd { border: 1px dashed var(--line); background: transparent; color: var(--muted); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.alpha-filter { display: flex; flex-wrap: wrap; gap: 3px; margin: -2px 0 12px; }
.alpha { border: 0; background: transparent; color: var(--muted); min-width: 23px; height: 25px; padding: 0 2px; border-radius: 7px; font-size: 12px; font-weight: 600; cursor: pointer; }
.alpha:hover { background: var(--brand-tint); }
.alpha.on { background: var(--accent); color: #1b1d21; }
.alpha.off { opacity: .28; pointer-events: none; }
#cdPin.on { color: var(--accent); }
.cd-meta { margin-bottom: 8px; }
.od-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: inline-block; margin-left: 6px; flex-shrink: 0; }
.cd-cadence { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cadence-sel { border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; font-size: 13px; background: var(--card); }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat-v { font-size: 22px; font-weight: 700; color: var(--ink); }
.stat-l { font-size: 13px; color: var(--muted); margin-top: 2px; }
.stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.stat.good .stat-v { color: var(--teal); }
.stat.warn { border-color: #fde68a; background: #fffbeb; }
.stat.warn .stat-v { color: #b45309; }
.stat.tap { cursor: pointer; }
.st-chip { font-size: 11px; padding: 1px 8px; border-radius: 999px; font-weight: 600; }
.st-open { background: #eef2f7; color: #475569; }
.st-prog { background: #dbeafe; color: #1d4ed8; }
.st-deliv { background: #fef3c7; color: #b45309; }
.st-paid { background: #dcfce7; color: #15803d; }
.st-hold { background: #f1f5f9; color: #64748b; }
.st-lost { background: #fee2e2; color: #b91c1c; }
.card.overdue { border-color: #fecaca; }
.od-flag { color: var(--danger); font-weight: 600; }
.stale-flag { color: #b45309; font-weight: 600; }
.nd-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.nd-form input, .nd-form select { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font-size: 14px; box-sizing: border-box; width: 100%; }
.nd-form > button { border: 0; background: var(--teal); color: #fff; border-radius: 10px; padding: 10px; font-weight: 600; }
.nd-kind { display: flex; gap: 6px; }
.nd-k { flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px; font-size: 13px; }
.nd-k.on { background: var(--accent); color: #1b1d21; border-color: var(--accent); }
.nd-form textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font: inherit; font-size: 14px; box-sizing: border-box; resize: vertical; }
.seed-btn { display: block; margin: 14px auto 0; border: 0; background: var(--teal); color: #fff; border-radius: 10px; padding: 10px 18px; font-weight: 600; }
.deal-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.deal-hist { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.hist-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 3px 0; }
.pay-status { font-size: 14px; font-weight: 600; margin: 4px 0 6px; color: var(--ink); }
.rem-quick { display: flex; gap: 8px; margin-bottom: 10px; }
.rem-quick input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 14px; }
.rem-quick button { border: 0; background: var(--teal); color: #fff; border-radius: 10px; padding: 0 16px; font-weight: 600; }
.rem-when { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; font-size: 14px; box-sizing: border-box; margin-top: 6px; }
.tap-title { cursor: pointer; }
.tap-title:active { opacity: .6; }
select.field-v { cursor: pointer; background: transparent; }
.pay-nudge { margin: 14px 0 6px; padding: 11px; background: var(--brand-tint); border: 1px solid var(--line); border-radius: 12px; }
.pay-nudge .actions { margin-top: 8px; }
.pay-nudge .opp-add { margin-top: 8px; }
.pay-nudge .opp-add input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font-size: 14px; }
.pay-nudge .opp-add button { border: 0; background: var(--teal); color: #fff; border-radius: 10px; padding: 0 14px; font-weight: 600; }
.cd-input { bottom: 0; }
.card.tap { cursor: pointer; }
.card.tap:active { transform: scale(.99); }
.tl-note .body::before { content: "\1F4DD  "; }
.tl-reminder .body::before { content: "\23F0  "; }
.card.done { opacity: .6; }

/* ---- header actions ---- */
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-ghost { padding: 7px 10px; font-size: 15px; line-height: 1; }

/* ---- dark mode (graphite surfaces, silver text, champagne accent) ---- */
html[data-theme="dark"] {
  --brand: #3d424a;            /* lighter graphite so primary actions lift off the dark bg */
  --brand-d: #cdd2da;          /* light slate — text/icons on dark */
  --brand-tint: #26282d;       /* dark chip surface */
  --brand-tint-line: #34373d;
  --bg: #161719;               /* near-black graphite */
  --card: #1e2024;             /* elevated surface */
  --ink: #ffffff;              /* pure white text (always readable on dark) */
  --muted: #b9bdc6;            /* light gray — still clearly legible on dark */
  --line: #2c2f34;
  /* --accent (champagne) is intentionally unchanged — it pops on dark */
}
html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select { background: var(--card); color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] .mic-btn.rec { background: #4a1f1f; border-color: #6b2b2b; }
