:root {
  --bg: #f5f4f0;
  --panel: #ffffff;
  --ink: #1f2328;
  --ink-2: #57606a;
  --ink-3: #8b949e;
  --line: #e3e1da;
  --line-2: #d0cec6;
  --accent: #1d4e89;
  --accent-ink: #ffffff;
  --accent-soft: #e8eef7;
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --q-bg: #faf9f6;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 8px rgba(0, 0, 0, 0.04);
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 650; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.env-banner { background: #ffd33d; color: #3d2e00; text-align: center; font-size: 13px; font-weight: 650; padding: 6px 12px; }

/* ---------- top bar */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; gap: 16px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: 9px; }
.brand-logo { width: 28px; height: 28px; display: block; }
.brand-accent { color: var(--accent); }
.client-topbar { position: static; }
.spacer { flex: 1; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 24px; }
.narrow { max-width: 720px; }

/* ---------- controls */
button, .btn {
  font: inherit; font-size: 14px; font-weight: 550;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--ink);
  border-radius: 6px; padding: 7px 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
button:hover, .btn:hover { background: #f3f2ee; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover, .btn.primary:hover { background: #163d6c; }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.ok:hover { background: #136129; }
button.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
button.ghost:hover { background: #ecebe6; color: var(--ink); }
button.danger { color: var(--bad); }
button.sm { padding: 4px 10px; font-size: 13px; }
button.xs, .btn.xs { padding: 2px 8px; font-size: 12px; font-weight: 500; }

input[type=text], input[type=password], input[type=search], textarea, select {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line-2); border-radius: 6px; padding: 8px 10px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
label.field { display: block; font-size: 13px; font-weight: 550; color: var(--ink-2); }
label.field > input, label.field > textarea { margin-top: 4px; font-weight: 400; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap;
  background: #efeee9; color: var(--ink-2);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.progress { height: 6px; background: #ebe9e3; border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); transition: width 0.3s; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px;
  z-index: 100; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.toast.err { background: var(--bad); }

/* ---------- login */
.login { max-width: 380px; margin: 12vh auto; }
.login h1 { margin-bottom: 4px; }

/* ---------- dashboard */
.dash-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.matter-list { display: grid; gap: 10px; }
.matter-row {
  display: grid; grid-template-columns: 1fr 220px 140px; gap: 20px; align-items: center;
  padding: 16px 20px; text-decoration: none; color: inherit;
}
.matter-row:hover { border-color: var(--line-2); background: #fdfdfb; }
.matter-row .title { font-weight: 600; }
.empty { text-align: center; padding: 60px 20px; color: var(--ink-2); }

/* ---------- matter page */
.matter-head { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.matter-head .meta { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.matter-head .meta b { color: var(--ink); font-weight: 550; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab {
  border: none; background: none; border-radius: 0; padding: 10px 14px; font-weight: 550; color: var(--ink-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { background: none; color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count { font-size: 12px; background: #ebe9e3; color: var(--ink-2); border-radius: 999px; padding: 0 7px; margin-left: 4px; }
.tab .count.bad { background: var(--bad); color: #fff; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { max-width: 260px; }

.share-box { padding: 16px 20px; margin-bottom: 18px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.share-box code { background: var(--q-bg); border: 1px solid var(--line); border-radius: 5px; padding: 6px 10px; font-size: 13px; flex: 1; min-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* import */
.dropzone {
  border: 2px dashed var(--line-2); border-radius: var(--radius); padding: 40px 20px; text-align: center;
  background: var(--panel); cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-size: 17px; font-weight: 600; margin-bottom: 4px; }

/* requisition rows (shared) */
.reqs { display: grid; gap: 10px; }
.req {
  display: grid; grid-template-columns: 64px 1fr 1fr; gap: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.req > .num { padding: 14px 0 14px 16px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.req > .q { padding: 14px 18px; background: var(--q-bg); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.req > .r { padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.req .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; color: var(--ink-3); margin-bottom: 4px; }
.req .text { font-family: var(--serif); font-size: 15.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.req .text.empty-reply { font-family: var(--sans); font-style: italic; color: var(--ink-3); font-size: 14px; }
.req textarea.reply { font-family: var(--serif); font-size: 15.5px; min-height: 90px; }
.req.st-approved { border-left: 3px solid var(--ok); }
.req.st-query { border-left: 3px solid var(--bad); }
.req.st-changed { border-left: 3px solid var(--warn); }
.req-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.req-foot .saved { font-size: 12px; color: var(--ink-3); }
.req.heading { display: block; background: transparent; border: none; padding: 14px 4px 2px; }
.req.heading .h { font-weight: 700; font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); }
.req.heading .h.stem { text-transform: none; letter-spacing: 0; font-family: var(--serif); font-size: 15.5px; font-weight: 600; color: var(--ink); padding-top: 4px; white-space: pre-wrap; }

.thread { display: grid; gap: 6px; }
.cmt { font-size: 14px; padding: 8px 11px; border-radius: 7px; background: #f3f2ee; }
.cmt.client { background: var(--warn-soft); }
.cmt.solicitor { background: var(--accent-soft); }
.cmt.system { background: transparent; padding: 0 2px; color: var(--ink-3); font-size: 12.5px; font-style: italic; }
.cmt .who { font-weight: 600; font-size: 12px; color: var(--ink-2); }
.cmt .who span { font-weight: 400; color: var(--ink-3); margin-left: 6px; }
.cmt .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.reply-box { display: grid; gap: 6px; }
.reply-box textarea { min-height: 60px; font-size: 14px; }
.prev-approved { font-size: 13px; background: var(--warn-soft); border-radius: 6px; padding: 8px 10px; }
.prev-approved .text { font-size: 14px; }

/* question editor */
.qedit { display: grid; grid-template-columns: 90px 1fr auto; gap: 10px; align-items: start; padding: 10px 12px; }
.qedit.is-heading { background: #f1f0eb; }
.qedit.is-heading textarea { font-weight: 650; }
.qedit textarea { font-family: var(--serif); font-size: 15px; min-height: 44px; }
.qedit .num-in { font-weight: 700; text-align: center; }
.qedit .acts { display: flex; flex-direction: column; gap: 3px; }
.qedit-list { display: grid; gap: 6px; }
.notice { padding: 12px 16px; border-radius: 8px; background: var(--accent-soft); color: #123a66; font-size: 14px; margin-bottom: 14px; }
.notice.warn { background: var(--warn-soft); color: #6b4a00; }

/* ---------- client page */
.client-hero { padding: 22px 24px; margin-bottom: 16px; }
.client-hero h1 { font-family: var(--serif); font-weight: 600; font-size: 24px; }
.client-hero .msg { margin-top: 12px; white-space: pre-wrap; }
.how { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13.5px; color: var(--ink-2); margin-top: 14px; }
.how span b { color: var(--ink); }
.sticky-progress {
  position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 10px 0 12px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.sticky-progress .progress { flex: 1; min-width: 120px; }
.approved-note { font-size: 13px; color: var(--ok); font-weight: 550; display: inline-flex; align-items: center; gap: 6px; }

.modal-back { position: fixed; inset: 0; background: rgba(20, 20, 20, 0.35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { max-width: 440px; width: 100%; }

@media (max-width: 860px) {
  .wrap, .topbar-inner { padding-left: 16px; padding-right: 16px; }
  .req { grid-template-columns: 1fr; }
  .req > .num { padding: 12px 16px 0; }
  .req > .q { border: none; background: transparent; padding-top: 4px; }
  .req > .r { border-top: 1px solid var(--line); background: #fff; }
  .matter-row { grid-template-columns: 1fr; gap: 8px; }
  .grid2 { grid-template-columns: 1fr; }
  .qedit { grid-template-columns: 1fr; }
  .qedit .acts { flex-direction: row; flex-wrap: wrap; }
}

@media print {
  .topbar, .toolbar, .tabs, .share-box, button, .reply-box, .sticky-progress { display: none !important; }
  body { background: #fff; }
  .req { break-inside: avoid; box-shadow: none; }
}

/* ---------- accounts, firms and two-sided matters */
.topbar-firm { font-weight: 600; text-decoration: none; }
.topbar-user { margin-right: 4px; }
#topbar-right { display: flex; align-items: center; gap: 12px; }
input[type=email] { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line-2); border-radius: 6px; padding: 8px 10px; width: 100%; }
label.field > input:disabled { background: var(--q-bg); color: var(--ink-2); }
.members { display: grid; gap: 6px; margin-top: 10px; }
.member { display: flex; gap: 12px; flex-wrap: wrap; padding: 8px 0; border-top: 1px solid var(--line); }
.side-choice { display: block; text-align: left; white-space: normal; padding: 16px 18px; border-radius: var(--radius); background: var(--panel); }
.side-choice .title { font-weight: 650; font-size: 16px; margin-bottom: 4px; }
.side-choice.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.side-tag { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 1px 7px; border-radius: 4px; }
.side-tag.purchaser { background: #efe7fb; color: #5b2a9c; }
.side-tag.vendor { background: #e3f1ef; color: #0e5c52; }
.other-side { background: var(--q-bg); }
.release-box { padding: 16px 20px; margin-bottom: 14px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; border-left: 3px solid var(--accent); }
.qedit.locked { grid-template-columns: 90px 1fr auto; background: var(--q-bg); }
.qedit.locked .text { font-family: var(--serif); font-size: 15px; white-space: pre-wrap; padding: 6px 0; }
.qedit.locked.is-heading .text { font-weight: 650; }
.qedit .num-static { font-weight: 700; text-align: center; padding-top: 6px; color: var(--ink-2); }
.qedit.draft { border-left: 3px solid var(--warn); }

/* Export: one label with Word and PDF buttons joined together */
.export-group { display: inline-flex; align-items: center; gap: 0; }
.export-group .export-label { font-size: 13px; color: var(--ink-2); margin-right: 8px; white-space: nowrap; }
.export-group .btn { border-radius: 0; }
.export-group .btn:first-of-type { border-radius: 6px 0 0 6px; }
.export-group .btn:last-of-type { border-radius: 0 6px 6px 0; margin-left: -1px; }
.release-box.done { border-left-color: var(--ok); background: var(--ok-soft); }

/* Read-only replies page for the purchaser's solicitors */
.share-head { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: flex-start; margin-bottom: 18px; }
.share-head-main { flex: 1; min-width: 260px; }
.share-details { flex-basis: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 20px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 14px; }
.share-details > div { display: flex; flex-direction: column; gap: 1px; }
.share-details .muted { font-size: 12px; }
.share-promo { display: flex; gap: 14px; align-items: center; padding: 16px 20px; margin: 26px 0 40px; text-decoration: none; color: var(--ink); }
.share-promo:hover { border-color: var(--line-2); }
/* Read-only links list on the matter screen */
.share-links { display: grid; gap: 6px; margin-top: 12px; flex-basis: 100%; }
.share-link { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; padding: 8px 0; border-top: 1px solid var(--line); }
.share-link.off { opacity: .55; }
.share-link code { background: var(--q-bg); border: 1px solid var(--line); border-radius: 5px; padding: 3px 8px; font-size: 12px; flex: 1; min-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Firm logo */
.logo-preview { border: 1px solid var(--line); border-radius: 6px; padding: 16px; background: #fff; display: flex; align-items: center; min-height: 80px; }
.logo-preview img { max-height: 68px; max-width: 260px; display: block; }
.logo-preview.empty { color: var(--ink-3); font-size: 13px; justify-content: center; background: var(--q-bg); border-style: dashed; }
.share-head .firm-logo { display: block; max-height: 56px; max-width: 240px; margin-bottom: 14px; }
