/* Morgan Branch Lead Desk — a quiet operating system, not a SaaS dashboard. */
:root {
  --ink: #0a0a0a;
  --white: #ffffff;
  --paper: #f7f6f4;
  --lav: #C9B8E8;
  --lav-soft: #f1ecfa;
  --lav-line: #ddd0ef;
  --pow: #B8D4E8;
  --pow-soft: #eef6fc;
  --line: #e7e4ec;
  --muted: #74747d;
  --ink-soft: #3a3a42;
  --danger: #b23b3b;
  --serif: "Playfair Display", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
/* The hidden attribute must win over the display rules below (login/app/modal/
   toast all set display), otherwise toggling `el.hidden` would not hide them. */
[hidden] { display: none !important; }
body { font-family: var(--sans); color: var(--ink); background: var(--paper); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; cursor: pointer; }
em { font-family: var(--serif); font-style: italic; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); } .sm { font-size: 12.5px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 7px; font: 600 13.5px/1 var(--sans); padding: 11px 18px; border-radius: 10px; border: 1.5px solid transparent; cursor: pointer; transition: background .16s, border-color .16s, transform .1s; }
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--lav); color: var(--ink); }
.btn--primary:hover { background: #bda9e0; }
.btn--primary:disabled { background: #e9e5f1; color: #a7a2b3; cursor: not-allowed; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn--ghost:hover { border-color: var(--lav-line); color: var(--ink); }
.btn--danger { background: transparent; border-color: #e6c6c6; color: var(--danger); }
.btn--danger:hover { background: #fbf1f1; }
.btn--mini { padding: 7px 12px; font-size: 12.5px; }

/* ── Login ── */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--ink); }
.login__box { width: 100%; max-width: 400px; background: var(--paper); border-radius: 16px; padding: 34px 30px; }
.login__brand { font-family: var(--serif); font-size: 22px; font-weight: 600; }
.login__brand em { font-weight: 500; }
.login__sub { color: var(--muted); font-size: 13px; margin-top: 6px; }
.login__form { margin-top: 22px; }
.login__form label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 14px; }
.login__form input { display: block; width: 100%; margin-top: 6px; font: 400 15px var(--sans); padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 9px; background: var(--white); }
.login__form input:focus { outline: none; border-color: var(--lav); }
.login__note { font-size: 13px; color: var(--ink-soft); margin-bottom: 14px; }
.login__secret { display: block; font-family: ui-monospace, Menlo, monospace; font-size: 14px; letter-spacing: .04em; background: var(--white); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 14px; word-break: break-all; }
.login__err { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.login .btn { width: 100%; justify-content: center; }
.login__foot { margin-top: 18px; font-size: 12px; color: var(--muted); }

/* ── App shell ── */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.rail { background: var(--ink); color: #efeef3; display: flex; flex-direction: column; padding: 22px 16px; position: sticky; top: 0; height: 100vh; }
.rail__brand { font-family: var(--serif); font-size: 18px; font-weight: 600; padding: 0 8px 22px; }
.rail__brand em { color: var(--lav); font-weight: 500; }
.rail__nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.rail__item { padding: 11px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; color: #c9c8d2; }
.rail__item:hover { background: rgba(255,255,255,.06); color: #fff; }
.rail__item.is-active { background: var(--lav); color: var(--ink); }
.rail__foot { border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; font-size: 12.5px; }
.rail__who { display: block; color: #9b9aa6; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; }
.rail__signout { color: var(--lav); font-weight: 600; }
.app__scrim { display: none; }

.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 26px; border-bottom: 1px solid var(--line); background: rgba(247,246,244,.9); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; }
.topbar__burger { display: none; font-size: 22px; background: none; border: none; cursor: pointer; }
.topbar__title { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.view { padding: 30px 26px 60px; max-width: 1120px; }

/* ── Headings / layout ── */
.h1 { font-family: var(--serif); font-weight: 600; font-size: 27px; letter-spacing: -.01em; }
.h2 { font-family: var(--serif); font-weight: 500; font-size: 18px; margin-bottom: 12px; }
.rowbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.rowbar__actions { display: flex; gap: 10px; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; margin-top: 18px; }
.count, .kcol__n { font: 600 12px var(--sans); background: var(--lav-soft); color: #6b5a97; border-radius: 999px; padding: 2px 9px; margin-left: 6px; }

/* Collapsible log / timeline panels (native <details>) */
details.panel > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-weight: 500; font-size: 18px; color: var(--ink); }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::after { content: ""; width: 8px; height: 8px; margin-left: auto; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s ease; }
details.panel[open] > summary::after { transform: rotate(225deg); }
details.panel[open] > summary { margin-bottom: 12px; }
details.panel > *:not(summary) { margin-top: 0; }

/* ── Scheduling: calendar, agenda, settings (Stage F1) ── */
.cal__bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.cal__bar h2 { flex: 1; min-width: 120px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal__dow { font: 600 11px var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; text-align: center; padding: 2px 0; }
.cal__cell { min-height: 92px; border: 1px solid var(--line); border-radius: 10px; padding: 6px; background: var(--white); display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.cal__cell--out { background: #faf9fc; color: var(--muted); }
.cal__cell--today { border-color: var(--lav); box-shadow: 0 0 0 2px var(--lav-soft); }
.cal__day { font: 600 12px var(--sans); color: var(--ink-soft); }
.cal__empty { margin-top: 10px; text-align: center; }
.apptchip { display: block; width: 100%; text-align: left; border: 0; border-radius: 6px; padding: 3px 6px; font: 500 11px var(--sans); background: var(--lav-soft); color: #4a3f70; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.apptchip__t { font-weight: 700; }
.apptchip--completed { background: #e3f3e8; color: #2b5a3b; }
.apptchip--no_show { background: #fdeaea; color: #8a2b2b; }
.apptchip--cancelled_by_owner, .apptchip--cancelled_by_client { background: #eceaf0; color: #8a8694; text-decoration: line-through; }
.cal__more { display: block; width: 100%; text-align: left; margin-top: 2px; border: 0; background: none; padding: 2px 6px; border-radius: 6px; font: 600 11px var(--sans); color: #6b5a97; cursor: pointer; }
.cal__more:hover { background: var(--lav-soft); }
.agenda { display: none; }
.agenda__day { border-top: 1px solid var(--line); padding: 10px 0; }
.agenda__date { font: 600 12px var(--sans); color: var(--muted); margin-bottom: 6px; }
.agenda__item { display: block; width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; background: var(--white); cursor: pointer; font-size: 14px; }
.schd__enable { font-size: 15px; }
.schd__day { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 7px 0; border-top: 1px solid var(--line); }
.schd__day:first-of-type { border-top: 0; }
.schd__day .chk { min-width: 150px; }
.schd__day input[type=time] { width: auto; }
@media (max-width: 720px) { .cal__wrap { display: none; } .agenda { display: block; } }

/* ── Stat cards ── */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 22px 0 4px; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.stat__n { font-family: var(--serif); font-size: 34px; font-weight: 600; }
.stat__k { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 4px; }

/* ── Tables ── */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl--rows tbody tr, .tbl tbody tr[data-act] { cursor: pointer; }
.tbl tbody tr[data-act]:hover { background: var(--lav-soft); }
.chip { display: inline-block; font-size: 11.5px; font-weight: 600; background: var(--pow-soft); border: 1px solid #d3e6f4; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.chip--done { background: #eef7f0; border-color: #cfe6d6; color: #2f7d4f; }
.chip--off { background: #f1eef4; border-color: var(--line); color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--lav); vertical-align: middle; }

/* ── Filters ── */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.in { font: 400 14px var(--sans); padding: 9px 12px; border: 1.5px solid var(--line); border-radius: 9px; background: var(--white); color: var(--ink); }
.in:focus { outline: none; border-color: var(--lav); }
.in--mini { padding: 6px 8px; font-size: 12.5px; margin-top: 8px; width: 100%; }
#fSearch { min-width: 220px; flex: 1; }

/* ── Lead detail ── */
.back { display: inline-block; color: #6b5a97; font-weight: 600; font-size: 13px; margin-bottom: 12px; }
.ident { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 22px; background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; }
.ident .k { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 3px; }
.frow { display: flex; gap: 10px; }
.note { border-bottom: 1px solid var(--line); padding: 12px 0; }
.note:last-child { border-bottom: none; }
.note__meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.task { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: none; }
.tl { list-style: none; }
.tl li { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 13.5px; }
.tl__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--lav); flex: 0 0 auto; }
.tl__when { margin-left: auto; color: var(--muted); font-size: 12.5px; }

/* ── Pipeline (stages stacked as full-width vertical bands) ── */
.pstack { display: flex; flex-direction: column; gap: 16px; margin-top: 18px; }
.pstage { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.pstage--empty { padding: 13px 18px; background: var(--paper); }
.pstage__head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.pstage--empty .pstage__head { margin-bottom: 0; }
.pstage__marker { width: 10px; height: 10px; border-radius: 50%; background: var(--lav); flex: 0 0 auto; }
.pstage--empty .pstage__marker { background: var(--lav-line); }
.pstage__name { font-family: var(--serif); font-weight: 500; font-size: 16px; }
.pstage__n { font: 600 12px var(--sans); background: var(--lav-soft); color: #6b5a97; border-radius: 999px; padding: 2px 10px; }
.pstage--empty .pstage__n { background: var(--paper); border: 1px solid var(--line); color: var(--muted); }
/* Responsive wrapping card grid: many side-by-side on desktop, fewer on tablet,
   one full-width card per row on mobile — no forced horizontal scroll. */
.pstage__cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 12px; }
.pstage__empty { color: var(--muted); font-size: 13px; }
.kcard { border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; background: var(--paper); }
.pstage .kcard { background: var(--white); }
.kcard:hover { border-color: var(--lav-line); }
.kcard__name { font-weight: 600; font-size: 13.5px; }
.kcard__dir { font-size: 12.5px; color: var(--ink-soft); margin: 3px 0; }
.kcard__fu { font-size: 12px; color: var(--muted); }

/* ── Modal ── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal__scrim { position: absolute; inset: 0; background: rgba(10,10,10,.45); }
.modal__box { position: relative; background: var(--paper); border-radius: 16px; padding: 28px 26px; width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; }
.modal__close { position: absolute; top: 12px; right: 14px; font-size: 22px; background: none; border: none; cursor: pointer; color: var(--muted); }
.mform { margin-top: 16px; display: flex; flex-direction: column; gap: 14px; }
.mform .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fld { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.fld .in, .fld input, .fld select, .fld textarea { font-weight: 400; text-transform: none; letter-spacing: 0; width: 100%; }
.checks { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.ck { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-soft); font-weight: 500; text-transform: none; letter-spacing: 0; }
.mform__err { color: var(--danger); font-size: 13px; min-height: 16px; }
.mform__note { font-size: 14px; color: var(--ink-soft); }
.mform__actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ── Note / task actions ── */
.note__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.note__head .note__meta { margin-bottom: 0; }
.task__actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/* ── Assessments ── */
.asmt { border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 12px; background: var(--paper); }
.asmt:last-child { margin-bottom: 0; }
.asmt__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.asmt__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; margin: 14px 0; }
.asmt__grid .k, .sr .k { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 3px; }
.asmt__actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ── Saved result / answer summary ── */
.sr { margin-top: 12px; }
.sr__private { font-size: 12px; font-weight: 600; color: #6b5a97; background: var(--lav-soft); border: 1px solid var(--lav-line); border-radius: 8px; padding: 8px 12px; margin-bottom: 16px; }
.sr__row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.sr__row:last-child { border-bottom: none; }
.sr__why p { margin: 0 0 8px; font-size: 14px; color: var(--ink-soft); line-height: 1.6; }
.sr__why p:last-child { margin-bottom: 0; }
.rl { margin: 0; padding-left: 20px; }
.rl li { margin: 2px 0; }

/* Clean print for the saved result (hide the app chrome). */
@media print {
  .rail, .topbar, .modal__scrim, .modal__close, .mform__actions, .toast { display: none !important; }
  .modal { position: static; padding: 0; }
  .modal__box { max-width: none; max-height: none; box-shadow: none; padding: 0; }
  body, .app { background: #fff; }
}

/* ── Toast ── */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 13.5px; z-index: 200; }

/* ── Responsive ── */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  /* Wide tables scroll inside their container instead of overflowing the page. */
  .panel { overflow-x: auto; }
  #leadsTable { overflow-x: auto; }
  .tbl--rows { min-width: 640px; }
  .rail { position: fixed; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s ease; z-index: 40; }
  .rail.is-open { transform: none; }
  .app__scrim { display: block; position: fixed; inset: 0; background: rgba(10,10,10,.4); border: none; z-index: 30; }
  .topbar__burger { display: block; }
  .stats { grid-template-columns: 1fr 1fr; }
  .cols { grid-template-columns: 1fr; }
  .ident { grid-template-columns: 1fr 1fr; }
  .mform .two { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .ident { grid-template-columns: 1fr; }
  .view { padding: 22px 16px 50px; }
  .filters { flex-direction: column; }
  #fSearch { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Protection Assessment card: reflection-state chips + expandable detail */
.chip--ai { background:#e8f0fe; color:#1a3d8f; }
.chip--fallback { background:#f3ecd9; color:#6b5a1e; }
.asmt__nextsteps { margin:12px 0; display:flex; flex-direction:column; gap:8px; }
.nextstep { background:#eef7f0; border:1px solid #cfe6d6; border-radius:8px; padding:8px 12px; }
.nextstep > .k { display:inline; font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:.05em; color:#2f7d4f; margin-right:6px; }
.nextstep > b { color:#1f5c39; }
.asmt__more { margin-top:10px; }
.asmt__more > summary { cursor:pointer; font-weight:600; font-size:0.9rem; padding:6px 0; }
.asmt__section { margin:12px 0; }
.asmt__section > .k { display:block; font-size:0.78rem; text-transform:uppercase; letter-spacing:0.04em; opacity:0.6; margin-bottom:4px; }
.asmt__section p { margin:6px 0; line-height:1.55; }
.asmt__section ul { margin:6px 0; padding-left:20px; }

/* Quote Overview workspace (Stage B) */
.qgrid { display:grid; grid-template-columns:repeat(2,1fr); gap:12px 16px; margin:6px 0 12px; }
.qf { display:block; margin:12px 0; }
.qf > .k { display:block; font-size:0.78rem; text-transform:uppercase; letter-spacing:0.04em; color:var(--muted); margin-bottom:5px; }
.qf textarea.in { width:100%; resize:vertical; font-family:var(--sans); }
.chk { display:flex; gap:9px; align-items:flex-start; font-size:0.92rem; color:var(--ink-soft); margin:6px 0; }
.chk input { margin-top:3px; width:16px; height:16px; accent-color:#8a79ba; flex:0 0 auto; }
@media (max-width:640px) { .qgrid { grid-template-columns:1fr; } }

/* Lead primary journey status — one prominent "where this lead is now" summary. */
.journey { display:flex; align-items:baseline; gap:12px; flex-wrap:wrap; margin:0 0 18px; padding:12px 16px; background:var(--lav-soft); border:1px solid var(--lav-line); border-left:4px solid var(--lav); border-radius:12px; }
.journey__k { font-size:0.72rem; letter-spacing:0.06em; text-transform:uppercase; color:var(--muted); }
.journey__v { font-family:var(--serif); font-size:1.15rem; font-weight:600; color:var(--ink); }
.journey--completed, .journey--closed { background:#f3f2f5; border-color:var(--line); border-left-color:var(--muted); }
