/* ═══════════════════════════════════════════════════════════════════
   MARCHETTI & ASSOCIATES LLP · Client Portal
   Identity: "the engraved letterhead."
   Iron-gall ink chrome (sidebar · gate · mobile nav) around an ivory
   bond workspace · claret working ink · brass for matters awaiting,
   bay green for the settled. Marcellus (engraver's Roman — the
   letterhead face) · Albert Sans (UI) · DM Mono (docket metadata:
   MAT numbers, statuses, dates, amounts).
   Signature devices: the scotch rule (engraved double hairline),
   the ampersand seal, and the ink/bond chrome split.
   Distinct from Docket (court-form grey/oxblood pleading paper) and
   Countersign (kraft desk) — this is the stationery the CLIENT holds.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;

  /* ink chrome */
  --ink: #251419;
  --ink-deep: #180D11;
  --ink-raise: #37242C;
  --ink-line: rgba(240, 233, 218, 0.14);
  --bone: #F0E9DA;
  --bone-dim: #B3A496;

  /* the bond */
  --bond: #F2EDE1;
  --sheet: #FCFAF4;
  --sheet-2: #F5F0E4;
  --flax: #EDE5D2;
  --rule: #DFD7C4;
  --rule-2: #EAE4D5;
  --edge: #CDC4AD;          /* form + ghost-button borders */

  /* printed matter */
  --print: #2A2019;
  --umber: #70675A;

  /* counsel ink */
  --claret: #6B2231;
  --claret-deep: #4F1723;
  --claret-wash: #F3E5E3;
  --claret-ring: rgba(107, 34, 49, 0.18);

  /* marks */
  --brass: #8A6931;         /* awaiting / pending */
  --bay: #3F6549;           /* settled / closed / paid */
  --danger: #A63A24;        /* referenced from app.js */

  /* type */
  --font-display: Marcellus, "Iowan Old Style", Georgia, serif;
  --font-sans: "Albert Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "DM Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* rhythm */
  --radius-s: 4px;
  --radius-m: 10px;
  --radius-l: 12px;
  --speed: 150ms;
  --col: 1120px;            /* content column */

  /* the scotch rule — thick over thin, like engraved stationery */
  --scotch: linear-gradient(var(--rule), var(--rule)) 0 calc(100% - 3px) / 100% 2px no-repeat,
            linear-gradient(var(--rule), var(--rule)) 0 100% / 100% 1px no-repeat;
  --scotch-claret: linear-gradient(var(--claret), var(--claret)) 0 0 / 100% 2px no-repeat,
                   linear-gradient(var(--claret), var(--claret)) 0 4px / 100% 1px no-repeat;
}

/* ---------- base ---------- */

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bond); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    repeating-linear-gradient(0deg, rgba(42, 32, 25, 0.02) 0 1px, transparent 1px 5px),
    var(--bond);
  color: var(--print);
  font: 400 15px/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: var(--font-mono); }
::selection { background: var(--claret-wash); }
:focus-visible { outline: 2px solid var(--claret); outline-offset: 2px; }
.hidden { display: none !important; }
/* the attribute form must always win — a layout rule that sets display on a
   section would otherwise defeat the hidden attribute (see DEVELOPMENT.md) */
[hidden] { display: none !important; }

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- the firm's marks ---------- */

.brand-seal {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-s);
  background: var(--claret);
  color: var(--bone);
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1;
  padding-bottom: 3px;
}
.brand-lockup { display: grid; gap: 3px; min-width: 0; }
.brand-name {
  font-family: var(--font-display);
  font-size: 13px;
  line-height: 1.3;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  white-space: nowrap;
}
.brand-llp { letter-spacing: 0.08em; opacity: 0.62; }
.brand-sub {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--umber);
}

/* ---------- buttons ---------- */

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  border: 1px solid var(--edge);
  border-radius: var(--radius-s);
  background: var(--sheet);
  color: var(--print);
  font-size: 14px;
  font-weight: 600;
  transition: background var(--speed) ease, border-color var(--speed) ease, color var(--speed) ease;
}
.button:hover { border-color: var(--claret); color: var(--claret); background: var(--sheet); }
.button:active { transform: translateY(1px); }
.button.primary { border-color: var(--claret); background: var(--claret); color: var(--bone); }
.button.primary:hover { border-color: var(--claret-deep); background: var(--claret-deep); color: var(--bone); }
.button.full { width: 100%; }
.button:disabled { opacity: 0.55; cursor: progress; transform: none; }

