:root {
  --teal: #0e7c86;
  --teal-dark: #0a5c64;
  --teal-light: #e6f4f5;
  --ink: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f7fafb;
  --white: #ffffff;
  --green: #15803d;
  --green-bg: #dcfce7;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--teal-dark);
  color: white;
  flex-shrink: 0;
  padding: 24px 0;
}
.sidebar .brand {
  padding: 0 20px 20px;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  margin-bottom: 12px;
}
.sidebar .brand small { display: block; font-weight: 400; opacity: 0.75; font-size: 12px; margin-top: 2px; }
.sidebar nav a {
  display: block;
  padding: 10px 20px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 14px;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.08); }
.sidebar nav a.active { background: var(--teal); color: white; font-weight: 600; }

.main { flex: 1; padding: 28px 36px; max-width: 1100px; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.subtitle { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }

.attention-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.attention-row:last-child { border-bottom: none; }
.attention-row a { color: var(--ink); text-decoration: none; }
.attention-row a:hover { color: var(--teal-dark); }
.attention-row .dismiss-btn { background: none; color: var(--muted); border: none; padding: 2px 8px; font-size: 16px; line-height: 1; cursor: pointer; }
.attention-row .dismiss-btn:hover { color: var(--red); }

.stat { text-align: left; }
.stat .num { font-size: 26px; font-weight: 700; color: var(--teal-dark); }
.stat .label { font-size: 13px; color: var(--muted); }
a.stat-link { display: block; text-decoration: none; color: inherit; transition: box-shadow .15s, border-color .15s; }
a.stat-link:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); border-color: var(--teal); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.gray { background: #f1f5f9; color: var(--muted); }
.badge.teal { background: var(--teal-light); color: var(--teal-dark); }

button, .btn {
  background: var(--teal);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:hover, .btn:hover { background: var(--teal-dark); }
button.secondary, .btn.secondary { background: white; color: var(--teal-dark); border: 1px solid var(--teal); }
button.secondary:hover { background: var(--teal-light); }
button.danger { background: white; color: var(--red); border: 1px solid var(--red-bg); }
button.danger:hover { background: var(--red-bg); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.small { padding: 5px 10px; font-size: 12px; }

input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: white;
}
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--ink); }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: white; border-radius: var(--radius); padding: 24px;
  width: 480px; max-width: 90vw; max-height: 85vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.empty { color: var(--muted); font-size: 14px; padding: 24px; text-align: center; }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: white;
  padding: 12px 18px; border-radius: 8px; font-size: 14px; z-index: 100; max-width: 360px;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.pill-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.pill-tabs button { background: white; color: var(--muted); border: 1px solid var(--border); }
.pill-tabs button.active { background: var(--teal); color: white; border-color: var(--teal); }

.rec-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--red); margin-right: 6px; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.transcript-box { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-size: 13px; max-height: 220px; overflow-y: auto; }

a { color: var(--teal-dark); }

.config-warning { background: var(--amber-bg); color: var(--amber); border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }
.config-ok { background: var(--green-bg); color: var(--green); border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }

.dropdown-menu {
  display: none; position: absolute; right: 0; top: 100%; margin-top: 4px;
  background: white; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12); z-index: 20; min-width: 160px; overflow: hidden;
}
.dropdown-menu.open { display: flex; flex-direction: column; }
.dropdown-menu button {
  background: white; color: var(--ink); border: none; border-radius: 0;
  padding: 10px 14px; font-weight: 500; text-align: left; justify-content: flex-start;
}
.dropdown-menu button:hover { background: var(--bg); }
.dropdown-menu button.danger { color: var(--red); }

/* ================= Mobile ================= */
.mobile-topbar { display: none; }
.mobile-nav-overlay { display: none; }
.mobile-only { display: none; }

/* Card-style rows used instead of a table on Clients, Schedule, and Invoices
   on mobile — a squeezed/scrolling table doesn't read well on a phone, and an
   absolutely-positioned dropdown inside a horizontally-scrolling table gets
   clipped, so these three lists get a dedicated stacked layout below 768px. */
