/*
 * Inuka Distributor Admin — brand stylesheet.
 * Brand: Inuka Africa guidelines (green #317D46, red #E3332C, white, black, grey #7A7A7A; Roboto).
 *
 * Contrast notes (WCAG AA, 4.5:1 for normal text):
 *   #317D46 on white ≈ 5.1:1  → OK for text and as a button background with white text.
 *   #E3332C on white ≈ 4.4:1  → below AA for normal text, so it is used for borders and accents;
 *                                danger text and buttons use --ia-red-strong (≈ 6.3:1).
 *   #7A7A7A on white ≈ 4.3:1  → large text and borders only; small secondary text uses --text-muted.
 */

@font-face { font-family: "Roboto"; font-style: normal; font-weight: 300; font-display: swap; src: url("../fonts/roboto-latin-300-normal.woff2") format("woff2"); }
@font-face { font-family: "Roboto"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/roboto-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Roboto"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/roboto-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Roboto"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/roboto-latin-700-normal.woff2") format("woff2"); }

:root {
    /* Brand */
    --ia-green: #317D46;
    --ia-green-dark: #276438;
    --ia-green-tint: #EAF3EC;
    --ia-red: #E3332C;
    --ia-red-strong: #B8261F;
    --ia-red-tint: #FDECEB;
    --ia-white: #FFFFFF;
    --ia-black: #000000;
    --ia-grey: #7A7A7A;

    /* Functional */
    --text: #1A1A1A;
    --text-muted: #5C5C5C;
    --border: #D6D6D6;
    --surface: #FFFFFF;
    --surface-alt: #F5F6F5;
    --focus: #1F5FBF;
    --warn-text: #7A4D00;
    --warn-tint: #FFF4D6;
    --warn-border: #E0B54A;
    --info-text: #1D4E89;
    --info-tint: #EAF1FB;
    --info-border: #9DB8DE;

    --font: "Roboto", system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    --radius: 6px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --topbar-h: 60px;
    --sidebar-w: 240px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-weight: 400;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--surface-alt);
}

h1, h2, h3 { font-weight: 700; line-height: 1.25; margin: 0 0 var(--space-3); color: var(--ia-black); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; font-weight: 500; margin-top: var(--space-5); }
h3 { font-size: 1.05rem; font-weight: 500; }
p { margin: 0 0 var(--space-3); }
small, .caption { font-weight: 300; font-size: 0.85rem; color: var(--text-muted); }

a { color: var(--ia-green); text-underline-offset: 2px; }
a:hover { color: var(--ia-green-dark); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link { position: absolute; left: var(--space-2); top: -100px; z-index: 100; background: var(--ia-white); padding: var(--space-2) var(--space-3); border-radius: var(--radius); }
.skip-link:focus { top: var(--space-2); }

.mono { font-family: var(--font-mono); font-size: 0.9em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Top bar ─────────────────────────────────────────── */

.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap;
    min-height: var(--topbar-h);
    padding: var(--space-2) var(--space-4);
    background: var(--ia-white);
    border-bottom: 3px solid var(--ia-green);
}
.topbar__brand { display: flex; align-items: center; gap: var(--space-3); text-decoration: none; color: var(--ia-black); }
/* Logo is shown unaltered with clear space around it. */
.topbar__logo { display: block; height: 36px; width: auto; margin: var(--space-1) 0; }
.topbar__app { font-weight: 500; font-size: 1rem; padding-left: var(--space-3); border-left: 1px solid var(--border); }
.topbar__context { flex: 1 1 auto; display: flex; justify-content: center; }
.topbar__distributor { font-weight: 500; }
.topbar__user { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }
.topbar__name { font-weight: 500; text-decoration: none; color: var(--text); }
.topbar__name:hover { text-decoration: underline; }

.switcher { display: flex; align-items: center; gap: var(--space-2); }
.switcher__label { font-weight: 500; font-size: 0.9rem; }
.switcher select { min-width: 220px; }

.inline-form { display: inline; margin: 0; }

/* A POST action that reads as a link (e.g. "Start again", "Sign out"). */
.link-button {
    padding: 0; border: 0; background: none; font: inherit; color: var(--ia-green);
    text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.link-button:hover { color: var(--ia-green-dark); }

/* ── Layout ──────────────────────────────────────────── */

.layout { display: flex; align-items: flex-start; min-height: calc(100vh - var(--topbar-h)); }

.sidebar {
    flex: 0 0 var(--sidebar-w);
    align-self: stretch;
    background: var(--ia-white);
    border-right: 1px solid var(--border);
    padding: var(--space-3) 0;
}
.sidebar__toggle { display: none; }
.sidebar__group {
    margin: var(--space-4) var(--space-4) var(--space-1);
    font-size: 0.75rem; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted);
}
.sidebar__list { list-style: none; margin: 0; padding: 0; }
.sidebar__link {
    display: block; padding: var(--space-2) var(--space-4);
    color: var(--text); text-decoration: none; border-left: 3px solid transparent;
}
.sidebar__link:hover { background: var(--ia-green-tint); color: var(--ia-black); }
.sidebar__link.is-active { border-left-color: var(--ia-green); background: var(--ia-green-tint); font-weight: 500; color: var(--ia-black); }
.sidebar__link--disabled { color: var(--text-muted); cursor: not-allowed; }

.content { flex: 1 1 auto; min-width: 0; padding: var(--space-5) var(--space-6) var(--space-6); }
.content:focus { outline: none; }

/* ── Page furniture ──────────────────────────────────── */

.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-1); margin: 0 0 var(--space-3); padding: 0; font-size: 0.9rem; }
.breadcrumbs li + li::before { content: "/"; margin-right: var(--space-1); color: var(--ia-grey); }
.breadcrumbs [aria-current] { color: var(--text-muted); }

