/* ==========================================================================
   Reporting workbench — light theme, full width, data first.
   The product cost table is the application. Controls collapse into one
   toolbar; setup and ops live in a right-hand drawer, never above the work.
   ========================================================================== */

:root {
    --bg:            #eef1f5;
    --surface:       #ffffff;
    --surface-2:     #f7f9fb;
    --surface-3:     #eef2f7;
    --border:        #dde3ea;
    --border-strong: #c4ccd6;

    --text:          #16202b;
    --text-muted:    #5b6878;
    --text-faint:    #8a95a3;

    --brand:         #1e63d0;
    --brand-strong:  #1a58bb;
    --brand-dark:    #164ea6;
    --brand-soft:    #e7f0fd;

    --success:       #126b3f;
    --success-soft:  #e4f5eb;
    --danger:        #b3261e;
    --danger-soft:   #fdeae8;
    --warning:       #8a5a00;
    --warning-soft:  #fdf1dc;

    --radius:    8px;
    --radius-sm: 5px;
    --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
    --shadow-md: 0 6px 20px rgba(16,24,40,.12);
    --shadow-lg: -8px 0 34px rgba(16,24,40,.18);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --topbar-h: 52px;
}

* { box-sizing: border-box; }

/* The [hidden] attribute must always win over component display rules.
   Without this, `.drawer { display:flex }` beat `hidden` and the setup drawer
   stayed permanently on screen, covering the page. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
    margin: 0; padding: 0;
    font-family: var(--font); font-size: 13.5px; line-height: 1.5;
    color: var(--text); background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
body.drawer-open { overflow: hidden; }

h1,h2,h3,h4 { margin: 0 0 8px; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.02rem; }
h3 { font-size: .92rem; margin-top: 18px; }
p { margin: 0 0 8px; }
a { color: var(--brand); }
.muted { color: var(--text-muted); }
.small { font-size: .85em; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1 1 auto; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------------------- topbar --- */
.topbar {
    position: sticky; top: 0; z-index: 60;
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    min-height: var(--topbar-h);
    padding: 7px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; flex: 0 0 30px; border-radius: 7px;
    background: var(--brand); color: #fff; font-weight: 800; font-size: .78rem; letter-spacing: .02em;
}

/* toolbar: the whole report form on one line */
.toolbar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.tb-field { display: flex; flex-direction: column; gap: 2px; position: relative; }
.tb-field > span {
    font-size: .66rem; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; color: var(--text-faint);
}
.toolbar input[type=date], .toolbar select, .tb-select {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    padding: 5px 8px; height: 31px;
}
.tb-select { cursor: pointer; text-align: left; min-width: 132px; font-weight: 500; }
.tb-select:hover { border-color: var(--brand); color: var(--brand); }
.toolbar button.primary {
    height: 31px; padding: 0 16px; font-weight: 650;
    background: var(--brand); color: #fff; border: 1px solid var(--brand);
    border-radius: var(--radius-sm); cursor: pointer;
}
.toolbar button.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.popover {
    position: absolute; top: calc(100% + 6px); left: 0; z-index: 70;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    padding: 10px; width: 460px; max-height: 340px; overflow: auto;
}

/* presence */
.presence { display: flex; align-items: center; gap: 7px; }
.presence #live-user-info {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
    background: var(--surface-3); color: var(--text-muted);
    font-size: .75rem; font-weight: 700;
}
#active-user-list { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
#active-user-list li {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px; border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--border);
    font-size: .76rem; font-weight: 650; white-space: nowrap;
}
.icon-btn {
    width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
    background: var(--surface); color: var(--text-muted);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    font-size: 1.05rem; cursor: pointer;
}
.icon-btn:hover { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }

/* ------------------------------------------------------- partner bar ---- */
.partner-bar {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 8px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.pb-label { font-size: .66rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
.pb-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 6px 3px 11px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border-strong); font-size: .82rem;
}
.pb-chip button {
    background: var(--brand-soft); color: var(--brand); border: none;
    border-radius: 999px; padding: 2px 9px; font-size: .74rem; font-weight: 650; cursor: pointer;
}
.pb-chip button:hover { background: var(--brand); color: #fff; }

/* ---------------------------------------------------------- work area --- */
.work { padding: 16px; }
.empty-state {
    background: var(--surface); border: 1px dashed var(--border-strong);
    border-radius: var(--radius); padding: 56px 24px; text-align: center; color: var(--text-muted);
}
.empty-state h2 { color: var(--text); }

.run-meta { font-size: .85rem; color: var(--text-muted); margin-bottom: 10px; }
.run-meta p { margin: 0 0 3px; }

/* Headline numbers. Deliberately NOT sticky: a sticky tile row collided with
   the sticky table header and clipped it. The column headers are what you need
   while scrolling a long table. */
.stat-row {
    display: flex; gap: 10px; flex-wrap: wrap;
    padding: 10px 0 12px; margin-bottom: 4px;
}
.stat {
    display: flex; flex-direction: column; gap: 1px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 9px 16px; min-width: 150px;
    box-shadow: var(--shadow-sm);
}
.stat-k { font-size: .66rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
.stat-v { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.is-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.stat.is-primary .stat-k { color: rgba(255,255,255,.8); }

/* table tools */
.table-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 18px 0 6px; }
.table-tools h2 { margin: 0; }
.table-tools input[type=search] {
    font: inherit; padding: 6px 10px; min-width: 240px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
}
.table-tools .chk { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--text-muted); cursor: pointer; }

/* ------------------------------------------------------------ tables ---- */
table { border-collapse: collapse; width: 100%; }

.reimbursement-summary-table, .admin-table, .report-history-table {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); font-size: .88rem; margin: 0 0 18px;
    /* NOTE: no `overflow:hidden` here — it silently breaks position:sticky on
       the header cells and drops the header below the first row. */
}
.reimbursement-summary-table th, .admin-table th, .report-history-table th {
    position: sticky; top: var(--topbar-h); z-index: 25;
    background: var(--surface-3); color: var(--text-muted);
    font-size: .68rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase;
    text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border-strong);
}
.admin-table th, .report-history-table th { position: static; }
.reimbursement-summary-table td, .admin-table td, .report-history-table td {
    padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top;
}
.reimbursement-summary-table tbody tr:nth-child(even) > td { background: var(--surface-2); }
.reimbursement-summary-table tbody tr:hover > td,
.admin-table tbody tr:hover td { background: var(--brand-soft); }

.reimbursement-summary-table .cost-input,
.reimbursement-summary-table .row-total,
.reimbursement-summary-table .selling-price,
.reimbursement-summary-table .item-margin,
.reimbursement-summary-table .total-cell,
.reimbursement-summary-table .quantity,
.payout-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

.reimbursement-summary-table tfoot td {
    font-weight: 700; background: var(--surface-3);
    border-top: 2px solid var(--border-strong); border-bottom: none; padding: 9px 10px;
}
.reimbursement-summary-table input[type=number] {
    width: 88px; padding: 4px 7px; text-align: right; font: inherit;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
}
.reimbursement-summary-table input[type=number]:focus {
    outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.item-cost-input.cost-zero {
    background: var(--danger-soft) !important; border-color: var(--danger) !important;
    color: var(--danger); font-weight: 700;
}

.cost-meta { font-size: .75rem; color: var(--text-muted); display: block; margin-top: 3px; }
.history-toggle { cursor: pointer; color: var(--brand); font-weight: 650; margin-left: 5px; }
.cost-history-table { display: none; width: 100%; margin-top: 6px; font-size: .78rem; border: 1px solid var(--border); }
.cost-history-table th, .cost-history-table td { padding: 3px 7px; position: static; text-transform: none; letter-spacing: 0; font-size: 1em; }
.cost-history-table td:nth-child(1) { text-align: right; }
.cost-history-table td:nth-child(3) { color: var(--text-faint); white-space: nowrap; }

.my-editing-row > td { background: var(--brand-soft) !important; }
.my-editing-row > td:first-child { box-shadow: inset 3px 0 0 var(--user-edit-color); }
.other-user-editing-row > td { background: var(--surface-3) !important; }
.other-user-editing-row > td:first-child { box-shadow: inset 3px 0 0 currentColor; }
.other-user-hovering-row > td { background: var(--warning-soft) !important; }
.cost-meta .other-user-label { font-weight: 700; margin-left: 4px; }
.cost-meta .locked-by-label { font-weight: 700; color: var(--danger); margin-left: 4px; }

/* Person colours are arbitrary, so they are shown as a dot — never as text
   colour or a full background, where contrast is unreadable. */
.who { display: inline-flex; align-items: center; gap: 5px; font-weight: 650; color: var(--text); }
.who-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; border: 1px solid rgba(0,0,0,.15); }

