/* ===== Tokens (.ux-profile.md: Stripe, WCAG 2.1 AA, Lucide, navy + copper) ===== */
:root {
  --vp-narrow: 375px;
  --vp-medium: 768px;
  --vp-wide: 1280px;

  /* Surfaces L0–L3 */
  --surface-l0: #f6f7f9;
  --surface-l1: #ffffff;
  --surface-l2: #ffffff;
  --surface-l3: #ffffff;
  --surface-sunken: #eef1f5;
  --foreground: #172233;
  --text-secondary: #4a5568;
  --text-meta: #566173;
  --border-l1: color-mix(in srgb, var(--foreground) 9%, transparent);
  --border-l2: color-mix(in srgb, var(--foreground) 11%, transparent);
  --border-strong: color-mix(in srgb, var(--foreground) 22%, transparent);
  --border-input: #8a94a6; /* 3:1 on white for component boundaries */
  --shadow-l1: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-l2: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-l3: 0 8px 24px rgba(0, 0, 0, 0.07);

  /* Brand */
  --accent: #213e6a;          /* navy — the only interactive hue */
  --accent-hover: #182f52;
  --accent-soft: #e9eef5;
  --copper: #c27a50;          /* logo mark only, never body text */
  --attention: #8a4a22;       /* darkened copper for "soon" dates, passes 4.5:1 */
  --attention-soft: #f8ede6;
  --danger: #b42318;
  --danger-hover: #912018;
  --success: #1f6b45;

  /* Type */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-brand: Fraunces, Georgia, "Times New Roman", serif;
  --font-regular: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --text-meta-size: 0.75rem;
  --text-secondary-size: 0.875rem;
  --text-body: 1rem;
  --text-h4: 1.2rem;
  --text-h3: 1.44rem;
  --text-h2: 1.728rem;
  --text-h1: 2.074rem;
  --leading-tight: 1.2;
  --leading-body: 1.55;
  --leading-meta: 1.4;

  /* Space */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --prose-max: 70ch;

  --radius-sm: 6px;
  --radius-md: 8px;
  --hit: 44px;

  /* Motion */
  --motion-100: 100ms;
  --motion-150: 150ms;
  --motion-200: 200ms;
  --motion-300: 300ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; width: 100%; }
body {
  font-family: var(--font-ui);
  font-size: var(--text-body);
  font-weight: var(--font-regular);
  line-height: var(--leading-body);
  color: var(--foreground);
  background: var(--surface-l0);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-weight: var(--font-semibold); line-height: var(--leading-tight); margin: 0; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-4); top: -100px; z-index: 400;
  background: var(--surface-l3); padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-l2); border-radius: var(--radius-md);
}
.skip-link:focus { top: var(--space-4); }

.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }

/* ===== App shell (full width, never capped) ===== */
.app { width: 100%; min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
  background: var(--surface-l1);
  border-right: 1px solid var(--border-l1);
  padding: var(--space-6) var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-8);
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: var(--space-3); text-decoration: none; color: var(--foreground); min-height: var(--hit); }
.brand-mark { width: 36px; height: 36px; flex: none; display: block; }
.brand-name { font-family: var(--font-brand); font-size: var(--text-h3); font-weight: var(--font-semibold); line-height: var(--leading-tight); letter-spacing: -0.02em; color: var(--accent); white-space: nowrap; }

.nav { display: flex; flex-direction: column; gap: var(--space-1); }
.nav-heading { font-size: var(--text-meta-size); line-height: var(--leading-meta); color: var(--text-meta); padding: var(--space-4) var(--space-3) var(--space-1); }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--hit); padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary); text-decoration: none;
  font-weight: var(--font-medium); font-size: var(--text-secondary-size);
}
a.nav-item:hover { background: var(--surface-l0); color: var(--foreground); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-item.is-soon { color: var(--text-meta); font-weight: var(--font-regular); }
.nav-item.is-soon .soon { margin-left: auto; font-size: var(--text-meta-size); }
.sidebar-foot { margin-top: auto; font-size: var(--text-meta-size); line-height: var(--leading-meta); color: var(--text-meta); padding: 0 var(--space-3); }

.topbar { display: none; }

.main-wrap { min-width: 0; }
main {
  width: 100%;
  max-width: var(--vp-wide);
  margin-inline: auto;
  padding: var(--space-8) var(--space-8) var(--space-12);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--hit); padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-weight: var(--font-medium); font-size: var(--text-secondary-size);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-l1); color: var(--foreground); border-color: var(--border-strong); }