.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.page-header h1 { margin-bottom: var(--space-1); }
.page-header__sub { color: var(--text-muted); margin: 0; }
.page-header__sub a { margin-left: var(--space-2); }
.page-header__sub .is-current { font-weight: 700; }
.page-header__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

section { margin-bottom: var(--space-5); }

/* ── Alerts ──────────────────────────────────────────── */

.alert {
    border: 1px solid; border-left-width: 5px; border-radius: var(--radius);
    padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3);
}
.alert__label { font-weight: 500; margin-right: var(--space-1); }
.alert--success { background: var(--ia-green-tint); border-color: var(--ia-green); color: #1E4D2B; }
.alert--error { background: var(--ia-red-tint); border-color: var(--ia-red); color: var(--ia-red-strong); }
.alert--warning { background: var(--warn-tint); border-color: var(--warn-border); color: var(--warn-text); }
.alert--info { background: var(--info-tint); border-color: var(--info-border); color: var(--info-text); }

.pending-api {
    border: 1px dashed var(--ia-grey); border-radius: var(--radius);
    padding: var(--space-3) var(--space-4); color: var(--text-muted); background: var(--surface);
    margin-bottom: var(--space-2);
}

/* ── Buttons ─────────────────────────────────────────── */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    min-height: 40px; padding: var(--space-2) var(--space-4);
    border: 1px solid transparent; border-radius: var(--radius);
    font: inherit; font-weight: 500; line-height: 1.2; text-decoration: none;
    cursor: pointer; white-space: nowrap;
}
.btn--primary { background: var(--ia-green); color: var(--ia-white); }
.btn--primary:hover { background: var(--ia-green-dark); color: var(--ia-white); }
.btn--secondary { background: var(--ia-white); color: var(--ia-green); border-color: var(--ia-green); }
.btn--secondary:hover { background: var(--ia-green-tint); color: var(--ia-green-dark); }
.btn--danger { background: var(--ia-red-strong); color: var(--ia-white); }
.btn--danger:hover { background: #9A1F19; color: var(--ia-white); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: var(--surface-alt); color: var(--ia-black); }
.btn--small { min-height: 32px; padding: var(--space-1) var(--space-3); font-size: 0.875rem; }
.btn--block { width: 100%; }
.btn.is-disabled, .btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Badges ──────────────────────────────────────────── */

.badge {
    display: inline-block; padding: 2px var(--space-2); border-radius: 999px;
    font-size: 0.78rem; font-weight: 500; line-height: 1.4; border: 1px solid; white-space: nowrap;
}
.badge--ok { background: var(--ia-green-tint); color: #1E4D2B; border-color: #A9CBB2; }
.badge--info { background: var(--info-tint); color: var(--info-text); border-color: var(--info-border); }
.badge--warn { background: var(--warn-tint); color: var(--warn-text); border-color: var(--warn-border); }
.badge--bad { background: var(--ia-red-tint); color: var(--ia-red-strong); border-color: #F0A5A1; }
.badge--muted { background: #EFEFEF; color: var(--text-muted); border-color: var(--border); }
.badge--role { background: var(--ia-green); color: var(--ia-white); border-color: var(--ia-green); }

/* ── Cards ───────────────────────────────────────────── */

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); }
.card { background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--ia-green); border-radius: var(--radius); padding: var(--space-4); }
.card__label { margin: 0 0 var(--space-1); font-weight: 500; color: var(--text-muted); }
.card__value { margin: 0 0 var(--space-1); font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.card__meta { margin: 0; font-size: 0.85rem; font-weight: 300; color: var(--text-muted); }

/* ── Tables ──────────────────────────────────────────── */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: var(--space-2) var(--space-3); text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.table thead th { background: var(--surface-alt); font-weight: 500; font-size: 0.875rem; white-space: nowrap; }
.table tbody tr:hover { background: #FAFBFA; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.is-inactive td { color: var(--text-muted); }
.table td.actions { text-align: right; white-space: nowrap; }
.table .num { text-align: right; }

.pagination { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-3); }
.pagination__summary { margin-right: auto; color: var(--text-muted); }

/* ── Forms ───────────────────────────────────────────── */

.form { max-width: 640px; }
.form--grid { max-width: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 var(--space-5); }
.form--grid .form__actions, .form--grid > .alert, .form--grid > .field__hint { grid-column: 1 / -1; }

.field { margin-bottom: var(--space-4); }
.field__label { display: block; font-weight: 500; margin-bottom: var(--space-1); }
.field__required { color: var(--ia-red-strong); }
.field__hint { margin: var(--space-1) 0 0; font-size: 0.85rem; color: var(--text-muted); }
.field__error { margin: var(--space-1) 0 0; font-size: 0.875rem; font-weight: 500; color: var(--ia-red-strong); }
.field--checkbox { display: flex; align-items: center; gap: var(--space-2); }
.field--checkbox .field__hint, .field--checkbox .field__error { flex-basis: 100%; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="tel"],
input[type="date"], input[type="time"], input[type="search"], input[type="file"], select, textarea {
    width: 100%; min-height: 40px; padding: var(--space-2) var(--space-3);
    font: inherit; color: var(--text); background: var(--ia-white);
    border: 1px solid #8F8F8F; border-radius: var(--radius);
}
input[type="file"] { padding: 6px; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--ia-green); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-alt); color: var(--text-muted); }
.field--error input, .field--error select, .field--error textarea { border-color: var(--ia-red); border-width: 2px; }