/* -------------------------------------------------------- payout ------- */
.partner-payout {
    background: var(--surface); border: 1px solid var(--border);
    border-left: 4px solid var(--brand);
    border-radius: var(--radius); padding: 14px 18px; margin: 0 0 14px;
    box-shadow: var(--shadow-sm);
}
.partner-payout h2 { margin: 0 0 4px; color: var(--brand-dark); }
.partner-payout .pp-meta { font-size: .8rem; color: var(--text-muted); margin: 2px 0; }
.payout-table { width: auto; min-width: 320px; margin: 10px 0 0; }
.payout-table td { padding: 5px 20px 5px 0; border-bottom: 1px solid var(--border); }
.payout-table tr.sub td { font-size: .8rem; color: var(--text-muted); border-bottom: 1px dotted var(--border); }
.payout-table tr.grand td {
    font-weight: 800; font-size: 1.3rem; color: var(--brand-dark);
    border-top: 2px solid var(--brand); border-bottom: none; padding-top: 9px;
}

/* -------------------------------------------------------- drawer ------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(16,24,40,.4); z-index: 90; }
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 100;
    width: clamp(600px, 66vw, 1500px); background: var(--surface);
    border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
}
.drawer-head {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.drawer-head strong { font-size: .95rem; }
.drawer .admin-area { flex: 1 1 auto; overflow-y: auto; padding: 0 20px 20px; }
.drawer .admin-nav {
    position: sticky; top: 0; z-index: 5; background: var(--surface);
    display: flex; gap: 2px; flex-wrap: wrap; padding-top: 8px;
    border-bottom: 1px solid var(--border); margin-bottom: 14px;
}
.admin-toggle {
    background: transparent; color: var(--text-muted); border: none;
    /* NOTE: hover must set background AND colour together — see :hover below. */
    border-bottom: 2px solid transparent; padding: 8px 12px;
    font: inherit; font-weight: 650; cursor: pointer; border-radius: 0;
}
.admin-toggle:hover { background: var(--surface-2); color: var(--brand-dark); border-bottom-color: var(--border-strong); }
.admin-toggle.active { color: var(--brand); border-bottom-color: var(--brand); }
.admin-panel { padding-bottom: 8px; }
/* Wider drawer: keep table text on one line and stop stray wrapping. */
.drawer .admin-table td, .drawer .admin-table th { white-space: nowrap; }
.drawer .admin-table td.wrap, .drawer .report-history-table td:nth-child(6) { white-space: normal; }
.drawer .admin-table { table-layout: auto; width: 100%; }
.drawer h3 { margin-top: 14px; }
.drawer .card-title { margin-bottom: 10px; }

