/* ImConvey design system — tokens only via custom properties. Teal/slate "fatigue-free" palette. */
:root {
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --accent-strong: color-mix(in srgb, var(--accent) 82%, #000);

  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-2: #475569;
  --muted: #64748b;

  --success: #15803d; --success-soft: #dcfce7;
  --warning: #b45309; --warning-soft: #fef3c7;
  --danger:  #b91c1c; --danger-soft:  #fee2e2;
  --info:    #1d4ed8; --info-soft:    #dbeafe;

  --chart-1: var(--accent); --chart-2: #6366f1; --chart-3: #f59e0b; --chart-4: #ec4899; --chart-5: #0ea5e9; --chart-6: #84cc16;

  --font-display: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", Consolas, monospace;

  --radius-sm: 6px; --radius: 10px; --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 40px rgba(15, 23, 42, .18);
  --sidebar-w: 248px;
  --topbar-h: 58px;
}
[data-theme="dark"] {
  --accent-ink: #04201d;
  --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
  --accent-strong: color-mix(in srgb, var(--accent) 70%, #fff);
  --bg: #0b1220;
  --surface: #111a2b;
  --surface-2: #152036;
  --surface-3: #1b2740;
  --border: #243149;
  --border-strong: #33425f;
  --text: #e2e8f0;
  --text-2: #b6c2d3;
  --muted: #8a99b0;
  --success: #4ade80; --success-soft: rgba(74, 222, 128, .14);
  --warning: #fbbf24; --warning-soft: rgba(251, 191, 36, .14);
  --danger:  #f87171; --danger-soft:  rgba(248, 113, 113, .14);
  --info:    #60a5fa; --info-soft:    rgba(96, 165, 250, .14);
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
body { margin: 0; font: 14px/1.55 var(--font-body); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.25; margin: 0 0 .5em; color: var(--text); letter-spacing: -.01em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; } h4 { font-size: .95rem; }
p { margin: 0 0 .75em; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
code, pre { font-family: var(--font-mono); font-size: .9em; }
pre { background: var(--surface-3); padding: .75rem; border-radius: var(--radius-sm); overflow-x: auto; }
.muted { color: var(--muted); }
.small, small { font-size: .85em; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.inline { display: inline; }
.hidden, [hidden] { display: none !important; }
.skip-link { position: absolute; left: -999px; top: 0; }
.skip-link:focus { left: 8px; top: 8px; z-index: 100; background: var(--surface); padding: .5rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: .75rem .6rem 2rem; }
.brand { display: flex; align-items: center; gap: .6rem; padding: .4rem .5rem .9rem; color: var(--text); font-family: var(--font-display); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-weight: 800; flex-shrink: 0; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-section { margin-bottom: .35rem; }
.nav-heading { list-style: none; cursor: pointer; font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: .55rem .6rem .3rem; }
.nav-heading::-webkit-details-marker { display: none; }
.nav-link { display: flex; align-items: center; gap: .55rem; padding: .38rem .6rem; border-radius: var(--radius-sm); color: var(--text-2); font-size: .9rem; }
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link.active { font-weight: 600; }
/* Multicolour nav icons (palette cycles per section; the SVG uses currentColor). */
:root { --ic-1:#3a8ef6; --ic-2:#2eb87a; --ic-3:#d4952a; --ic-4:#a855f7; --ic-5:#ec4899; --ic-6:#06b6d4; --ic-7:#f2542d; --ic-8:#6366f1; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ic-1:#6aa9ff; --ic-2:#4fd49a; --ic-3:#f0b54d; --ic-4:#c08bff; --ic-5:#f472b6; --ic-6:#22d3ee; --ic-7:#ff7a55; --ic-8:#8b8ff8; } }
:root[data-theme="dark"] { --ic-1:#6aa9ff; --ic-2:#4fd49a; --ic-3:#f0b54d; --ic-4:#c08bff; --ic-5:#f472b6; --ic-6:#22d3ee; --ic-7:#ff7a55; --ic-8:#8b8ff8; }
.nav-icon { width: 17px; height: 17px; flex-shrink: 0; transition: transform .15s ease; }
.nav-link:hover .nav-icon { transform: scale(1.1); }
.nav-link:nth-of-type(8n+1) .nav-icon { color: var(--ic-1); }
.nav-link:nth-of-type(8n+2) .nav-icon { color: var(--ic-2); }
.nav-link:nth-of-type(8n+3) .nav-icon { color: var(--ic-3); }
.nav-link:nth-of-type(8n+4) .nav-icon { color: var(--ic-4); }
.nav-link:nth-of-type(8n+5) .nav-icon { color: var(--ic-5); }
.nav-link:nth-of-type(8n+6) .nav-icon { color: var(--ic-6); }
.nav-link:nth-of-type(8n+7) .nav-icon { color: var(--ic-7); }
.nav-link:nth-of-type(8n+8) .nav-icon { color: var(--ic-8); }
.nav-link.active { background: var(--accent); color: #fff; box-shadow: 0 6px 16px -6px var(--accent); }
.nav-link.active .nav-icon { color: #fff; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-title { font-family: var(--font-display); }
.topbar-search { flex: 1; max-width: 520px; }
.topbar-search input { width: 100%; background: var(--surface-2); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer; font-size: 1rem; }
.icon-btn:hover { background: var(--surface-3); text-decoration: none; }
.dot-count { position: absolute; top: 2px; right: 0; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: .65rem; font-weight: 700; display: grid; place-items: center; }
.user-chip { list-style: none; display: flex; align-items: center; gap: .5rem; cursor: pointer; padding: .25rem .5rem; border-radius: 999px; }
.user-chip::-webkit-details-marker { display: none; }
.user-chip:hover { background: var(--surface-3); }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; font-size: .85rem; }
.content { padding: 1.5rem; max-width: 1400px; width: 100%; margin: 0 auto; }
.only-mobile { display: none; }
.sidebar-backdrop { display: none; }
.impersonation-bar { background: var(--warning-soft); color: var(--warning); padding: .5rem 1rem; text-align: center; font-weight: 600; display: flex; gap: 1rem; justify-content: center; align-items: center; }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .only-mobile { display: inline-grid; }
  .hide-mobile { display: none; }
  .content { padding: 1rem; }
}

/* ---------- Dropdown ---------- */
.dropdown { position: relative; }
.dropdown > summary { list-style: none; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: .35rem; z-index: 60; }
.dropdown-menu a, .dropdown-menu .linklike { display: block; width: 100%; text-align: left; padding: .45rem .6rem; border-radius: var(--radius-sm); color: var(--text); }
.dropdown-menu a:hover, .dropdown-menu .linklike:hover { background: var(--surface-3); text-decoration: none; }
.dropdown-head { padding: .45rem .6rem .6rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; display: flex; flex-direction: column; }
.linklike { background: none; border: 0; font: inherit; color: var(--accent-strong); cursor: pointer; padding: 0; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown-menu form { margin: 0; }
.dropdown-menu .linklike { font-weight: 500; }
/* Destructive actions live quietly in a menu rather than in a red box on the page. */
.dropdown-menu .menu-danger { color: var(--danger); }
.dropdown-menu .menu-danger:hover { background: var(--danger-soft); }
details.disclosure > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: .5rem; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before { content: "B8"; color: var(--muted); transition: transform .15s; }
details.disclosure[open] > summary::before { transform: rotate(90deg); }
details.disclosure[open] > summary { margin-bottom: .85rem; }

/* ---------- Page structure ---------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-header h1 { margin-bottom: .15rem; }
.page-header p { margin: 0; color: var(--muted); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.breadcrumbs { font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 1fr) 320px; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-sidebar { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: .85rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: 1.15rem 1.25rem; }
.card + .card { margin-top: 1rem; }
.grid > .card + .card { margin-top: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin: -.15rem 0 .85rem; }
.card-header h2, .card-header h3 { margin: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-header { padding: 1rem 1.25rem 0; }
.stat { display: flex; flex-direction: column; gap: .15rem; }
.stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-value { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; }
.stat-sub { font-size: .8rem; color: var(--muted); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty h3 { color: var(--text-2); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem .9rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 600 .875rem/1.2 var(--font-body); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); background: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .55; pointer-events: none; }

/* ---------- Forms ---------- */
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=date], input[type=time], input[type=datetime-local], input[type=tel], input[type=url], input[type=color], select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: 400 .9rem/1.4 var(--font-body);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 2rem; }
textarea { min-height: 90px; resize: vertical; }
input[type=file] { font: inherit; color: var(--text-2); }
input[type=file]::file-selector-button { margin-right: .6rem; padding: .4rem .75rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); font-weight: 600; cursor: pointer; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; }
.field { display: flex; flex-direction: column; gap: .3rem; }
/* Forms written as <label>Text <input></label> (without class="field") must still stack
   label above control, full width — otherwise the input sits inline, shrunk to content. */
form label:not(.check):not(.chip):not(.seg label):has(> input:not([type=checkbox]):not([type=radio]):not([type=hidden])),
form label:not(.check):not(.chip):has(> select),
form label:not(.check):not(.chip):has(> textarea) {
  display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; font-weight: 600; color: var(--text-2);
}
form label:has(> input[type=checkbox]), form label:has(> input[type=radio]) {
  display: inline-flex; align-items: center; gap: .45rem; font-weight: 500; cursor: pointer;
}
/* Stacked bare labels inside a form get breathing room when they are not in a grid. */
form > label + label, form > label + .field, form > .field + label { margin-top: .85rem; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
.field > span, .field > label, .label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: .78rem; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; }
.form-grid { display: grid; gap: .9rem 1rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 150px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .35rem; font-family: var(--font-display); }

/* ---------- Segmented control & chips ---------- */
.seg { display: inline-flex; background: var(--surface-3); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label, .seg a, .seg button { padding: .32rem .75rem; border-radius: 5px; font-weight: 600; font-size: .82rem; color: var(--text-2); cursor: pointer; border: 0; background: none; }
.seg input:checked + label, .seg a.active, .seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); text-decoration: none; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .22rem .65rem; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); font-size: .8rem; font-weight: 600; color: var(--text-2); cursor: pointer; }
.chip.active, .chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.chip input { display: none; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 700; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge-open, .badge-active, .badge-paid, .badge-done, .badge-completed, .badge-verified, .badge-approved, .badge-ok, .badge-published, .badge-confirmed, .badge-success { background: var(--success-soft); color: var(--success); }
.badge-in_progress, .badge-sent, .badge-pending, .badge-part_paid, .badge-todo, .badge-scheduled, .badge-info, .badge-running, .badge-queued { background: var(--info-soft); color: var(--info); }
.badge-on_hold, .badge-waiting, .badge-draft, .badge-warning, .badge-high, .badge-review { background: var(--warning-soft); color: var(--warning); }
.badge-overdue, .badge-failed, .badge-rejected, .badge-urgent, .badge-suspended, .badge-danger, .badge-cancelled, .badge-void { background: var(--danger-soft); color: var(--danger); }
.badge-closed, .badge-na, .badge-skipped, .badge-archived, .badge-low { background: var(--surface-3); color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: .6rem .75rem; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.data-table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table a.row-link { color: var(--text); font-weight: 600; }
.pagination { display: flex; gap: .35rem; justify-content: flex-end; align-items: center; padding: .75rem; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: .15rem; border-bottom: 1px solid var(--border); margin-bottom: 1.1rem; overflow-x: auto; scrollbar-width: thin; }
.tab { padding: .6rem .85rem; font-weight: 600; font-size: .875rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; background: none; border-top: 0; border-left: 0; border-right: 0; cursor: pointer; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active, .tab[aria-selected="true"] { color: var(--accent-strong); border-bottom-color: var(--accent); }
.tab-count { margin-left: .3rem; font-size: .72rem; background: var(--surface-3); padding: .05rem .4rem; border-radius: 999px; }

/* ---------- Flash ---------- */
.flash { position: relative; padding: .7rem 2.3rem .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-weight: 500; border: 1px solid transparent; }
.flash-success { background: var(--success-soft); color: var(--success); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-info { background: var(--info-soft); color: var(--info); }
.flash-warning { background: var(--warning-soft); color: var(--warning); }
.flash-close { position: absolute; right: .5rem; top: .45rem; border: 0; background: none; color: inherit; font-size: 1.2rem; cursor: pointer; }
.callout { padding: .8rem 1rem; border-radius: var(--radius); background: var(--surface-2); border-left: 3px solid var(--accent); }
.callout-warning { border-left-color: var(--warning); background: var(--warning-soft); }
.callout-danger { border-left-color: var(--danger); background: var(--danger-soft); }

/* ---------- Modal (<dialog>) with sticky footer ---------- */
dialog.modal { border: 0; border-radius: var(--radius-lg); padding: 0; width: min(640px, calc(100vw - 2rem)); max-height: calc(100vh - 3rem); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.modal-lg { width: min(960px, calc(100vw - 2rem)); }
dialog.modal-xl { width: min(1280px, calc(100vw - 2rem)); height: calc(100vh - 3rem); }
dialog.modal::backdrop { background: rgba(15, 23, 42, .5); }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100vh - 3rem); height: 100%; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 1.1rem 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer { position: sticky; bottom: 0; display: flex; gap: .5rem; justify-content: flex-end; padding: .85rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface); }

/* ---------- Floating action cluster ---------- */
.fab-cluster { position: fixed; right: 1.25rem; bottom: 1.25rem; display: flex; flex-direction: column; gap: .5rem; z-index: 30; }
.fab { width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); border: 0; box-shadow: var(--shadow-lg); font-size: 1.4rem; cursor: pointer; display: grid; place-items: center; }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 260px; width: 100%; }
.chart-box.sm { height: 180px; } .chart-box.lg { height: 340px; }
.chart-box svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-legend { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .78rem; color: var(--muted); margin-top: .4rem; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }
.chart-tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: .75rem; padding: .25rem .5rem; border-radius: 4px; white-space: nowrap; transform: translate(-50%, -120%); }
.progress { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- Lists, timeline, kanban ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: .75rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--border); }
.timeline > li { position: relative; padding: 0 0 1rem .75rem; }
.timeline > li::before { content: ""; position: absolute; left: -1.43rem; top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline > li.done::before { background: var(--accent); }
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: 1rem; overflow-x: auto; padding-bottom: .5rem; }
.kanban-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem; min-height: 300px; }
.kanban-col.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.kanban-col h3 { font-size: .85rem; display: flex; justify-content: space-between; padding: .2rem .3rem .6rem; }
.kanban-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .7rem; margin-bottom: .5rem; box-shadow: var(--shadow-sm); cursor: grab; }
.kanban-card.dragging { opacity: .5; }
.launcher-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .75rem; }
.launcher-item { display: block; padding: .85rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.launcher-item:hover { border-color: var(--accent); text-decoration: none; box-shadow: var(--shadow); }
.launcher-item strong { display: block; margin-bottom: .15rem; }
.launcher-item span { font-size: .82rem; color: var(--muted); }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.cal-grid > div { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); min-height: 105px; padding: .3rem; font-size: .78rem; background: var(--surface); }
.cal-grid .cal-head { min-height: 0; background: var(--surface-2); font-weight: 700; text-align: center; color: var(--muted); }
.cal-grid .cal-out { background: var(--surface-2); color: var(--muted); }
.cal-grid .cal-today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-event { display: block; padding: .1rem .35rem; margin-top: .2rem; border-radius: 4px; background: var(--accent-soft); color: var(--accent-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }

/* ---------- Auth & errors ---------- */
.auth-body { background: radial-gradient(circle at 20% 0%, var(--accent-soft), transparent 50%), var(--bg); }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: min(420px, 100%); padding: 2rem; }
.auth-brand { display: flex; align-items: center; gap: .6rem; font-family: var(--font-display); font-weight: 800; margin-bottom: 1.25rem; }
.auth-title { font-size: 1.4rem; margin-bottom: .2rem; }
.auth-links { margin-top: 1rem; font-size: .85rem; text-align: center; }
.auth-foot { margin-top: 1rem; font-size: .8rem; }
.error-card { width: min(640px, 100%); text-align: center; padding: 2.5rem 2rem; }
.error-code { font-family: var(--font-display); font-size: 3rem; font-weight: 800; color: var(--accent); margin: 0; }
.debug { text-align: left; font-size: .75rem; max-height: 50vh; white-space: pre-wrap; }

