:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #667085;
  --border: #e3e6eb;
  --sidebar-bg: #16202e;
  --sidebar-text: #c9d2de;
  --sidebar-active: #2a3a50;
  --primary: #2458d6;
  --primary-hover: #1c47b0;
  --link: #2458d6;
  --danger: #c93434;
  --warning-text: #a15c00;
  --success-bg: #e8f6ee;
  --success-text: #1d6b3f;
  --error-bg: #fdecec;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --surface: #1a2029;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --border: #2b3340;
    --sidebar-bg: #0b0f15;
    --sidebar-active: #1f2a3a;
    --primary: #3b6ae0;
    --primary-hover: #2f5bc8;
    --link: #8fb0ff;
    --danger: #ef6464;
    --warning-text: #f0b35a;
    --success-bg: #173324;
    --success-text: #8fd9ad;
    --error-bg: #3a1c1c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 20px 0 8px; }

/* App shell: sidebar (a slide-in drawer below 900px), phone top bar, main content */
.layout { display: flex; min-height: 100vh; }
.content { flex: 1; min-width: 0; padding: 28px 32px; max-width: 1100px; }
.content:focus { outline: none; }  /* focused by the skip link */
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; padding: 8px 14px; border-radius: 6px; background: #1c47b0; color: #fff; }
.skip-link:focus { top: 12px; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-button {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 8px; background: none; color: inherit; cursor: pointer;
}
.icon-button:hover { background: rgba(255, 255, 255, 0.1); }
.icon-button .icon { width: 22px; height: 22px; }

.sidebar {
  width: 240px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px; padding: 14px 12px;
  background: var(--sidebar-bg); color: var(--sidebar-text);
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; min-height: 40px; padding: 0 2px 0 10px; }
.brand { color: #fff; font-weight: 700; font-size: 1.2rem; }
.brand:hover { text-decoration: none; }
.sidebar-close, .sidebar-toggle { display: none; }
/* Wider screens: the menu button beside the brand hides the sidebar down to a strip that keeps just
   that button (static/js/app.js; base.html's <head> script brings the choice back on every page). */
@media (min-width: 900px) {
  .js .sidebar-toggle { display: inline-flex; }
  .sidebar-hidden .sidebar { width: 64px; }
  .sidebar-hidden .sidebar > :not(.sidebar-top), .sidebar-hidden .brand { display: none; }
  .sidebar-hidden .sidebar-top { padding: 0; }
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--sidebar-text); }
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--primary); }
.nav a:focus-visible, .menu-button:focus-visible { outline: 2px solid #8fb0ff; outline-offset: 1px; }
.sidebar .nav { flex: 1; }
.nav-bottom { margin-top: auto; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.08); }

/* Menu panels: <details class="menu"> (static/js/app.js closes them on an outside click or Escape) */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-button { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; cursor: pointer; color: #fff; }
.menu-button:hover, .menu[open] > .menu-button { background: var(--sidebar-active); }
.menu-button-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.menu-button .chevron { width: 16px; height: 16px; opacity: 0.7; transition: transform 0.15s; }
.menu[open] > .menu-button .chevron { transform: rotate(180deg); }
.sidebar-workspace-name, .user-name, .user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-workspace-name { font-weight: 600; }
.user-name { font-weight: 600; font-size: 0.9rem; }
.user-email { font-size: 0.78rem; color: var(--sidebar-text); }
.workspace-mark {
  width: 30px; height: 30px; flex-shrink: 0; display: grid; place-items: center; border-radius: 7px;
  background: var(--primary); color: #fff; font-weight: 700; object-fit: contain;
}
img.workspace-mark { background: #fff; padding: 3px; }
.avatar {
  width: 30px; height: 30px; flex-shrink: 0; display: grid; place-items: center; border-radius: 50%;
  background: #3b4a61; color: #fff; font-size: 0.75rem; font-weight: 700;
}
.menu-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; padding: 6px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}
.user-menu .menu-panel { top: auto; bottom: calc(100% + 4px); }
.menu form { margin: 0; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px;
  background: none; color: var(--text); font: inherit; font-size: 0.92rem; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--bg); text-decoration: none; }
.menu-item:focus-visible { background: var(--bg); outline: 2px solid var(--primary); outline-offset: -2px; }
.menu-item .icon { width: 16px; height: 16px; color: var(--muted); }
.menu-item.is-current { font-weight: 600; cursor: default; }
.menu-item.is-current:hover { background: none; }
.menu-item.is-current .icon { color: var(--primary); }
.menu-heading { padding: 8px 10px 4px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.menu-divider { height: 1px; margin: 6px 4px; background: var(--border); }
.workspace-menu { margin-bottom: 6px; }
.user-menu { margin-top: auto; }  /* at the bottom even when there's no nav (no workspace yet) */

.topbar, .nav-backdrop { display: none; }
.nav-backdrop { cursor: pointer; }  /* iOS only sends taps on clickable-looking elements */

@media (max-width: 899px) {
  .layout { flex-direction: column; }
  .content { padding: 20px 16px; }
  .nav a { padding: 10px 12px; }  /* bigger tap targets */

  /* Without JS the sidebar is a block at the top of the page. */
  .no-js .sidebar { position: static; width: auto; height: auto; overflow: visible; }
  .no-js .nav { flex-direction: row; flex-wrap: wrap; }
  .no-js .nav-bottom { margin: 0; padding: 0; border: 0; }
  .no-js .user-menu { margin-top: 0; }

  /* With JS it's a drawer, opened from the top bar. */
  .js .topbar {
    display: flex; align-items: center; gap: 6px; position: sticky; top: 0; z-index: 30;
    height: 56px; padding: 0 8px; background: var(--sidebar-bg); color: #fff;
  }
  .topbar-brand { color: #fff; font-weight: 700; font-size: 1.1rem; }
  .topbar-brand:hover { text-decoration: none; }
  .topbar-workspace {
    margin-left: auto; margin-right: 8px; max-width: 45%; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; font-size: 0.85rem; color: var(--sidebar-text);
  }
  .js .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 50; width: min(300px, 86vw); height: auto;
    transform: translateX(-100%); visibility: hidden; box-shadow: 0 0 40px rgba(0, 0, 0, 0.3);
  }
  .js.nav-open .sidebar { transform: none; visibility: visible; }
  /* Slide only while opening or closing (app.js sets nav-animate), not when the layout changes. */
  .js.nav-animate .sidebar { transition: transform 0.2s ease, visibility 0s linear 0.2s; }
  .js.nav-animate.nav-open .sidebar { transition: transform 0.2s ease; }
  .js .sidebar-close { display: inline-flex; }
  .js.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(10, 15, 25, 0.5); }
  .js { scroll-padding-top: 64px; }  /* links to #sections land below the sticky top bar */
  .js.nav-open body { overflow: hidden; }
}
@media (prefers-reduced-motion: reduce) { .sidebar, .menu-button .chevron { transition: none !important; } }

/* Tracker */
.content.wide { max-width: none; }
.tracker-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface); }
.segmented a { padding: 6px 14px; color: var(--text); font-size: 0.9rem; }
.segmented a + a { border-left: 1px solid var(--border); }
.segmented a:hover { text-decoration: none; background: var(--bg); }
.segmented a.active { background: var(--primary); color: #fff; }
.tracker-nav { display: flex; gap: 6px; align-items: center; }
.tracker-nav .btn.active { border-color: var(--primary); color: var(--link); }
.range-label { margin-left: 6px; font-weight: 600; }
.tracker-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.tracker-filters input[type="search"] { min-width: 200px; }
@media (max-width: 720px) {  /* two filters per row */
  .tracker-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .tracker-filters input[type="search"] { grid-column: 1 / -1; min-width: 0; }
  .tracker-filters select { width: 100%; min-width: 0; }
}
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 0.9rem; white-space: nowrap; }
.count { display: inline-block; min-width: 1.4em; padding: 0 6px; border-radius: 999px; background: var(--border); color: var(--muted); font-size: 0.75rem; text-align: center; font-weight: 600; }