.link-button {
  border: 0;
  padding: 0;
  background: none;
  color: var(--claret);
  font-weight: 600;
}
.link-button:hover { text-decoration: underline; }

.icon-button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--umber);
  font-size: 16px;
  transition: background var(--speed) ease, color var(--speed) ease;
}
.icon-button:hover { background: var(--sheet-2); color: var(--print); }

/* ---------- forms ---------- */

.form-stack { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--umber);
}
.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--edge);
  border-radius: var(--radius-s);
  background: var(--sheet);
  color: var(--print);
  font-size: 14px;
  transition: border-color var(--speed) ease, box-shadow var(--speed) ease;
}
.field input { height: 42px; padding: 0 12px; }
.field textarea { min-height: 132px; padding: 10px 12px; line-height: 1.55; resize: vertical; }
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--claret);
  box-shadow: 0 0 0 3px var(--claret-ring);
}
.field input::placeholder,
.field textarea::placeholder { color: #A79D8C; }
.form-error {
  margin: 0;
  min-height: 18px;
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.45;
}

/* ---------- the gate: dark chambers, engraved letterhead ---------- */

.auth-view {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px 20px;
  background:
    radial-gradient(90rem 50rem at 50% -14rem, rgba(107, 34, 49, 0.22), transparent 62%),
    repeating-linear-gradient(90deg, rgba(240, 233, 218, 0.016) 0 1px, transparent 1px 6px),
    var(--ink-deep);
}
.auth-panel {
  width: min(100%, 432px);
  background: var(--sheet);
  border: 1px solid rgba(24, 13, 17, 0.6);
  border-radius: var(--radius-m);
  padding: 34px 34px 28px;
  box-shadow: 0 1px 0 rgba(240, 233, 218, 0.07), 0 34px 90px -18px rgba(0, 0, 0, 0.65);
}
.auth-brand {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding-bottom: 20px;
  background: var(--scotch);
  color: var(--print);
  text-decoration: none;
}
.auth-brand .brand-lockup { justify-items: center; gap: 6px; }
.auth-brand .brand-name { font-size: 15px; white-space: normal; text-align: center; }
.auth-heading { margin: 22px 0 20px; text-align: center; }
.auth-heading h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  letter-spacing: 0.01em;
}
.auth-heading p { margin: 8px 0 0; color: var(--umber); font-size: 14px; }

.demo-login {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-s);
  background: var(--sheet-2);
}
.demo-login > div { display: grid; gap: 3px; min-width: 0; }
.demo-login strong {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
}
.demo-login code { font-size: 12px; color: var(--print); overflow-wrap: anywhere; }
.demo-login .button { min-height: 34px; padding: 0 12px; font-size: 12.5px; flex: 0 0 auto; }

.auth-switch { margin: 20px 0 0; text-align: center; color: var(--umber); font-size: 13px; }
.security-note {
  margin: 24px 0 0;
  text-align: center;
  color: var(--umber);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ---------- app shell: ink chrome, bond workspace ---------- */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  padding: 0 14px;
  background:
    repeating-linear-gradient(90deg, rgba(240, 233, 218, 0.015) 0 1px, transparent 1px 6px),
    linear-gradient(var(--ink), var(--ink-deep));
  color: var(--bone);
  overflow-y: auto;
}
.sidebar :focus-visible { outline-color: var(--bone); }
.side-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 8px 20px;
  color: var(--bone);
  text-decoration: none;
}
.side-brand .brand-name { font-size: 12px; white-space: normal; }
.side-brand .brand-sub { color: var(--bone-dim); }
.side-nav {
  display: grid;
  gap: 2px;
  padding: 16px 0;
  border-top: 1px solid var(--ink-line);
}
.nav-item {
  height: 38px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--bone-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  text-align: left;
  transition: background var(--speed) ease, color var(--speed) ease, box-shadow var(--speed) ease;
}
.nav-item:hover { background: var(--ink-raise); color: var(--bone); }
.nav-item.active { color: var(--bone); background: var(--ink-raise); box-shadow: inset 2px 0 0 var(--claret), inset 3px 0 0 rgba(240, 233, 218, 0.25); }