/* ---------- Public site baseline ---------- */
.public-body { background: var(--surface); }

@media print { .sidebar, .topbar, .fab-cluster, .flash-close { display: none !important; } .content { padding: 0; } }

/* ======================================================================
   Component layer for class names used by module views.
   Several modules were written against these names without styles existing,
   which left controls, the document viewer and editors unstyled.
   ====================================================================== */

/* A control that carries .field itself (rather than a wrapping label). */
input.field, select.field, textarea.field { display: block; width: 100%; }
.field-wrap, .field-label { display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; font-weight: 600; color: var(--text-2); }
.field-wrap:has(> input[type=checkbox]), .field-label:has(> input[type=checkbox]),
.field-wrap:has(> input[type=radio]), .field-label:has(> input[type=radio]) { flex-direction: row; align-items: center; gap: .45rem; font-weight: 500; }
.field-wrap.span-2, .field-label.span-2 { grid-column: 1 / -1; }
.form-grid > .field-wrap, .form-grid > .field-label { min-width: 0; }
.inline-checkbox { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; }

.empty-state { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty-state h3 { color: var(--text-2); }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain > li { padding: .55rem 0; border-bottom: 1px solid var(--border); }
.list-plain > li:last-child { border-bottom: 0; }
.list-item { transition: background .12s; }
.list-item:hover { background: var(--surface-2); }
.list-item.active, .list-item[aria-current="true"] { background: var(--accent-soft); }
.side-col { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.side-col > .card + .card { margin-top: 0; }

/* ---------- In-browser document viewer ---------- */
.doc-viewer { display: flex; flex-direction: column; height: min(80vh, 960px); min-height: 440px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
dialog .doc-viewer { height: calc(100vh - 9rem); border: 0; border-radius: 0; }
.doc-viewer-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem .9rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.doc-viewer-toolbar strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-viewer-body { flex: 1; min-height: 0; overflow: auto; background: var(--surface-3); }
.doc-viewer-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.doc-viewer-body > .empty { margin: 3rem auto; max-width: 520px; }
/* Word documents render as a page of paper, in both themes. */
.doc-viewer-docx { max-width: 860px; margin: 1.5rem auto; padding: 3rem 3.5rem; background: #fff; color: #1e293b; box-shadow: var(--shadow); border-radius: 4px; line-height: 1.6; font-family: Georgia, "Times New Roman", serif; }
.doc-viewer-docx h1, .doc-viewer-docx h2, .doc-viewer-docx h3 { color: #0f172a; }
.doc-viewer-docx table { border-collapse: collapse; width: 100%; margin: .75rem 0; }
.doc-viewer-docx td, .doc-viewer-docx th { border: 1px solid #cbd5e1; padding: .35rem .5rem; vertical-align: top; }
.doc-viewer-docx img { max-width: 100%; }
.doc-viewer-text, .doc-viewer-pre { margin: 0; }
.doc-viewer-text pre, .doc-viewer-pre { padding: 1rem 1.25rem; background: transparent; white-space: pre-wrap; word-break: break-word; min-height: 100%; color: var(--text); }
@media (max-width: 700px) { .doc-viewer-docx { padding: 1.5rem 1.25rem; margin: .75rem; } }

/* ---------- Rich-text editor (document templates) ---------- */
.rte-toolbar { display: flex; flex-wrap: wrap; gap: .25rem; padding: .4rem; border: 1px solid var(--border-strong); border-bottom: 0; border-radius: var(--radius-sm) var(--radius-sm) 0 0; background: var(--surface-2); }
.rte-toolbar button, .rte-toolbar select { font: 600 .82rem/1 var(--font-body); padding: .38rem .6rem; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--text-2); cursor: pointer; }
.rte-toolbar select { width: auto; border-color: var(--border); background-color: var(--surface); padding-right: 1.75rem; }
.rte-toolbar button:hover { background: var(--surface-3); color: var(--text); }
.rte-toolbar button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-strong); }
.rte-toolbar .rte-sep { width: 1px; align-self: stretch; margin: .15rem .2rem; background: var(--border); }
.rte-toolbar + .rte-editor { border-top-left-radius: 0 !important; border-top-right-radius: 0 !important; border-color: var(--border-strong) !important; }
.rte-editor { color: var(--text); font-weight: 400; font-size: .92rem; line-height: 1.65; overflow-wrap: anywhere; }
.rte-editor:focus { outline: none; border-color: var(--accent) !important; box-shadow: 0 0 0 3px var(--accent-soft); }
.rte-editor p { margin: 0 0 .75em; }
.rte-editor ul, .rte-editor ol { padding-left: 1.4rem; }
.rte-editor .merge-tag, .rte-editor code { background: var(--accent-soft); color: var(--accent-strong); padding: 0 .25rem; border-radius: 3px; font-size: .88em; }

/* ---------- Form builder toolbox ---------- */
.toolbox { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
.toolbox > * { justify-content: flex-start; text-align: left; font-weight: 500; font-size: .82rem; padding: .45rem .6rem; }

/* ---------- Public form & signature pad ---------- */
.public-form-wrap .card { padding: 1.75rem 2rem; }
.public-form-wrap h1 { font-size: 1.5rem; }
.sig-pad-wrap { display: flex; flex-direction: column; align-items: flex-start; }
.sig-pad { display: block; cursor: crosshair; }
@media (max-width: 600px) { .public-form-wrap .card { padding: 1.25rem; } }

/* ---------- Narrow-screen integrity ----------
   Grid/flex children default to min-width:auto (their content's size), which lets a wide input,
   table or long word stretch a column past the screen. Let them shrink, and let rows wrap. */
.grid > *, .form-grid > *, .grid-sidebar > *, .card, .card-header > *, .page-header > * { min-width: 0; }
.card-header { flex-wrap: wrap; row-gap: .5rem; }
.chips, .filters, .actions, .row, .topbar-actions { flex-wrap: wrap; }
.callout, .card, .empty, td, dd { overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .card { padding: 1rem; }
  .page-header h1 { font-size: 1.35rem; }
  .page-header { gap: .75rem; }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; }
  .form-actions { justify-content: stretch; }
  .form-actions .btn { flex: 1 1 auto; }
}
/* Month grid: events sit inside narrow day cells, so they truncate rather than widen the grid. */
.cal-grid > div { min-width: 0; overflow: hidden; }
.cal-grid .chip, .cal-grid a { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { .cal-grid > div { min-height: 64px; padding: .2rem; font-size: .7rem; } }