.btn-secondary:hover { border-color: var(--border-input); background: var(--surface-l0); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn[disabled] { cursor: not-allowed; color: var(--text-meta); background: var(--surface-l0); border-color: var(--border-l2); }

.icon-btn {
  width: var(--hit); height: var(--hit); padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md); border: 1px solid transparent;
  background: transparent; color: var(--text-secondary); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-l0); color: var(--foreground); border-color: var(--border-l2); }

/* Tooltip (real surface, shown on hover + focus) */
.tip-wrap { position: relative; display: inline-flex; }
.tip {
  position: absolute; top: calc(100% + var(--space-1)); right: 0; z-index: 100;
  background: var(--foreground); color: #fff;
  font-size: var(--text-meta-size); line-height: var(--leading-meta);
  padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm);
  white-space: nowrap; pointer-events: none;
  opacity: 0; transform: translateY(-4px);
  transition: opacity var(--motion-100) var(--ease-in), transform var(--motion-100) var(--ease-in);
}
.tip.tip-left { right: auto; left: 0; }
.tip kbd { font-family: inherit; font-size: var(--text-meta-size); border: 1px solid rgba(255,255,255,.35); border-radius: 4px; padding: 0 var(--space-1); margin-left: var(--space-1); }
@media (hover: none) { .search-box kbd { display: none; } }
@media (hover: hover) {
  .tip-wrap:hover .tip { opacity: 1; transform: none; transition-timing-function: var(--ease-out); transition-duration: var(--motion-150); }
}
.tip-wrap:has(:focus-visible) .tip { opacity: 1; transform: none; transition-timing-function: var(--ease-out); transition-duration: var(--motion-150); }
.tip-wrap.tip-hidden .tip { opacity: 0 !important; }

/* ===== Page header ===== */
.crumbs { display: flex; align-items: center; gap: var(--space-1); font-size: var(--text-secondary-size); color: var(--text-secondary); margin-bottom: var(--space-2); flex-wrap: wrap; }
.crumbs a { display: inline-flex; align-items: center; gap: var(--space-1); min-height: var(--hit); text-decoration: none; font-weight: var(--font-medium); }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: var(--text-meta); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.page-head h1 { font-size: var(--text-h1); letter-spacing: -0.01em; }
.page-head .lede { margin-top: var(--space-2); color: var(--text-secondary); max-width: var(--prose-max); }
.page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.page-rule { border: 0; border-top: 1px solid var(--border-l1); margin: var(--space-6) 0; }

/* ===== Notice banner ===== */
.notice {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  background: var(--surface-l1); border: 1px solid var(--border-l1); border-left: 3px solid var(--accent);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
  font-size: var(--text-secondary-size); color: var(--text-secondary);
  margin-bottom: var(--space-4);
}
.notice p { flex: 1 1 260px; }
.notice.is-error { border-left-color: var(--danger); }

/* ===== List toolbar ===== */
.toolbar { display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; }
.search { flex: 1 1 320px; max-width: 480px; display: flex; flex-direction: column; gap: var(--space-1); }
.search label { font-size: var(--text-secondary-size); font-weight: var(--font-medium); }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: var(--space-3); top: 50%; transform: translateY(-50%); color: var(--text-meta); pointer-events: none; }
.search-box input { padding-left: 40px; padding-right: 40px; }
.search-box kbd {
  position: absolute; right: var(--space-3); top: 50%; transform: translateY(-50%);
  font-family: inherit; font-size: var(--text-meta-size); color: var(--text-meta);
  border: 1px solid var(--border-l2); border-radius: 4px; padding: 0 6px; line-height: 20px;
}

.input, .select {
  width: 100%; min-height: var(--hit);
  padding: 0 var(--space-3);
  background: var(--surface-l1);
  border: 1px solid var(--border-input); border-radius: var(--radius-md);
  font-size: var(--text-body);
}
.input:hover, .select:hover { border-color: var(--text-secondary); }
.input:focus-visible, .select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent); }
.input[aria-invalid="true"] { border-color: var(--danger); }