.account-block {
  margin-top: auto;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 10px;
  padding: 16px 8px 22px;
  border-top: 1px solid var(--ink-line);
}
.avatar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--ink-line);
  background: var(--ink-raise);
  color: var(--bone-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.account-copy { display: grid; gap: 2px; min-width: 0; }
.account-copy strong,
.account-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { font-size: 12.5px; font-weight: 600; color: var(--bone); }
.account-copy span { font-family: var(--font-mono); font-size: 10px; color: var(--bone-dim); }
.account-block .icon-button { color: var(--bone-dim); }
.account-block .icon-button:hover { background: var(--ink-raise); color: var(--bone); }

/* ---------- workspace ---------- */

.workspace { min-width: 0; padding: 0 clamp(20px, 4vw, 56px) 80px; }

.topbar {
  max-width: var(--col);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 42px 0 26px;
}
.topbar h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(26px, 2.4vw, 31px);
  font-weight: 400;
  letter-spacing: 0.005em;
}
.topbar p { margin: 7px 0 0; color: var(--umber); font-size: 14px; }
.mobile-brand { display: none; }

/* ---------- the dossier surface ---------- */

.matter-layout {
  max-width: var(--col);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(264px, 300px) minmax(0, 1fr);
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(42, 32, 25, 0.04), 0 14px 34px -22px rgba(42, 32, 25, 0.22);
}

/* ledger: matter list */

.matter-list-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--rule);
  background: var(--sheet);
}
.section-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 12px;
  background: var(--scotch);
}
.section-label-row h2 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--umber);
}
.count { font-family: var(--font-mono); font-size: 11px; font-weight: 500; color: var(--claret); }

.matter-list { display: flex; flex-direction: column; }
.matter-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  width: 100%;
  padding: 15px 18px 15px 20px;
  border: 0;
  background: transparent;
  text-align: left;
  transition: background var(--speed) ease, box-shadow var(--speed) ease;
}
.matter-row + .matter-row { border-top: 1px solid var(--rule-2); }
.matter-row:last-child { border-bottom: 1px solid var(--rule-2); }
.matter-row:hover { background: var(--sheet-2); box-shadow: inset 2px 0 0 var(--claret); }
.matter-row:focus-visible { outline-offset: -2px; }
.matter-row.active { background: var(--sheet-2); box-shadow: inset 2px 0 0 var(--claret); }
.matter-row.active strong { color: var(--claret); }

/* one status → one dot color, shared by ledger rows and detail chip */
.matter-row,
.status { --dot: #A99F8D; }
.status-intake,
.status-pending,
.status-review,
.status-in_review,
.status-awaiting_documents,
.status-awaiting_signature,
.status-on_hold { --dot: var(--brass); }
.status-open,
.status-active,
.status-in_progress,
.status-filed { --dot: var(--claret); }
.status-closed,
.status-complete,
.status-completed,
.status-resolved,
.status-done { --dot: var(--bay); }

.row-dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--dot); }

.row-main { min-width: 0; }
.matter-row strong {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  margin-top: 4px;
}
.matter-row small {
  flex: 0 1 auto;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--umber);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-status {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--umber);
  white-space: nowrap;
  text-align: right;
}

.list-empty { padding: 36px 24px; text-align: center; }
.list-empty strong { display: block; font-family: var(--font-display); font-size: 16px; font-weight: 400; }
.list-empty p { margin: 6px 0 18px; color: var(--umber); font-size: 12.5px; line-height: 1.55; }

/* ---------- matter detail ---------- */

.matter-detail { min-width: 0; padding: 32px 44px 48px; }

.empty-detail {
  min-height: 460px;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  padding: 48px 16px;
}
.empty-icon { font-family: var(--font-display); font-size: 30px; line-height: 1; color: var(--claret); }
.empty-detail h2 { margin: 14px 0 0; font-family: var(--font-display); font-size: 23px; font-weight: 400; }
.empty-detail p { max-width: 40ch; margin: 8px 0 22px; color: var(--umber); font-size: 14px; line-height: 1.6; }

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.detail-title-line { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.detail-title-line h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  letter-spacing: 0.005em;
  overflow-wrap: anywhere;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--umber);
  white-space: nowrap;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dot); }