.form__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-top: var(--space-2); }

.filters {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 var(--space-4);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: var(--space-4) var(--space-4) 0; margin-bottom: var(--space-4);
}
.filters .field { flex: 1 1 180px; }
.filters .field--checkbox { flex: 0 0 auto; min-height: 40px; }
.filters__actions { display: flex; gap: var(--space-2); margin-bottom: var(--space-4); }

.form--wide { max-width: 980px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 var(--space-5); }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: var(--space-4) var(--space-4) 0; margin: 0 0 var(--space-4); }
.fieldset legend { font-weight: 500; padding: 0 var(--space-2); }
.fieldset > .field__hint { margin-bottom: var(--space-3); }

/* ── Panels, details, helpers ────────────────────────── */

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4) var(--space-5); margin-bottom: var(--space-4); }
.panel h2:first-child { margin-top: 0; }
.details { margin: 0 0 var(--space-3); }
.details__row { display: grid; grid-template-columns: minmax(160px, 240px) 1fr; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid #EEEEEE; }
.details__row:last-child { border-bottom: 0; }
.details dt { font-weight: 500; color: var(--text-muted); }
.details dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.muted { color: var(--text-muted); font-size: 0.875rem; }
.muted-note { color: var(--text-muted); font-size: 0.9rem; }
.empty { color: var(--text-muted); text-align: center; padding: var(--space-5) var(--space-3) !important; }
.th-sub { font-weight: 300; font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.steps { padding-left: var(--space-5); }
.steps li { margin-bottom: var(--space-2); }
.help { margin-top: var(--space-6); }
.code { background: #F0F2F0; border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4); overflow-x: auto; font-family: var(--font-mono); font-size: 0.85rem; }
code { font-family: var(--font-mono); font-size: 0.9em; }

.cards--compact { margin-bottom: var(--space-4); }
.cards--compact .card__value { font-size: 1.3rem; }

.quick-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-5); }
.quick-link { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-3) var(--space-4); background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ia-green); border-radius: var(--radius); text-decoration: none; color: var(--text); }
.quick-link:hover { background: var(--ia-green-tint); color: var(--ia-black); }
.quick-link strong { color: var(--ia-green-dark); }
.quick-link span { font-size: 0.875rem; color: var(--text-muted); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 0 var(--space-4); }
.grid-2 > .panel { margin-bottom: var(--space-4); }
.inline-add { border-top: 1px solid var(--border); margin-top: var(--space-4); padding-top: var(--space-3); }
.inline-add h3 { margin-top: 0; }
.inline-add__fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 var(--space-4); align-items: end; }
.inline-add__fields .form__actions { margin-bottom: var(--space-4); }
.plain-list { list-style: none; margin: 0 0 var(--space-3); padding: 0; }
.plain-list li { padding: var(--space-2) 0; border-bottom: 1px solid #EEEEEE; display: flex; flex-direction: column; gap: 2px; }
.plain-list li:last-child { border-bottom: 0; }
.field-errors { margin: var(--space-1) 0 0; padding-left: var(--space-4); font-size: 0.875rem; color: var(--ia-red-strong); }
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); margin-bottom: var(--space-3); flex-wrap: wrap; }
.tabs__tab { padding: var(--space-2) var(--space-4); text-decoration: none; color: var(--text); border-bottom: 3px solid transparent; }
.tabs__tab:hover { background: var(--ia-green-tint); color: var(--ia-black); }
.tabs__tab.is-active { border-bottom-color: var(--ia-green); font-weight: 500; }

