:root {
  /* --teal/--teal-dark/--teal-tint are overwritten at runtime from
     config.js's CLIENT.themeColor/themeColorDark — these are just the
     fallback shown for a split second before that JS runs. */
  --teal: #2c5f7c;
  --teal-dark: #1c3f52;
  --amber: #b8812a;
  --amber-tint: #faf1e2;
  --teal-tint: #eaf0f3;
  --ink: #1a1d24;
  --muted: #5c6470;
  --line: #e5e3dc;
  --bg: #f7f5f0;
  --card: #ffffff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; overflow-wrap: break-word; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  display: flex; flex-direction: column; height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
}

#pin-gate {
  position: fixed; inset: 0; z-index: 100;
  background: var(--teal); display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#pin-gate.unlocked { display: none; }
.pin-box { width: 100%; max-width: 300px; text-align: center; }
.pin-title { color: #fff; font-weight: 800; font-size: 1.15rem; margin: 0 0 4px; }
.pin-sub { color: #d7e6c9; font-size: 0.88rem; margin: 0 0 20px; }
#pin-input {
  width: 100%; text-align: center; letter-spacing: 0.4em; font-size: 1.4rem;
  padding: 14px; border-radius: 10px; border: none; margin-bottom: 12px;
}
.pin-error { color: #ffd7d7; font-size: 0.82rem; margin: -4px 0 12px; }

#load-error {
  position: fixed; inset: 0; z-index: 90;
  background: var(--bg); display: none; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
#load-error.show { display: flex; }
.load-error-box { max-width: 300px; }
.load-error-title { font-weight: 800; font-size: 1.1rem; margin: 0 0 6px; color: var(--ink); }
.load-error-sub { color: var(--muted); font-size: 0.9rem; margin: 0 0 20px; }

header.app {
  background: var(--teal); color: #fff;
  padding: calc(env(safe-area-inset-top) + 16px) 18px 14px;
  position: sticky; top: 0; z-index: 5;
  box-shadow: 0 2px 8px rgba(20, 30, 10, 0.12);
  flex-shrink: 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
header.app p.eyebrow { margin: 0; font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: #b9c8dc; }
header.app h1 { margin: 2px 0 0; font-size: 1.25rem; }
/* Lives inside the sticky header, not the scrolling content, so it's always
   reachable regardless of how far down an add-on screen has been scrolled. */
.header-back {
  display: none; background: none; border: none; color: #fff; font-family: inherit;
  font-weight: 700; font-size: 0.78rem; padding: 0; margin: 0 0 4px; cursor: pointer;
}
.header-back.show { display: block; }

.refresh-btn {
  background: rgba(255, 255, 255, 0.16); border: none; color: #fff;
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.refresh-btn:active { background: rgba(255, 255, 255, 0.3); }
.refresh-btn svg { width: 16px; height: 16px; }
.refresh-btn.spinning svg { animation: spin 0.7s linear; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

main { padding: 6px 16px 16px; flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.screen { display: none; }
.screen.active { display: block; }

.search-wrap { padding: 12px 0 4px; }
input[type="text"], input[type="tel"], textarea {
  width: 100%; padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--line); font-size: 0.95rem; background: var(--card);
  font-family: inherit; color: var(--ink);
}
textarea { resize: vertical; min-height: 84px; }
input[type="text"]:focus, input[type="tel"]:focus, textarea:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(20, 30, 10, 0.04);
}
.row { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.card h3 { margin: 0 0 3px; font-size: 0.98rem; }
.card p { margin: 0; font-size: 0.85rem; color: var(--muted); }
.src { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }
.right { text-align: right; flex-shrink: 0; }
.time { margin: 5px 0 0; font-size: 0.72rem; color: #9aa2ac; }

.badge { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.badge-new { background: var(--teal-tint); color: var(--teal); }
.badge-contacted { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge-quoted { background: var(--amber-tint); color: var(--amber); }

.status-pill {
  flex: 1; border: none; cursor: pointer; font-family: inherit;
  font-weight: 700; font-size: 0.78rem; padding: 9px 6px; border-radius: 999px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.status-pill.badge-new.active { background: var(--teal); color: #fff; }
.status-pill.badge-contacted.active { background: var(--muted); color: #fff; border-color: var(--muted); }
.status-pill.badge-quoted.active { background: var(--amber); color: #fff; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 0.9rem; }

.section-label { font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 4px 0 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: none; cursor: pointer; font-family: inherit; transition: background 0.15s, opacity 0.15s, transform 0.1s; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--teal); color: #fff; font-weight: 700; font-size: 0.9rem; padding: 11px 18px; border-radius: 10px; width: 100%; box-shadow: 0 1px 2px rgba(20,30,10,0.08); }
.btn-primary:active { background: var(--teal-dark); }
.btn-outline { background: var(--card); color: var(--muted); font-weight: 700; font-size: 0.9rem; padding: 11px 18px; border-radius: 10px; border: 1px solid var(--line); }
.btn-outline:active { background: var(--bg); }
.btn-danger { background: var(--card); color: #b23a3a; font-weight: 700; font-size: 0.9rem; padding: 11px 18px; border-radius: 10px; border: 1px solid #f0c6c6; }
.btn-danger:active { background: #fdf1f1; }
.btn-danger-solid { background: #d94b4b; color: #fff; font-weight: 700; font-size: 0.9rem; padding: 11px 18px; border-radius: 10px; }
.btn-danger-solid:active { background: #b23a3a; }

.detail-row { display: flex; align-items: baseline; gap: 6px; font-size: 0.88rem; padding: 3px 0; }
.detail-row .k { color: var(--muted); flex-shrink: 0; }
.detail-row .v { color: var(--ink); font-weight: 600; }

.record-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 16px; font-size: 0.95rem; font-weight: 700; color: var(--ink);
}
.record-dot { width: 14px; height: 14px; border-radius: 50%; background: #d94b4b; flex-shrink: 0; }
.record-dot.pulsing { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
.record-btn.recording { border-color: #d94b4b; }
.record-sub { font-size: 0.78rem; color: var(--muted); font-weight: 500; margin-left: auto; }

.check-row { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; padding: 4px 0; }
.check-box { width: 16px; height: 16px; border-radius: 4px; flex-shrink: 0; display: inline-block; border: 1.5px solid var(--line); }
.check-box.done { background: var(--teal); border-color: var(--teal); }
.done-text { text-decoration: line-through; color: var(--muted); }
/* Flex items refuse to shrink below their content's natural width by
   default — without this, a long checklist item pushes the row wide
   instead of wrapping, same bug as the lead notes fix below. */
.check-row span:last-child { min-width: 0; flex: 1; }

.segmented {
  display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 3px; margin: 4px 0 16px;
}
.seg-btn {
  flex: 1; background: none; border: none; font-family: inherit;
  padding: 9px 6px; border-radius: 8px; font-size: 0.85rem; font-weight: 700; color: var(--muted);
}
.seg-btn.active { background: var(--card); color: var(--teal); box-shadow: 0 1px 3px rgba(15,21,38,0.12); }
.sub-panel { display: none; }
.sub-panel.active { display: block; }

#toast {
  position: fixed; left: 50%; bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 10px;
  font-size: 0.85rem; font-weight: 600; text-align: center;
  max-width: calc(100% - 32px);
  opacity: 0; pointer-events: none; z-index: 60;
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: 0 4px 16px rgba(20, 30, 10, 0.18);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

nav.tabbar {
  flex-shrink: 0;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; padding: 2px 4px calc(env(safe-area-inset-bottom, 0px) + 2px);
  box-shadow: 0 -2px 8px rgba(20, 30, 10, 0.06);
}
nav.tabbar button {
  flex: 1; background: none; border: none; font-family: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 2px; color: var(--muted); font-size: 0.66rem; font-weight: 600;
  transition: color 0.15s;
}
nav.tabbar button .ic { line-height: 1; }
nav.tabbar button .ic svg { width: 22px; height: 22px; display: block; margin: 0 auto; }
nav.tabbar button.active { color: var(--teal); }

/* ---------- Add-on menu (kebab button in header) ---------- */
.addon-menu {
  position: absolute; top: 40px; right: 42px; z-index: 20;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(20, 30, 10, 0.18);
  min-width: 170px; padding: 6px; display: none;
}
.addon-menu.open { display: block; }
.addon-menu button {
  display: block; width: 100%; text-align: left; background: none; border: none;
  font-family: inherit; font-size: 0.88rem; font-weight: 600; color: var(--ink);
  padding: 10px 12px; border-radius: 8px;
}
.addon-menu button:active { background: var(--bg); }

/* ---------- Social posts (add-on screen) ---------- */
.btn-back {
  background: none; border: none; font-family: inherit; cursor: pointer;
  font-weight: 700; font-size: 0.88rem; color: var(--teal); padding: 4px 0 14px; display: block;
}
.social-month-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 18px; }
.social-month-row p { margin: 0; font-size: 0.85rem; color: var(--muted); }
.social-month-row .btn-outline { width: auto; padding: 8px 14px; font-size: 0.82rem; }

.week-group { margin-bottom: 24px; }
.week-label { font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--amber); font-weight: 700; margin: 0 0 2px; }
.week-angle { font-size: 1rem; font-weight: 800; color: var(--ink); margin: 0 0 8px; }
.photo-note { font-size: 0.8rem; color: var(--ink); background: var(--teal-tint); border-radius: 8px; padding: 9px 12px; margin: 0 0 10px; }
.photo-note b { color: var(--teal); }

.platform-card.done { opacity: 0.5; }
.platform-label { font-size: 0.7rem; letter-spacing: 0.05em; text-transform: uppercase; font-weight: 700; color: var(--teal); margin: 0 0 6px; }
.caption-text { font-size: 0.88rem; color: var(--ink); margin: 0 0 12px; white-space: pre-wrap; }
.card-actions { display: flex; gap: 8px; }
.card-actions .btn { flex: 1; padding: 9px 6px; font-size: 0.8rem; }
.status-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.82rem; font-weight: 700; padding: 2px 0; }
.status-line.is-copied { color: var(--teal); }
.status-line.is-skipped { color: var(--muted); }
.status-line button { background: none; border: none; font-family: inherit; font-weight: 700; font-size: 0.8rem; color: var(--teal); padding: 0; cursor: pointer; }

.social-done-banner { background: var(--teal-tint); border-radius: 10px; padding: 12px 16px; margin-bottom: 18px; }
.social-done-banner p { margin: 0; font-size: 0.88rem; color: var(--teal); font-weight: 600; }
.social-empty { text-align: center; padding: 34px 10px; }
.social-empty p { color: var(--muted); font-size: 0.9rem; margin: 0 0 16px; }
.social-generating { text-align: center; padding: 34px 10px; color: var(--muted); font-size: 0.9rem; }

/* ---------- Business insights (add-on screen) ---------- */
.insight-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.insight-tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: 0 1px 2px rgba(20, 30, 10, 0.04); }
.insight-tile .num { margin: 0; font-size: 1.5rem; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.insight-tile .label { margin: 2px 0 0; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.insight-tile .delta { margin: 5px 0 0; font-size: 0.72rem; font-weight: 700; }
.insight-tile .delta.up { color: #2f8f4e; }
.insight-tile .delta.down { color: #b23a3a; }

.insight-narrative { background: var(--teal-tint); border-radius: 10px; padding: 14px 16px; margin-bottom: 18px; }
.insight-narrative .tag { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; color: var(--teal); margin: 0 0 6px; display: block; }
.insight-narrative p:last-child { margin: 0; font-size: 0.9rem; color: var(--ink); line-height: 1.5; }

.insight-section { margin-bottom: 18px; }
.insight-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; font-size: 0.88rem; border-bottom: 1px solid var(--line); }
.insight-row:last-child { border-bottom: none; }
.insight-row .k { color: var(--ink); font-weight: 600; }
.insight-row .v { color: var(--muted); font-variant-numeric: tabular-nums; }