/* ------------------------------------------------------- forms/admin --- */
label { font-weight: 600; }
input[type=text], input[type=date], input[type=number], input[type=password], input[type=search], select, textarea {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 6px 9px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type=color] { padding: 2px; height: 30px; width: 42px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
input:disabled { background: var(--surface-3); color: var(--text-faint); cursor: not-allowed; }

.frow { margin: 8px 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.frow > label:first-child { width: 210px; font-weight: 650; }
.frow input[type=text], .frow input[type=password], .frow input[type=number], .frow select { min-width: 210px; }

button, .action-button {
    font: inherit; font-weight: 650; padding: 7px 14px;
    border: 1px solid var(--brand); border-radius: var(--radius-sm);
    background: var(--brand); color: #fff; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .action-button:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
button.mini, button.secondary {
    background: var(--surface); color: var(--text); border-color: var(--border-strong);
    padding: 4px 9px; font-size: .82rem; margin-right: 4px;
}
button.mini:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
button.mini.danger { color: var(--danger); }
button.mini.danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.status-checkboxes, .date-criteria-options { display: flex; flex-wrap: wrap; gap: 6px; }
.status-checkboxes label {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border-strong);
    font-size: .8rem; font-weight: 500; cursor: pointer;
}
.status-checkboxes label:hover { border-color: var(--brand); color: var(--brand); }
.status-checkboxes label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); font-weight: 650; }

.overrides-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 12px 0; background: var(--surface-2); }
.overrides-box legend { font-weight: 700; padding: 0 6px; }
.ov-picker { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.ov-search { flex: 1 1 300px; min-width: 260px; }
.ov-search input[type=text] { width: 100%; }
.ov-staging { flex: 1 1 320px; min-width: 280px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; background: var(--surface); }
.ov-staging-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.prod-results { max-height: 230px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 6px; }
.prod-results:empty { border: none; }
.prow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.prow:last-child { border-bottom: none; }
.prow:hover { background: var(--brand-soft); }
.prow.is-staged { background: var(--success-soft); color: var(--success); }
.prow .prow-add { font-size: .76rem; font-weight: 700; color: var(--brand); white-space: nowrap; }
.prow.is-staged .prow-add { color: var(--success); }

/* -------------------------------------------------------- misc --------- */
.gate { max-width: 420px; margin: 12vh auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow-md); }
.gate input[type=text] { width: 100%; margin: 8px 0 14px; }

.alert { margin: 10px 16px 0; padding: 9px 13px; border-radius: var(--radius-sm); border: 1px solid; font-size: .86rem; }
.alert-error   { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.name-error-message, .status-error-message { color: var(--danger); font-weight: 650; }

.action-buttons { margin: 14px 0; display: flex; gap: 10px; flex-wrap: wrap; }
.chart-panel { margin: 10px 0 16px; }
.chart-panel > summary {
    cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px;
    font-weight: 650; font-size: .9rem; color: var(--text-muted);
    padding: 6px 0; user-select: none;
}
.chart-panel > summary::-webkit-details-marker { display: none; }
.chart-panel > summary::before { content: '▸'; font-size: .8em; }
.chart-panel[open] > summary::before { content: '▾'; }
.chart-container { position: relative; height: 190px; margin: 4px 0 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; }
hr { border: none; border-top: 1px solid var(--border); color: var(--border); margin: 18px 0; }

#toast-notification {
    position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(8px);
    background: #16202b; color: #fff; padding: 10px 18px; border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md); z-index: 1000; display: none; opacity: 0;
    transition: opacity .2s ease, transform .2s ease;
}
#toast-notification.show { display: block; opacity: 1; transform: translateX(-50%) translateY(0); }

/* The dot is translucent through its own background colour, not through
   element opacity: opacity applies to children too, and it faded the name
   label until the text was unreadable against the page. */
.mouse-blob {
    position: absolute; width: 20px; height: 20px; border-radius: 50%;
    pointer-events: none; z-index: 9999;
    border: 2px solid #fff; box-shadow: var(--shadow-sm);
    transition: left .1s linear, top .1s linear;
}
.mouse-blob-label {
    position: absolute; top: 50%; left: 100%; transform: translateY(-50%);
    margin-left: 6px; padding: 1px 7px; border-radius: 999px;
    background: rgba(22,32,43,.85); color: #fff; font-size: 10px; font-weight: 650; white-space: nowrap;
}

@media (max-width: 1000px) {
    .toolbar { width: 100%; }
    .stat-row { position: static; }
    .reimbursement-summary-table th { position: static; }
}

/* Report-history type tags */
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .74rem; font-weight: 650;
       background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border); white-space: nowrap; }