.filters-anchor { position: relative; }
.btn .count {
  min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px;
  background: var(--accent); color: #fff; font-size: var(--text-meta-size); line-height: 20px; text-align: center;
}
.popover {
  position: absolute; top: calc(100% + var(--space-2)); left: 0; z-index: 100;
  width: 300px; max-width: calc(100vw - 32px);
  background: var(--surface-l2); border: 1px solid var(--border-l2); border-radius: var(--radius-md);
  box-shadow: var(--shadow-l2);
  padding: var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-4);
}
.popover[hidden] { display: none; }
.popover.is-entering { animation: pop-in var(--motion-150) var(--ease-out); }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.popover fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.popover legend, .popover .field-label { font-size: var(--text-secondary-size); font-weight: var(--font-medium); margin-bottom: var(--space-1); padding: 0; }
.check {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--hit); font-size: var(--text-secondary-size); cursor: pointer;
  border-radius: var(--radius-sm); padding: 0 var(--space-2); margin: 0 calc(var(--space-2) * -1);
}
.check:hover { background: var(--surface-l0); }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.popover-foot { display: flex; justify-content: space-between; border-top: 1px solid var(--border-l1); padding-top: var(--space-3); }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-3); min-height: var(--hit); }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: 32px; padding: 0 var(--space-1) 0 var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface-l1); font-size: var(--text-secondary-size);
}
.chip button {
  width: 32px; height: 32px; display: inline-grid; place-items: center;
  border: 0; background: transparent; cursor: pointer; border-radius: var(--radius-sm); color: var(--text-secondary);
  position: relative;
}
.chip button::after { content: ""; position: absolute; inset: -6px; } /* 44px tap area */
.chip button:hover { background: var(--surface-l0); color: var(--foreground); }

/* ===== Table frame (L1 + hairlines) ===== */
.frame {
  margin-top: var(--space-4);
  background: var(--surface-l1);
  border: 1px solid var(--border-l1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-l1);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-secondary-size); }
thead th {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface-l0);
  text-align: left; font-weight: var(--font-medium); color: var(--text-secondary);
  border-bottom: 1px solid var(--border-l1);
  padding: 0 var(--space-4); height: 44px; white-space: nowrap;
}
th .sort {
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: var(--hit); border: 0; background: transparent; padding: 0; cursor: pointer;
  font-weight: var(--font-medium); color: var(--text-secondary);
}
th .sort:hover { color: var(--foreground); }
th[aria-sort] .sort { color: var(--foreground); }
th .sort .icon { opacity: 0; }
th[aria-sort] .sort .icon { opacity: 1; }
tbody td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-l1); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: #f9fafb; }
tbody tr.row:focus-within { background: #f9fafb; }
.case-link { color: var(--accent); font-weight: var(--font-medium); font-size: var(--text-body); text-decoration: none; }
.case-link:hover { text-decoration: underline; }
.cell-meta { display: block; font-size: var(--text-meta-size); line-height: var(--leading-meta); color: var(--text-meta); margin-top: 2px; }
.col-case { min-width: 240px; }
.col-court { min-width: 200px; }
.col-role { min-width: 130px; }
.col-date { min-width: 190px; }
.col-status { min-width: 96px; }
.col-go { width: 52px; text-align: right; }
.col-go .icon { color: var(--text-meta); margin-top: 2px; }
.when { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-meta-size); line-height: var(--leading-meta); color: var(--text-meta); margin-top: 2px; }
.when.is-soon { color: var(--attention); font-weight: var(--font-medium); }
.status { display: inline-flex; align-items: center; gap: var(--space-2); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.status.is-closed { color: var(--text-secondary); }
.status.is-closed::before { background: transparent; border: 1.5px solid var(--text-meta); }
.muted { color: var(--text-meta); }

.empty { padding: var(--space-12) var(--space-6); display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); max-width: 560px; margin: 0 auto; }
.empty h2 { font-size: var(--text-h4); }
.empty p { color: var(--text-secondary); }
.empty .empty-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-3); }
.empty-icon { width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--surface-l0); border: 1px solid var(--border-l1); display: grid; place-items: center; color: var(--text-secondary); margin-bottom: var(--space-2); }

.pager {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-2) var(--space-4); border-top: 1px solid var(--border-l1);
  font-size: var(--text-secondary-size); color: var(--text-secondary);
}
.pager-buttons { display: flex; gap: var(--space-2); }

