/* CIR-RFMS — single stylesheet. No external fonts or assets (closed network, strict CSP). */

:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #1b2430;
    --muted: #5b6776;
    --brand: #0b5394;
    --brand-hover: #094579;
    --brand-soft: #e7f0fa;
    --brand-contrast: #ffffff;
    --border: #d9dfe7;
    --border-strong: #c3ccd7;
    --danger: #b3261e;
    --danger-soft: #fdecea;
    --ok: #1e7b3a;
    --ok-soft: #e8f5ec;
    --warn: #8a5a00;
    --warn-soft: #fff4dc;
    --info: #0b5394;
    --info-soft: #e7f0fa;
    --violet: #5b3fa8;
    --violet-soft: #efeafb;
    --focus: #2f7fd6;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-lg: 0 10px 30px rgba(16, 24, 40, .14);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f141a;
        --surface: #171e26;
        --surface-2: #1c242e;
        --text: #e6ebf1;
        --muted: #9aa7b6;
        --brand: #6aaef0;
        --brand-hover: #8cc1f4;
        --brand-soft: #1a2c40;
        --brand-contrast: #0b1118;
        --border: #2b3542;
        --border-strong: #3a4757;
        --danger: #ff8a80;
        --danger-soft: #3a1c1b;
        --ok: #7bd88f;
        --ok-soft: #16301f;
        --warn: #f3c164;
        --warn-soft: #3a2e14;
        --info: #6aaef0;
        --info-soft: #1a2c40;
        --violet: #b9a4f5;
        --violet-soft: #2a2343;
        --focus: #8cc1f4;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-hover); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }

.skip { position: absolute; left: -999px; top: 8px; padding: 8px 14px; background: var(--brand); color: var(--brand-contrast); border-radius: 6px; z-index: 100; }
.skip:focus { left: 8px; }