.list-cards { display: none; }
.list-card { background: white; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.list-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.list-card-title { font-weight: 700; font-size: 15px; }
.list-card-title a { color: var(--ink); text-decoration: none; }
.list-card-sub { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.list-card-row { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.list-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* Prospect cards on the Intake page specifically want generous, well-separated
   tap targets since this is the page most likely to be used one-handed on a
   phone — the whole card opens the review/detail panel, so its own buttons
   need stopPropagation() (handled in intake.js) to stay independently usable. */
.prospect-card { cursor: pointer; }

/* Appointment cards on the client page's Appointments tab — same
   whole-card-clickable pattern, but backed by event delegation + a data-action
   attribute (see client.js) rather than a raw onclick, so nested buttons with
   their own data-action are matched first without needing stopPropagation(). */
.appt-card { cursor: pointer; }
.appt-card:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.prospect-card .list-card-actions { gap: 10px; }
.prospect-card .list-card-actions button { min-height: 44px; padding: 10px 16px; font-size: 14px; }

/* Invoice rows/cards on the main Invoices page and the client Billing tab
   (see public/js/invoices-shared.js) — the whole row/card opens the invoice
   detail panel; inner links (client name) use stopPropagation() to stay
   independently usable. */
.clickable-row { cursor: pointer; }
tr.clickable-row:hover { background: var(--bg); }
.clickable-row:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ================= Full-screen panel (mobile) / large docked panel (desktop) =================
   Used for the Intake prospect/assessment-review panel, and reusable for any future
   "don't navigate away, but this is too big for a small centered modal" need. Sticky
   header/footer + a scrolling body is done with flexbox rather than position:fixed,
   which is the technique that actually holds up under iOS Safari's quirky handling of
   fixed-position elements inside a scrolling/transformed ancestor. */
.panel-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; justify-content: center; z-index: 70;
}
.panel {
  background: white; width: 100%; max-width: 680px;
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-header {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: white;
}
.panel-body { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; }
.panel-footer {
  flex: 0 0 auto; display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--border); background: white;
}
.panel-footer button { flex: 1; justify-content: center; min-height: 48px; font-size: 15px; }

@media (min-width: 769px) {
  .panel-backdrop { align-items: center; }
  .panel { max-height: 88vh; border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,0.2); }
}
@media (max-width: 768px) {
  .panel-backdrop { align-items: stretch; }
  .panel { max-width: 100%; height: 100vh; height: 100dvh; }
}

/* Bottom sheet — secondary actions. Slides up from the bottom on mobile (true
   bottom sheet); a small centered card on desktop, same as any other modal. */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; justify-content: center; z-index: 80;
}
.sheet { background: white; width: 100%; max-width: 420px; padding: 10px 16px 22px; }
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 999px; margin: 6px auto 14px; }
.sheet button { width: 100%; justify-content: flex-start; min-height: 48px; font-size: 15px; margin-bottom: 8px; }
.sheet button:last-child { margin-bottom: 0; }

@media (min-width: 769px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: var(--radius); }
}
@media (max-width: 768px) {
  .sheet-backdrop { align-items: flex-end; }
  .sheet { border-radius: 16px 16px 0 0; }
}

/* Assessment review — read-only question/answer pairs, always stacked (never
   side-by-side), so it stays readable on a narrow phone screen. */
.assessment-review-section { margin-bottom: 22px; }
.assessment-review-section:last-child { margin-bottom: 0; }
.assessment-review-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-bottom: 12px; }
.assessment-review-field { margin-bottom: 14px; }
.assessment-review-field:last-child { margin-bottom: 0; }
.assessment-review-question { font-size: 14px; font-weight: 600; color: var(--ink); margin-bottom: 3px; line-height: 1.4; }
.assessment-review-answer { font-size: 14px; color: var(--ink); white-space: pre-wrap; line-height: 1.5; }
.assessment-review-answer.unanswered { color: var(--muted); font-style: italic; }