/* ===== Form page ===== */
.form-col { max-width: 640px; }
.form { margin-top: var(--space-6); display: flex; flex-direction: column; gap: var(--space-6); }
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field > label, .field legend { font-weight: var(--font-medium); font-size: var(--text-body); padding: 0; }
.field .opt { font-weight: var(--font-regular); color: var(--text-meta); font-size: var(--text-secondary-size); }
.field .req { color: var(--text-meta); font-weight: var(--font-regular); font-size: var(--text-secondary-size); }
.help, .err { font-size: var(--text-secondary-size); line-height: var(--leading-body); min-height: 1.55em; }
.help { color: var(--text-secondary); }
.err { color: var(--danger); display: flex; gap: var(--space-1); align-items: flex-start; }
.err .icon { margin-top: 3px; }
fieldset.field { border: 0; margin: 0; padding: 0; }
.radio-list { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-1); }
.radio {
  display: flex; align-items: flex-start; gap: var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4); background: var(--surface-l1); cursor: pointer;
}
.radio:hover { border-color: var(--border-input); }
.radio:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio input { margin: 3px 0 0; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.radio strong { display: block; font-weight: var(--font-medium); }
.radio span span { display: block; font-size: var(--text-secondary-size); color: var(--text-secondary); }
fieldset.field.is-invalid .radio { border-color: var(--danger); }
.row-2 { display: grid; grid-template-columns: 200px 1fr; gap: var(--space-4); }
.form-bar {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; justify-content: flex-end; gap: var(--space-2); align-items: center;
  background: var(--surface-l0);
  border-top: 1px solid var(--border-l1);
  padding: var(--space-4) 0;
  margin-top: var(--space-2);
}
.form-bar .draft-note { margin-right: auto; font-size: var(--text-meta-size); line-height: var(--leading-meta); color: var(--text-meta); }

/* ===== Detail page ===== */
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin-top: var(--space-2); color: var(--text-secondary); font-size: var(--text-secondary-size); }
.meta-line .dot { color: var(--text-meta); }
.panel { background: var(--surface-l1); border: 1px solid var(--border-l1); border-radius: var(--radius-md); box-shadow: var(--shadow-l1); }
.panel-head { padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--border-l1); }
.panel-head h2 { font-size: var(--text-h4); font-weight: var(--font-semibold); }
.facts { margin: 0; display: grid; grid-template-columns: 200px minmax(0, 1fr); }
.facts dt, .facts dd { margin: 0; padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--border-l1); }
.facts dt { color: var(--text-secondary); font-size: var(--text-secondary-size); }
.facts dd { font-size: var(--text-body); }
.facts dt:nth-last-of-type(1), .facts dd:last-of-type { border-bottom: 0; }
.next-date-card { display: flex; gap: var(--space-4); align-items: flex-start; padding: var(--space-6); border-bottom: 1px solid var(--border-l1); }
.date-tile { width: 56px; flex: none; text-align: center; border: 1px solid var(--border-l2); border-radius: var(--radius-md); overflow: hidden; }
.date-tile .m { display: block; background: var(--accent); color: #fff; font-size: var(--text-meta-size); line-height: 20px; font-weight: var(--font-medium); text-transform: uppercase; letter-spacing: 0.04em; }
.date-tile .d { display: block; font-size: var(--text-h3); line-height: 40px; font-weight: var(--font-semibold); }
.next-date-card h3 { font-size: var(--text-body); font-weight: var(--font-semibold); line-height: var(--leading-body); }
.next-date-card p { color: var(--text-secondary); font-size: var(--text-secondary-size); }
.more-anchor { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + var(--space-2)); z-index: 100; min-width: 200px;
  background: var(--surface-l2); border: 1px solid var(--border-l2); border-radius: var(--radius-md);
  box-shadow: var(--shadow-l2); padding: var(--space-1);
}
.menu[hidden] { display: none; }
.menu.is-entering { animation: pop-in var(--motion-150) var(--ease-out); }
.menu [role="menuitem"] {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  min-height: var(--hit); padding: 0 var(--space-3); border: 0; background: transparent;
  border-radius: var(--radius-sm); cursor: pointer; text-align: left; font-size: var(--text-secondary-size);
}
.menu [role="menuitem"]:hover, .menu [role="menuitem"]:focus-visible { background: var(--surface-l0); outline-offset: -2px; }
.menu .is-danger { color: var(--danger); }