/* ── Chart (inline SVG; single series in brand green) ── */

.chart { margin: 0 0 var(--space-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); }
.chart__head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
.chart__title { font-weight: 500; }
.chart__meta { color: var(--text-muted); font-size: 0.875rem; }
.chart__svg { display: block; width: 100%; height: auto; }
.chart__grid line { stroke: #E4E6E4; stroke-width: 1; }
.chart__baseline { stroke: #9A9A9A; stroke-width: 1; }
.chart__tick { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
.chart__mark { fill: var(--ia-green); }
.chart__hit { fill: transparent; }
.chart__bar:hover .chart__mark { fill: var(--ia-green-dark); }
.chart__bar:hover .chart__hit { fill: rgba(49, 125, 70, 0.06); }
.chart__table { margin-top: var(--space-3); }
.chart__table summary { cursor: pointer; color: var(--ia-green); font-weight: 500; }
.chart__table .table-wrap { margin-top: var(--space-2); max-height: 360px; overflow-y: auto; }

@media (forced-colors: active) {
    .chart__mark { fill: CanvasText; }
}

/* ── Plain layout (sign-in, errors) ─────────────────── */

.plain { background: var(--surface-alt); }
.plain__main { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-5) var(--space-4); }
.plain__card {
    width: 100%; max-width: 440px; background: var(--surface);
    border: 1px solid var(--border); border-top: 5px solid var(--ia-green); border-radius: var(--radius);
    padding: var(--space-6);
}
.plain__brand { text-align: center; margin-bottom: var(--space-4); }
.plain__logo { display: inline-block; height: 60px; width: auto; margin: var(--space-3) 0; }
.plain__app { margin: 0; font-weight: 500; color: var(--text-muted); }
.plain__tagline { text-align: center; font-weight: 300; font-size: 1.1rem; color: var(--ia-green); margin-bottom: var(--space-4); }
.plain__title { font-size: 1.35rem; }
.plain__note { margin-top: var(--space-4); font-size: 0.85rem; color: var(--text-muted); }

.error-page__code { font-weight: 500; color: var(--text-muted); margin-bottom: var(--space-1); }
.error-page__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }

/* ── Progressive enhancement ─────────────────────────── */

.js .js-hide { display: none; }

/* ── Responsive (down to tablet and phone) ───────────── */

@media (max-width: 960px) {
    .layout { flex-direction: column; }
    .sidebar { flex: none; width: 100%; border-right: 0; border-bottom: 1px solid var(--border); padding: 0; }
    .sidebar__toggle {
        display: block; padding: var(--space-3) var(--space-4); font-weight: 500; cursor: pointer;
        list-style-position: inside;
    }
    .sidebar__nav { padding-bottom: var(--space-3); }
    .content { padding: var(--space-4); }
    .topbar__context { order: 3; flex-basis: 100%; justify-content: flex-start; }
}

@media (max-width: 600px) {
    .topbar__app { display: none; }
    .switcher { flex-wrap: wrap; }
    .switcher select { min-width: 0; }
    .plain__card { padding: var(--space-5) var(--space-4); }
}

@media print {
    .topbar, .sidebar, .page-header__actions, .filters, .pagination, .form__actions { display: none !important; }
    .content { padding: 0; }
}