/* Shared step-progress bar and error banner — used by any multi-step guided
   flow (currently just Convert to Client). Kept generic/reusable rather than
   duplicating assessment.css's own progress bar into this file. */
.progress-track { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--teal); transition: width .2s ease; }
.error-banner { background: var(--red-bg); color: var(--red); border-radius: 8px; padding: 12px 14px; font-size: 13px; margin-bottom: 14px; }
.error-banner strong { display: block; margin-bottom: 4px; }
.reference-box { background: var(--bg, #f8fafc); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; }

/* Convert to Client — step inputs need larger tap targets/font on mobile per
   the mobile-first requirement (16px+ avoids iOS auto-zoom-on-focus too). */
.step-field { margin-bottom: 16px; }
.step-field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.step-field input, .step-field textarea, .step-field select { font-size: 16px; min-height: 44px; }
.step-field textarea { min-height: 80px; }
.dup-match { padding: 12px 0; border-top: 1px solid rgba(0,0,0,0.08); }
.dup-match:first-of-type { border-top: none; padding-top: 8px; }
.dup-match-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

@media (max-width: 768px) {
  .mobile-only { display: block; }
  .list-cards { display: block; }
  table.desktop-table { display: none; }

  /* Plain (non-desktop-table) tables — e.g. the client Overview's Contact
     info / Additional contacts tables, and the Dashboard's mini
     communications/upcoming/unpaid-invoice tables — were never given a
     mobile-card treatment like the main data tables above. Without a width
     constraint they size to their widest unwrapped cell (a long email
     address, or just a header row's label text), which forces the whole
     page wider than the viewport. table-layout:fixed + wrapping keeps them
     inside their card instead of pushing the page into horizontal scroll.
     Explicitly overrides the generic `table { white-space: nowrap;
     overflow-x: auto }` rule further below (an older "make wide tables
     internally scrollable" strategy) — for these small label/value and
     contact-list tables, wrapping in place reads better on a narrow screen
     than an in-row horizontal swipe. */
  table:not(.desktop-table) {
    table-layout: fixed; width: 100%;
    display: table; white-space: normal; overflow-x: visible;
  }
  table:not(.desktop-table) th,
  table:not(.desktop-table) td { overflow-wrap: break-word; word-break: break-word; }

  /* Grid items default to min-width:auto, which sizes the track to fit its
     content's "automatic minimum size" — a calculation that ignores
     overflow-wrap/word-break entirely, so a single long unbreakable string
     (a long email address, a generated test name with no spaces) still
     forces the grid track — and the whole page — wider than the viewport,
     even with the table fix above in place. min-width:0 opts every grid
     item out of that automatic minimum, letting the wrapping rules above
     actually take effect. */
  .grid-2 > *, .grid-3 > *, .grid-4 > * { min-width: 0; }

  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 40;
    background: var(--teal-dark); color: white;
    padding: 12px 16px;
  }
  .hamburger-btn, .back-btn { background: none; border: none; color: white; font-size: 22px; padding: 4px 8px; line-height: 1; }
  .hamburger-btn:hover, .back-btn:hover { background: rgba(255,255,255,0.1); border-radius: 6px; }
  .mobile-topbar-title { font-weight: 700; font-size: 16px; }

  .app-shell { display: block; min-height: auto; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
    width: 240px; max-width: 80vw;
    transform: translateX(-100%);
    transition: transform .2s ease;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-nav-overlay.visible {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 50;
  }

  .main { padding: 16px; max-width: 100%; }

  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .row { flex-direction: column; }

  .section-header { flex-direction: column; align-items: flex-start; gap: 10px; }

  #header-actions { display: flex; flex-wrap: wrap; gap: 8px; }

  .pill-tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .pill-tabs button { flex-shrink: 0; }

  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

  .hide-mobile { display: none; }

  .modal { padding: 16px; width: 100%; }

  /* Prevents iOS Safari from auto-zooming the page when a field is tapped. */
  input, select, textarea { font-size: 16px; }
}