/* ===== Dialogs (L3) ===== */
dialog { padding: 0; border: 0; background: transparent; color: inherit; max-width: none; max-height: none; }
dialog::backdrop { background: rgba(15, 23, 42, 0.5); }
.confirm {
  width: min(440px, calc(100vw - 32px));
  background: var(--surface-l3); border: 1px solid var(--border-l2); border-radius: var(--radius-md);
  box-shadow: var(--shadow-l3);
}
.confirm[open] { animation: dialog-in var(--motion-200) var(--ease-out); }
.confirm[open]::backdrop { animation: fade-in var(--motion-200) var(--ease-out); }
.confirm.is-closing { animation: dialog-out var(--motion-150) var(--ease-in) forwards; }
.confirm.is-closing::backdrop { animation: fade-out var(--motion-150) var(--ease-in) forwards; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes dialog-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
.confirm h2 { font-size: var(--text-h4); padding: var(--space-6) var(--space-6) 0; overflow-wrap: anywhere; }
.confirm p { padding: var(--space-3) var(--space-6) 0; color: var(--text-secondary); }
.confirm .dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-6); flex-wrap: wrap; }

.drawer {
  position: fixed; inset: 0 auto 0 0; margin: 0; height: 100%;
  width: min(300px, 85vw);
  background: var(--surface-l3); border-right: 1px solid var(--border-l2);
  box-shadow: var(--shadow-l3);
  padding: var(--space-4);
}
.drawer[open] { display: flex; flex-direction: column; gap: var(--space-6); animation: drawer-in var(--motion-200) var(--ease-out); }
.drawer[open]::backdrop { animation: fade-in var(--motion-200) var(--ease-out); }
.drawer.is-closing { animation: drawer-out var(--motion-150) var(--ease-in) forwards; }
.drawer.is-closing::backdrop { animation: fade-out var(--motion-150) var(--ease-in) forwards; }
@keyframes drawer-in { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes drawer-out { from { transform: none; } to { transform: translateX(-100%); } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }

/* ===== Toast ===== */
.toast-region { position: fixed; bottom: var(--space-6); left: 50%; transform: translateX(-50%); z-index: 400; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: var(--space-3);
  background: var(--foreground); color: #fff; border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4); font-size: var(--text-secondary-size);
  box-shadow: var(--shadow-l3);
  animation: toast-in var(--motion-200) var(--ease-out);
}
.toast.is-leaving { animation: toast-out var(--motion-150) var(--ease-in) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(8px); } }