.tag-partner { background: var(--brand-soft); color: var(--brand-dark); border-color: var(--brand); }
.status-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 3px; }
.status-list li { font-size: .74rem; background: var(--surface-3); border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; }

/* Live collaboration cursors must never affect layout or scroll extents. */
#mouse-blob-container {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    overflow: hidden; pointer-events: none; z-index: 9998;
}
.alert-ok { background: var(--success-soft); border-color: var(--success); color: var(--success); }

/* Payout breakdown is supporting detail; the tiles carry the headline numbers. */
.partner-payout > summary { cursor: pointer; font-weight: 700; color: var(--brand-dark); padding: 2px 0; list-style: none; }
.partner-payout > summary::-webkit-details-marker { display: none; }
.partner-payout > summary::before { content: '▾ '; font-size: .8em; }
.partner-payout:not([open]) > summary::before { content: '▸ '; }
.ov-list { margin-top: 8px; }
.ov-list > summary { cursor: pointer; font-size: .82rem; color: var(--text-muted); font-weight: 600; }
.ov-list ul { margin: 6px 0 0 18px; padding: 0; font-size: .82rem; color: var(--text-muted); columns: 2; }

/* Report history: virtualised-feel infinite scroll inside the drawer. */
.history-scroll { max-height: 62vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.history-scroll .report-history-table { margin: 0; border: none; border-radius: 0; }
.history-scroll .report-history-table th { position: sticky; top: 0; z-index: 3; }
.history-sentinel { padding: 10px; text-align: center; }
.pb-chip select { font: inherit; font-size: .74rem; border: 1px solid var(--border-strong); border-radius: 999px; padding: 1px 6px; background: var(--surface); color: var(--text-muted); }

/* Settings: grouped, labelled, with inline guidance. */
.set-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 16px; background: var(--surface-2); }
.set-group legend { font-weight: 700; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: 0 6px; }
.set-group .frow { margin: 10px 0; align-items: flex-start; }
.set-group .frow > label:first-child { width: 190px; padding-top: 6px; }
.hint { font-size: .78rem; color: var(--text-faint); flex: 1 1 240px; }
/* The settings status picker uses the shared .status-picker sizing. An older
   rule here forced a 150px min-height, left over from when this was a multi
   select; it opened the dropdown 150px too low, over the next field. */

/* ---- Shared order-status picker (toolbar, partner form, settings) ---- */
.status-picker { position: relative; display: inline-block; }
.status-picker .sp-toggle {
    font: inherit; height: 31px; padding: 0 12px; min-width: 140px; text-align: left;
    background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); cursor: pointer; font-weight: 500;
}
.status-picker .sp-toggle::after { content: ' ▾'; color: var(--text-faint); }
.status-picker .sp-toggle:hover { border-color: var(--brand); color: var(--brand); background: var(--surface); }
.status-picker .sp-panel {
    position: absolute; top: calc(100% + 6px); left: 0; z-index: 80;
    width: 340px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 8px;
}
.status-picker .sp-tools { display: flex; gap: 6px; margin-bottom: 6px; }
.status-picker .sp-search { flex: 1 1 auto; min-width: 0; }
.status-picker .sp-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.status-picker .sp-item {
    display: flex; align-items: center; gap: 7px; padding: 4px 7px;
    border-radius: var(--radius-sm); font-size: .84rem; font-weight: 500;
    color: var(--text); cursor: pointer;
}
/* Hover must keep text readable — set colour whenever background changes. */
.status-picker .sp-item:hover { background: var(--brand-soft); color: var(--brand-dark); }
.status-picker .sp-item:has(input:checked) { background: var(--surface-3); color: var(--text); font-weight: 650; }
.status-picker .sp-item:has(input:checked):hover { background: var(--brand-soft); color: var(--brand-dark); }

/* Reserve space for content that arrives asynchronously, so the toolbar and
   main area do not jump (this was the main source of layout shift). */
.presence { min-width: 150px; justify-content: flex-end; }
#active-user-list { min-height: 22px; align-items: center; }
.work { min-height: 55vh; }
.status-picker .sp-toggle { min-width: 150px; }
.table-tools { min-height: 34px; }
/* Presence is fixed-width so late-arriving colleagues never reflow the toolbar. */
.presence { width: 190px; overflow: hidden; flex: 0 0 190px; }