.matter-number {
  margin: 7px 0 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--claret);
}

.detail-meta { display: flex; gap: 32px; margin: 0; text-align: right; }
.detail-meta > div { display: grid; gap: 4px; }
.detail-meta dt {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--umber);
}
.detail-meta dd { margin: 0; font-family: var(--font-mono); font-size: 12px; color: var(--print); }

.detail-tabs { display: flex; gap: 26px; margin-top: 28px; border-bottom: 1px solid var(--rule); }
.detail-tabs button {
  padding: 0 2px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  color: var(--umber);
  font-size: 13px;
  font-weight: 600;
  transition: color var(--speed) ease, border-color var(--speed) ease;
}
.detail-tabs button:hover { color: var(--print); }
.detail-tabs button.active { color: var(--print); border-bottom-color: var(--claret); }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 36px 44px;
  padding-top: 28px;
}
.timeline-panel h3,
.details-panel h3,
.messages-panel h3 {
  margin: 0 0 20px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--umber);
}
.details-panel { border-left: 1px solid var(--rule); padding-left: 44px; }

/* timeline */

.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li {
  position: relative;
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 14px;
  padding-bottom: 28px;
}
.timeline li:last-child { padding-bottom: 4px; }
.timeline li:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 22px;
  bottom: 2px;
  border-left: 1px solid var(--rule);
}
.timeline li > span {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  display: grid;
  place-items: center;
  border: 2px solid var(--rule);
  border-radius: 50%;
  background: var(--sheet);
  z-index: 1;
}
.timeline strong { display: block; font-size: 13px; font-weight: 600; }
.timeline small {
  display: block;
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--umber);
}
.timeline p { margin: 6px 0 0; color: var(--umber); font-size: 12.5px; line-height: 1.5; }

/* real update entries from counsel — every entry is a recorded event */
.timeline li.event > span { border-color: var(--claret); background: var(--claret); }
.timeline li.event > span::after { content: "✓"; color: var(--bone); font-size: 9px; font-weight: 700; line-height: 1; }
.timeline li.event small { margin-top: 1px; }
.timeline li.event p { margin-top: 5px; color: var(--print); font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
.timeline li.loading > span { border-style: dashed; border-color: var(--edge); }
.timeline-note { margin: 0; color: var(--umber); font-size: 12.5px; line-height: 1.55; }

/* skeleton entries — the ledger being inked in */
.timeline li.skel > span { border-style: dashed; border-color: var(--edge); }
.timeline li.skel small,
.timeline li.skel p {
  display: block;
  height: 10px;
  margin: 3px 0 0;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--flax) 30%, var(--sheet-2) 50%, var(--flax) 70%);
  background-size: 200% 100%;
  animation: inking 1.4s linear infinite;
}
.timeline li.skel small { width: 52%; max-width: 180px; }
.timeline li.skel p { height: 12px; width: 88%; margin-top: 8px; }
.timeline li.skel + li.skel small { width: 40%; }
.timeline li.skel + li.skel p { width: 72%; }
@keyframes inking { to { background-position: -200% 0; } }

/* edit form */

.save-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.save-state {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--bay);
}

/* messages ledger — the detail panel quotes the live thread's tail */

.messages-panel { grid-column: 1 / -1; border-top: 1px solid var(--rule); padding-top: 26px; }
.messages-panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.messages-panel-head h3 { margin-bottom: 0; }
.messages-panel-head .link-button { font-size: 12.5px; white-space: nowrap; }
.message-empty { display: flex; align-items: center; gap: 14px; }
.message-dot { flex: 0 0 auto; width: 12px; height: 12px; border: 2px dashed var(--edge); border-radius: 50%; }
.message-empty strong { display: block; font-size: 13.5px; font-weight: 600; }
.message-empty p { margin: 3px 0 0; color: var(--umber); font-size: 12.5px; }