.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
@media (max-width: 720px) {  /* one column at a time, swiped */
  .board { grid-auto-columns: 86%; scroll-snap-type: x mandatory; }
  .board-column { scroll-snap-align: start; }
}
.board-column { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.board-column.overdue { border-color: var(--danger); }
.board-column.overdue .column-title { color: var(--danger); }
.board-column.current { border-color: var(--primary); }
.column-header { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.column-title { font-weight: 600; }
.column-sub { font-size: 0.8rem; color: var(--muted); }
.column-items { padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.column-empty { margin: 4px; }

.deadline-card { border: 1px solid var(--border); border-left-width: 3px; border-radius: 6px; padding: 8px 10px; background: var(--bg); font-size: 0.88rem; }
.deadline-card.statutory { border-left-color: var(--danger); }
.deadline-card.contractual { border-left-color: var(--primary); }
.deadline-card.meeting { border-left-color: #8a5cf6; }
.client-handled { opacity: 0.55; }
.is-done .card-title { text-decoration: line-through; }
.card-date { font-size: 0.8rem; font-weight: 600; }
.card-entity { display: block; font-weight: 600; margin-top: 2px; }
.card-title { margin: 2px 0 6px; }
.card-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.card-actions { display: flex; gap: 6px; }
.overdue-text { color: var(--danger); font-weight: 600; }

/* Tags: what a tracker item is */
.tags { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: middle; }
.badge.badge-filing { background: var(--error-bg); color: var(--danger); }
.badge.badge-payment { background: #fdf0dc; color: #8f4d00; }
.badge.badge-contractual { background: #e7eefc; color: #2458d6; }
.badge.badge-meeting { background: #efe9fe; color: #6d3fd6; }
@media (prefers-color-scheme: dark) {
  .badge.badge-payment { background: #3a2a14; color: #f3c27a; }
  .badge.badge-contractual { background: #1c2a47; color: #9bb8f5; }
  .badge.badge-meeting { background: #2a2145; color: #c4b0fb; }
}

.group-row th { background: var(--bg); color: var(--text); text-transform: none; letter-spacing: 0; font-size: 0.9rem; }
.group-row.overdue th { color: var(--danger); }
.group-row.current th { color: var(--link); }
.tracker-table tr.statutory td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.tracker-table tr.contractual td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.tracker-table tr.meeting td:first-child { box-shadow: inset 3px 0 0 #8a5cf6; }

/* Tasks */
.tick {
  width: 18px; height: 18px; padding: 0; border: 1.5px solid var(--muted); border-radius: 4px;
  background: var(--surface); color: #fff; font-size: 12px; line-height: 1; cursor: pointer; flex-shrink: 0;
}
.tick:hover { border-color: var(--primary); }
.tick.done { background: var(--primary); border-color: var(--primary); }
.task-progress { margin: 4px 0 6px; font-size: 0.85rem; }
.progress-line { display: inline-flex; align-items: center; gap: 6px; }
.task-progress progress, .progress-line progress { width: 70px; height: 6px; accent-color: var(--primary); }
.next-task { display: flex; align-items: center; gap: 6px; margin-top: 4px; min-width: 0; }
.next-task-title { flex: 1; min-width: 0; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.success-text { color: var(--success-text); font-weight: 600; }
.deadline-card.task { border-left-style: dashed; border-left-color: var(--muted); }
.card-for { margin: -4px 0 6px; }
.badge.badge-task { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.who { display: inline-flex; gap: 3px; flex-wrap: wrap; }
.who-chip {
  display: inline-block; min-width: 1.9em; padding: 1px 5px; border-radius: 999px; text-align: center;
  background: var(--border); color: var(--text); font-size: 0.72rem; font-weight: 700;
}
.task-table td { vertical-align: top; }
.tick-cell { width: 28px; }
.task-row.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-row.skipped { opacity: 0.55; }
a.task-title { font-weight: 600; color: var(--text); }
a.task-title:hover { color: var(--link); }
.task-for { margin-top: 2px; }
.link-action { background: none; border: 0; padding: 0; font: inherit; font-size: 0.85rem; color: var(--muted); cursor: pointer; }
.link-action:hover { color: var(--text); text-decoration: underline; }
.later-tasks { margin-top: 8px; }
.later-tasks summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; margin: 8px 0; }
.card > details > table th:first-child, .card > details > table td:first-child { padding-left: 0; }
.card > details > table th:last-child, .card > details > table td:last-child { padding-right: 0; }

/* My work */
.work-filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 16px; }
.work-filters input[type="search"] { flex: 1; min-width: 200px; }
.filter-group { display: inline-flex; align-items: center; gap: 8px; }
.filter-label { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.segmented a { white-space: nowrap; }
/* Radio segmented controls (My work filters): the radio is hidden, its label is the button. */
.segmented label { position: relative; padding: 6px 14px; font-size: 0.9rem; cursor: pointer; white-space: nowrap; }
.segmented label + label { border-left: 1px solid var(--border); }
.segmented label:hover { background: var(--bg); }
.segmented label.active, .segmented label:has(input:checked) { background: var(--primary); color: #fff; }
.segmented label:has(input:focus-visible) { outline: 2px solid currentColor; outline-offset: -4px; }
.segmented input[type="radio"] { position: absolute; inset: 0; opacity: 0; margin: 0; pointer-events: none; }
.segmented .count { margin-left: 2px; }
.segmented .active .count, .segmented label:has(input:checked) .count { background: rgba(255, 255, 255, 0.25); color: #fff; }
.work-list .task-table td { padding-top: 12px; padding-bottom: 12px; }
.work-list .task-main { min-width: 200px; }
.work-list .task-for-cell { min-width: 180px; }
.empty-state p { margin: 0; }
.more-later { margin: -8px 0 20px; padding: 10px 14px; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); }
.filter-group { flex-wrap: wrap; }

@media (max-width: 720px) { .segmented a, .segmented label { padding: 6px 10px; } }
@media (max-width: 360px) { .segmented a, .segmented label { padding: 6px 8px; } }

/* A narrow task list (tasks/_task_row.html rows in a .task-list inside a .task-list-box) shows each
   task as a small card: phones, and small laptops where the sidebar takes room. */
.task-list-box { container: task-list / inline-size; }
@container task-list (max-width: 760px) {
  .task-list, .task-list tbody { display: block; }
  .task-list tr.group-row, .task-list tr.group-row th { display: block; }
  .task-list tr.task-row {
    display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; column-gap: 8px; row-gap: 2px;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
  }
  table.task-list tr.task-row > td { padding: 0; border: 0; }  /* beats .table-wrap's first/last-cell padding */
  .task-list .tick-cell { grid-row: 1 / 4; width: auto; }
  .task-list .task-main { grid-column: 2; min-width: 0; }
  .task-list .who-cell { grid-column: 3; grid-row: 1; }
  .task-list .task-for-cell { grid-column: 2 / 4; min-width: 0; }
  .task-list .due-cell { grid-column: 2; white-space: normal; }  /* beside the timer and Not needed buttons */
  .task-list .due-cell div { display: inline; }
  .task-list .due-cell div::before { content: " · "; }
  .task-list .actions-cell { grid-column: 3; }
  .card:not(.table-wrap) > .task-list tr.task-row, .card > details > .task-list tr.task-row { padding-left: 0; padding-right: 0; }  /* the card pads it */
}

/* Time: the timer bar (on every page while a timer runs), timer buttons, the timesheet and the report */
#timer-bar { position: sticky; top: 0; z-index: 25; }
#timer-bar:has(.timer-bar) { margin-top: -8px; padding-top: 8px; background: var(--bg); }  /* nothing shows through above it */
@media (max-width: 899px) { .js #timer-bar { top: 56px; } }  /* below the phone top bar */
.timer-bar {
  display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 16px; padding: 8px 12px;
  border: 1px solid var(--primary); border-radius: var(--radius); background: var(--surface);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08); font-size: 0.92rem;
}
.timer-dot { width: 9px; height: 9px; flex-shrink: 0; border-radius: 50%; background: var(--danger); animation: timer-pulse 1.6s ease-in-out infinite; }
@keyframes timer-pulse { 50% { opacity: 0.3; } }
.timer-clock { font-weight: 700; font-variant-numeric: tabular-nums; }
.timer-what { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
@media (prefers-reduced-motion: reduce) { .timer-dot { animation: none; } }

.btn .icon { width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px; }
.icon.icon-fill { fill: currentColor; stroke: none; }
.timer-toggle {
  display: inline-grid; place-items: center; width: 26px; height: 26px; padding: 0; vertical-align: middle;
  border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--muted); cursor: pointer;
}
.timer-toggle .icon { width: 11px; height: 11px; }
.timer-toggle:not(.is-running) .icon { margin-left: 2px; }  /* the triangle looks centred */
.timer-toggle:hover { color: var(--link); border-color: var(--primary); }
.timer-toggle.is-running { background: var(--danger); border-color: var(--danger); color: #fff; }
.timer-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.actions-cell .timer-toggle { margin-right: 10px; }

.time-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 16px; }
.time-totals { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 20px; margin-bottom: 8px; }
.time-totals a { margin-left: auto; font-size: 0.9rem; }

/* Week grid: hours per client (rows) and day (columns); the client column stays put while a phone scrolls the days. */
.week-grid th, .week-grid td { padding: 9px 10px; }
.week-grid thead th { text-align: right; white-space: nowrap; }
.week-grid thead th:first-child { text-align: left; }
.week-grid abbr { text-decoration: none; }
.week-grid th[scope="row"] { min-width: 170px; text-transform: none; letter-spacing: 0; font-size: 0.92rem; font-weight: 600; color: var(--text); }
.week-grid th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.week-grid .today { background: rgba(59, 106, 224, 0.08); }
.week-grid thead .today { color: var(--link); }
.week-grid .total { font-weight: 700; }
.week-grid tfoot th, .week-grid tfoot td { border-top: 2px solid var(--border); font-weight: 700; }
@media (max-width: 560px) {  /* more room for the days */
  .week-grid th[scope="row"] { min-width: 110px; max-width: 150px; font-size: 0.85rem; }
  .week-grid th, .week-grid td { padding: 8px; }
}

/* Entries by day (timesheet), and on a client's or task's page */
.day-list { padding-top: 6px; padding-bottom: 6px; }
.day + .day { border-top: 1px solid var(--border); }
.day-header { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; padding: 10px 0; }
.day-title { margin: 0; font-size: 0.98rem; }
.day-total { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.entry-list { list-style: none; margin: 0 0 6px; padding: 0; }
.entry { display: flex; align-items: flex-start; gap: 12px; padding: 8px 0; border-top: 1px dashed var(--border); }
.entry-hours { flex: 0 0 3.2rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.entry-main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.entry-main .badge { margin-left: 4px; }
.entry-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Report */
.report-filters .report-dates { display: none; }
.report-filters:has(select[name="period"] option[value="custom"]:checked) .report-dates { display: inline-flex; }
.report-table th[scope="row"] { text-transform: none; letter-spacing: 0; font-size: 0.95rem; font-weight: 600; color: var(--text); }
.report-table .report-subline th[scope="row"] { padding-left: 36px; font-weight: normal; color: var(--muted); }
.report-subline td { color: var(--muted); }
.report-table tfoot th, .report-table tfoot td { border-top: 2px solid var(--border); font-weight: 700; }

/* Typing hours into the week grid. The table scrolls sideways on its own, above the grid's buttons. */
.card.week-grid-card { overflow: visible; }  /* beats .table-wrap's */
.grid-scroll { overflow-x: auto; border-radius: var(--radius) var(--radius) 0 0; }
.week-grid td:has(.hours-input) { padding-left: 4px; padding-right: 4px; }
.hours-input {
  width: 4.2em; padding: 4px 6px; text-align: right; font-variant-numeric: tabular-nums;
  border-color: transparent; background: var(--bg);
}
.hours-input:hover { border-color: var(--border); }
.hours-input:focus { background: var(--surface); }
.week-grid td.has-error .hours-input { border-color: var(--danger); background: var(--error-bg); }
.cell-error { display: block; max-width: 7em; margin-top: 2px; margin-left: auto; font-size: 0.72rem; line-height: 1.2; color: var(--danger); white-space: normal; }
.cell-fixed { cursor: help; border-bottom: 1px dotted var(--muted); }
.grid-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 20px; border-top: 1px solid var(--border); }
.grid-add { flex-wrap: wrap; }
.grid-add select { max-width: 280px; }
.grid-dirty { display: none; color: var(--warning-text); font-weight: 600; }
.week-grid-card.is-dirty .grid-dirty { display: inline; }

/* Where the week's timesheet stands (not submitted, submitted, approved, returned) */
.week-status {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  margin-bottom: 16px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.week-status-text { margin: 0; flex: 1; min-width: 220px; }
.week-status.is-submitted { border-color: var(--primary); }
.week-status.is-approved { border-color: var(--success-text); background: var(--success-bg); }
.week-status.is-returned { border-color: #d98a1c; background: #fdf0dc; }
@media (prefers-color-scheme: dark) { .week-status.is-returned { background: #3a2a14; } }
.return-week > summary { list-style: none; }
.return-week > summary::-webkit-details-marker { display: none; }
/* Opened, "Return…" takes a line of its own for the note (a popover would run off a phone's screen). */
.week-status .actions:has(.return-week[open]), .return-week[open] { flex-basis: 100%; }
.return-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.return-form input { flex: 1; min-width: 180px; }

.form-notice { padding: 10px 14px; border: 1px solid #d98a1c; border-radius: var(--radius); background: #fdf0dc; color: #6b3b00; }
@media (prefers-color-scheme: dark) { .form-notice { background: #3a2a14; color: #f3c27a; } }
fieldset.form-grid { border: 0; padding: 0; margin: 0; min-width: 0; }
.badge.badge-billed { background: var(--success-bg); color: var(--success-text); }
.badge.badge-returned { background: #fdf0dc; color: #8f4d00; }
@media (prefers-color-scheme: dark) { .badge.badge-returned { background: #3a2a14; color: #f3c27a; } }
.unrated { margin-left: 2px; color: var(--warning-text); cursor: help; }
.table-card-heading { margin: 0; padding: 16px 20px 4px; }
.table-card-empty { margin: 0; padding: 8px 20px 20px; }

/* Log time form: "Non-billable" only means something for client time. */
.time-form:has(select[name="time-entity"] option[value=""]:checked) .field-non-billable { display: none; }
.field-non-billable { column-gap: 12px; }
.actions .push-right { margin-left: auto; }

/* Modal dialog (static/js/app.js) */
.modal {
  padding: 0; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal::backdrop { background: rgba(16, 22, 32, 0.45); }
.modal-card { padding: 20px 24px 24px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.modal-header h2 { margin: 0; font-size: 1.2rem; }
.modal-close { background: none; border: 0; font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); color: var(--text); }

/* Task form: two columns, the client/engagement/deadline block re-rendered when it changes */
.task-form { max-width: none; }
.form-grid, .task-links, .time-links { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 16px; }
.form-grid .span-2 { grid-column: span 2; }
.task-links noscript, .time-links noscript { grid-column: 1 / -1; }  /* the no-JS hint spans however many columns there are */
.task-page-form { max-width: 680px; }
@media (max-width: 560px) {
  .form-grid, .task-links, .time-links { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
}
.missing-steps { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.progress-cell { min-width: 160px; }
.checklist { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0 16px; }
.checklist legend { font-weight: 700; padding: 0 6px; }
.checklist-table th, .checklist-table td { padding: 6px 6px; }
.checklist-table input[type="text"] { width: 100%; min-width: 180px; }
.checklist-table .days input { width: 5rem; }
.checklist-table select { max-width: 220px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.checklist { min-width: 0; }  /* a fieldset otherwise grows to fit its table */
.checklist-rows { container: checklist / inline-size; overflow-x: auto; }
@media (min-width: 721px) {
  .sr-only-wide { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
/* A narrow checklist (phones, small laptops) shows each step as a stack of labelled fields. */
@container checklist (max-width: 840px) {
  .checklist-table thead { display: none; }
  .checklist-table, .checklist-table tbody, .checklist-table tr, .checklist-table td { display: block; }
  .checklist-table tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .checklist-table tbody tr:last-child { border-bottom: 0; }
  .checklist-table td, .card > .checklist-table td:first-child { padding: 4px 0; border: 0; text-align: left; }
  .checklist-table td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 2px; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
  .checklist-table input[type="text"], .checklist-table select { width: 100%; max-width: none; min-width: 0; }
}

/* Workspace picker */
.workspace-list { list-style: none; margin: 16px 0 0; padding: 0; max-width: 640px; }
.workspace-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; padding: 16px 20px; }
.workspace-card.current { border-color: var(--primary); }
.workspace-name { font-weight: 600; font-size: 1.05rem; }
.workspace-info { flex: 1; min-width: 0; }
.workspace-logo { width: 44px; height: 44px; object-fit: contain; border-radius: 6px; background: #fff; border: 1px solid var(--border); padding: 3px; }

/* Firm logo */
.logo-preview { margin-bottom: 12px; }
.logo-preview img { max-width: 220px; max-height: 90px; object-fit: contain; border: 1px solid var(--border); border-radius: 6px; padding: 8px; background: #fff; }

/* Settings pages */
.settings-form { max-width: 680px; }
.settings-form.engagement-page { max-width: 960px; }
.engagement-page .form { max-width: none; }
.engagement-page .form > .field { max-width: 600px; }
.settings-form .card { scroll-margin-top: 16px; }
.item-list { list-style: none; margin: 0 0 8px; padding: 0; }
.item-list .item { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.item-list .item:last-child { border-bottom: 0; }
.item-title { font-weight: 600; }
.item-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.logo-grid .item { flex-direction: column; align-items: stretch; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.logo-grid .item:last-child { border-bottom: 1px solid var(--border); }
.logo-grid .item.is-default { border-color: var(--primary); }
.logo-grid .item-actions { justify-content: flex-start; }
.logo-thumb { width: 100%; height: 80px; object-fit: contain; background: #fff; border-radius: 6px; }

/* Settings: a menu panel beside the section being edited (a row of chips on smaller screens) */
.settings-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-menu {
  position: sticky; top: 20px; display: flex; flex-direction: column; gap: 14px; padding: 10px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.settings-menu-group { display: flex; flex-direction: column; gap: 2px; }
.settings-menu-heading { padding: 4px 10px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.settings-menu a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 6px; color: var(--text); font-size: 0.93rem; }
.settings-menu a .icon { width: 16px; height: 16px; color: var(--muted); }
.settings-menu a:hover { background: var(--bg); text-decoration: none; }
.settings-menu a.active { background: #e7eefc; color: var(--primary); font-weight: 600; }
.settings-menu a.active .icon { color: var(--primary); }
@media (prefers-color-scheme: dark) { .settings-menu a.active { background: #1c2a47; color: #9bb8f5; } }
.settings-body { min-width: 0; max-width: 720px; }
.settings-body > h2 { font-size: 1.25rem; margin-bottom: 4px; }
.settings-body > .section-intro { margin: 0 0 16px; }
.settings-body .form { max-width: none; }  /* as wide as the list cards */
.card-heading { margin: 0 0 12px; font-size: 1rem; }
.item-with-icon { display: flex; gap: 12px; align-items: flex-start; min-width: 0; }
.item-with-icon > .icon { margin-top: 3px; color: var(--muted); }
@media (max-width: 1099px) {
  .settings-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .settings-menu { position: static; flex-direction: row; flex-wrap: wrap; gap: 6px; padding: 0; border: 0; background: none; }
  .settings-menu-group { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .settings-menu-heading { display: none; }
  .settings-menu a { white-space: nowrap; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
  .settings-menu a.active { border-color: var(--primary); }
}

/* Sign-in and invite pages */
.auth-page { max-width: 400px; margin: 10vh auto; padding: 0 16px; }
.auth-brand { font-size: 1.5rem; font-weight: 700; text-align: center; margin-bottom: 20px; }
.auth-card h1 { font-size: 1.3rem; margin-bottom: 16px; }
.auth-card .form { max-width: none; }
.btn-block { width: 100%; }
.card.notice { border-color: var(--primary); }
.invite-link { display: flex; gap: 8px; margin-top: 8px; }
.invite-link input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: 0.85rem; }

/* Building blocks */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.right { text-align: right; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.plain-list li:last-child { border-bottom: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat { display: flex; flex-direction: column; color: var(--text); }
.stat:hover { text-decoration: none; border-color: var(--primary); }
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--muted); }

/* Buttons */
.btn {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-outline { color: var(--danger); }
.btn-danger-outline:hover { border-color: var(--danger); }
.btn-small { padding: 3px 10px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Tables */
.table-wrap { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
.card > table th:first-child, .card > table td:first-child { padding-left: 0; }
.card > table th:last-child, .card > table td:last-child { padding-right: 0; }
.table-wrap table th:first-child, .table-wrap table td:first-child { padding-left: 20px; }
.table-wrap table th:last-child, .table-wrap table td:last-child { padding-right: 20px; }
.card > .table-scroll > table th:first-child, .card > .table-scroll > table td:first-child,
.card > details > .table-scroll > table th:first-child, .card > details > .table-scroll > table td:first-child { padding-left: 0; }
.card > .table-scroll > table th:last-child, .card > .table-scroll > table td:last-child,
.card > details > .table-scroll > table th:last-child, .card > details > .table-scroll > table td:last-child { padding-right: 0; }
@media (max-width: 720px) { .hide-sm { display: none; } }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--border);
  color: var(--muted);
}
.badge-active { background: var(--success-bg); color: var(--success-text); }
.badge-prospect { background: #e7eefc; color: #2458d6; }
@media (prefers-color-scheme: dark) { .badge-prospect { background: #1c2a47; color: #9bb8f5; } }

.details { display: grid; grid-template-columns: 180px 1fr; gap: 10px 16px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 720px) { .details { grid-template-columns: 1fr; gap: 2px; } .details dd { margin-bottom: 10px; } }

/* Forms */
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input[type="search"] { flex: 1; min-width: 200px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
select { max-width: 100%; }  /* long options (client names) can't widen the page */

.form { max-width: 640px; }
.form .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.form .field input:not([type="checkbox"]):not([type="radio"]), .form .field select, .form .field textarea { width: 100%; }
/* Radio groups (rendered by Django as a fieldset) */
.field fieldset { border: 0; padding: 0; margin: 0; }
.field fieldset legend { font-weight: 600; font-size: 0.9rem; padding: 0; margin-bottom: 4px; }
.field fieldset label { display: inline-flex; gap: 8px; align-items: center; font-weight: normal; font-size: 0.95rem; }
.field fieldset > div > div { margin: 2px 0; }
.field label { font-weight: 600; font-size: 0.9rem; }
.field .helptext { color: var(--muted); font-size: 0.85rem; }
.field:has(input[type="checkbox"]) { flex-direction: row; align-items: center; flex-wrap: wrap; }

.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { display: flex; flex-direction: column; gap: 4px; min-width: 0; max-width: 100%; }
/* Inline forms use placeholders instead; help text would misalign the row. */
.inline-form .helptext { display: none; }

/* Entity form: the household fields only for an individual */
.form:has(select[name="entity_type"]) .field:not(.has-error):has([name="household_head"], [name="household_role"]) { display: none; }
.form:has(select[name="entity_type"] option[value="individual"]:checked) .field:has([name="household_head"], [name="household_role"]) { display: flex; }

/* Share register entry form: show From/To only for the types that use them */
.txn-form .field-from_party, .txn-form .field-to_party { display: none; }
.txn-form:has(select[name="transaction_type"] option[value="issue"]:checked) .field-to_party,
.txn-form:has(select[name="transaction_type"] option[value="transfer"]:checked) .field-from_party,
.txn-form:has(select[name="transaction_type"] option[value="transfer"]:checked) .field-to_party,
.txn-form:has(select[name="transaction_type"] option[value="redemption"]:checked) .field-from_party { display: flex; }
.txn-form input[type="number"] { width: 8rem; }

.section-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-header h2, .section-header .filters { margin: 0; }
.section-header .filters { align-items: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.table-scroll { overflow-x: auto; }
tr.future { opacity: 0.45; }
form.inline { display: inline; }
details.past { margin-top: 12px; }
details.past summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }

.warning { color: var(--warning-text); }

.errorlist { list-style: none; margin: 0 0 8px; padding: 0; color: var(--danger); font-size: 0.9rem; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }

/* Messages: toasts in the corner, so they show wherever the page is scrolled; confirmations fade out. */
#messages { position: fixed; right: 20px; bottom: 20px; z-index: 35; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.message {
  padding: 10px 14px; border-radius: 6px; background: var(--success-bg); color: var(--success-text);
  border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); pointer-events: auto;
}
.message-success { animation: message-out 0.4s ease 6s forwards; }
.message-error { background: var(--error-bg); color: var(--danger); }
.message-info { background: var(--surface); color: var(--text); animation: message-out 0.4s ease 6s forwards; }
.message-warning { background: #fdf0dc; color: #8f4d00; }
@media (prefers-color-scheme: dark) { .message-warning { background: #3a2a14; color: #f3c27a; } }
@keyframes message-out { to { opacity: 0; visibility: hidden; } }
@media (max-width: 720px) { #messages { right: 16px; bottom: 16px; } }
@media (prefers-reduced-motion: reduce) { .message-success, .message-info { animation-duration: 0s; } }

/* htmx: dim results while a search request is in flight */
.results { transition: opacity 150ms; }
.results.htmx-request { opacity: 0.55; }

.pagination { display: flex; gap: 12px; align-items: center; justify-content: center; }

/* Print: just the page content */
@media print {
  .topbar, .sidebar, .skip-link, .nav-backdrop, #messages, #timer-bar { display: none !important; }
  .layout { display: block; }
  .content { max-width: none; padding: 0; }
}

/* Page subtitles (under an h1), links that look like text, a label that isn't a <label> */
.page-subtitle { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 4px 0 0; color: var(--muted); }
.plain-link { color: var(--text); }
.plain-link:hover { color: var(--link); }
.field-label { font-weight: 600; font-size: 0.9rem; }
form.is-dirty .grid-dirty { display: inline; }  /* forms with data-unsaved-guard (static/js/app.js) */

/* --- Billing ------------------------------------------------------------------------------------ */
.billing-stats { margin-bottom: 16px; }
.billing-stats .stat-value { font-size: 1.6rem; }
.billing-notes {
  display: flex; flex-direction: column; gap: 4px; list-style: none; margin: 0 0 16px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 0.92rem;
}
.billing-source { display: flex; align-items: center; gap: 8px; margin: -8px 0 16px; color: var(--muted); font-size: 0.9rem; }
.billing-source .icon { width: 16px; height: 16px; }
h1 .badge { vertical-align: middle; font-size: 0.8rem; }
.payment-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.invoice-table td, .payment-table td { vertical-align: middle; }

/* Where an invoice stands (models.Invoice.state) */
.badge-inv-unpaid { background: #e7eefc; color: #2458d6; }
.badge-inv-partly_paid { background: #fdf0dc; color: #8f4d00; }
.badge-inv-overdue { background: var(--error-bg); color: var(--danger); }
.badge-inv-paid { background: var(--success-bg); color: var(--success-text); }
.badge-inv-void { text-decoration: line-through; }
@media (prefers-color-scheme: dark) {
  .badge-inv-unpaid { background: #1c2a47; color: #9bb8f5; }
  .badge-inv-partly_paid { background: #3a2a14; color: #f3c27a; }
}

/* Billed and received by month: two series in the reference palette's first two slots, checked with the
   dataviz palette validator against this app's light and dark card surfaces. */
.rev-card { --series-1: #2a78d6; --series-2: #eb6834; --chart-grid: #eceef1; --chart-base: #c3c8d0; }
@media (prefers-color-scheme: dark) {
  .rev-card { --series-1: #3987e5; --series-2: #d95926; --chart-grid: #262e3a; --chart-base: #3a4452; }
}
.rev-card .is-billed { --series: var(--series-1); }
.rev-card .is-received { --series: var(--series-2); }
.rev-legend { display: flex; flex-wrap: wrap; gap: 4px 18px; list-style: none; margin: 0; padding: 0; font-size: 0.88rem; }
.rev-legend li { display: inline-flex; align-items: center; gap: 6px; }
.rev-key { width: 10px; height: 10px; border-radius: 2px; background: var(--series); }
.rev-plot { position: relative; height: 240px; margin-top: 18px; }
.rev-grid { position: absolute; top: 0; right: 0; bottom: 26px; left: 52px; display: flex; flex-direction: column; justify-content: space-between; }
.rev-gridline { position: relative; border-top: 1px solid var(--chart-grid); }
.rev-gridline:last-child { border-top-color: var(--chart-base); }
.rev-tick {
  position: absolute; right: calc(100% + 8px); top: -0.55em; font-size: 0.72rem; line-height: 1; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.rev-months {
  position: absolute; top: 0; right: 0; bottom: 0; left: 52px; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr));
  list-style: none; margin: 0; padding: 0;
}
.rev-month { position: relative; display: grid; grid-template-rows: minmax(0, 1fr) 26px; border-radius: 6px; outline: none; cursor: default; }
.rev-bars { display: flex; align-items: flex-end; justify-content: center; gap: 2px; min-height: 0; border-radius: 6px 6px 0 0; }
.rev-bar { width: min(18px, 36%); border-radius: 4px 4px 0 0; background: var(--series); }
.rev-month-label { align-self: center; text-align: center; font-size: 0.75rem; color: var(--muted); }
.rev-month:hover .rev-bars, .rev-month:focus-visible .rev-bars { background: rgba(127, 137, 150, 0.12); }
.rev-month:focus-visible { box-shadow: inset 0 0 0 2px var(--primary); }
.rev-tip {
  position: absolute; top: -6px; left: 50%; z-index: 5; display: none; flex-direction: column; gap: 3px; min-width: 170px;
  padding: 8px 10px; transform: translate(-50%, -100%); border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); font-size: 0.82rem; white-space: nowrap; pointer-events: none;
}
.rev-month:hover .rev-tip, .rev-month:focus-visible .rev-tip { display: flex; }
.rev-month:nth-child(-n+2) .rev-tip { left: 0; transform: translate(0, -100%); }
.rev-month:nth-last-child(-n+2) .rev-tip { left: auto; right: 0; transform: translate(0, -100%); }
.rev-tip-title { font-weight: 600; color: var(--muted); }
.rev-tip strong { margin-right: 4px; color: var(--text); font-variant-numeric: tabular-nums; }
.rev-line { display: inline-block; width: 12px; height: 2px; margin-right: 6px; vertical-align: middle; background: var(--series); }
.rev-table { margin-top: 14px; }
.rev-table summary { cursor: pointer; color: var(--link); font-size: 0.9rem; }
.rev-table table { margin-top: 8px; }

/* An invoice as the client sees it (and prints) */
.invoice-doc { max-width: 820px; padding: 40px 44px; }
.inv-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 28px; }
.inv-firm { font-size: 0.9rem; line-height: 1.45; color: var(--muted); }
.inv-logo { display: block; max-width: 180px; max-height: 70px; margin-bottom: 10px; object-fit: contain; }
.inv-firm-name { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.inv-meta { margin-left: auto; text-align: right; }
.inv-title { margin-bottom: 8px; font-size: 1.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.inv-stamp {
  display: inline-block; margin-left: 8px; padding: 1px 8px; border: 2px solid var(--danger); border-radius: 6px;
  color: var(--danger); font-size: 0.9rem; letter-spacing: 0.08em; vertical-align: middle;
}
.inv-meta dl { display: grid; grid-template-columns: auto auto; justify-content: end; gap: 2px 14px; margin: 0; font-size: 0.92rem; }
.inv-meta dt { color: var(--muted); }
.inv-meta dd { margin: 0; font-weight: 600; text-align: right; }
.inv-to { margin-bottom: 24px; }
.inv-label { margin-bottom: 4px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.inv-client { font-weight: 700; }
.inv-lines { margin-bottom: 20px; font-variant-numeric: tabular-nums; }
.inv-lines th, .inv-lines td { padding: 9px 8px; }
.inv-lines thead th { border-bottom: 2px solid var(--text); color: var(--text); }
.inv-lines tfoot th, .inv-lines tfoot td { padding-top: 5px; padding-bottom: 5px; border-bottom: 0; }
.inv-lines tfoot th { text-align: right; text-transform: none; letter-spacing: 0; font-size: 0.95rem; font-weight: 500; color: var(--text); }
.inv-lines tfoot tr:first-child th, .inv-lines tfoot tr:first-child td { padding-top: 14px; }
.inv-lines .inv-total th, .inv-lines .inv-total td { border-top: 1px solid var(--text); font-weight: 700; }
.inv-lines .inv-balance th, .inv-lines .inv-balance td { font-weight: 700; }
.inv-notes { margin-bottom: 16px; }
.inv-footer { padding-top: 14px; border-top: 1px solid var(--border); font-size: 0.85rem; color: var(--muted); }
.invoice-extras { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 20px; max-width: 820px; }
@media (max-width: 900px) { .invoice-extras { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 720px) {
  .invoice-doc { padding: 22px 16px; }
  .inv-meta { margin-left: 0; text-align: left; }
  .inv-meta dl { justify-content: start; }
  .inv-meta dd { text-align: left; }
}

/* The invoice form: its fees as rows, totalled as they're typed (static/js/app.js) */
.invoice-form { max-width: 980px; }
.invoice-form-heading { margin: 8px 0 6px; font-size: 1rem; }
.invoice-lines { min-width: 640px; }
.invoice-lines th, .invoice-lines td { padding: 6px 6px; border-bottom: 0; }
.invoice-lines td:first-child input { width: 100%; min-width: 200px; }
.invoice-lines input[type="number"] { width: 8rem; text-align: right; }
.invoice-lines tfoot th, .invoice-lines tfoot td { padding-top: 4px; padding-bottom: 4px; }
.invoice-lines tfoot tr:first-child th, .invoice-lines tfoot tr:first-child td { padding-top: 10px; border-top: 2px solid var(--border); }
.invoice-lines tfoot tr:last-child { font-weight: 700; }
.invoice-line.has-error input { border-color: var(--danger); }
.invoice-lines .errorlist { margin: 2px 0 0; font-size: 0.8rem; }

@media print {
  .invoice-page-header, .invoice-extras, .billing-source { display: none !important; }
  .invoice-doc { max-width: none; margin: 0; padding: 0; border: 0; background: #fff; }
  .invoice-doc, .invoice-doc th, .invoice-doc td, .invoice-doc dt, .invoice-doc .inv-firm, .invoice-doc .inv-label, .invoice-doc .inv-footer { color: #000; }
}

/* Billing overview: last year's figure under the Billed and Received cards, the two breakdown cards side
   by side, the row for the chosen client type; the invoice form's service column. */
.stat-change { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.stat-delta.is-up { color: var(--success-text); font-weight: 600; }
.stat-delta.is-down { color: var(--danger); font-weight: 600; }
.report-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; margin-bottom: 16px; }
.report-pair > .card { margin-bottom: 0; }
.report-table tr.is-selected th, .report-table tr.is-selected td { background: var(--bg); }
.overview-pagination { padding: 8px 20px 16px; }
.invoice-line-service select { width: 8.5rem; min-width: 0; }

/* --- Client portal: the firm's pages ------------------------------------------------------------- */
/* The sidebar's count of documents that need the firm (new from clients, changes asked for) */
.nav-badge {
  margin-left: auto; min-width: 1.6em; padding: 0 6px; border-radius: 999px; background: var(--primary); color: #fff;
  font-size: 0.72rem; font-weight: 700; line-height: 1.6; text-align: center;
}
.sidebar-hidden .nav-badge { display: none; }

/* What needs attention: counts that filter the list */
.attention-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.attention-stat { margin-bottom: 0; padding: 14px 16px; border-top: 3px solid var(--border); }
.attention-stat .stat-value { font-size: 1.5rem; line-height: 1.2; }
.attention-stat .stat-label { font-size: 0.88rem; }
.attention-stat.is-waiting { border-top-color: #d98a1c; }
.attention-stat.is-changes { border-top-color: var(--danger); }
.attention-stat.is-new { border-top-color: var(--primary); }
.attention-stat.is-zero .stat-value { color: var(--muted); }
.attention-stat.is-selected { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.attention-chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0 0 16px; padding: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); font-size: 0.88rem;
}
.chip:hover { text-decoration: none; border-color: var(--muted); }
.chip.is-waiting { border-color: #d98a1c; }
.chip.is-changes { border-color: var(--danger); color: var(--danger); }
.chip.is-new { border-color: var(--primary); color: var(--link); }

/* Where a document stands */
.badge.badge-new, .badge.badge-portal, .badge.badge-progress { background: #e7eefc; color: #2458d6; }
.badge.badge-waiting { background: #fdf0dc; color: #8f4d00; }
.badge.badge-you { background: none; box-shadow: inset 0 0 0 1px var(--border); color: var(--text); }
.badge.badge-past-due { background: var(--error-bg); color: var(--danger); }
.badge.badge-approved { background: var(--success-bg); color: var(--success-text); }
.badge.badge-changes { background: var(--error-bg); color: var(--danger); }
.badge.badge-invited { background: #efe9fe; color: #6d3fd6; }
.badge .icon { width: 12px; height: 12px; margin-right: 3px; vertical-align: -1px; }
@media (prefers-color-scheme: dark) {
  .badge.badge-new, .badge.badge-portal, .badge.badge-progress { background: #1c2a47; color: #9bb8f5; }
  .badge.badge-waiting { background: #3a2a14; color: #f3c27a; }
  .badge.badge-invited { background: #2a2145; color: #c4b0fb; }
}
.vis { display: inline-flex; align-items: center; gap: 5px; font-size: 0.88rem; font-weight: 600; white-space: nowrap; }
.vis .icon { width: 15px; height: 15px; }
.vis-shared { color: var(--success-text); }
.vis-firm { color: var(--muted); }
.vis-client { color: var(--link); }
.vis-date { display: block; }

/* A file: its type as a coloured label, then its name */
.file-badge {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; min-width: 38px; height: 22px;
  padding: 0 5px; border-radius: 5px; background: #667085; color: #fff; font-size: 0.66rem; font-weight: 800;
  letter-spacing: 0.04em; line-height: 1;
}
.file-badge.file-pdf { background: #c8372d; }
.file-badge.file-sheet { background: #1e7e45; }
.file-badge.file-doc { background: #2b579a; }
.file-badge.file-image { background: #7c4ddb; }
.file-badge.file-mail { background: #a35f00; }

/* The firm's list of documents; narrow, each document becomes a small card */
.doc-list-box { container: doc-list / inline-size; }
.doc-table td { vertical-align: middle; }
.doc-table .badge { white-space: nowrap; }
.doc-main { min-width: 240px; }
.doc-title-line { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; }
.doc-title { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.doc-title:hover { color: var(--link); }
.doc-meta { margin-top: 3px; }
.doc-note, .doc-opened { display: flex; align-items: flex-start; gap: 6px; margin-top: 4px; }
.doc-note .icon, .doc-opened .icon { width: 14px; height: 14px; margin-top: 2px; flex-shrink: 0; color: var(--muted); }
.doc-note { color: var(--text); }
.doc-actions { text-align: right; white-space: nowrap; }
.btn.icon-only .icon { margin-right: 0; }
.btn-share { border-color: var(--success-text); color: var(--success-text); }
.btn-share:hover { border-color: var(--success-text); background: var(--success-bg); }
.doc-row.is-new td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
@container doc-list (max-width: 760px) {
  .doc-table thead { display: none; }
  .doc-table, .doc-table tbody { display: block; }
  .doc-table tr.doc-row {
    display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 14px 20px; border-bottom: 1px solid var(--border);
  }
  .doc-table tbody tr.doc-row:last-child { border-bottom: 0; }
  .doc-list-box table.doc-table tr.doc-row > td { padding: 0; border: 0; min-width: 0; }
  .doc-table .doc-vis .vis-date { display: inline; margin-left: 6px; }
  .doc-table .doc-actions { text-align: left; margin-top: 4px; }
  .doc-table tr.doc-row.is-new { box-shadow: inset 3px 0 0 var(--primary); }
  .doc-table tr.doc-row.is-new td:first-child { box-shadow: none; }
  .card:not(.table-wrap) > .doc-list-box .doc-table tr.doc-row { padding-left: 0; padding-right: 0; }  /* the card pads it */
}
.card:not(.table-wrap) > .doc-list-box .doc-table th:first-child, .card:not(.table-wrap) > .doc-list-box .doc-table td:first-child { padding-left: 0; }
.card:not(.table-wrap) > .doc-list-box .doc-table th:last-child, .card:not(.table-wrap) > .doc-list-box .doc-table td:last-child { padding-right: 0; }
.doc-section .section-header h2 { display: flex; align-items: center; gap: 8px; }
.doc-section-empty .empty-engagement { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* A client's page: the portal section */
.portal-signin-line { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 12px; }
.portal-signin-line .icon { margin-top: 3px; color: var(--muted); }
.recent-docs li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.recent-docs .doc-title-line { flex: 1 1 260px; min-width: 0; }

/* Who can sign in; copying invite links */
.access-table td { vertical-align: middle; }
.copy-field { display: flex; gap: 8px; align-items: center; margin: 6px 0 4px; max-width: 560px; }
.copy-field input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: 0.82rem; }
.portal-link-card .item-with-icon { align-items: flex-start; }
.portal-link-card .item-with-icon > div { flex: 1; min-width: 0; }
.portal-closed-notice { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 16px; }
.portal-closed-notice .icon { margin-top: 2px; }

/* Uploading: a box to choose files or drop them on */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 112px; padding: 18px; border: 2px dashed var(--border); border-radius: 10px; background: var(--bg);
  color: var(--muted); text-align: center; cursor: pointer; font-weight: normal;
}
.dropzone:hover, .dropzone.is-dragging { border-color: var(--primary); color: var(--text); }
.dropzone.is-dragging { background: rgba(59, 106, 224, 0.08); }
.dropzone:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.dropzone .icon { width: 26px; height: 26px; color: var(--primary); }
.dropzone-text strong { color: var(--link); }
.dropzone-files { color: var(--text); font-size: 0.88rem; font-weight: 600; overflow-wrap: anywhere; }
.dropzone.has-files { border-style: solid; border-color: var(--primary); }
.dropzone input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.has-error .dropzone { border-color: var(--danger); }
.upload-form { max-width: none; }
.doc-links { margin-bottom: 4px; }
.visibility-field fieldset > div { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.upload-page { max-width: 720px; }

/* Yes/no settings: what it is and what it does, with a switch (portal/_toggle.html) */
.toggle-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 11px 0; }
.toggle-row + .toggle-row { border-top: 1px solid var(--border); }
.toggle-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; cursor: pointer; }
.toggle-label { font-weight: 600; font-size: 0.95rem; }
.toggle-help { color: var(--muted); font-size: 0.85rem; font-weight: normal; }
input.switch {
  -webkit-appearance: none; appearance: none; position: relative; flex-shrink: 0; width: 40px; height: 23px; margin: 1px 0 0;
  padding: 0; border: 0; border-radius: 999px; background: #c3c8d0; cursor: pointer; transition: background 0.15s;
}
input.switch::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.15s;
}
input.switch:checked { background: var(--primary); }
input.switch:checked::before { transform: translateX(17px); }
input.switch:focus { outline: none; }
input.switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-color-scheme: dark) { input.switch { background: #3a4452; } }
@media (prefers-reduced-motion: reduce) { input.switch, input.switch::before { transition: none; } }
.form .toggle-row { margin-bottom: 4px; }
.portal-settings .sub-fields { margin: 0 0 6px 18px; padding: 2px 0 2px 16px; }
.portal-settings .sub-fields .field { margin: 8px 0 4px; }
.portal-settings:has(#id_show_deadlines:not(:checked)) .sub-fields { opacity: 0.5; }

/* A document's page, the portal settings */
.client-note { margin: 8px 0 0; padding: 8px 12px; border-left: 3px solid var(--border); background: var(--bg); border-radius: 0 6px 6px 0; }
.compact-list li { padding: 4px 0; }
.approval-actions { margin-top: 8px; }
.sub-fields { margin: -6px 0 12px 26px; padding-left: 12px; border-left: 2px solid var(--border); }
.portal-settings .card { max-width: none; }
.portal-intro .steps { margin: 12px 0 16px; padding-left: 20px; }
.portal-intro .steps li { margin-bottom: 8px; }
.portal-intro .steps li::marker { color: var(--primary); font-weight: 700; }

/* --- Client portal: what the client sees ------------------------------------------------------- */
body.portal-page { min-height: 100vh; display: flex; flex-direction: column; }
.portal-preview-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 20px; background: #fdf0dc; color: #6b3b00;
  font-size: 0.9rem; border-bottom: 1px solid #f0cf9b;
}
.portal-preview-bar > span { flex: 1; min-width: 220px; }
@media (prefers-color-scheme: dark) { .portal-preview-bar { background: #3a2a14; color: #f3c27a; border-bottom-color: #5a4220; } }

.portal-header { position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--border); }
.portal-bar { display: flex; align-items: center; gap: 16px; max-width: 1040px; margin: 0 auto; padding: 10px 20px; }
.portal-brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 1.05rem; flex-shrink: 0; }
.portal-brand:hover { text-decoration: none; }
.portal-logo { display: block; max-height: 38px; max-width: 170px; object-fit: contain; }
.portal-client { flex: 1; min-width: 0; display: flex; }
.client-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 16px; border-left: 1px solid var(--border); }
.client-button {
  display: flex; align-items: center; gap: 10px; max-width: 100%; padding: 5px 10px; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; color: var(--text);
}
.client-button:hover, .client-menu[open] > .client-button { border-color: var(--muted); }
.client-button-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.client-button-label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.client-button-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-button .chevron { width: 16px; height: 16px; color: var(--muted); transition: transform 0.15s; }
.client-menu[open] .chevron { transform: rotate(180deg); }
.client-menu { min-width: 0; }
.client-menu .menu-panel { right: auto; min-width: 260px; max-width: calc(100vw - 32px); }
.account-button { display: block; border-radius: 50%; cursor: pointer; }
.account-button:focus-visible, .client-button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.portal-page .avatar { background: var(--primary); }
.account-menu { flex-shrink: 0; }
.account-menu .menu-panel { left: auto; right: 0; min-width: 220px; }

.portal-nav { border-top: 1px solid var(--border); }
.portal-nav-inner { display: flex; gap: 22px; max-width: 1040px; margin: 0 auto; padding: 0 20px; overflow-x: auto; scrollbar-width: none; }
.portal-nav a {
  position: relative; display: inline-flex; align-items: center; gap: 7px; padding: 11px 0 9px; border-bottom: 2px solid transparent;
  color: var(--muted); font-weight: 500; white-space: nowrap;
}
.portal-nav a .icon { width: 17px; height: 17px; }
.portal-nav a:hover { color: var(--text); text-decoration: none; }
.portal-nav a.active { color: var(--text); font-weight: 600; border-bottom-color: var(--primary); }
.portal-nav a.active .icon { color: var(--primary); }
.portal-nav a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.nav-count {
  min-width: 1.5em; padding: 0 6px; border-radius: 999px; background: var(--primary); color: #fff;
  font-size: 0.7rem; font-weight: 700; line-height: 1.6; text-align: center;
}

.portal-main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 24px 20px 40px; }
.portal-main:focus { outline: none; }
.portal-page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.portal-page-header h1 { font-size: 1.55rem; }
.portal-page-header p { margin: 4px 0 0; }
.portal-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }
.portal-footer-inner { display: flex; flex-wrap: wrap; gap: 4px 18px; max-width: 1040px; margin: 0 auto; padding: 16px 20px; }
.portal-footer strong { color: var(--text); }

/* Overview */
.portal-welcome { display: flex; gap: 12px; align-items: flex-start; border-left: 3px solid var(--primary); }
.portal-welcome > .icon { color: var(--primary); margin-top: 2px; }
.portal-welcome p { margin: 0 0 8px; }
.portal-welcome p:last-child { margin-bottom: 0; }
.portal-glance { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.glance { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 14px 16px; color: var(--text); border-top: 3px solid var(--border); }
.glance:hover { text-decoration: none; border-color: var(--primary); }
.glance.is-new { border-top-color: var(--primary); }
.glance.is-alert { border-top-color: #d98a1c; }
.glance-value { font-size: 1.45rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.glance-label { color: var(--muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.portal-attention { border-color: #d98a1c; }
.portal-attention h2, .portal-callout { display: flex; align-items: center; gap: 8px; }
.portal-attention h2 .icon { color: #d98a1c; }
.portal-columns { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 0 20px; align-items: start; }
@media (max-width: 900px) { .portal-columns { grid-template-columns: minmax(0, 1fr); } }
.portal-narrow { max-width: 560px; }

/* Documents */
.portal-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.portal-filters input[type="search"] { flex: 1; min-width: 200px; }
.portal-callout { margin: 0 0 16px; padding: 10px 14px; border: 1px solid #d98a1c; border-radius: var(--radius); background: #fdf0dc; color: #6b3b00; }
@media (prefers-color-scheme: dark) { .portal-callout { background: #3a2a14; color: #f3c27a; } }
.portal-year-title { display: flex; align-items: center; gap: 8px; font-size: 1.2rem; margin-bottom: 4px; }
.portal-section-title {
  margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
.portal-year-title + .portal-section-title { border-top: 0; margin-top: 8px; padding-top: 0; }
.portal-doc-list { list-style: none; margin: 0; padding: 0; }
.portal-doc {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 12px; align-items: start; padding: 12px 0;
  border-bottom: 1px solid var(--border); scroll-margin-top: 130px;
}
.portal-doc:last-child { border-bottom: 0; }
.portal-doc > .file-badge { margin-top: 1px; }
.portal-doc-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.portal-doc-title { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.portal-doc-title:hover { color: var(--link); }
.portal-doc-meta { margin-top: 2px; }
.portal-doc-main > p { margin: 4px 0 0; }
.portal-doc-message { display: flex; gap: 8px; margin: 8px 0 0; padding: 8px 12px; border-radius: 6px; background: var(--bg); font-size: 0.92rem; }
.portal-doc-message .icon { width: 15px; height: 15px; margin-top: 3px; color: var(--muted); }
.portal-doc-actions { display: flex; gap: 6px; }
.portal-received { display: flex; align-items: flex-start; gap: 6px; margin: 4px 0 0; color: var(--success-text); }
.portal-received .icon { width: 14px; height: 14px; margin-top: 3px; }
.approve-box {
  margin-top: 10px; padding: 10px 12px; border: 1px solid #d98a1c; border-radius: var(--radius); background: #fffaf2;
}
@media (prefers-color-scheme: dark) { .approve-box { background: #241c10; } }
.approve-box > p { margin: 0 0 8px; }
.approve-box > p:last-child { margin: 8px 0 0; }
.approve-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.changes-box > summary { list-style: none; }
.changes-box > summary::-webkit-details-marker { display: none; }
.changes-box[open] { flex-basis: 100%; }
.changes-form { max-width: none; margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.changes-form label { font-weight: 600; font-size: 0.9rem; }
.changes-form textarea { width: 100%; }
.is-compact .portal-doc { padding: 9px 0; }
.portal-empty { text-align: center; padding: 36px 20px; }
.portal-empty > .icon { width: 38px; height: 38px; color: var(--muted); stroke-width: 1.5; }
.portal-empty h2 { margin: 10px 0 6px; }
.portal-empty p { max-width: 460px; margin: 0 auto 12px; }

/* Deadlines */
.deadline-month-title {
  margin: 16px 0 4px; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
.deadline-month-title:first-of-type { margin-top: 4px; }
.deadline-list, .done-list, .deadline-docs, .team-list, .firm-lines, .service-list, .people-list { list-style: none; margin: 0; padding: 0; }
.deadline { display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.deadline:last-child { border-bottom: 0; }
.deadline-date {
  display: flex; flex-direction: column; align-items: center; justify-content: center; flex-shrink: 0; width: 50px; height: 52px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); line-height: 1.1;
}
.deadline-month { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--danger); }
.deadline-day { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.deadline.is-client .deadline-date { border-style: dashed; }
.deadline-main { flex: 1; min-width: 0; }
.deadline-title { font-weight: 600; overflow-wrap: anywhere; }
.deadline-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 3px; }
.deadline-docs { margin-top: 6px; }
.deadline-docs li { padding: 2px 0; }
.deadline-docs a { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; }
.deadline-docs .icon { width: 14px; height: 14px; }
.is-compact .deadline-date { width: 44px; height: 46px; }
.is-compact .deadline-day { font-size: 1.1rem; }
.done-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.done-item:last-child { border-bottom: 0; }
.done-mark {
  display: inline-grid; place-items: center; width: 26px; height: 26px; flex-shrink: 0; border-radius: 50%;
  background: var(--success-bg); color: var(--success-text);
}
.done-mark .icon { width: 14px; height: 14px; }
.done-main { flex: 1; min-width: 0; }
.done-title { font-weight: 600; overflow-wrap: anywhere; }

/* Deadlines: calendar view */
.calendar-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.calendar-title { margin: 0; }
.tracker-nav .btn.is-disabled { opacity: 0.4; cursor: default; }
.calendar-grid { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.calendar-weekdays, .calendar-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar-weekday {
  padding: 6px 4px; text-align: center; font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--border);
}
.calendar-week + .calendar-week { border-top: 1px solid var(--border); }
.calendar-day { min-height: 92px; padding: 6px; border-left: 1px solid var(--border); min-width: 0; }
.calendar-day:first-child { border-left: 0; }
.calendar-day.is-outside { background: var(--bg); }
.calendar-day.is-outside .calendar-day-number { color: var(--muted); opacity: 0.6; }
.calendar-day-number { font-size: 0.85rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.calendar-day.is-today .calendar-day-number span[aria-hidden] {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 4px; border-radius: 12px;
  background: var(--primary); color: #fff;
}
.calendar-items { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.calendar-item {
  display: flex; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 4px; font-size: 0.78rem; line-height: 1.3;
  background: var(--primary); color: #fff; border: 1px solid transparent;
}
.calendar-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calendar-item.is-client { background: transparent; color: var(--text); border: 1px dashed var(--primary); }
.calendar-item.is-past-due { border-color: var(--danger); color: var(--danger); }
.calendar-item.is-done { background: var(--success-bg); color: var(--success-text); }
.calendar-item-mark { display: inline-grid; flex-shrink: 0; }
.calendar-item-mark .icon { width: 11px; height: 11px; }
.calendar-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0 0; }
.calendar-key { display: inline-flex; align-items: center; gap: 6px; }
.calendar-key::before { content: ""; width: 12px; height: 12px; border-radius: 3px; border: 1px solid transparent; }
.calendar-key.is-firm::before { background: var(--primary); }
.calendar-key.is-client::before { border: 1px dashed var(--primary); }
.calendar-key.is-done::before { background: var(--success-bg); border-color: var(--success-text); }
@media (max-width: 560px) {  /* an agenda: only the days with something on them */
  .calendar-weekdays { display: none; }
  .calendar-week { grid-template-columns: 1fr; }
  .calendar-week + .calendar-week { border-top: 0; }
  .calendar-day { border-left: 0; border-top: 1px solid var(--border); min-height: 0; }
  .calendar-day.is-empty, .calendar-day.is-outside { display: none; }
  .calendar-week:first-child .calendar-day:first-of-type { border-top: 0; }
  .calendar-day-number { font-size: 0.8rem; }
  .calendar-day.is-today .calendar-day-number span[aria-hidden]::after { content: " · Today"; }
  .calendar-day.is-today .calendar-day-number span[aria-hidden] { min-width: 0; border-radius: 12px; padding: 0 8px; }
  .calendar-item { font-size: 0.85rem; padding: 4px 8px; }
  .calendar-item-title { white-space: normal; overflow-wrap: anywhere; }
}

/* Team, the firm's details, services, people */
.team-person { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.team-person:last-child { border-bottom: 0; }
.team-person .avatar { width: 36px; height: 36px; font-size: 0.8rem; }
.team-person-text { min-width: 0; }
.team-name { font-weight: 600; }
.team-reach { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 2px; }
.team-reach a, .firm-lines li { display: inline-flex; align-items: center; gap: 6px; overflow-wrap: anywhere; }
.team-reach .icon { width: 14px; height: 14px; }
.firm-lines li { display: flex; align-items: flex-start; padding: 5px 0; }
.firm-lines .icon { width: 16px; height: 16px; margin-top: 3px; color: var(--muted); flex-shrink: 0; }
.firm-card .btn-block { margin-top: 12px; text-align: center; }
.service-list li, .people-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.service-list li:last-child, .people-list li:last-child { border-bottom: 0; }
.service-name, .people-name { font-weight: 600; }

/* Invoices */
.portal-invoices td { vertical-align: middle; }
.portal-invoices .badge { margin-left: 6px; }
.show-sm { display: none; }

/* Sign-in pages */
.portal-auth-brand { display: flex; justify-content: center; margin-bottom: 20px; }
.portal-auth-logo { display: block; max-height: 64px; max-width: 240px; object-fit: contain; }
.portal-auth .auth-card h1 { margin-bottom: 8px; }

/* Phones: the sections move to a bar at the bottom of the screen, in reach of a thumb */
@media (max-width: 720px) {
  .portal-header { position: static; }
  .portal-bar { gap: 10px; padding: 10px 16px; }
  .portal-logo { max-height: 32px; max-width: 120px; }
  .portal-brand .portal-firm { display: none; }
  .client-name { padding-left: 10px; font-size: 0.95rem; }
  .portal-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; border-top: 1px solid var(--border);
    background: var(--surface); box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  }
  .portal-nav-inner { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0; padding: 0 4px env(safe-area-inset-bottom); }
  .portal-nav a {
    flex-direction: column; gap: 2px; padding: 8px 2px 7px; border-bottom: 0; border-top: 2px solid transparent;
    font-size: 0.7rem; font-weight: 500;
  }
  .portal-nav a .icon { width: 21px; height: 21px; }
  .portal-nav a.active { border-top-color: var(--primary); color: var(--link); }
  .portal-nav .nav-count { position: absolute; top: 4px; left: calc(50% + 6px); }
  .portal-main { padding: 18px 16px 96px; }
  .portal-footer-inner { padding-bottom: 84px; }
  .portal-page-header h1 { font-size: 1.35rem; }
  .portal-doc { grid-template-columns: auto minmax(0, 1fr); }
  .portal-glance { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .glance { padding: 12px 14px; }
  .glance-value { font-size: 1.2rem; }
  .portal-doc-actions { grid-column: 2; }
  .show-sm { display: block; }
  .portal-preview-bar { padding: 8px 16px; }
  .portal-page #messages { bottom: 84px; }  /* above the bar */
}

@media print {
  .portal-header, .portal-nav, .portal-footer, .portal-preview-bar { display: none !important; }
  .portal-main { max-width: none; padding: 0; }
}

/* --- Client portal: to-dos ------------------------------------------------------------------------ */
/* How much is done */
.todo-progress { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.todo-progress progress { width: 90px; height: 8px; accent-color: var(--success-text); }
.todo-summary-progress .todo-progress progress { width: 220px; height: 10px; }
.todo-summary-progress .todo-progress .small { font-size: 0.95rem; font-weight: 600; }
.todo-summary p { margin: 8px 0 0; }

/* The firm's lists of to-dos */
.todo-table td { vertical-align: middle; }
.todo-title { font-weight: 600; color: var(--text); }
.todo-title:hover { color: var(--link); }
.todo-status .badge { margin: 2px 4px 2px 0; white-space: nowrap; }
.todo-table tr.has-new td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.card > .table-scroll > .todo-table tr.has-new td:first-child { padding-left: 10px; }  /* off the new-answers bar */
.attention-stat.is-todo-new { border-top-color: var(--primary); }
.attention-stat.is-todo-overdue { border-top-color: var(--danger); }
.attention-stat.is-todo-waiting { border-top-color: #d98a1c; }
.chip.is-todo-new { border-color: var(--primary); color: var(--link); }
.chip.is-todo-overdue { border-color: var(--danger); color: var(--danger); }

/* Making a to-do: one row per item */
.todo-form { max-width: 980px; }
.todo-editor { min-width: 0; margin: 8px 0 16px; padding: 12px 16px 4px; border: 1px solid var(--border); border-radius: var(--radius); }
.todo-editor legend { padding: 0 6px; font-weight: 700; }
.todo-editor > p { margin: 0 0 10px; }
.todo-rows { container: todo-rows / inline-size; }
.todo-row {
  display: grid; grid-template-columns: 150px minmax(0, 1.4fr) minmax(0, 1fr) 128px 64px; gap: 8px; align-items: start;
  padding: 6px 0; border-bottom: 1px dashed var(--border);
}
.todo-row > div { min-width: 0; }
.todo-row input[type="text"], .todo-row select { width: 100%; }
.todo-row-head { padding-top: 0; border-bottom: 1px solid var(--border); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.todo-row-remove { padding-top: 7px; text-align: right; }
.todo-row .todo-row-format { visibility: hidden; }
.todo-row:has(select[name$="-kind"] option[value="information"]:checked) .todo-row-format { visibility: visible; }
.todo-row-errors { grid-column: 1 / -1; }
.todo-row.has-error input[type="text"]:invalid, .todo-row.has-error .errorlist + input { border-color: var(--danger); }
.todo-row .errorlist { margin: 4px 0 0; font-size: 0.8rem; }
.todo-editor-more { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 10px 0 8px; }
@container todo-rows (max-width: 700px) {
  .todo-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 10px 0; }
  .todo-row-head { display: none; }
  .todo-row-label, .todo-row-details { grid-column: 1 / -1; }
  .todo-row .todo-row-format { display: none; }
  .todo-row:has(select[name$="-kind"] option[value="information"]:checked) .todo-row-format { display: block; }
  .todo-row-remove { text-align: left; padding-top: 0; }
}

/* A to-do on the firm's side: each item with what the client gave */
.review-list, .todo-items, .todo-files, .review-files, .todo-overview { list-style: none; margin: 0; padding: 0; }
.review-item { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 6px 12px; padding: 14px 0; border-bottom: 1px solid var(--border); scroll-margin-top: 20px; }
.review-item:last-child { border-bottom: 0; }
.review-item.is-new { box-shadow: inset 3px 0 0 var(--primary); padding-left: 10px; margin-left: -10px; }
.review-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.review-label { font-weight: 600; overflow-wrap: anywhere; }
.review-response { margin-top: 8px; padding: 8px 12px; border-radius: 6px; background: var(--bg); }
.review-files li { padding: 3px 0; }
.review-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; justify-content: flex-end; }
.send-back > summary { list-style: none; }
.send-back > summary::-webkit-details-marker { display: none; }
.send-back-form { max-width: none; width: min(340px, 80vw); margin-top: 8px; }
.send-back-form .field { margin-bottom: 8px; }
.send-back-form textarea { width: 100%; }
.todo-returned-note { display: flex; align-items: flex-start; gap: 6px; margin-top: 6px; color: var(--warning-text); }
.todo-returned-note .icon { width: 14px; height: 14px; margin-top: 3px; flex-shrink: 0; }
@media (max-width: 720px) {
  .review-item { grid-template-columns: 26px minmax(0, 1fr); }
  .review-actions { grid-column: 2; justify-content: flex-start; }
}

/* Where an item stands: an empty circle to do, a green tick done, a cross when it's not needed */
.todo-check {
  display: inline-grid; place-items: center; width: 24px; height: 24px; flex-shrink: 0; margin-top: 1px;
  border: 2px solid #c3c8d0; border-radius: 50%; color: #fff;
}
.todo-check .icon { width: 13px; height: 13px; stroke-width: 3; }
.is-done > .todo-check { border-color: var(--success-text); background: var(--success-text); }
.is-not_needed > .todo-check { border-color: var(--border); color: var(--muted); }
.is-not_needed .todo-item-label, .is-not_needed .review-label { color: var(--muted); text-decoration: line-through; }
.todo-kind { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.todo-kind .icon { width: 13px; height: 13px; }
.todo-answer { overflow-wrap: anywhere; }

/* The client's to-dos */
.todo-card { scroll-margin-top: 130px; }
.todo-card.is-overdue { border-color: var(--danger); }
.todo-card-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 20px; }
.todo-card-title { min-width: 0; flex: 1 1 280px; }
.todo-card-title h2 { margin: 0 0 6px; font-size: 1.15rem; }
.todo-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.todo-card > .portal-doc-message { margin-top: 12px; }
.todo-items { margin-top: 8px; }
.todo-item { display: flex; gap: 12px; padding: 14px 0; border-top: 1px solid var(--border); scroll-margin-top: 130px; }
.todo-item-main { flex: 1; min-width: 0; }
.todo-item-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.todo-item-label { font-weight: 600; overflow-wrap: anywhere; }
.todo-item-details { margin: 2px 0 0; }
.todo-returned {
  display: flex; align-items: flex-start; gap: 8px; margin: 8px 0 0; padding: 8px 12px; border-radius: 6px;
  background: #fdf0dc; color: #6b3b00;
}
.todo-returned .icon { width: 15px; height: 15px; margin-top: 2px; flex-shrink: 0; }
@media (prefers-color-scheme: dark) { .todo-returned { background: #3a2a14; color: #f3c27a; } }
.todo-response { max-width: 620px; margin-top: 10px; }
.todo-response .field { margin-bottom: 10px; }
.todo-response textarea { width: 100%; }
.todo-response input[type="date"], .todo-response input[type="number"] { max-width: 240px; }
.todo-response fieldset > div { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.todo-response .actions { margin-top: 2px; }
.dropzone.dropzone-compact { flex-direction: row; flex-wrap: wrap; min-height: 64px; padding: 12px 14px; gap: 4px 10px; }
.dropzone-compact .icon { width: 20px; height: 20px; }
.dropzone-compact .dropzone-files { flex-basis: 100%; }
.dropzone-compact .dropzone-files:empty { display: none; }
.todo-given { margin-top: 8px; padding: 8px 12px; border-radius: 6px; background: var(--bg); }
.todo-given .todo-answer { margin-bottom: 2px; }
.todo-given.is-earlier { background: none; border: 1px dashed var(--border); }
.todo-files li { padding: 3px 0; }
.todo-files a { display: inline-flex; align-items: center; gap: 8px; overflow-wrap: anywhere; }
.todo-change { margin-top: 6px; }
.todo-attach { margin: -2px 0 10px; }
.todo-attach > summary { display: inline-flex; align-items: center; gap: 6px; list-style: none; color: var(--link); }
.todo-attach > summary::-webkit-details-marker { display: none; }
.todo-attach > summary .icon { width: 14px; height: 14px; }
.todo-attach[open] > summary { margin-bottom: 8px; }
.todo-change > summary { display: inline-block; list-style: none; }
.todo-change > summary::-webkit-details-marker { display: none; }
.todo-change > summary.link-action { color: var(--link); }
.done-todo > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 10px 0; list-style: none; cursor: pointer; border-top: 1px solid var(--border); }
.done-todo > summary::-webkit-details-marker { display: none; }
.done-todo:first-of-type > summary { border-top: 0; }
.done-todo-title { font-weight: 600; }
.done-todo[open] > summary .done-todo-title { color: var(--link); }

/* The overview: the to-dos still open */
.todo-overview li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px 16px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.todo-overview li:first-child { border-top: 0; }
.todo-overview-title { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.todo-overview-title:hover { color: var(--link); }
@media (max-width: 720px) {
  .todo-overview li { grid-template-columns: minmax(0, 1fr) auto; }
  .todo-overview li .todo-progress { grid-column: 1; grid-row: 2; }
  .todo-overview li .btn { grid-column: 2; grid-row: 1 / 3; }
  .todo-progress progress { width: 70px; }
}

/* --- Emails ---------------------------------------------------------------------------------------------- */
/* "Email the client about it" only means something once the document is shared */
.form:has(.visibility-field input[value="firm"]:checked) .shared-only { display: none; }

/* Shared documents, or items sent back, that the client hasn't been emailed about yet */
.email-pending { border-color: #b9ccf5; }
.email-pending-head { display: flex; align-items: flex-start; gap: 12px; }
.email-pending-head h2 { margin: 0 0 2px; font-size: 1.05rem; }
.email-pending-head p { margin: 0; }
.email-pending-icon {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex-shrink: 0; border-radius: 50%;
  background: #e7eefc; color: var(--primary);
}
.email-pending-icon .icon { width: 17px; height: 17px; }
.email-pending-list { margin: 10px 0 6px 46px; padding: 0; list-style: none; }
.email-pending-list li { padding: 2px 0; overflow-wrap: anywhere; }
.email-pending-form { margin-left: 46px; }
.email-pending-form .actions { margin-top: 8px; }
.email-note > summary { display: inline-block; list-style: none; color: var(--link); }
.email-note > summary::-webkit-details-marker { display: none; }
.email-note textarea { display: block; width: 100%; max-width: 620px; margin-top: 6px; }
@media (max-width: 720px) { .email-pending-list, .email-pending-form { margin-left: 0; } }
@media (prefers-color-scheme: dark) {
  .email-pending { border-color: #2c3f66; }
  .email-pending-icon { background: #1c2a47; color: #9bb8f5; }
}

/* How emails go out (settings, the email log) */
.email-setup-notice, .email-failed-notice { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 16px; }
.email-setup-notice .icon, .email-failed-notice .icon { margin-top: 2px; flex-shrink: 0; }
.email-setup-notice code { font-size: 0.85em; }
.reminder-fields { min-width: 0; margin: 4px 0 12px; padding: 0; border: 0; }
.reminder-fields legend { margin-bottom: 6px; padding: 0; }
.reminder-fields .field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 16px; align-items: end; }
.reminder-fields p { margin: 0; }

/* The email log */
.email-table td { vertical-align: top; }
.email-table tr.is-failed td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.email-to, .email-subject { overflow-wrap: anywhere; }
.email-subject a { color: var(--text); }
.email-subject a:hover { color: var(--link); }
.email-error { color: var(--danger); overflow-wrap: anywhere; }
.email-error.small, .email-table .email-error { max-width: 320px; margin-top: 4px; }

/* A to-do's emails: sending it with an email, when the next reminder goes, what was sent */
.todo-send-form { display: inline-flex; align-items: center; gap: 10px; }
.todo-form-emails { margin: 4px 0 8px; }
.todo-reminders { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 12px; color: var(--muted); }
.todo-reminders > .icon { width: 14px; height: 14px; flex-shrink: 0; }
.todo-reminders form { display: inline; }
.email-history { margin: 0; padding: 0; list-style: none; }
.email-history li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.email-history li:last-child { border-bottom: 0; }
.email-history-when { min-width: 110px; }
.invite-email-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 10px; }

/* --- Reminders ------------------------------------------------------------------------------------------- */
/* A client's reminders, on its portal page */
.reminders-summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 8px; }
.reminders-summary p { margin: 0; }
.reminders-setup { margin-top: 12px; }
.reminders-setup > summary { display: inline-flex; list-style: none; }
.reminders-setup > summary::-webkit-details-marker { display: none; }
.reminders-setup[open] > summary { margin-bottom: 14px; }
.reminders-form { max-width: 780px; }
.reminders-form fieldset { min-width: 0; margin: 0 0 14px; padding: 0; border: 0; }
.reminders-form legend { margin-bottom: 6px; padding: 0; }
.reminders-form .field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 16px; align-items: end; }
.recipients-field label { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-weight: 400; overflow-wrap: anywhere; }
.recipients-field input[type="checkbox"] { flex-shrink: 0; }
.reminders-past { margin-top: 10px; }
.reminders-past > summary { display: inline-block; list-style: none; color: var(--link); }
.reminders-past > summary::-webkit-details-marker { display: none; }
.reminders-past[open] > summary { margin-bottom: 8px; }
.reminders-clients { margin-top: 14px; }
.reminder-summary p { margin: 2px 0 0; }

/* Lists of reminders */
.reminder-table td { vertical-align: top; }
.reminder-table tr.needs-amount td:first-child { box-shadow: inset 3px 0 0 #d98a1c; }
.reminder-about a { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.reminder-about a:hover { color: var(--link); }
.reminder-table tr.is-skipped .reminder-about a { color: var(--muted); text-decoration: line-through; }
.reminder-about .icon { width: 12px; height: 12px; margin-right: 3px; color: var(--success-text); vertical-align: -1px; }
.attention-stat.is-reminder-soon { border-top-color: var(--primary); }
.attention-stat.is-reminder-amount { border-top-color: #d98a1c; }

/* One reminder: the form, and what they'll read */
.reminder-layout { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 960px) { .reminder-layout { grid-template-columns: minmax(0, 1fr); } }
.reminder-form textarea, .template-grid textarea { width: 100%; font-family: inherit; }
.reminder-form .form-grid { align-items: end; }
.fields-help { margin: -4px 0 12px; }
.fields-help > summary { display: inline-block; list-style: none; color: var(--link); }
.fields-help > summary::-webkit-details-marker { display: none; }
.fields-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 8px 0; font-size: 0.85rem; }
.fields-list dt, .fields-list dd { margin: 0; }
.fields-list dd { color: var(--muted); }
.reminder-preview h2 { margin: 0 0 4px; font-size: 1rem; }
.preview-subject { margin: 12px 0 8px; font-weight: 700; overflow-wrap: anywhere; }
.preview-body { padding: 12px 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); overflow-wrap: anywhere; }
.preview-body p { margin: 0 0 10px; }
.preview-body p:last-child { margin-bottom: 0; }
.preview-facts { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 10px 0 0; padding: 10px 14px; border-radius: 6px; background: var(--bg); }
.preview-facts dt { color: var(--muted); }
.preview-facts dd { margin: 0; font-weight: 600; }

/* The templates (settings) */
.template-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .template-grid { grid-template-columns: minmax(0, 1fr); } }
.template-preview { align-self: start; padding: 12px 14px; border: 1px dashed var(--border); border-radius: 6px; background: var(--bg); font-size: 0.9rem; overflow-wrap: anywhere; }
.template-preview p { margin: 0 0 8px; }
.template-preview p:last-child { margin-bottom: 0; }
.template-fields code { white-space: nowrap; }
