:root {
  --primary: #1F3A5F; /* neutral default; /api/brand.css sets the practice's own */
  --accent: #C27C0E;
  --ochre: #A68032;
  --bg: #F5F6F5;
  --surface: #FFFFFF;
  --sage: #A5A88B;
  --text: #2B2D24;
  --muted: #6B6E5F;
  --line: #E1E3DA;
  --danger: #B42318;
  --ok: #2F7D32;
  --radius: 10px;
  font-family: "Segoe UI", Inter, system-ui, -apple-system, Arial, sans-serif;
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; overflow-x: hidden; }
h1 { font-size: 19px; margin: 0 0 2px; color: var(--primary); }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--primary); }
p { margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 12.5px; min-height: 1em; margin: 3px 0; }

.topbar { display: flex; align-items: center; justify-content: space-between; background: var(--primary); color: #fff; padding: 7px 16px; position: sticky; top: 0; z-index: 5; flex-wrap: wrap; gap: 8px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topbar-actions .btn { padding: 5px 10px; font-size: 12px; }
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-name { font-weight: 800; font-size: 16px; }
.brand-sub { color: var(--accent); font-size: 11.5px; font-weight: 600; }

.layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: calc(100vh - 46px); max-width: 100vw; overflow-x: clip; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.main { padding: 12px 18px 28px; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }

.matter-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.matter-list li button { width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: 8px; padding: 7px 9px; cursor: pointer; font: inherit; color: inherit; }
.matter-list li button:hover { background: var(--bg); }
.matter-list li button.active { background: #F7EFD6; border-color: var(--accent); }
.matter-list .ml-name { font-weight: 700; font-size: 13.5px; display: block; }
.matter-list .ml-meta { font-size: 11.5px; color: var(--muted); display: block; }
.matter-list .empty { color: var(--muted); font-size: 12.5px; padding: 6px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px; }
details.panel > summary { cursor: pointer; font-weight: 700; color: var(--primary); font-size: 14px; }
details.panel[open] > summary { margin-bottom: 10px; }
.welcome .steps li { margin-bottom: 5px; }

.matter-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 8px; }
.matter-head-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; max-width: 100%; }
.report-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
.card .label { font-size: 11.5px; color: var(--muted); font-weight: 600; line-height: 1.25; }
.card .value { font-size: 17px; font-weight: 800; color: var(--primary); margin-top: 1px; }
.card.highlight { border-color: var(--accent); background: #FBF5E3; }

.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.grid-form .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field .hint { font-weight: 400; font-size: 11.5px; }
.input { font: inherit; font-size: 13.5px; color: var(--text); background: #fff; border: 1px solid #CDD0C3; border-radius: 7px; padding: 6px 9px; width: 100%; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea.input { resize: vertical; }
.input.money { text-align: right; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text); font-weight: 500; }

.btn { font: inherit; font-size: 13px; font-weight: 700; border-radius: 8px; padding: 6px 12px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--primary); }
.btn.primary:hover { background: var(--ochre); color: #fff; }
.btn.secondary { background: var(--primary); color: #fff; }
.btn.secondary:hover { background: #3d4124; }
.btn.ghost { background: transparent; border-color: #CDD0C3; color: var(--text); }
.btn.ghost:hover { background: var(--bg); }
.btn.ghost.light { color: #fff; border-color: rgba(255, 255, 255, .5); }
.btn.ghost.light:hover { background: rgba(255, 255, 255, .12); }
.btn.danger { background: transparent; border-color: #E8B4AF; color: var(--danger); }
.btn.danger:hover { background: #FBE4E1; }
.btn.small { font-size: 12px; padding: 4px 8px; border-radius: 6px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.actions .spacer { flex: 1; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: -4px -4px 14px; padding-bottom: 10px; }
.tab { font: inherit; font-size: 14px; font-weight: 700; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); cursor: pointer; transition: all .15s ease; }
.tab .num { display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 50%; background: var(--line); color: var(--primary); font-size: 12px; margin-right: 6px; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab.active .num { background: var(--accent); color: var(--primary); font-weight: 800; }
.tab.done { border-color: #86efac; background: #f0fdf4; color: #166534; }
.tab.done .num { background: #16a34a; color: #fff; }
.tab.done.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab.done.active .num { background: #16a34a; color: #fff; }
.tab-check { color: #16a34a; font-weight: 800; margin-left: 4px; }
.tab.active .tab-check { color: #86efac; }
.tab-intro { font-size: 13.5px; color: var(--muted); margin-bottom: 12px; }


.lines { width: 100%; border-collapse: collapse; margin: 8px 0; }
.lines th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.lines td { padding: 4px 4px; vertical-align: top; }
.lines .col-amount { width: 130px; }
.lines .col-kind { width: 150px; }
.lines .col-date { width: 150px; }
.lines .col-basis { width: 130px; }
.lines .col-gst { width: 80px; text-align: center; }
.lines .col-x { width: 36px; }

.calc { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: flex-end; background: var(--bg); border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.calc strong { color: var(--primary); }
.calc .err { color: var(--danger); }

.notice { border-radius: 10px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 12px; border: 1px solid; }
.notice.warn { background: #FFF8E6; border-color: #F0D58A; color: #6B4E00; }
.notice.info { background: #F0F4EA; border-color: #CBD5B8; color: #3D4524; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }
.convert-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: #FBF5E3; border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; }
.convert-bar .convert-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.edit-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #FFF8E6; border: 1px solid var(--accent); border-radius: 10px; padding: 9px 14px; margin-bottom: 12px; font-size: 13.5px; font-weight: 600; color: var(--primary); }

.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; background: #fff; margin-bottom: 18px; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc-table th { text-align: left; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); background: #FAFBF9; white-space: nowrap; }
.doc-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; word-break: break-word; }
.doc-table td.num { text-align: right; white-space: nowrap; }
.doc-table tr.void td { color: var(--muted); text-decoration: line-through; }
.doc-table tr.void td.keep { text-decoration: none; }
.doc-table .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--primary); white-space: nowrap; }
.badge.ok { background: #E3F1E4; color: var(--ok); }
.badge.void { background: #FBE4E1; color: var(--danger); }
.badge.due { background: #FBF0D2; color: #7A5A00; }

.settings dl { display: grid; grid-template-columns: 220px 1fr; gap: 6px 12px; font-size: 14px; margin: 0 0 16px; }
.settings dt { color: var(--muted); font-weight: 600; }
.settings dd { margin: 0; }

.dialog { border: none; border-radius: 14px; padding: 20px 22px; width: min(560px, 94vw); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(30, 32, 20, .45); }
.dialog .field { margin-bottom: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Messages: top-centre under the header, above everything (incl. dialogs via the popover top layer),
   errors stay until dismissed so they can actually be read. */
.toast { display: none; position: fixed; inset: auto; top: 78px; left: 50%; transform: translateX(-50%); margin: 0; border: 0;
  background: var(--primary); color: #fff; padding: 12px 14px 12px 18px; border-radius: 10px; font-size: 15px; line-height: 1.45;
  width: max-content; max-width: min(720px, 92vw); box-shadow: 0 8px 28px rgba(0,0,0,.28); z-index: 2147483000; }
.toast.show, .toast:popover-open { display: flex; align-items: flex-start; gap: 14px; }
.toast .toast-msg { white-space: pre-wrap; overflow-wrap: anywhere; flex: 1; }
.toast .toast-close { background: rgba(255,255,255,.18); border: 0; color: #fff; width: 26px; height: 26px; border-radius: 50%; font-size: 14px; cursor: pointer; flex: none; line-height: 1; }
.toast .toast-close:hover { background: rgba(255,255,255,.34); }
.toast.error { background: var(--danger); }

.folder-picker-row { display: flex; gap: 8px; align-items: stretch; }
.folder-picker-row .input { flex: 1; font-family: Consolas, monospace; font-size: 13px; }
.immi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 8px 12px; margin-bottom: 16px; width: 100%; }
.immi-kv { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; min-width: 0; box-sizing: border-box; }
.immi-kv .k { color: var(--muted); font-weight: 600; font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.immi-kv .v { color: var(--text); font-weight: 700; font-size: 13px; word-break: break-word; }
.immi-kv input.small-input { border: 1px solid #C4C8B8; border-radius: 6px; background: #fff; width: 100%; box-sizing: border-box; }
.copy-btn { font: inherit; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 6px; border: 1px solid #CDD0C3; background: #fff; color: var(--primary); cursor: pointer; flex-shrink: 0; }
.copy-btn:hover { background: var(--accent); border-color: var(--accent); }
.audit-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; background: #fff; }
.audit-item.crit { border-color: #E8B4AF; background: #FFF5F4; }
.audit-item.warn { border-color: #F0D58A; background: #FFFDF5; }
.audit-item.pass { border-color: #C5DEC6; background: #F6FBF6; }

/* Renamed Files Table: High-density, fits window cleanly without overflow */
.files-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.files-table th { background: #F6F7F3; color: var(--text); font-weight: 700; font-size: 12px; padding: 10px 12px; border-bottom: 2px solid var(--line); vertical-align: bottom; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-sizing: border-box; }
.files-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top !important; box-sizing: border-box; }
.files-table tr:hover td { background: #FAFBF8; }

.files-table td.col-orig { font-size: 11.5px; color: var(--muted); word-break: break-word; overflow-wrap: anywhere; line-height: 1.35; }

.files-table td.col-clean { line-height: 1.35; }
.clean-name-box { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.clean-name-box strong { font-size: 12.5px; color: #2B3014; word-break: break-word; overflow-wrap: anywhere; }

.files-table td.col-person { font-size: 12.5px; line-height: 1.35; font-weight: 600; color: var(--text); word-break: break-word; overflow-wrap: anywhere; }
.files-table td.col-person .dob-badge { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted); margin-top: 3px; }

.files-table td.col-dates { font-size: 12px; white-space: nowrap; line-height: 1.45; color: var(--text); }
.files-table td.col-dates .date-line { display: block; white-space: nowrap; }
.files-table td.col-dates .date-line strong { color: #8F3B34; }

.files-table td.col-summary { font-size: 12.5px; color: #2D311E; line-height: 1.45; word-break: break-word; overflow-wrap: anywhere; }

@media (max-width: 1200px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); }
  .matter-list { max-height: 220px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-form, .immi-grid { grid-template-columns: 1fr; }
  .main { padding: 10px; }
}

/* Microsoft 365 & OneDrive 1-Click UI */
.btn-ms-login {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  color: #5E5E5E;
  border: 1px solid #8C8C8C;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.btn-ms-login:hover {
  background: #fbfbfb;
  border-color: #666666;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  color: #262626;
}
.btn-ms-login:active {
  background: #f0f0f0;
}
.btn-ms-login svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.m365-card {
  border-radius: 10px;
  padding: 18px 20px;
  margin: 14px 0 24px 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border: 1px solid #E5E7EB;
  background: #ffffff;
}
.m365-card.connected {
  border-left: 4px solid #10B981;
  background: #F0FDF4;
}
.m365-card.disconnected {
  border-left: 4px solid #3B82F6;
  background: #F8FAFC;
}


/* ---------- Deadline diary ---------- */
.dy-badge { display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 4px; border-radius: 99px; background: #DC2626; color: #fff; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; }
.dy-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.dy-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.dy-tile { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 14px; border: 2px solid; border-radius: 12px; cursor: pointer; text-align: left; font: inherit; }
.dy-tile:focus-visible, .dy-link:focus-visible { outline: 3px solid #1D4ED8; outline-offset: 2px; }
.dy-tile-n { font-size: 30px; font-weight: 800; line-height: 1; }
.dy-tile-l { font-size: 13px; font-weight: 700; }
.dy-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.dy-tools .input { max-width: 320px; }
.dy-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.dy-group { margin: 14px 0; }
.dy-group-h { font-size: 15px; margin: 0 0 6px; }
.dy-count { background: #E5E7EB; color: #374151; border-radius: 99px; padding: 0 8px; font-size: 12px; margin-left: 4px; }
.dy-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; padding: 10px 12px; margin: 6px 0; background: #fff; border: 1px solid #E5E7EB; border-left: 6px solid #9CA3AF; border-radius: 8px; }
.dy-soft { border-left-style: dashed; }
.dy-main { flex: 1 1 340px; min-width: 0; }
.dy-when { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dy-chip { padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.dy-tag { padding: 0 7px; border: 1px solid #D1D5DB; border-radius: 4px; font-size: 11px; color: #4B5563; }
.dy-tag-hard { border-color: #991B1B; color: #991B1B; font-weight: 700; }
.dy-what { margin-top: 2px; font-size: 14px; }
.dy-who { font-size: 13px; margin-top: 2px; }
.dy-link { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: #1D4ED8; cursor: pointer; text-decoration: underline; }
.dy-note { font-size: 12.5px; color: #4B5563; margin-top: 2px; }
.dy-actions { display: flex; align-items: flex-start; gap: 6px; flex-wrap: wrap; }
.dy-extra, .dy-hist { flex: 1 1 100%; }
.dy-pop { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px; background: #F9FAFB; border-radius: 6px; }
.dy-hist { font-size: 12.5px; color: #374151; border-top: 1px dashed #E5E7EB; padding-top: 6px; }
.dy-hist ul { margin: 0; padding-left: 18px; }
.dy-empty { text-align: center; padding: 30px 12px; border: 2px dashed #D1D5DB; border-radius: 12px; }
.dy-recent { margin-top: 16px; }
.dy-recent summary { cursor: pointer; font-weight: 600; }
.dy-mini { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13.5px; }
.dy-dialog { border: 0; border-radius: 12px; padding: 20px; width: min(560px, 94vw); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.dy-dialog::backdrop { background: rgba(17, 24, 39, .5); }
.dy-two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dy-helper { background: #F0F9FF; border: 1px solid #BAE6FD; border-radius: 8px; padding: 8px 10px; margin: 0 0 8px; }
@media (max-width: 640px) { .dy-two { grid-template-columns: 1fr; } .dy-actions { width: 100%; } }

.dy-sugg { margin-top: 10px; border-top: 1px dashed #E5E7EB; padding-top: 8px; }
.dy-sugg summary { cursor: pointer; font-weight: 600; font-size: 13.5px; }
.dy-sugg-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid #F3F4F6; }

.dy-settings { margin: 0 0 12px; background: #F9FAFB; border: 1px solid #E5E7EB; border-radius: 8px; padding: 8px 12px; }
.dy-settings summary { cursor: pointer; font-weight: 600; font-size: 13.5px; }
.dy-set-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 8px; }
.dy-set-grid fieldset { border: 1px solid #E5E7EB; border-radius: 6px; padding: 8px 10px; background: #fff; }
.dy-set-grid legend { font-weight: 700; font-size: 13px; padding: 0 4px; }

/* ---------- Diary: view switcher, month and by-client views, phone layout ---------- */
.dy-modes { display: inline-flex; gap: 4px; padding: 4px; background: #F3F4F6; border-radius: 10px; margin: 0 0 12px; flex-wrap: wrap; }
.dy-mode { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font: inherit; font-weight: 600; font-size: 13.5px; color: #374151; cursor: pointer; }
.dy-mode[aria-selected="true"] { background: #fff; color: #111827; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.dy-mode:focus-visible, .dy-daynum:focus-visible, .dy-chipday:focus-visible, .dy-more:focus-visible { outline: 3px solid #1D4ED8; outline-offset: 1px; }
.dy-monthbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.dy-monthlabel { margin: 0; font-size: 18px; min-width: 150px; text-align: center; }
.dy-overdue-note { margin: 0 0 8px; padding: 6px 10px; background: #FEF2F2; color: #B91C1C; border-radius: 6px; font-size: 13px; }
.dy-grid { border: 1px solid #E5E7EB; border-radius: 8px; overflow: hidden; background: #fff; }
.dy-dow, .dy-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.dy-dow > div { padding: 6px 4px; text-align: center; font-size: 12px; font-weight: 700; color: #4B5563; background: #F9FAFB; border-bottom: 1px solid #E5E7EB; }
.dy-cell { min-height: 96px; padding: 3px; border-right: 1px solid #F3F4F6; border-bottom: 1px solid #F3F4F6; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dy-cell:nth-child(7n) { border-right: 0; }
.dy-cell:nth-child(6), .dy-cell:nth-child(7) { background: #FCFCFD; }
.dy-out { opacity: .55; }
.dy-today { background: #FFFBEB !important; box-shadow: inset 0 0 0 2px #F59E0B; }
.dy-sel { box-shadow: inset 0 0 0 2px #1D4ED8; }
.dy-daynum { align-self: flex-start; border: 0; background: transparent; font: inherit; font-weight: 700; font-size: 13px; padding: 2px 6px; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.dy-dot { display: inline-block; min-width: 16px; padding: 0 4px; border-radius: 99px; color: #fff; font-size: 11px; line-height: 16px; text-align: center; }
.dy-chips { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dy-chipday { display: flex; flex-direction: column; align-items: flex-start; border: 1px solid; border-left-width: 4px; border-radius: 4px; padding: 1px 4px; text-align: left; font: inherit; font-size: 11.5px; line-height: 1.2; cursor: pointer; min-width: 0; width: 100%; }
.dy-chipday-soft { border-style: dashed; border-left-style: solid; }
.dy-chipday-t, .dy-chipday-w { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.dy-chipday-w { opacity: .8; font-size: 10.5px; }
.dy-more { border: 0; background: transparent; color: #1D4ED8; font: inherit; font-size: 11.5px; text-align: left; cursor: pointer; padding: 0 4px; }
.dy-client { margin: 8px 0; border: 1px solid #E5E7EB; border-radius: 8px; background: #fff; padding: 0 10px 8px; }
.dy-client > summary { cursor: pointer; padding: 10px 8px; border-left: 6px solid #9CA3AF; margin: 0 -10px 4px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; list-style-position: inside; }
.dy-client-name { font-weight: 700; }

@media (max-width: 640px) {
  .dy-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dy-tile-n { font-size: 26px; }
  .dy-row { padding: 12px; }
  .dy-actions { width: 100%; }
  .dy-actions .btn { flex: 1 1 calc(50% - 6px); min-height: 44px; }
  .dy-tools .input { max-width: none; width: 100%; }
  .dy-check { min-height: 40px; }
  .dy-check input { width: 20px; height: 20px; }
  .dy-mode { flex: 1; padding: 10px 6px; min-height: 44px; }
  .dy-modes { display: flex; }
  .dy-cell { min-height: 54px; align-items: center; }
  .dy-chips { display: none; }
  .dy-daynum { flex-direction: column; min-width: 40px; min-height: 40px; justify-content: center; font-size: 14px; }
  .dy-dot { font-size: 10px; }
  .dy-monthbar .btn { min-height: 44px; min-width: 44px; }
  .dy-dialog { width: 100vw; max-width: 100vw; margin: 0; border-radius: 12px 12px 0 0; position: fixed; bottom: 0; top: auto; max-height: 92vh; overflow-y: auto; }
  .dy-pop { flex-direction: column; align-items: stretch; }
  .dy-pop .btn { min-height: 44px; }
}

/* Statutory form cards: the three buttons sit in the same place on every card */
.form-actions{display:grid;gap:6px;margin-top:auto}
.form-actions .btn{width:100%;box-sizing:border-box;display:flex;align-items:center;justify-content:center;text-align:center;text-decoration:none;font-weight:700;min-height:38px}
.form-actions .btn[disabled]{opacity:.45;cursor:not-allowed}

/* ---- New layout: no client sidebar; Home, Clients page, header picker, client journey bar ---- */
.layout { grid-template-columns: minmax(0, 1fr); }
.sidebar { display: none; }
.main { max-width: 1180px; margin: 0 auto; }
.topnav { display: flex; align-items: center; gap: 6px; flex: 1 1 auto; margin-left: 18px; flex-wrap: wrap; }
.topnav-btn { background: transparent; color: #fff; border: 0; border-bottom: 2px solid transparent; padding: 6px 10px; font-size: 13px; cursor: pointer; opacity: .85; }
.topnav-btn.on { border-bottom-color: var(--accent); opacity: 1; font-weight: 600; }
.picker-wrap { position: relative; }
.picker-btn { background: #fff; color: var(--text); border: 0; border-radius: 8px; padding: 6px 12px; min-width: 210px; text-align: left; font-size: 13px; cursor: pointer; }
.picker-pop { position: absolute; top: calc(100% + 6px); left: 0; width: 380px; max-width: 92vw; background: #fff; color: var(--text); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.22); padding: 8px; z-index: 40; }
.picker-pop .input { width: 100%; margin-bottom: 6px; }
.hm-hello { font-size: 22px; font-weight: 600; color: var(--primary); margin: 6px 0 12px; }
.hm-search { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.hm-search input { flex: 1; border: 0; outline: 0; font-size: 15px; background: transparent; }
.hm-results { background: #fff; border: 1px solid var(--line); border-radius: 10px; margin-top: 6px; overflow: hidden; }
.hm-label { font-size: 12px; color: var(--muted); margin: 18px 0 6px; }
.hm-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.hm-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--text); }
.hm-card:hover { border-color: var(--sage); }
.hm-n { font-size: 24px; font-weight: 600; color: var(--primary); }
.hm-list { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.hm-row { display: flex; align-items: center; gap: 10px; width: 100%; background: #fff; border: 0; border-top: 1px solid var(--line); padding: 10px 14px; text-align: left; cursor: pointer; font-size: 13.5px; color: var(--text); }
.hm-list .hm-row:first-child, .picker-pop .hm-row:first-child { border-top: 0; }
.hm-row:hover { background: #FAFBF9; }
.hm-name { flex: 1; min-width: 0; font-weight: 600; }
.hm-sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hm-pill { font-size: 11px; padding: 2px 9px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.hm-chev { color: var(--muted); }
.hm-more { color: var(--primary); justify-content: space-between; font-weight: 600; }
.hm-empty { padding: 14px; color: var(--muted); font-size: 13px; }
.hm-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.hm-chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.hm-chip { background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 4px 11px; font-size: 12px; cursor: pointer; color: var(--text); }
.hm-chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.hm-test { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.hm-test-tag { font-size: 10px; background: #FEF3C7; color: #92400E; padding: 1px 6px; border-radius: 99px; font-weight: 700; }
.hm-table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); }
.hm-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.hm-table td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.hm-table tbody tr[data-open] { cursor: pointer; }
.hm-table tbody tr[data-open]:hover { background: #FAFBF9; }
#journeyBar { padding: 12px 16px; }
.jb-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.jb-back { background: none; border: 0; color: var(--primary); cursor: pointer; font-size: 13px; font-weight: 600; padding: 0; }
.jb-ref { font-size: 12px; color: var(--muted); }

/* ---- One-row top bar with Tools and Account menus; setup notice only on Home ---- */
.topbar { flex-wrap: nowrap; gap: 10px; }
.topnav { margin-left: 12px; }
.topbar-actions { margin-left: auto; flex-wrap: nowrap; }
.tb-menu { position: relative; }
.tb-pop { position: absolute; right: 0; top: calc(100% + 6px); min-width: 250px; background: #fff; color: var(--text); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.22); padding: 6px; z-index: 45; display: flex; flex-direction: column; }
.tb-pop[hidden] { display: none; }
.tb-item { background: none; border: 0; text-align: left; padding: 9px 12px; border-radius: 8px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.tb-item:hover { background: #F4F5EF; }
.topbar .dy-badge { margin-left: 4px; }
.warn-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; background: #FFFBEB; border: 1px solid #F59E0B; border-radius: 10px; padding: 9px 14px; margin-bottom: 12px; font-size: 13px; color: #92400E; }
body.not-home #warnings { display: none; }
@media (max-width: 900px) { .topbar { flex-wrap: wrap; } }

/* ---------- Phases of work ---------- */
#phasesPanel { border: 1.5px solid #cbd5b0; background: #fbfcf6; }
.ph-dialog { border: none; border-radius: 14px; padding: 20px 22px; width: min(560px, 94vw); box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .35); }
.ph-dialog::backdrop { background: rgba(15, 23, 42, .45); }
.ph-warn { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; margin-bottom: 10px; }
.ph-agr { border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px 12px; margin: 10px 0; }
.ph-agr legend { font-weight: 700; font-size: 13px; padding: 0 6px; }
.ph-radio { display: block; padding: 4px 0; font-size: 13.5px; cursor: pointer; }
.ph-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.jb-phase { margin-left: auto; margin-right: 12px; font-size: 12px; font-weight: 700; color: var(--primary); background: #eef0e2; border-radius: 99px; padding: 2px 10px; }

/* Matter page flow: one next step, shared documents once, each phase's money cycle */
.fl-next { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; padding: 12px 14px; border-radius: 12px; border: 1.5px solid #facc15; background: #fefce8; }
.fl-next.wait { border-color: #f59e0b; background: #fffbeb; }
.fl-next.ok { border-color: #10b981; background: #ecfdf5; }
.fl-next-text { flex: 1 1 320px; min-width: 0; }
.fl-next-label { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: #6b7280; }
.fl-next-title { font-size: 15px; font-weight: 800; margin-top: 2px; }
.fl-next-sub { font-size: 12.5px; margin-top: 2px; line-height: 1.45; color: #4b5563; }
.fl-next-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.fl-label { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 12px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: #6b7280; margin: 16px 0 6px; }
.fl-bal { font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; color: #374151; }
.fl-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.fl-tile { text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; cursor: pointer; display: grid; gap: 2px; font: inherit; }
.fl-tile:hover { border-color: var(--sage); }
.fl-tile.active { box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 25%, transparent); border-color: var(--primary); }
.fl-tile-t { font-size: 13px; font-weight: 700; }
.fl-tile-s { font-size: 12px; color: #6b7280; }
.fl-tile.ok { background: #f0fdf4; border-color: #86efac; }
.fl-tile.ok .fl-tile-s { color: #166534; font-weight: 600; }
.fl-tile.warn { background: #fffbeb; border-color: #fcd34d; }
.fl-tile.warn .fl-tile-s { color: #92400e; font-weight: 600; }
.fl-phase { border: 1px solid #e2e6d3; border-radius: 12px; padding: 10px 12px; background: #fff; margin-top: 6px; }
.fl-phase.current { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 12%, transparent); }
.fl-phase.past { background: #f7f8f3; }
.fl-phase.past > summary { cursor: pointer; font-size: 13px; list-style: none; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.fl-phase.past > summary::-webkit-details-marker { display: none; }
.fl-tick { color: #166534; font-weight: 800; }
.fl-past-docs { color: #6b7280; font-size: 12px; }
.fl-phase-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.fl-badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #e5e7eb; color: #374151; }
.fl-badge.now { background: var(--primary); color: #fff; }
.fl-warn { font-size: 12px; font-weight: 600; color: #92400e; background: #fffbeb; border: 1px solid #fcd34d; border-radius: 99px; padding: 2px 9px; }
.fl-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; margin-top: 8px; }
.fl-phase-head + .fl-steps { margin-top: 0; }
.fl-step-box { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 9px; align-items: center; text-align: left; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff; font: inherit; }
.fl-step-btn { cursor: pointer; }
.fl-step-btn:hover { border-color: var(--primary); }
.fl-n { grid-row: 1 / span 2; display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid #d1d5db; font-size: 12px; font-weight: 800; color: #6b7280; background: #fff; }
.fl-t { font-size: 13px; font-weight: 700; }
.fl-s { font-size: 12px; color: #6b7280; }
.fl-step.done .fl-step-box { background: #f0fdf4; border-color: #86efac; }
.fl-step.done .fl-n { background: #dcfce7; border-color: #4ade80; color: #166534; }
.fl-step.now .fl-step-box { border-color: #f59e0b; background: #fffbeb; }
.fl-step.now .fl-n { background: #fef3c7; border-color: #f59e0b; color: #92400e; }
.fl-step.now .fl-s { color: #92400e; font-weight: 600; }
.fl-step.todo .fl-t { color: #374151; }
.fl-step.active .fl-step-box { box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent); }
.fl-docs { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin: 5px 2px 0; }
.fl-doc { font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: #fff; border: 1px solid #d1d5db; color: #374151; text-decoration: none; }
.fl-doc:hover { border-color: var(--primary); }
.fl-link { background: none; border: 0; color: var(--primary); cursor: pointer; font-size: 12px; font-weight: 600; padding: 0 2px; }
.fl-foot { margin-top: 12px; }
.fl-tools { margin-top: 8px; text-align: right; }
.fl-link.danger { color: #b91c1c; }
.fl-step.locked .fl-step-box { opacity: .65; }

/* A brand-new client: just the short form, nothing else on the page yet */
#matterView.is-new .matter-head-actions > button:not(#btnDeleteMatter),
#matterView.is-new #mStageWrap, #matterView.is-new #ledgerCards, #matterView.is-new #flowPanel, #matterView.is-new #docPanel,
#matterView.is-new #historyPanel, #matterView.is-new #fileNotesPanel, #matterView.is-new #onedrivePanel, #matterView.is-new #keyDatesPanel,
#matterView.is-new #nextPanel, #matterView.is-new #questionnairePanel, #matterView.is-new #questionnaireFormsPanel, #matterView.is-new #pipelinePanel, #matterView.is-new #closurePanel, #matterView.is-new #dossierPanel, #matterView.is-new #journeyBar { display: none !important; }
.nc-steps { display: flex; gap: 8px; flex-wrap: wrap; }
.nc-chip { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: #f3f4f6; color: #6b7280; }
.nc-chip.on { background: #dbeafe; color: #1e40af; font-weight: 700; }
.nc-more > summary { cursor: pointer; font-size: 13px; color: #4b5563; }

/* Phases of work: the empty state of a new client */
.fl-empty { border: 1.5px dashed #cbd5e1; border-radius: 12px; padding: 16px; background: #f8fafc; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.fl-empty-t { font-size: 15px; font-weight: 800; }
.fl-empty-s { font-size: 12.5px; color: #4b5563; line-height: 1.5; max-width: 560px; }
.fl-empty-note { font-size: 12px; color: #6b7280; }

.hm-noname { color: #9ca3af; font-style: italic; font-weight: 600; }

/* Letter of advice editor (public/letter-editor.js) */
.le-wrap { border: 1px solid #d1d5db; border-radius: 10px; background: #fff; overflow: hidden; }
.le-bar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 6px; background: #f9fafb; border-bottom: 1px solid #e5e7eb; position: relative; }
.le-btn { font-weight: 400; min-width: 32px; height: 30px; padding: 0 9px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; color: #1f2937; font-size: 13px; cursor: pointer; }
.le-btn:hover { background: #f3f4f6; }
.le-sep { width: 1px; height: 20px; background: #e5e7eb; margin: 0 3px; }
.le-hint { font-size: 12px; color: #92400e; background: #fef3c7; border-radius: 6px; padding: 3px 8px; margin-left: 6px; }
.le-edit { min-height: 260px; max-height: 70vh; overflow: auto; padding: 12px 14px; font-size: 14px; line-height: 1.55; outline: none; color: #111827; text-align: left; font-weight: 400; } /* the .field box around it is semi-bold: without this, B would think everything is already bold */
.le-edit:focus { box-shadow: inset 0 0 0 2px #e5d5a0; }
.le-edit p { margin: 0 0 6px; }
.le-edit h3 { font-size: 16px; margin: 12px 0 6px; color: #4b5320; }
.le-edit ul, .le-edit ol { margin: 0 0 8px 22px; padding: 0; }
.le-edit table.le-table { border-collapse: collapse; width: 100%; margin: 6px 0 10px; font-size: 13px; }
.le-edit table.le-table td { border: 1px solid #d1d5db; padding: 5px 7px; vertical-align: top; min-width: 40px; }
.le-edit table.le-table tr:first-child td { background: #4b5320; color: #fff; font-weight: 700; }
@media (max-width: 640px) { .le-btn { height: 36px; } .le-edit { min-height: 200px; } }

/* ---- Matter page: four tabs, one prompt, a quiet header ---- */
#matterView[data-tab="overview"] [data-mtab]:not([data-mtab~="overview"]),
#matterView[data-tab="people"] [data-mtab]:not([data-mtab~="people"]),
#matterView[data-tab="money"] [data-mtab]:not([data-mtab~="money"]),
#matterView[data-tab="records"] [data-mtab]:not([data-mtab~="records"]) { display: none !important; }
.mtabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line, #e5e7eb); margin: 4px 0 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.mtabs[hidden] { display: none; }
.mtab { background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -2px; padding: 10px 16px; font-size: 14px; font-weight: 600; color: var(--muted, #6b7280); cursor: pointer; white-space: nowrap; }
.mtab:hover { color: var(--primary); }
.newdoc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.newdoc-card { display: flex; flex-direction: column; gap: 3px; text-align: left; background: #fff; border: 1.5px solid var(--line, #e5e7eb); border-radius: 10px; padding: 12px; cursor: pointer; font: inherit; color: inherit; }
.newdoc-card:hover { border-color: var(--primary); }
.newdoc-card.on { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); background: #f8fafc; }
.newdoc-card .nd-icon { font-size: 22px; line-height: 1; }
.newdoc-card .nd-name { font-size: 14px; font-weight: 800; color: var(--primary); }
.newdoc-card .nd-what { font-size: 12.5px; color: #64748b; line-height: 1.35; }
.mtab { border-radius: 8px 8px 0 0; }
.mtab.on { color: #fff; background: var(--primary); border-bottom-color: var(--primary); }
.mtab.on:hover { color: #fff; }
.mtab-badge { font-size: 11px; font-weight: 700; color: #92400e; background: #fffbeb; border: 1px solid #fcd34d; border-radius: 99px; padding: 1px 8px; margin-left: 6px; }
#f956Panel { padding: 0; border: 0; background: none; box-shadow: none; }
#journeyBar { padding: 0 2px; border: 0; background: none; box-shadow: none; margin-bottom: 4px; }
#journeyBar .jb-top { margin-bottom: 4px; }
.jb-ref { display: none; }
.mh-more { position: relative; }
.mh-more > summary { list-style: none; cursor: pointer; }
.mh-more > summary::-webkit-details-marker { display: none; }
.mh-more-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; background: #fff; border: 1px solid var(--line, #e5e7eb); border-radius: 10px; box-shadow: 0 12px 30px rgba(0, 0, 0, .18); padding: 6px; display: flex; flex-direction: column; gap: 2px; min-width: 240px; }
.mh-more-pop .btn { width: 100%; justify-content: flex-start; text-align: left; }
#matterView.is-new .mh-more, #matterView.is-new .mtabs, #matterView.is-new #f956Panel { display: none !important; }
@media (max-width: 600px) { .mtab { padding: 10px 9px; font-size: 13px; } .mtab-badge { display: none; } }

/* Phone: the header scrolls away (it took a fifth of the screen), fee lines stack, long buttons wrap */
@media (max-width: 700px) {
  .topbar { position: static; }
  #fileNotesPanel .btn { white-space: normal; height: auto; text-align: left; }
  .lines thead { display: none; }
  .lines, .lines tbody { display: block; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr 36px; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .lines td { padding: 0; width: auto !important; }
  .lines td:has([data-k="description"]), .lines td:has([data-k="date"]), .lines td:has([data-k="basis"]) { grid-column: 1 / -1; }
  .lines td.col-gst { order: 1; grid-column: 1 / -1; text-align: left; }
  .lines td.col-gst::after { content: " GST-free"; font-size: 12.5px; color: var(--muted); }
}

.mtabs { position: sticky; top: var(--topbar-h, 0px); z-index: 4; background: var(--bg); }
