:root {
  --bg:#f6f7f9;            /* app background */
  --card:#ffffff;          /* white surface / cards */
  --surface:#f2f4f7;       /* low container — inputs, group heads */
  --surface-2:#eceef1;     /* container — hover, chips */
  --line:#e6e8eb;          /* neutral border */
  --brand:#E73C3E;         /* PANTONE 2034 C */
  --brand-dark:#c81e25;    /* hover / active */
  --brand-tint:#ffdad7;    /* light red — chips, active nav bg */
  --text:#191c1e;
  --muted:#5b5f64;
  --radius-card:16px;
  --radius:10px;
  --radius-pill:9999px;
  --shadow:0 4px 12px rgba(27,31,36,.05);
  --shadow-lift:0 8px 24px rgba(27,31,36,.08);
}
* { box-sizing: border-box; }
body { margin:0; font:14px/1.5 'Inter',-apple-system,Segoe UI,Roboto,sans-serif; background:var(--bg); color:var(--text); }
.view.hidden, .overlay.hidden, .app.hidden, .hidden { display:none; }
.error { color:#c0392b; min-height:1em; }
.empty { color:var(--muted); padding:16px; }
.mono { font-family:'JetBrains Mono',ui-monospace,SFMono-Regular,Menlo,monospace; font-size:13px; }
.strong { font-weight:600; }

.login-card { max-width:340px; margin:12vh auto; background:var(--card); padding:32px; border-radius:var(--radius-card); box-shadow:var(--shadow-lift); display:flex; flex-direction:column; gap:14px; }
.login-card h1 { font-size:20px; font-weight:800; margin:0 0 6px; color:var(--brand); }
.login-card label { display:flex; flex-direction:column; gap:4px; font-size:12px; color:var(--muted); }
.login-card input { padding:10px 12px; border:1px solid var(--line); border-radius:var(--radius); font-size:14px; background:var(--surface); }
.login-card input:focus { outline:none; border-color:var(--brand); box-shadow:0 0 0 3px rgba(231,60,62,.15); }
button, .btn { cursor:pointer; border:none; background:var(--brand); color:#fff; padding:9px 16px; border-radius:var(--radius); font:inherit; font-weight:600; text-decoration:none; display:inline-block; transition:background .15s ease, transform .1s ease; }
button:hover:not(:disabled), .btn:hover { background:var(--brand-dark); }
button:active:not(:disabled), .btn:active { transform:scale(.97); }
button.ghost, .ghost.btn { background:var(--card); color:var(--text); border:1px solid var(--line); }
button.ghost:hover, .ghost.btn:hover { background:var(--surface); }

.topbar { display:flex; justify-content:space-between; align-items:center; gap:16px; padding:0 20px; height:64px; background:var(--card); border-bottom:1px solid var(--line); position:sticky; top:0; z-index:5; }
.controls { display:flex; gap:8px; align-items:center; }
.controls input, .controls select { padding:8px 14px; border:1px solid var(--line); border-radius:var(--radius-pill); font:inherit; font-size:13px; background:var(--surface); color:var(--text); }
.controls input { min-width:220px; }
.controls input:focus, .controls select:focus { outline:none; border-color:var(--brand); box-shadow:0 0 0 3px rgba(231,60,62,.15); }
.controls #dashboard-link { border-radius:var(--radius-pill); padding:8px 16px; }

/* ---- Grid (list view) ---- */
.list { padding:16px; }
.grid-wrap { background:var(--card); border:1px solid var(--line); border-radius:10px; overflow:auto; }
table.grid { width:100%; border-collapse:collapse; font-size:13px; }
table.grid th, table.grid td { text-align:left; padding:10px 14px; border-bottom:1px solid var(--line); white-space:nowrap; }
table.grid thead th { position:sticky; top:0; background:#fafbfc; color:var(--muted); font-weight:600; font-size:12px; text-transform:uppercase; letter-spacing:.02em; z-index:1; }
table.grid tbody tr.grow { cursor:pointer; }
table.grid tbody tr.grow:hover { background:#fdecec; }
.badge { display:inline-block; font-size:11px; padding:2px 8px; border-radius:999px; background:var(--brand-tint); color:var(--brand); }
a.wa { font-size:11px; font-weight:600; color:#16a34a; border:1px solid #bbf7d0; background:#f0fdf4; padding:2px 8px; border-radius:6px; text-decoration:none; }
a.wa:hover { background:#dcfce7; }

/* ---- Centered detail modal ---- */
.overlay { position:fixed; inset:0; background:rgba(17,20,24,.45); display:flex; align-items:center; justify-content:center; padding:24px; z-index:20; }
.modal { position:relative; background:var(--card); width:min(720px,94vw); max-height:88vh; overflow:auto; border-radius:16px; box-shadow:0 18px 60px rgba(0,0,0,.25); padding:32px 36px; }
.modal .close { position:absolute; top:14px; right:16px; background:none; color:var(--muted); font-size:26px; padding:2px 8px; }
.modal h2 { margin:0 0 18px; font-size:22px; }
.modal h3 { margin:22px 0 6px; font-size:14px; color:var(--muted); text-transform:uppercase; letter-spacing:.03em; }

.info-grid { display:grid; grid-template-columns:1fr 1fr; gap:14px 28px; }
.edit-row { margin-top:18px; }
.field { margin:14px 0 0; }
.field label { display:block; font-size:12px; color:var(--muted); margin-bottom:5px; }
.field .val { font-size:15px; }
.field textarea, .field select { width:100%; padding:10px 12px; border:1px solid var(--line); border-radius:8px; font:inherit; }
.row-actions { display:flex; gap:10px; margin-top:20px; }

.calls { width:100%; border-collapse:collapse; margin-top:6px; font-size:13px; }
.calls th, .calls td { text-align:left; border-bottom:1px solid var(--line); padding:6px 8px; }
.calls th { color:var(--muted); font-weight:600; }

@media (max-width:560px){ .info-grid { grid-template-columns:1fr; } .modal { padding:24px 20px; } }

.toast { position:fixed; bottom:18px; left:50%; transform:translateX(-50%); background:#1b1f24; color:#fff; padding:10px 16px; border-radius:8px; opacity:0; transition:opacity .2s; z-index:30; }
.toast.show { opacity:1; }

/* ---- App shell (sidebar + content) ---- */
.app { display:flex; min-height:100vh; }
.sidebar { width:256px; flex:0 0 256px; background:var(--surface); color:var(--muted); display:flex; flex-direction:column; padding:24px 12px; border-right:1px solid var(--line); position:sticky; top:0; height:100vh; align-self:flex-start; overflow-y:auto; }
.sidebar-brand { display:flex; align-items:center; gap:12px; padding:4px 8px 28px; }
.brand-mark { width:40px; height:40px; flex:0 0 40px; background:var(--brand); border-radius:var(--radius); display:flex; align-items:center; justify-content:center; }
.brand-text { display:flex; flex-direction:column; line-height:1.1; }
.brand-name { font-weight:900; font-size:22px; color:var(--brand); }
.brand-sub { font-size:11px; color:var(--muted); opacity:.8; }
.sidebar .nav { list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:4px; flex:1; }
.nav-item { width:100%; text-align:left; background:transparent; color:var(--muted); padding:10px 14px; border-radius:var(--radius); font-size:13px; font-weight:600; transition:background .15s, color .15s; }
.nav-item:hover:not(:disabled) { background:var(--surface-2); color:var(--text); }
.nav-item.active { background:var(--brand-tint); color:var(--brand); box-shadow:inset 3px 0 0 var(--brand); }
.nav-item:disabled { color:#a3a8af; cursor:not-allowed; }
.nav-item .soon { font-size:10px; opacity:.7; margin-left:4px; }
.sidebar-foot { border-top:1px solid var(--line); padding-top:14px; display:flex; flex-direction:column; gap:8px; }
.sidebar-foot .who { font-size:12px; color:var(--muted); padding:0 4px; word-break:break-word; }
#content { flex:1; min-width:0; }
.page-title { font-weight:600; font-size:20px; color:var(--brand); }

/* ---- S2 grouped grid ---- */
.s2-group { margin-bottom:14px; }
.s2-group-head { width:100%; display:flex; align-items:center; gap:8px; background:var(--card); border:1px solid var(--line); border-radius:10px 10px 0 0; color:var(--text); padding:10px 14px; font-weight:600; }
.s2-group-head.collapsed { border-radius:10px; }
.s2-group-head:hover { background:#fdecec; }
.s2-group-head .caret { color:var(--muted); width:14px; }
.s2-group-head .s2-group-label { flex:1; text-align:left; }
.s2-group-head .s2-group-count { font-size:11px; background:var(--brand-tint); color:var(--brand); padding:2px 8px; border-radius:999px; }
.s2-group .grid-wrap { border-radius:0 0 10px 10px; border-top:none; }

/* ---- S2 right-side drawer ---- */
.drawer-backdrop { position:fixed; inset:0; background:rgba(17,20,24,.45); z-index:25; }
.drawer { position:fixed; top:0; right:0; height:100vh; width:min(520px,96vw); background:var(--surface); border-top-left-radius:24px; border-bottom-left-radius:24px; box-shadow:-12px 0 40px rgba(0,0,0,.18); z-index:26; display:flex; flex-direction:column; overflow:hidden; }
.drawer.hidden { display:none; }  /* beat the .drawer display:flex so it stays collapsed until a row is clicked */
.drawer-head { display:flex; align-items:center; justify-content:space-between; padding:18px 20px; border-bottom:1px solid var(--line); background:var(--card); }
.drawer-title { font-weight:600; font-size:15px; }
.drawer .close { background:none; color:var(--muted); font-size:24px; padding:0 6px; }
.drawer .close:hover { background:none; color:var(--brand); }
.drawer-body { overflow:auto; padding:16px; }
.drawer-body h3 { margin:0 0 10px; font-size:12px; font-weight:700; color:var(--muted); text-transform:uppercase; letter-spacing:.06em; }
.s2-fields { display:flex; flex-direction:column; }
.s2-fields .field { margin:10px 0 0; }
/* Two-column layout for the Client/Employment group (paired fields side by side). */
.s2-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px 16px; align-items:start; }
.s2-grid .field { margin:0; }
.s2-grid .field.span2 { grid-column:1 / -1; }
@media (max-width:560px){ .s2-grid { grid-template-columns:1fr; } }
.s2-fields .field label { display:block; font-size:11px; font-weight:600; color:var(--muted); text-transform:uppercase; letter-spacing:.02em; margin-bottom:5px; }
.s2-fields .field input, .s2-fields .field select, .s2-fields .field textarea { width:100%; padding:9px 12px; border:1px solid var(--line); border-radius:var(--radius); font:inherit; background:var(--surface); }
.s2-fields .field input:focus, .s2-fields .field select:focus, .s2-fields .field textarea:focus { outline:none; border-color:var(--brand); box-shadow:0 0 0 3px rgba(231,60,62,.15); }
.s2-fields .field .val { font-size:14px; background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); padding:9px 12px; }
.s2-fields .field .val.muted { background:transparent; border:none; padding:0; }
.s2-fields .val.pre { white-space:pre-wrap; background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); padding:9px 12px; font-size:13px; }
.val.muted, .muted { color:var(--muted); }
.s2-multi { position:relative; }
.s2-multi .chk { display:flex; align-items:center; gap:5px; font-size:13px; font-weight:400; color:var(--text); }
.s2-multi-toggle { display:flex; align-items:center; justify-content:space-between; gap:8px; width:100%; min-height:38px; padding:6px 12px; background:var(--surface); color:var(--text); border:1px solid var(--line); border-radius:var(--radius); font:inherit; font-weight:400; text-align:left; }
.s2-multi-toggle:hover { background:var(--surface-2); border-color:var(--brand); }
.s2-multi-chips { display:flex; flex-wrap:wrap; gap:4px; }
.s2-multi-caret { color:var(--muted); font-size:11px; flex:0 0 auto; }
.s2-multi-menu { position:absolute; z-index:40; top:calc(100% + 4px); left:0; width:min(460px, 86vw); max-height:300px; overflow:auto; background:var(--card); border:1px solid var(--line); border-radius:var(--radius); box-shadow:0 10px 30px rgba(0,0,0,.18); padding:12px 14px; display:grid; grid-template-columns:1fr 1fr; gap:8px 16px; }
/* Beat the generic .s2-fields .field label/input rules (field titles, 100%-width
   inputs) which otherwise stretch the checkbox full-width and clip the bank name. */
.s2-multi-menu label.chk { display:flex; align-items:center; gap:6px; margin:0; font-size:13px; font-weight:400; color:var(--text); text-transform:none; letter-spacing:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.s2-multi-menu .chk input { width:auto; padding:0; margin:0; flex:0 0 auto; }
.s2-multi-menu.hidden { display:none; }

/* ---- S2 attachments ---- */
.att-list { display:flex; flex-direction:column; gap:6px; }
.att-row { display:flex; align-items:center; justify-content:space-between; gap:10px; background:#fafbfc; border:1px solid var(--line); border-radius:8px; padding:7px 11px; }
.att-row a { color:var(--brand); text-decoration:none; word-break:break-all; }
.att-row a:hover { text-decoration:underline; }
.att-del { background:none; color:var(--muted); font-size:14px; padding:0 6px; }
.att-del:hover { color:#c0392b; }
.att-upload { display:block; margin-top:10px; }
.att-upload input[type=file] { font-size:13px; }
.att-upload.is-uploading input[type=file] { opacity:.5; pointer-events:none; }
/* Upload-in-progress indicator (S2 Document Upload) */
.att-uploading { display:flex; align-items:center; gap:8px; margin-top:8px; font-size:13px; font-weight:600; color:var(--brand); }
.att-uploading[hidden] { display:none; }
.att-spinner { width:15px; height:15px; border:2px solid rgba(231,60,62,.25); border-top-color:var(--brand); border-radius:50%; animation:att-spin .7s linear infinite; flex:none; }
@keyframes att-spin { to { transform:rotate(360deg); } }

@media (max-width:640px){ .sidebar { width:160px; flex-basis:160px; } .drawer { width:96vw; } }

/* ---- S3 Record Review: two-pane layout ---- */
.s3-split { display:flex; height:calc(100vh - 64px); }  /* full height under sticky 64px topbar */
.s3-list { width:340px; flex:0 0 340px; overflow:auto; border-right:1px solid var(--line); background:var(--surface); padding:14px; }
.s3-detail { flex:1; min-width:0; overflow:auto; padding:24px; background:var(--surface); }
.s3-detail-inner { max-width:1000px; margin:0 auto; }
.s3-detail .empty { text-align:center; }

/* White rounded "section card" wrapper (Stitch look) on the gray detail bg */
.s3-section { background:var(--card); border:1px solid var(--line); border-radius:var(--radius-card); padding:20px 22px; box-shadow:var(--shadow); margin-bottom:16px; }
.s3-section h3 { border-top:none !important; padding-top:0 !important; margin-top:0 !important; }

/* Left list groups (mirror S2 group style) */
.s3-group { margin-bottom:12px; }
.s3-group-head { width:100%; display:flex; align-items:center; gap:8px; background:var(--card); border:1px solid var(--line); border-radius:10px; color:var(--text); padding:9px 12px; font-weight:600; }
.s3-group-head:hover { background:#fdecec; }
.s3-group-head .caret { color:var(--muted); width:14px; }
.s3-group-head .s3-group-label { flex:1; text-align:left; font-size:13px; }
.s3-group-head .s3-group-count { font-size:11px; background:var(--brand-tint); color:var(--brand); padding:2px 8px; border-radius:999px; }
.s3-group-items { margin-top:6px; display:flex; flex-direction:column; gap:6px; }
.s3-group-items.hidden { display:none; }

/* Record-review card in the left list */
.s3-card { display:flex; gap:10px; background:var(--card); color:var(--text); border:1px solid var(--line); border-radius:12px; padding:10px; cursor:pointer; text-align:left; box-shadow:var(--shadow); transition:box-shadow .15s, transform .1s; }
.s3-card .s3-card-title { color:var(--text); }
.s3-card:hover { box-shadow:var(--shadow-lift); }
.s3-card.active { border-color:var(--brand); box-shadow:0 0 0 2px var(--brand); }
.s3-thumb { width:48px; height:48px; flex:0 0 48px; border-radius:8px; object-fit:cover; background:var(--brand-tint); border:1px solid var(--line); }
.s3-thumb-ph { width:48px; height:48px; flex:0 0 48px; border-radius:8px; background:var(--brand-tint); border:1px solid var(--line); display:flex; align-items:center; justify-content:center; color:var(--muted); font-size:18px; }
.s3-card-body { min-width:0; flex:1; }
.s3-card-title { font-weight:600; font-size:13px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.s3-card-sub { font-size:12px; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

/* Detail pane content */
.s3-detail-inner h2 { font-size:20px; margin:0 0 16px; }
/* Top row: Document hero (left) + TEXT TO CLIENT (right) */
.s3-top { display:grid; grid-template-columns:280px minmax(0,1fr); gap:20px; align-items:start; }
.s3-top label { display:block; font-size:12px; color:var(--muted); margin-bottom:6px; }
.s3-hero { display:flex; flex-direction:column; gap:8px; }
.s3-hero-img { display:block; }
.s3-hero-img img { width:100%; max-height:340px; object-fit:contain; background:#fafbfc; border:1px solid var(--line); border-radius:10px; }
.s3-hero-file { display:inline-block; color:var(--brand); text-decoration:none; background:#fafbfc; border:1px solid var(--line); border-radius:8px; padding:8px 12px; word-break:break-all; }
.s3-hero-file:hover { text-decoration:underline; }
@media (max-width:680px){ .s3-top { grid-template-columns:1fr; } }
.s3-detail-inner h3 { margin:24px 0 12px; font-size:12px; font-weight:700; color:var(--muted); text-transform:uppercase; letter-spacing:.06em; border-top:1px solid var(--line); padding-top:16px; }
.s3-detail-inner .field { margin:12px 0 0; }
.s3-detail-inner .field label { display:block; font-size:11px; font-weight:600; color:var(--muted); text-transform:uppercase; letter-spacing:.02em; margin-bottom:5px; }
/* Boxed read-only values (Stitch trait): soft surface box for short read-only fields */
.s3-detail-inner .field .val { font-size:14px; background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); padding:9px 12px; min-height:38px; }
.s3-detail-inner .field .val.muted { background:transparent; border:none; padding:0; min-height:0; }
/* A boxed value that instead holds a colored status chip — drop the box so the chip shows cleanly */
.field .val.val-chip { background:transparent; border:none; padding:0; min-height:0; }
.s3-detail-inner .field .val.pre { white-space:pre-wrap; background:#fafbfc; border:1px solid var(--line); border-radius:8px; padding:9px 11px; font-size:13px; }
/* TEXT TO CLIENT sits in .s3-top-text (not a .field), so give its pre box the same
   wrapping + box treatment, otherwise newlines collapse and the text is squished. */
.s3-top-text .val.pre { white-space:pre-wrap; line-height:1.55; background:#fafbfc; border:1px solid var(--line); border-radius:8px; padding:11px 13px; font-size:13px; }
.s3-detail-inner .field select, .s3-detail-inner .field textarea { width:100%; padding:9px 11px; border:1px solid var(--line); border-radius:8px; font:inherit; }
.s3-fields { display:flex; flex-direction:column; }

/* 3-column layout (COMPANY REMARK group); a .span3 cell takes the whole row. */
.s3-grid3 { display:grid; grid-template-columns:repeat(3, minmax(0,1fr)); gap:14px 16px; align-items:start; }
.s3-grid3 .field { margin:0; }
.s3-grid3 .field.span3 { grid-column:1 / -1; }
.s3-grid3 .field.span3 .val.pre.big { min-height:140px; }
@media (max-width:680px){ .s3-grid3 { grid-template-columns:1fr; } }

/* Bank remark 3-per-row grid */
.s3-bank-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:12px; margin-top:8px; }
.s3-bank-card { background:var(--surface); border:1px solid var(--line); border-radius:12px; padding:12px; transition:border-color .15s; }
.s3-bank-card:hover { border-color:var(--brand); }
.s3-bank-card .bk-no { font-weight:700; font-size:11px; letter-spacing:.04em; text-transform:uppercase; color:var(--muted); margin-bottom:6px; }
.s3-bank-card .bk-line { font-size:12px; margin-top:4px; }
.s3-bank-card .bk-line .lab { color:var(--muted); }
.s3-bank-card .bk-line .pre { white-space:pre-wrap; }

@media (max-width:900px){ .s3-bank-grid { grid-template-columns:repeat(2,1fr); } }
@media (max-width:640px){ .s3-split { flex-direction:column; height:auto; } .s3-list { width:auto; flex-basis:auto; border-right:none; border-bottom:1px solid var(--line); } .s3-bank-grid { grid-template-columns:1fr; } }