/* ===== Calendar (Pattern 7) ===== */
.popover { max-height: min(70vh, 560px); overflow-y: auto; }
.cal-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); }
.cal-nav { display: flex; align-items: center; gap: var(--space-2); }
.cal-nav[hidden] { display: none; }
.cal-month { font-size: var(--text-h3); min-width: 9em; text-align: center; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface-l1); overflow: hidden; }
.seg-btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: var(--hit); padding: 0 var(--space-4); border: 0; background: transparent; cursor: pointer;
  color: var(--text-secondary); font-weight: var(--font-medium); font-size: var(--text-secondary-size);
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border-l2); }
.seg-btn:hover { color: var(--foreground); background: var(--surface-l0); }
.seg-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.seg-btn:focus-visible { outline-offset: -3px; }
.legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-top: var(--space-3); font-size: var(--text-meta-size); line-height: var(--leading-meta); color: var(--text-meta); }
.legend span { display: inline-flex; align-items: center; gap: var(--space-1); }
.cal-frame { margin-top: var(--space-3); }
.grid-msg {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2);
  min-height: var(--hit); padding: var(--space-1) var(--space-4);
  border-bottom: 1px solid var(--border-l1); font-size: var(--text-secondary-size); color: var(--text-secondary);
}
.cal-grid { width: 100%; table-layout: fixed; border-collapse: collapse; }
.cal-grid th {
  height: 36px; padding: 0 var(--space-2); text-align: left; background: var(--surface-l0);
  font-size: var(--text-secondary-size); font-weight: var(--font-medium); color: var(--text-secondary);
  border-bottom: 1px solid var(--border-l1);
}
.cal-grid abbr { text-decoration: none; }
.cal-grid td { padding: 0; vertical-align: top; border-right: 1px solid var(--border-l1); border-bottom: 1px solid var(--border-l1); }
.cal-grid td:last-child { border-right: 0; }
.cal-grid tr:last-child td { border-bottom: 0; }
.cal-cell {
  display: flex; flex-direction: column; align-items: stretch; gap: var(--space-1);
  width: 100%; height: 116px; padding: var(--space-2); margin: 0;
  border: 0; border-radius: 0; background: var(--surface-l1); color: var(--foreground);
  text-align: left; cursor: pointer; font-size: var(--text-secondary-size);
}
.cal-cell:hover { background: #f9fafb; }
.cal-cell.is-out { background: var(--surface-l0); color: var(--text-meta); }
.cal-cell.is-selected { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: -5px; border-radius: 0; }
.cal-num { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-weight: var(--font-medium); font-variant-numeric: tabular-nums; }
.cal-cell.is-today .cal-num { background: var(--accent); color: #fff; }
.cal-events { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-ev {
  display: flex; align-items: center; gap: var(--space-1); min-width: 0;
  padding: 2px var(--space-1); border-radius: 4px; background: var(--accent-soft); color: var(--accent);
  font-size: var(--text-secondary-size); line-height: 20px; white-space: nowrap;
}
.cal-ev > span { overflow: hidden; text-overflow: ellipsis; }
.cal-ev .icon { width: 14px; height: 14px; }
.cal-ev.is-deadline { background: var(--attention-soft); color: var(--attention); }
.cal-more { font-size: var(--text-meta-size); line-height: var(--leading-meta); color: var(--text-meta); padding-left: var(--space-1); }
.cal-dots { display: none; }
.day-panel { margin-top: var(--space-4); }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.day-head h2 .muted { font-weight: var(--font-regular); }
.day-empty { padding: var(--space-4) var(--space-6); color: var(--text-secondary); }
.ev-list { list-style: none; margin: 0; padding: 0; }
.ev-list li + li { border-top: 1px solid var(--border-l1); }
.ev-row {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 64px;
  padding: var(--space-3) var(--space-6); margin: 0; border: 0; background: transparent; text-align: left; cursor: pointer;
}
.ev-row:hover { background: #f9fafb; }
.ev-row:focus-visible { outline-offset: -3px; }
.ev-row > .icon:last-child { color: var(--text-meta); margin-left: auto; }
.ev-type { width: 36px; height: 36px; flex: none; border-radius: var(--radius-md); display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.ev-type.is-deadline { background: var(--attention-soft); color: var(--attention); }
.ev-main { display: flex; flex-direction: column; min-width: 0; }
.ev-title { font-weight: var(--font-medium); overflow-wrap: anywhere; }
.ev-meta { font-size: var(--text-secondary-size); color: var(--text-secondary); }
.agenda-day {
  display: flex; align-items: baseline; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-3) var(--space-6); background: var(--surface-l0);
  border-top: 1px solid var(--border-l1); border-bottom: 1px solid var(--border-l1);
  font-size: var(--text-body); line-height: var(--leading-body);
}
.agenda .agenda-day:first-child { border-top: 0; }
.panel + .panel { margin-top: var(--space-6); }
.sub-head { padding: var(--space-3) var(--space-6) var(--space-1); border-top: 1px solid var(--border-l1); font-size: var(--text-secondary-size); font-weight: var(--font-medium); color: var(--text-secondary); }

/* Slide-over (event preview) */
.sheet {
  position: fixed; inset: 0 0 0 auto; margin: 0; height: 100%; width: min(440px, 100vw);
  background: var(--surface-l3); border-left: 1px solid var(--border-l2); box-shadow: var(--shadow-l3);
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-in var(--motion-200) var(--ease-out); }
.sheet[open]::backdrop { animation: fade-in var(--motion-200) var(--ease-out); }
.sheet.is-closing { animation: sheet-out var(--motion-150) var(--ease-in) forwards; }
.sheet.is-closing::backdrop { animation: fade-out var(--motion-150) var(--ease-in) forwards; }
@keyframes sheet-in { from { transform: translateX(100%); } to { transform: none; } }
@keyframes sheet-out { from { transform: none; } to { transform: translateX(100%); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-6); border-bottom: 1px solid var(--border-l1); }
.ev-kind { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-secondary-size); font-weight: var(--font-medium); color: var(--text-secondary); }
.sheet-body { flex: 1; overflow-y: auto; padding: var(--space-6); }
.sheet-body h2 { font-size: var(--text-h3); overflow-wrap: anywhere; }
.sheet-facts { margin: var(--space-6) 0 0; display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: var(--space-4) var(--space-3); }
.sheet-facts dt { color: var(--text-meta); padding-top: 3px; }
.sheet-facts dd .cell-meta { margin-top: 0; }
.sheet-facts dd { margin: 0; overflow-wrap: anywhere; }
.sheet-facts .notes { white-space: pre-line; color: var(--text-secondary); }
.sheet-facts .case-link-lg { display: inline-flex; align-items: center; min-height: var(--hit); font-weight: var(--font-medium); }
.ext { display: inline-flex; align-items: center; gap: var(--space-1); min-height: var(--hit); font-size: var(--text-secondary-size); font-weight: var(--font-medium); }
.sheet-foot { display: flex; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border-l1); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: #fdf0ef; }

/* Form extras */
.textarea { min-height: 112px; padding: var(--space-3); line-height: var(--leading-body); resize: vertical; }
.radio-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); margin-top: var(--space-1); }
.radio-grid .radio strong { display: inline-flex; align-items: center; gap: var(--space-2); }
.select { appearance: auto; }

/* ===== Narrow (≤767.98px): chrome collapses to a menu ===== */
@media (max-width: 767.98px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; gap: var(--space-2);
    position: sticky; top: 0; z-index: 10;
    background: var(--surface-l1); border-bottom: 1px solid var(--border-l1);
    padding: var(--space-1) var(--space-2);
  }
  .topbar .brand-name { font-size: var(--text-h4); }
  main { padding: var(--space-6) var(--space-4) var(--space-12); }
  .page-head h1 { font-size: var(--text-h2); }
  .page-actions { width: 100%; }
  .page-actions .btn-primary { flex: 1 1 auto; }
  .search { max-width: none; flex-basis: 100%; }
  .search-box kbd { display: none; }
  .col-case { min-width: 168px; }
  .col-date { min-width: 160px; }
  thead th, tbody td { padding-inline: var(--space-3); }
  .row-2 { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { border-bottom: 0; padding-bottom: 0; }
  .facts dd { padding-top: var(--space-1); }
  .next-date-card, .panel-head { padding-inline: var(--space-4); }
  .facts dt, .facts dd { padding-inline: var(--space-4); }
  .form-bar .btn { flex: 1 1 auto; }
  .form-bar .draft-note { flex-basis: 100%; }
  .form-bar { flex-wrap: wrap; }
  .cal-cell { height: 56px; padding: var(--space-1); align-items: center; gap: 2px; }
  .cal-events { display: none; }
  .cal-dots { display: flex; gap: 3px; justify-content: center; min-height: 5px; }
  .dot-ev { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
  .cal-grid th { padding: 0; text-align: center; }
  .cal-num { width: 26px; height: 26px; }
  .cal-month { min-width: 0; font-size: var(--text-h4); }
  .cal-nav { flex: 1 1 100%; justify-content: space-between; }
  .seg { flex: 1 1 100%; }
  .seg-btn { flex: 1 1 50%; justify-content: center; }
  .ev-row, .agenda-day, .day-empty, .sub-head { padding-inline: var(--space-4); }
  .radio-grid { grid-template-columns: 1fr; }
  .sheet-body, .sheet-foot { padding-inline: var(--space-4); }
  .sheet-head { padding-left: var(--space-4); }
}

/* ===== Reduced motion: instant or opacity-only ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; }
  .popover.is-entering, .menu.is-entering,
  .confirm[open], .confirm[open]::backdrop,
  .drawer[open], .drawer[open]::backdrop,
  .sheet[open], .sheet[open]::backdrop,
  .toast { animation: fade-in var(--motion-100) linear; }
  .confirm.is-closing, .drawer.is-closing, .toast.is-leaving, .sheet.is-closing, .sheet.is-closing::backdrop,
  .confirm.is-closing::backdrop, .drawer.is-closing::backdrop { animation: fade-out var(--motion-100) linear forwards; }
  .tip { transform: none !important; }
}

/* ===== Real app: account, sign-in, saving, documents ===== */
.account { margin-top: auto; padding: var(--space-3); border-top: 1px solid var(--border-l1); display: flex; flex-direction: column; gap: 2px; }
.account:empty { display: none; }
.account + .sidebar-foot { margin-top: var(--space-2); }
.account-name { font-weight: var(--font-medium); font-size: var(--text-secondary-size); overflow-wrap: anywhere; }
.account-meta { font-size: var(--text-meta-size); line-height: var(--leading-meta); color: var(--text-meta); overflow-wrap: anywhere; }
.account-meta[data-kind="error"] { color: var(--danger); font-weight: var(--font-medium); }
.account-link { display: inline-flex; align-items: center; min-height: var(--hit); font-size: var(--text-secondary-size); font-weight: var(--font-medium); }
.account-signout { align-self: flex-start; margin-left: calc(var(--space-4) * -1); }

.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--space-6) var(--space-4); }
.auth-card {
  width: 100%; max-width: 440px; background: var(--surface-l1); border: 1px solid var(--border-l1);
  border-radius: var(--radius-md); box-shadow: var(--shadow-l2); padding: var(--space-8);
  display: flex; flex-direction: column; gap: var(--space-4);
}
.auth-brand { margin-bottom: var(--space-2); }
.auth-card h1 { font-size: var(--text-h2); }
.auth-card .lede { color: var(--text-secondary); }
.auth-card .notice { margin-bottom: 0; }
.auth-actions { display: flex; flex-direction: column; gap: var(--space-3); }
.btn-provider {
  justify-content: flex-start; min-height: 56px; padding: var(--space-2) var(--space-4);
  background: var(--surface-l1); color: var(--foreground); border-color: var(--border-strong); text-align: left;
}
.btn-provider:hover { border-color: var(--accent); background: var(--accent-soft); }
.provider-text { display: flex; flex-direction: column; }
.provider-text strong { font-weight: var(--font-semibold); font-size: var(--text-body); }
.provider-text span { font-weight: var(--font-regular); color: var(--text-secondary); }
.auth-note { display: flex; gap: var(--space-2); align-items: flex-start; font-size: var(--text-secondary-size); color: var(--text-secondary); }
.auth-note .icon { margin-top: 3px; flex: none; }
.auth-foot { font-size: var(--text-meta-size); line-height: var(--leading-meta); color: var(--text-meta); border-top: 1px solid var(--border-l1); padding-top: var(--space-3); }