/* ---- Sign in ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { width: 380px; max-width: 92vw; background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 26px; }
.login-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-head h1 { font-size: 1.02rem; margin: 0; }
.login-head p { margin: 2px 0 0; }
.login-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.login-field label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); }
.login-field input { width: 100%; padding: 9px 11px; }
.login-submit { width: 100%; text-align: center; padding: 10px; }
.login-foot { margin: 16px 0 0; text-align: center; }
.site-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.site-picker label { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
                     background: var(--surface); border: 1px solid var(--border-strong); font-size: .82rem; cursor: pointer; }
.site-picker label:hover { border-color: var(--brand); color: var(--brand); }
.site-picker label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); font-weight: 650; }

/* ---- Sharing: the dialog, and the public read-only page ---------------- */
.work-actions { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; }

.modal-scrim { position: fixed; inset: 0; background: rgba(17, 24, 39, .45);
    display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 200; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    width: min(680px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 18px 48px rgba(17, 24, 39, .22); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px;
    border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 16px 18px; }
.sh-sections { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.sh-sections .chk { font-weight: 500; }
#share-url { flex: 1 1 320px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }

.share-card { border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 16px; margin: 0 0 14px; background: var(--surface-2); }
.share-card h3 { margin: 0; font-size: .98rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* The page a recipient sees. Deliberately plain: no toolbar, no drawer. */
.share-body { background: var(--surface-2); margin: 0; }
.share-head { display: flex; align-items: center; gap: 14px; padding: 16px 24px;
    background: var(--surface); border-bottom: 1px solid var(--border); }
.share-head h1 { margin: 0; font-size: 1.1rem; }
.share-title { min-width: 0; }
.share-head .tag { margin-left: auto; }
.share-main { max-width: 1100px; margin: 0 auto; padding: 20px 24px 40px; }
.share-section { background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 18px; margin: 0 0 16px; }
.share-section > h2 { margin-top: 0; }
.share-note { background: var(--brand-soft); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 10px 14px; margin: 0 0 16px; }
.share-foot { max-width: 1100px; margin: 0 auto; padding: 0 24px 32px; }
.frozen-value { font-variant-numeric: tabular-nums; }
.share-gate { max-width: 460px; margin: 12vh auto; background: var(--surface); text-align: center;
    border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 24px; }
.share-gate h1 { font-size: 1.1rem; margin: 12px 0 6px; }

/* Asked-for deterrent against casual copying. */
.no-copy, .no-copy * { -webkit-user-select: none; user-select: none; }
@media print { .no-copy .share-main { display: none; } }

/* Visible only to screen readers. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Share dialog: sections with their own field choices. */
.sh-presets { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 10px; }
.sh-sections { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.sh-sec { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; background: var(--surface); }
.sh-sec-head { display: block; margin-bottom: 4px; }
.sh-fields { display: flex; flex-direction: column; gap: 2px; padding-left: 22px; }
.sh-fields .chk { font-weight: 500; font-size: .86rem; }
.sh-sec.is-off .sh-fields { opacity: .45; pointer-events: none; }

/* Shared page: facts row, charts, table relief. */
.share-facts { display: flex; flex-wrap: wrap; gap: 8px 28px; }
.share-facts .k { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.share-facts .v { font-weight: 650; }
.viz { width: 100%; height: 260px; }
.viz-table { margin-top: 8px; }
.viz-table summary { cursor: pointer; color: var(--text-muted); font-size: .86rem; }
.table-scroll { overflow-x: auto; }
.share-items td.num, .share-items th.num, .admin-table td.num, .admin-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.viz-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }
.viz-fig { margin: 0; }
.viz-fig figcaption { font-weight: 650; font-size: .9rem; margin: 0 0 4px; }

/* ---- Sharing, 0.20: dialog groups, link form, who opened, live views ---- */
/* Lines up a lone checkbox with the controls above it, which follow a label. */
.frow-pad { width: 210px; flex: 0 0 210px; }
.set-group .frow-pad { width: 190px; flex-basis: 190px; }
.gate-custom { border-left: 3px solid var(--border); padding-left: 10px; margin: 0 0 6px; }
.sh-warn { color: var(--warning); background: var(--warning-soft); border: 1px solid var(--warning);
    border-radius: var(--radius-sm); padding: 6px 10px; font-size: .84rem; margin: 6px 0; }
.sh-na { color: var(--text-muted); font-size: .78rem; font-weight: 500; }
.sh-fields .chk:has(input:disabled) { color: var(--text-muted); }
.lf-warnings ul { margin: 4px 0 8px 18px; padding: 0; font-size: .86rem; }
.modal-wide { width: min(920px, 100%); }

/* Count of live viewers on the Live views tab. */
.count-badge { display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 4px; border-radius: 999px;
    background: var(--brand); color: #fff; font-size: .72rem; line-height: 18px; text-align: center; }

/* A name that opens a person's journey: reads as a link, not a button. */
button.linkish { background: transparent; border: none; padding: 0; margin: 0; color: var(--brand-dark);
    font: inherit; font-weight: 650; text-align: left; cursor: pointer; text-decoration: underline;
    text-decoration-color: var(--border-strong); text-underline-offset: 2px; }
button.linkish:hover { background: transparent; border: none; color: var(--brand-dark); text-decoration-color: var(--brand-dark); }

.tag-signal { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.tag-staff  { background: var(--brand-soft); color: var(--brand-dark); border-color: var(--brand); }
.tag-export { background: var(--success-soft); color: var(--success); border-color: var(--success); }

/* Under each link: the people who opened it. The row that holds that table is
   not itself a data row, so it does not light up as one. */
.admin-table tbody tr.sh-people-row:hover td { background: transparent; }
.admin-table tbody tr.sh-people-row .sh-people-table tbody tr:hover td { background: var(--brand-soft); }
.sh-people-row > td { padding-top: 0; }
.sh-people { padding: 2px 0 6px 14px; border-left: 3px solid var(--border); }
.sh-people .admin-table { margin: 4px 0; }
.sh-people .hint { margin: 2px 0 0; }
.drawer .admin-table td.sh-tags { white-space: normal; min-width: 180px; }
.sh-tags .tag { margin: 1px 3px 1px 0; }
.sh-letters { background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 4px 8px; }
.sh-out:not(:empty) { margin-top: 10px; }
.sh-out-head { display: flex; align-items: center; gap: 10px; }
.sh-out-head h4 { margin: 0; font-size: .88rem; }
#admin-live h4 { margin: 10px 0 4px; font-size: .86rem; color: var(--text-muted); }

/* One person's journey: sessions in order, with what happened in each. */
.jr-person { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.jr-timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); }
.jr-session { margin: 0 0 12px; }
.jr-head { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.jr-time { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: .82rem; }
.jr-events { list-style: none; margin: 4px 0 0; padding: 0 0 0 12px; font-size: .86rem; }
.jr-events li { margin: 2px 0; }
.jr-end { color: var(--text-muted); }
.jr-gap { margin: 0 0 12px; font-weight: 650; color: var(--brand-dark); font-size: .84rem; }
.sh-link-to select { margin-right: 4px; }

/* Names visitors type, link labels and report titles can be long unbroken
   strings (an email address used as a label, say). Wrap them inside their
   cell rather than let the table push the drawer into sideways scrolling. */
#admin-shares .admin-table td,
#admin-live .admin-table td,
#journey-body td,
#journey-body .jr-person,
#journey-body li,
#journey-title { overflow-wrap: anywhere; }
/* Wrapping cells keep a readable width: breaking anywhere must not squeeze a
   report title down to a letter per line while a long name takes the room. */
#admin-live .admin-table td.wrap,
#admin-shares .admin-table td.wrap { min-width: 9rem; }
#admin-live button.linkish,
#admin-shares button.linkish { white-space: normal; overflow-wrap: anywhere; }