/* ---------- Top bar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px 24px;
    padding: 8px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; flex-shrink: 0; }
.brand:hover { color: var(--text); }
.brand .logo { color: var(--brand); display: inline-flex; }
.brand-text { display: flex; flex-direction: column; font-weight: 700; line-height: 1.15; letter-spacing: .01em; }
.brand-text small { font-weight: 400; color: var(--muted); font-size: .76rem; letter-spacing: 0; }

.mainnav { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; min-width: 0; }
.navlinks, .navuser { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.mainnav a, .menu > summary {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 11px; border-radius: 7px;
    color: var(--text); text-decoration: none; font-weight: 500; white-space: nowrap;
}
.mainnav a:hover, .menu > summary:hover { background: var(--surface-2); color: var(--text); }
.mainnav a.active, .menu > summary.active { color: var(--brand); background: var(--brand-soft); }

.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; user-select: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: ""; width: 7px; height: 7px; margin-left: 2px; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); opacity: .6; }
.menu[open] > summary::after { transform: translateY(1px) rotate(-135deg); }
.menu-panel {
    position: absolute; left: 0; top: calc(100% + 6px); min-width: 220px; z-index: 30;
    display: flex; flex-direction: column; padding: 6px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.menu-right .menu-panel { left: auto; right: 0; }
.menu-panel a { display: flex; }
.menu-form { margin: 0; }
.menu-button { display: flex; width: 100%; padding: 7px 11px; border: 0; border-radius: 7px; background: none; color: var(--text); font: inherit; font-weight: 500; text-align: left; cursor: pointer; }
.menu-button:hover { background: var(--surface-2); }
.menu-meta { margin: 4px 11px 8px; font-size: .85rem; color: var(--muted); }

.who { gap: 8px; }
.avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: var(--brand-contrast); font-weight: 700; font-size: .85rem; }

.nav-toggle {
    display: none; margin-left: auto; align-items: center; gap: 6px;
    padding: 7px 12px; border: 1px solid var(--border); border-radius: 7px;
    background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}

.bell { position: relative; }
.bell-link { position: relative; }
.bell .count { display: inline-block; min-width: 1.4em; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .75rem; font-weight: 700; line-height: 1.5; text-align: center; }
.bell .count[hidden], .bell .toast[hidden] { display: none; }
.bell .toast { position: absolute; right: 0; top: 130%; width: 300px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--brand); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 30; }

@media (max-width: 1080px) {
    .bell-label, .who-name { display: none; }
}
@media (max-width: 860px) {
    .topbar { flex-wrap: wrap; padding: 8px 14px; }
    .nav-toggle { display: inline-flex; }
    .mainnav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding: 6px 0 10px; }
    .topbar.open .mainnav { display: flex; }
    .navlinks, .navuser { flex-direction: column; align-items: stretch; }
    .navuser { border-top: 1px solid var(--border); padding-top: 8px; }
    .menu-panel { position: static; box-shadow: none; border: 0; padding: 0 0 0 14px; }
    .bell-label, .who-name { display: inline; }
    .bell .toast { left: 0; right: auto; }
}

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 1180px; margin: 28px auto; padding: 0 20px; flex: 1; }
.footer { text-align: center; padding: 16px 20px 24px; font-size: .8rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px 26px;
    margin-bottom: 20px;
}
.card.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
@media (max-width: 600px) {
    .container { margin: 16px auto; padding: 0 12px; }
    .card { padding: 16px; }
}

h1 { margin: 0 0 14px; font-size: 1.5rem; line-height: 1.25; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
h1 .btn { margin-left: auto; font-size: .95rem; }
h2 { margin: 28px 0 12px; font-size: 1.12rem; }
h2:first-child { margin-top: 0; }
p { margin: 0 0 12px; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 20px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .lead { margin: 4px 0 0; }
.backlink { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 10px; font-size: .9rem; text-decoration: none; }
.backlink::before { content: "←"; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: .92rem; margin: 0 0 14px; }
.meta-row strong { color: var(--text); font-weight: 600; }

/* ---------- Forms ---------- */
label { display: block; margin-bottom: 14px; font-weight: 600; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=search], select, textarea {
    display: block; width: 100%; margin-top: 5px; padding: 9px 11px;
    border: 1px solid var(--border-strong); border-radius: 7px;
    background: var(--surface); color: var(--text); font: inherit; font-weight: 400;
    transition: border-color .15s, box-shadow .15s;
}
select { width: auto; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
input[type=checkbox], input[type=radio] { width: 17px; height: 17px; accent-color: var(--brand); }
.help { margin: -8px 0 12px; }
.field-error { color: var(--danger); margin: -8px 0 12px; font-size: .9rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 16px; padding: 12px 16px; }
legend { font-weight: 700; padding: 0 6px; }
label.inline { display: inline; font-weight: 400; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.checkgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 12px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 18px; border: 1px solid transparent; border-radius: 7px;
    background: var(--brand); color: var(--brand-contrast);
    font: inherit; font-weight: 600; line-height: 1.3; text-decoration: none; cursor: pointer; white-space: nowrap;
    transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--brand-hover); color: var(--brand-contrast); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled=true] { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--brand); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 11px; font-size: .88rem; }
.linklike { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--brand); cursor: pointer; text-align: left; }
.linklike:hover { text-decoration: underline; }

.filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; margin-bottom: 18px; padding: 14px 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.filters label { margin: 0; font-weight: 600; font-size: .88rem; }
.filters input[type=text] { min-width: 12em; }

.actions { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: flex-end; margin: 16px 0; }
.actions form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.actions label { margin: 0; }

/* Action panel on a batch: one box per thing you can do now */
.action-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin: 18px 0; }
.action-box { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); display: flex; flex-direction: column; gap: 10px; }
.action-box h3 { margin: 0; font-size: .98rem; }
.action-box p { margin: 0; color: var(--muted); font-size: .9rem; }
.action-box form { display: flex; flex-direction: column; gap: 10px; align-items: stretch; margin: 0; }
.action-box label { margin: 0; }
.action-box .btn { align-self: flex-start; }
.action-box.primary { border-color: var(--brand); background: var(--brand-soft); }
.action-box.danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }

/* Verification checklist */
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.checklist li { padding-left: 22px; position: relative; }
.checklist li::before { position: absolute; left: 0; font-weight: 700; }
.checklist li.bad { color: var(--danger); }
.checklist li.bad::before { content: "✗"; }
.checklist li.warn { color: var(--warn); }
.checklist li.warn::before { content: "!"; left: 4px; }

/* ---------- Messages ---------- */
.flash {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 11px 14px; border-radius: var(--radius); margin-bottom: 16px;
    border: 1px solid var(--border); border-left-width: 4px; background: var(--surface);
    transition: opacity .2s, transform .2s;
}
.flash > span, .flash > div { flex: 1; }
.flash ul { margin: 6px 0 0; padding-left: 20px; }
.flash.leaving { opacity: 0; transform: translateY(-4px); }
.flash-close { background: none; border: 0; padding: 0 4px; font-size: 1.3rem; line-height: 1; color: inherit; opacity: .6; cursor: pointer; }
.flash-close:hover { opacity: 1; }
.flash-error { border-color: var(--danger); background: var(--danger-soft); color: var(--text); }
.flash-success { border-color: var(--ok); background: var(--ok-soft); color: var(--text); }
.flash-info { border-color: var(--info); background: var(--info-soft); color: var(--text); }
.flash-warning { border-color: var(--warn); background: var(--warn-soft); color: var(--text); }

/* ---------- Badges & status ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 10px; border-radius: 999px;
    background: var(--brand-soft); color: var(--brand); border: 1px solid transparent;
    font-size: .8rem; font-weight: 600; line-height: 1.6; white-space: nowrap; vertical-align: middle;
}
.badge-province { background: transparent; color: var(--text); border-color: var(--border-strong); font-weight: 500; }
.badge-duplicate, .badge-rejected_type, .badge-failed { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.badge-quarantined { background: var(--danger); color: #fff; }
.badge-stored { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }

/* Batch statuses, coloured by who holds the batch */
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-draft { background: var(--surface-2); color: var(--muted); border-color: var(--border-strong); }
.status-submitted, .status-under_verification { background: var(--info-soft); color: var(--info); }
.status-returned_to_province, .status-laxton_issues { background: var(--warn-soft); color: var(--warn); }
.status-verified, .status-queued_for_ict, .status-exported_for_laxton { background: var(--violet-soft); color: var(--violet); }
.status-laxton_uploaded { background: var(--ok-soft); color: var(--ok); }
.status-archived { background: transparent; color: var(--muted); border-color: var(--border); }

.muted { color: var(--muted); font-size: .9rem; }
code.secret { word-break: break-all; }
code.data { word-break: break-all; font-size: .8rem; color: var(--muted); }