.boot-loading { min-height: 100vh; display: flex; align-items: center; justify-content: center; gap: var(--space-3); color: var(--text-secondary); }
.boot-loading[hidden], .auth[hidden], .app[hidden], .save-banner[hidden] { display: none; }

.spinner {
  width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 800ms linear infinite;
}
.btn-primary .spinner { border-color: rgba(255,255,255,.4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

.save-banner {
  position: fixed; left: 50%; bottom: var(--space-6); transform: translateX(-50%); z-index: 300;
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  width: min(640px, calc(100vw - 32px)); padding: var(--space-3) var(--space-4);
  background: var(--surface-l3); border: 1px solid var(--border-l2); border-left: 3px solid var(--danger);
  border-radius: var(--radius-md); box-shadow: var(--shadow-l3); font-size: var(--text-secondary-size);
}
.save-banner p { flex: 1 1 280px; }
.save-banner .icon { color: var(--danger); }

.docs-head { display: flex; flex-direction: column; gap: var(--space-3); }
.docs-where { font-size: var(--text-secondary-size); color: var(--text-secondary); }
.docs-where a { font-weight: var(--font-medium); display: inline-flex; align-items: center; min-height: var(--hit); }
.docs-controls { display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; }
.docs-folder { flex: 0 1 220px; }
.docs-folder label { font-size: var(--text-secondary-size); }
.docs-buttons { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.docs-none { padding: var(--space-2) var(--space-6) var(--space-3); font-size: var(--text-secondary-size); color: var(--text-meta); }
.docs-body { min-height: 64px; }
.docs-body .sub-head:first-child { border-top: 0; }
.docs-error { margin: var(--space-4) var(--space-6); }
.new-doc { display: flex; flex-direction: column; gap: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--border-l1); }
.new-doc-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.upload-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-6); border-bottom: 1px solid var(--border-l1); }
.docs-skeleton { padding: var(--space-2) 0; }
.sk-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-6); }
.sk { display: block; background: var(--surface-sunken); border-radius: var(--radius-sm); animation: sk-pulse 1.2s ease-in-out infinite alternate; }
.sk-icon { width: 36px; height: 36px; flex: none; }
.sk-lines { flex: 1; display: flex; flex-direction: column; gap: var(--space-2); }
.sk-line { height: 12px; width: 60%; }
.sk-line.short { width: 35%; }
@keyframes sk-pulse { from { opacity: 1; } to { opacity: .55; } }
a.ev-row { color: inherit; text-decoration: none; }
a.ev-row:hover .ev-title { text-decoration: underline; }

@media (max-width: 767.98px) {
  .auth-card { padding: var(--space-6) var(--space-4); }
  .docs-folder { flex-basis: 100%; }
  .docs-buttons .btn { flex: 1 1 auto; }
  .docs-none, .sk-row, .upload-row { padding-inline: var(--space-4); }
  .docs-error { margin-inline: var(--space-4); }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: sk-pulse 1.2s linear infinite alternate; }
  .sk { animation: none; }
}
.notice[hidden] { display: none; }