.thread-tail { margin-top: 20px; display: grid; gap: 16px; }
.tail-msg { display: grid; gap: 4px; padding-left: 14px; border-left: 2px solid var(--claret); }
.tail-msg.from-you { border-left-color: var(--edge); }
.tail-msg-meta { display: flex; align-items: baseline; gap: 10px; }
.tail-msg-meta strong { font-size: 12.5px; font-weight: 600; }
.tail-msg:not(.from-you) .tail-msg-meta strong { color: var(--claret); }
.tail-msg-meta time { font-family: var(--font-mono); font-size: 10.5px; color: var(--umber); }
.tail-msg p { margin: 0; color: var(--umber); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }

/* ---------- shared pane furniture (messages + documents) ---------- */

.pane-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 28px 14px;
  background: var(--scotch);
}
.pane-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 400;
  overflow-wrap: anywhere;
}
.pane-sub { margin: 5px 0 0; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.02em; color: var(--umber); }

.pane-empty { margin: auto; padding: 40px 24px; text-align: center; }
.pane-empty .empty-icon { font-size: 26px; }
.pane-empty strong { display: block; margin-top: 12px; font-family: var(--font-display); font-size: 17px; font-weight: 400; }
.pane-empty p { max-width: 42ch; margin: 6px auto 0; color: var(--umber); font-size: 13px; line-height: 1.55; }
.pane-empty .button { margin-top: 18px; }
/* the lone loading line (billing) speaks in the metadata voice */
.pane-empty > p:only-child {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* ---------- messages thread ---------- */

.thread-pane { min-width: 0; display: flex; flex-direction: column; min-height: 560px; }
.thread-scroll {
  flex: 1;
  min-height: 0;
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px 28px;
}
/* while the conversation loads, ghost bubbles hold the floor */
.thread-scroll:empty::before,
.thread-scroll:empty::after {
  content: "";
  flex: 0 0 auto;
  height: 54px;
  border-radius: var(--radius-s);
  background: linear-gradient(90deg, var(--flax) 30%, var(--sheet-2) 50%, var(--flax) 70%);
  background-size: 200% 100%;
  animation: inking 1.4s linear infinite;
}
.thread-scroll:empty::before { width: min(58%, 380px); align-self: flex-start; border-left: 3px solid var(--rule); }
.thread-scroll:empty::after { width: min(46%, 320px); align-self: flex-end; }

.msg { max-width: min(76%, 520px); display: grid; gap: 5px; }
.msg.from-you { margin-left: auto; }
.msg-meta { display: flex; align-items: baseline; gap: 10px; }
.msg.from-you .msg-meta { justify-content: flex-end; }
.msg-meta strong { font-size: 11.5px; font-weight: 600; }
.msg.from-counsel .msg-meta strong { color: var(--claret); }
.msg-meta time { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.02em; color: var(--umber); }
.msg-bubble {
  margin: 0;
  padding: 10px 14px;
  color: var(--print);
  font-size: 13.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-line;
}
/* counsel writes on letterhead: white sheet, claret leader */
.msg.from-counsel .msg-bubble {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--claret);
  border-radius: 2px var(--radius-s) var(--radius-s) 2px;
  background: var(--sheet);
  box-shadow: 0 1px 2px rgba(42, 32, 25, 0.05);
}
/* the client's own notes: flax slips, right-hand margin */
.msg.from-you .msg-bubble {
  border: 1px solid #DFD5BC;
  border-radius: var(--radius-s);
  background: var(--flax);
}

.composer { border-top: 1px solid var(--rule); padding: 16px 28px 20px; display: grid; gap: 10px; }
.composer textarea {
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--edge);
  border-radius: var(--radius-s);
  background: var(--sheet);
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
}
.composer textarea:focus { outline: none; border-color: var(--claret); box-shadow: 0 0 0 3px var(--claret-ring); }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.composer-row .form-error { min-height: 0; flex: 1; }

/* ---------- documents ledger ---------- */