/* Workflow progress on a batch */
.stepper { display: flex; list-style: none; margin: 4px 0 20px; padding: 0; counter-reset: step; overflow-x: auto; }
.stepper li { flex: 1 1 0; min-width: 92px; position: relative; padding-top: 34px; text-align: center; font-size: .78rem; color: var(--muted); counter-increment: step; }
.stepper li::before {
    content: counter(step); position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 1;
    width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
    background: var(--surface); border: 2px solid var(--border-strong); color: var(--muted); font-weight: 700; font-size: .78rem;
}
.stepper li::after { content: ""; position: absolute; top: 12px; left: calc(-50% + 13px); right: calc(50% + 13px); height: 2px; background: var(--border-strong); }
.stepper li:first-child::after { display: none; }
.stepper li.done { color: var(--text); }
.stepper li.done::before { content: "✓"; background: var(--ok); border-color: var(--ok); color: #fff; }
.stepper li.done::after, .stepper li.current::after { background: var(--ok); }
.stepper li.current { color: var(--text); font-weight: 700; }
.stepper li.current::before { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); box-shadow: 0 0 0 4px var(--brand-soft); }
.stepper li.problem::before { content: "!"; background: var(--warn); border-color: var(--warn); color: #fff; box-shadow: 0 0 0 4px var(--warn-soft); }
.stepper .note { display: block; font-weight: 600; color: var(--warn); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tbody tr:last-child > * { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td a { font-weight: 600; }
.table-wrap td.muted, td.empty { text-align: center; padding: 28px 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.warn { color: var(--danger); font-weight: 700; }
.barcell { width: 55%; }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline-flex; gap: 6px; align-items: center; margin-right: 10px; }
.row-actions input[type=text] { width: 9em; padding: 5px 8px; margin: 0; display: inline-block; }
.row-actions select { display: inline-block; margin: 0; padding: 5px 8px; }
tr.rowlink { cursor: pointer; }

.pager { display: flex; gap: 16px; align-items: center; justify-content: center; margin-top: 16px; color: var(--muted); }

progress { width: 100%; height: 12px; accent-color: var(--brand); }
.barcell progress { height: 10px; }

/* Bar for dashboard counts (no inline styles: the value drives a <progress>) */
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--brand); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--brand); border-radius: 999px; }
progress { border: 0; border-radius: 999px; background: var(--surface-2); overflow: hidden; }

/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.chip { padding: 4px 13px; border: 1px solid var(--border-strong); border-radius: 999px; text-decoration: none; color: var(--text); font-size: .85rem; background: var(--surface); }
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip-on, .chip-on:hover { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }

/* ---------- Home ---------- */
.hello { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; }
.hello h1 { margin: 0 0 6px; }
.hello p { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }
.tile {
    display: flex; flex-direction: column; gap: 4px; padding: 18px 20px;
    background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow);
    color: var(--text); text-decoration: none; transition: border-color .15s, transform .1s;
}
.tile:hover { color: var(--text); border-color: var(--brand); transform: translateY(-1px); }
.tile .n { font-size: 2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: .92rem; }
.tile.hot { border-left-color: var(--warn); }
.tile.hot .n { color: var(--warn); }
.tile.zero .n { color: var(--muted); }
.quick { display: flex; flex-wrap: wrap; gap: 10px; }
.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }

/* ---------- Upload ---------- */
.dropzone {
    border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 36px 24px; text-align: center; margin: 16px 0;
    background: var(--surface-2); transition: border-color .15s, background-color .15s;
}
.dropzone .dz-icon { color: var(--brand); margin-bottom: 6px; }
.dropzone p { margin: 0 0 12px; font-size: 1.02rem; }
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.activity { list-style: none; padding: 0; margin: 0; font-size: .9rem; color: var(--muted); }
.steps-help { margin: 0 0 16px; padding-left: 20px; color: var(--muted); }
.steps-help li { margin-bottom: 4px; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--border); font-size: .9rem; }
.timeline li { position: relative; margin: 0 0 14px; padding-left: 14px; }
.timeline li::before { content: ""; position: absolute; left: -25px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); }
.timeline .when { display: block; color: var(--muted); font-size: .82rem; }

/* ---------- Notifications ---------- */
.notif-list { list-style: none; padding: 0; margin: 0; }
.notif-list li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.notif-list li.unread { border-left: 4px solid var(--brand); padding-left: 12px; background: var(--brand-soft); }

/* ---------- Sign-in ---------- */
.auth { max-width: 420px; margin: 6vh auto 0; }
.auth .card { padding: 30px 32px; }
.auth .auth-logo { color: var(--brand); display: flex; justify-content: center; margin-bottom: 10px; }
.auth h1 { justify-content: center; margin-bottom: 4px; }
.auth .lead { text-align: center; color: var(--muted); margin-bottom: 22px; }
.auth .fineprint { text-align: center; margin: 16px 0 0; }
.pw-field { position: relative; }
.pw-field input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; bottom: 6px; padding: 4px 8px; border: 0; background: none; color: var(--brand); font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