.docs-pane { min-width: 0; display: flex; flex-direction: column; min-height: 560px; }
.docs-error:empty { display: none; }
.docs-error { margin: 0; padding: 12px 28px 0; }
.doc-list { display: flex; flex-direction: column; padding-bottom: 6px; }
/* ghost rows while the folder opens */
.doc-list:empty { padding: 18px 28px; gap: 14px; }
.doc-list:empty::before,
.doc-list:empty::after {
  content: "";
  height: 44px;
  border-radius: var(--radius-s);
  background: linear-gradient(90deg, var(--flax) 30%, var(--sheet-2) 50%, var(--flax) 70%);
  background-size: 200% 100%;
  animation: inking 1.4s linear infinite;
}
.doc-list:empty::after { width: 72%; }
.doc-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 28px;
}
.doc-row + .doc-row { border-top: 1px solid var(--rule-2); }
/* exhibit tab */
.doc-kind {
  width: 44px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule);
  border-bottom: 2px solid var(--claret);
  border-radius: 3px 3px 2px 2px;
  background: var(--sheet-2);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--claret);
}
.doc-main { min-width: 0; }
.doc-main strong { display: block; font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; }
.doc-main small { display: block; margin-top: 3px; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.02em; color: var(--umber); }
.doc-download { min-height: 32px; padding: 0 12px; font-size: 12.5px; }

/* ---------- billing ledger ---------- */

.billing-surface {
  max-width: var(--col);
  margin: 0 auto;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(42, 32, 25, 0.04), 0 14px 34px -22px rgba(42, 32, 25, 0.22);
}
.billing-disclosure {
  margin: 0;
  padding: 11px 24px 11px 21px;
  border-bottom: 1px solid var(--rule);
  border-left: 3px solid var(--brass);
  background: var(--sheet-2);
  color: var(--umber);
  font-size: 12.5px;
  line-height: 1.5;
}
.invoice-ledger { display: flex; flex-direction: column; }
.invoice-row {
  display: grid;
  grid-template-columns: minmax(150px, 210px) minmax(0, 1fr) auto minmax(86px, auto) minmax(112px, auto);
  align-items: center;
  gap: 10px 22px;
  padding: 16px 24px;
}
.invoice-row + .invoice-row,
.invoice-ledger .billing-problem,
.invoice-ledger .pane-empty { border-top: 1px solid var(--rule-2); }
.invoice-ledger > :first-child { border-top: 0; }
.inv-id { min-width: 0; }
.inv-id strong { display: block; font-family: var(--font-mono); font-size: 12px; font-weight: 500; letter-spacing: 0.03em; color: var(--claret); }
.inv-id small { display: block; margin-top: 3px; font-size: 11.5px; color: var(--umber); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-desc { min-width: 0; }
.inv-desc p { margin: 0; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.inv-desc small { display: block; margin-top: 3px; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.02em; color: var(--umber); }
.inv-amount { font-family: var(--font-mono); font-size: 13.5px; text-align: right; white-space: nowrap; }
.inv-action { display: flex; justify-content: flex-end; min-width: 0; }
.inv-paid-note { font-family: var(--font-mono); font-size: 10.5px; color: var(--bay); white-space: nowrap; }
.billing-problem { margin: 0; padding: 12px 24px; color: var(--danger); font-size: 12.5px; }

/* invoice states share the dot device */
.status-sent { --dot: var(--brass); }
.status-overdue { --dot: var(--danger); }
.status-paid { --dot: var(--bay); }
.status.status-overdue { color: var(--danger); }

/* ---------- mobile nav ---------- */

.mobile-nav { display: none; }

/* ---------- dialog ---------- */

.dialog {
  width: min(94vw, 524px);
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  padding: 0;
  overflow: hidden;
  background: var(--sheet);
  color: var(--print);
  box-shadow: 0 40px 90px -16px rgba(24, 13, 17, 0.55);
}
.dialog::backdrop { background: rgba(24, 13, 17, 0.55); }
.dialog-card { display: grid; gap: 16px; padding: 25px 28px 24px; background: var(--scotch-claret); }
.dialog-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: start; }
.dialog-head h2 { margin: 0; font-family: var(--font-display); font-size: 21px; font-weight: 400; }
.dialog-head p { margin: 7px 0 0; color: var(--umber); font-size: 13.5px; line-height: 1.5; }
.dialog-head .icon-button { font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 2px; }

/* ---------- notice slip (toast) ----------
   A paper slip pinned to the bottom edge — never near the header,
   the wordmark, or the "+ New matter" action. */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 100;
  max-width: min(420px, calc(100vw - 32px));
  padding: 13px 18px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-s);
  background:
    var(--scotch-claret),
    linear-gradient(var(--sheet), var(--sheet));
  color: var(--print);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
  box-shadow: 0 18px 44px -12px rgba(24, 13, 17, 0.45);
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity var(--speed) ease, transform var(--speed) ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */

@media (max-width: 1240px) {
  .matter-layout { grid-template-columns: minmax(240px, 268px) minmax(0, 1fr); }
  .matter-detail { padding: 30px 32px 40px; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .details-panel { border-left: 0; padding-left: 0; border-top: 1px solid var(--rule); padding-top: 28px; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .workspace { padding: 0 16px 108px; }

  .topbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 18px 0 18px; }
  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 12px;
    background: var(--scotch);
  }
  .mobile-brand .brand-seal { width: 30px; height: 30px; font-size: 17px; }
  .mobile-brand .brand-name { font-size: 11px; }
  .mobile-brand .brand-sub { font-size: 8px; letter-spacing: 0.26em; }
  .topbar h1 { font-size: 26px; }
  .topbar > .button { width: 100%; }

  .matter-layout { grid-template-columns: minmax(0, 1fr); }
  .matter-list-panel { border-right: 0; border-bottom: 1px solid var(--rule); }
  .matter-list { max-height: 288px; overflow-y: auto; }
  .matter-detail { padding: 22px 18px 32px; }
  .detail-head { flex-direction: column; gap: 14px; }
  .detail-meta { text-align: left; gap: 24px; }
  .empty-detail { min-height: 320px; }

  .thread-pane, .docs-pane { min-height: 440px; }
  .thread-scroll { max-height: 52vh; padding: 18px 16px; }
  .msg { max-width: 88%; }
  .pane-head { padding: 18px 16px 12px; }
  .composer { padding: 14px 16px 18px; }
  .doc-row { padding: 13px 16px; }
  .doc-list:empty { padding: 16px; }
  .docs-error { padding: 12px 16px 0; }

  .billing-disclosure { padding: 11px 16px 11px 13px; }
  .invoice-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "id     status"
      "desc   desc"
      "amount action";
    row-gap: 12px;
    padding: 15px 16px;
  }
  .inv-id { grid-area: id; }
  .invoice-row .status { grid-area: status; justify-self: end; }
  .inv-desc { grid-area: desc; }
  .inv-amount { grid-area: amount; text-align: left; }
  .inv-action { grid-area: action; }
  .billing-problem { padding: 12px 16px; }

  /* the slip rises above the ink nav bar */
  .toast { bottom: calc(72px + env(safe-area-inset-bottom)); }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border-top: 1px solid var(--ink-line);
    background: rgba(24, 13, 17, 0.96);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav button {
    height: 56px;
    border: 0;
    background: transparent;
    color: var(--bone-dim);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    transition: color var(--speed) ease, box-shadow var(--speed) ease;
  }
  .mobile-nav button:focus-visible { outline-color: var(--bone); outline-offset: -3px; }
  .mobile-nav button.active { color: var(--bone); box-shadow: inset 0 2px 0 var(--claret), inset 0 3px 0 rgba(240, 233, 218, 0.25); }
}

@media (max-width: 520px) {
  .auth-view { padding: 24px 14px; }
  .auth-panel { padding: 28px 20px 24px; }
  .auth-brand .brand-name { font-size: 13px; letter-spacing: 0.1em; }
  .workspace { padding: 0 12px 108px; }
  .topbar h1 { font-size: 24px; }
  .matter-detail { padding: 20px 16px 30px; }
  .detail-title-line { flex-direction: column; align-items: flex-start; gap: 8px; }
  .detail-meta { flex-wrap: wrap; gap: 16px 24px; }
  .save-row { flex-direction: column; align-items: stretch; }
  .save-row .button { width: 100%; }
  .dialog-card { padding: 20px 18px; }

  .pane-head { flex-direction: column; gap: 12px; }
  .pane-head .button { width: 100%; }
  .doc-row { grid-template-columns: 44px minmax(0, 1fr); }
  .doc-row .doc-download { grid-column: 2; justify-self: start; }
  .messages-panel-head { flex-wrap: wrap; gap: 8px 16px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
  .button:active { transform: none; }
}
