/* ==========================================================================
   Kal-UKFinder — application stylesheet
   Layers: tokens, reset, layout, components, pages, admin, utilities
   ========================================================================== */

/* --- Tokens --------------------------------------------------------------- */
:root {
    --navy-900: #0b1b33;
    --navy-800: #12294a;
    --navy-700: #1b3a63;
    --blue-600: #1d5fd0;
    --blue-500: #2b6fe0;
    --blue-100: #e3edfd;
    --blue-050: #f2f7ff;

    --teal-600: #0f7c73;
    --teal-100: #d8f2ef;
    --amber-600: #a55f00;
    --amber-100: #fdf0d5;
    --red-600: #b3261e;
    --red-100: #fce8e6;
    --green-600: #14713d;
    --green-100: #dcf3e5;

    --ink:        #14181f;
    --ink-muted:  #525c6b;
    --ink-subtle: #6b7684;

    --surface:      #ffffff;
    --surface-alt:  #f5f7fa;
    --surface-sunk: #eef1f6;
    --border:       #d9dee7;
    --border-strong:#b9c1ce;

    --radius-sm: 4px;
    --radius:    8px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 2px rgba(11, 27, 51, .07);
    --shadow:    0 2px 8px rgba(11, 27, 51, .09);
    --shadow-lg: 0 12px 32px rgba(11, 27, 51, .14);

    --space-1: 4px;  --space-2: 8px;  --space-3: 12px;
    --space-4: 16px; --space-5: 24px; --space-6: 32px;
    --space-7: 48px; --space-8: 64px;

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

    --container: 1180px;
}

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

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

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--surface-alt);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 var(--space-3); line-height: 1.25; font-weight: 650; letter-spacing: -.011em; }
h1 { font-size: 1.95rem; letter-spacing: -.02em; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.12rem; }
h4 { font-size: 1rem; }
p  { margin: 0 0 var(--space-4); }

a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--blue-500);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

img { max-width: 100%; display: block; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }

/* --- Layout --------------------------------------------------------------- */
.container {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 var(--space-4);
}

.page { padding: var(--space-6) 0 var(--space-8); }

.layout-sidebar {
    display: grid;
    grid-template-columns: 288px 1fr;
    gap: var(--space-5);
    align-items: start;
}

.stack > * + * { margin-top: var(--space-4); }
.stack-sm > * + * { margin-top: var(--space-2); }

/* --- Site header ---------------------------------------------------------- */
.site-header {
    background: var(--navy-900);
    color: #fff;
    border-bottom: 4px solid var(--blue-600);
}

.site-header a { color: #fff; }

.site-header__bar {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    min-height: 68px;
    flex-wrap: wrap;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 1.22rem;
    font-weight: 700;
    letter-spacing: -.02em;
    text-decoration: none;
}
.brand:hover { text-decoration: none; }

.brand__mark {
    display: grid;
    place-items: center;
    width: 32px; height: 32px;
    border-radius: var(--radius-sm);
    background: var(--blue-500);
    font-size: .85rem;
    font-weight: 800;
    letter-spacing: -.04em;
}

.brand__uk { color: #8fbcff; }

.site-nav { display: flex; gap: var(--space-1); margin-left: auto; align-items: center; flex-wrap: wrap; }

.site-nav__link {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    font-size: .93rem;
    font-weight: 520;
    color: #ccd8ea;
    text-decoration: none;
}
.site-nav__link:hover { background: rgba(255, 255, 255, .1); color: #fff; text-decoration: none; }
.site-nav__link.is-active { background: rgba(255, 255, 255, .16); color: #fff; }

.site-nav__divider { width: 1px; height: 22px; background: rgba(255, 255, 255, .22); margin: 0 var(--space-2); }

/* --- Footer --------------------------------------------------------------- */
.site-footer {
    background: var(--navy-900);
    color: #a9b8cd;
    padding: var(--space-6) 0 var(--space-5);
    margin-top: var(--space-8);
    font-size: .9rem;
}
.site-footer a { color: #cfe0f7; }
.site-footer__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: var(--space-5);
}
.site-footer h4 { color: #fff; font-size: .85rem; text-transform: uppercase; letter-spacing: .07em; }
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li + li { margin-top: var(--space-1); }
.site-footer__base {
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid rgba(255, 255, 255, .13);
    display: flex; flex-wrap: wrap; gap: var(--space-3);
    justify-content: space-between;
    font-size: .84rem;
}

/* --- Buttons -------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--blue-600);
    color: #fff;
    font: inherit;
    font-size: .94rem;
    font-weight: 560;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn:hover { background: var(--navy-700); color: #fff; text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.btn--secondary { background: var(--surface); color: var(--navy-800); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--surface-sunk); color: var(--navy-900); }

.btn--ghost { background: transparent; color: var(--blue-600); border-color: transparent; }
.btn--ghost:hover { background: var(--blue-050); color: var(--navy-700); }

.btn--danger { background: var(--red-600); }
.btn--danger:hover { background: #8c1d17; }

.btn--sm { padding: 6px 12px; font-size: .855rem; }
.btn--lg { padding: 13px 26px; font-size: 1.02rem; }
.btn--block { width: 100%; }

/* --- Cards ---------------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card__header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
    flex-wrap: wrap;
}
.card__header h2, .card__header h3 { margin: 0; }
.card__body { padding: var(--space-5); }
.card__footer {
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* --- Badges & pills ------------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: .765rem;
    font-weight: 600;
    letter-spacing: .01em;
    background: var(--surface-sunk);
    color: var(--ink-muted);
    white-space: nowrap;
}
.badge--blue   { background: var(--blue-100);  color: var(--navy-700); }
.badge--teal   { background: var(--teal-100);  color: var(--teal-600); }
.badge--amber  { background: var(--amber-100); color: var(--amber-600); }
.badge--red    { background: var(--red-100);   color: var(--red-600); }
.badge--green  { background: var(--green-100); color: var(--green-600); }

.badge--dot::before {
    content: ""; width: 6px; height: 6px; border-radius: 50%;
    background: currentColor; display: inline-block;
}

/* --- Forms ---------------------------------------------------------------- */
.field { margin-bottom: var(--space-4); }

.field__label {
    display: block;
    margin-bottom: var(--space-2);
    font-size: .9rem;
    font-weight: 600;
    color: var(--navy-800);
}

.field__hint { display: block; font-size: .83rem; color: var(--ink-subtle); margin-bottom: var(--space-2); }
.field__error { display: block; font-size: .85rem; color: var(--red-600); font-weight: 550; margin-top: var(--space-2); }

.input, .select, .textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    font: inherit;
    font-size: .94rem;
    color: var(--ink);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-subtle); }
.textarea { min-height: 150px; resize: vertical; line-height: 1.55; }

.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7684' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
}

.field--invalid .input,
.field--invalid .select,
.field--invalid .textarea { border-color: var(--red-600); background: #fffafa; }

.checkbox, .radio {
    display: flex; align-items: flex-start; gap: var(--space-2);
    font-size: .92rem; cursor: pointer; padding: 3px 0;
}
.checkbox input, .radio input { margin: 3px 0 0; width: 17px; height: 17px; accent-color: var(--blue-600); flex-shrink: 0; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.field-row--3 { grid-template-columns: repeat(3, 1fr); }

fieldset { border: 0; padding: 0; margin: 0 0 var(--space-5); }
legend { padding: 0; font-size: .95rem; font-weight: 650; color: var(--navy-800); margin-bottom: var(--space-3); }

/* --- Alerts --------------------------------------------------------------- */
.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    border-left: 4px solid;
    margin-bottom: var(--space-4);
    font-size: .93rem;
    display: flex; gap: var(--space-3); align-items: flex-start;
}
.alert--success { background: var(--green-100); border-color: var(--green-600); color: #0d4d2a; }
.alert--error   { background: var(--red-100);   border-color: var(--red-600);   color: #7d1a14; }
.alert--warning { background: var(--amber-100); border-color: var(--amber-600); color: #6f4000; }
.alert--info    { background: var(--blue-100);  border-color: var(--blue-600);  color: var(--navy-800); }

.alert__icon { font-weight: 700; flex-shrink: 0; }

.error-summary {
    border: 2px solid var(--red-600);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-bottom: var(--space-5);
    background: #fffafa;
}
.error-summary h3 { color: var(--red-600); font-size: 1rem; margin-bottom: var(--space-2); }
.error-summary ul { margin: 0; padding-left: var(--space-5); }
.error-summary li { margin-bottom: var(--space-1); }
.error-summary a { color: var(--red-600); font-weight: 550; }

/* --- Tables --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table { width: 100%; border-collapse: collapse; font-size: .91rem; }
.table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; vertical-align: middle; }
.table thead th {
    background: var(--surface-alt);
    font-size: .78rem;
    font-weight: 680;
    text-transform: uppercase;
    letter-spacing: .045em;
    color: var(--ink-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--blue-050); }
.table__actions { display: flex; gap: var(--space-2); justify-content: flex-end; }
.table td.is-numeric, .table th.is-numeric { text-align: right; font-variant-numeric: tabular-nums; }
.table__check { width: 40px; }

/* --- Pagination ----------------------------------------------------------- */
.pagination { display: flex; align-items: center; gap: var(--space-1); flex-wrap: wrap; margin-top: var(--space-5); }
.pagination__link {
    min-width: 38px; height: 38px;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 var(--space-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--navy-800);
    font-size: .9rem; font-weight: 550;
    text-decoration: none;
}
.pagination__link:hover { background: var(--surface-sunk); text-decoration: none; }
.pagination__link.is-current { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }
.pagination__gap { padding: 0 var(--space-2); color: var(--ink-subtle); }
.pagination__meta { margin-left: auto; font-size: .88rem; color: var(--ink-muted); }

/* --- Hero ----------------------------------------------------------------- */
.hero {
    background: linear-gradient(160deg, var(--navy-900) 0%, var(--navy-700) 62%, #24507f 100%);
    color: #fff;
    padding: var(--space-8) 0;
}
.hero h1 { font-size: 2.45rem; max-width: 20ch; margin-bottom: var(--space-3); }
.hero p { font-size: 1.1rem; color: #c6d5ea; max-width: 58ch; margin-bottom: var(--space-5); }

.hero__search {
    display: flex; gap: var(--space-2); flex-wrap: wrap;
    background: rgba(255, 255, 255, .1);
    padding: var(--space-2);
    border-radius: var(--radius-lg);
    max-width: 720px;
    border: 1px solid rgba(255, 255, 255, .18);
}
.hero__search .input { flex: 1 1 240px; border-color: transparent; }
.hero__stats { display: flex; gap: var(--space-6); flex-wrap: wrap; margin-top: var(--space-6); }
.hero__stat strong { display: block; font-size: 1.85rem; font-weight: 700; letter-spacing: -.02em; }
.hero__stat span { font-size: .87rem; color: #a9bdd8; }

/* --- Filters -------------------------------------------------------------- */
.filters { position: sticky; top: var(--space-4); }
.filters__group { border-bottom: 1px solid var(--border); padding: var(--space-4) 0; }
.filters__group:first-child { padding-top: 0; }
.filters__group:last-child { border-bottom: 0; padding-bottom: 0; }
.filters__legend {
    font-size: .8rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--ink-muted); margin-bottom: var(--space-3);
}
.filters__options { max-height: 264px; overflow-y: auto; padding-right: var(--space-2); }
.filters__count { margin-left: auto; font-size: .8rem; color: var(--ink-subtle); font-variant-numeric: tabular-nums; }
.filters .checkbox { justify-content: flex-start; }
.filters .checkbox span { flex: 1; }

.filter-chips { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }
.filter-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 6px 4px 11px;
    background: var(--blue-100); color: var(--navy-700);
    border-radius: 999px; font-size: .84rem; font-weight: 550;
    text-decoration: none;
}
.filter-chip:hover { background: #cfe0fb; text-decoration: none; }
.filter-chip__x {
    display: grid; place-items: center;
    width: 18px; height: 18px; border-radius: 50%;
    background: rgba(27, 58, 99, .16); font-size: .74rem; line-height: 1;
}

/* --- Result list ---------------------------------------------------------- */
.results__header {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4);
}
.results__count { font-size: .93rem; color: var(--ink-muted); }
.results__count strong { color: var(--ink); }
.results__sort { display: flex; align-items: center; gap: var(--space-2); font-size: .9rem; }
.results__sort .select { width: auto; padding-top: 7px; padding-bottom: 7px; }

.result-list { display: grid; gap: var(--space-3); }

.result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    transition: border-color .12s ease, box-shadow .12s ease;
    position: relative;
}
.result-card:hover { border-color: var(--blue-500); box-shadow: var(--shadow); }
.result-card--featured { border-left: 4px solid var(--amber-600); }

.result-card__top { display: flex; justify-content: space-between; gap: var(--space-4); align-items: flex-start; }
.result-card__title { font-size: 1.08rem; font-weight: 640; margin: 0 0 var(--space-1); }
.result-card__title a { color: var(--navy-900); }
.result-card__title a:hover { color: var(--blue-600); }

/* Makes the whole card clickable without nesting interactive elements. */
.result-card__title a::after {
    content: ""; position: absolute; inset: 0; border-radius: var(--radius-lg);
}

.result-card__org { font-size: .93rem; color: var(--ink-muted); font-weight: 520; }
.result-card__meta {
    display: flex; gap: var(--space-3); flex-wrap: wrap;
    font-size: .86rem; color: var(--ink-subtle); margin-top: var(--space-2);
}
.result-card__meta span { display: inline-flex; align-items: center; gap: 5px; }
.result-card__excerpt { font-size: .91rem; color: var(--ink-muted); margin: var(--space-3) 0 0; }
.result-card__tags { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-3); }
.result-card__salary { font-weight: 640; color: var(--teal-600); font-size: .93rem; white-space: nowrap; }

/* Bookmark button sits above the card-wide click target. */
.bookmark-btn {
    position: relative; z-index: 2;
    display: inline-flex; align-items: center; gap: 6px;
    background: transparent; border: 1px solid var(--border-strong);
    border-radius: var(--radius); padding: 6px 11px;
    font: inherit; font-size: .84rem; font-weight: 550;
    color: var(--ink-muted); cursor: pointer;
}
.bookmark-btn:hover { border-color: var(--blue-500); color: var(--blue-600); background: var(--blue-050); }
.bookmark-btn.is-saved { background: var(--blue-100); border-color: var(--blue-500); color: var(--navy-700); }

/* --- Detail pages --------------------------------------------------------- */
.detail { display: grid; grid-template-columns: 1fr 320px; gap: var(--space-5); align-items: start; }
.detail__header { border-bottom: 1px solid var(--border); padding-bottom: var(--space-4); margin-bottom: var(--space-4); }
.detail__title { font-size: 1.75rem; margin-bottom: var(--space-2); }
.detail__org { font-size: 1.05rem; color: var(--ink-muted); font-weight: 550; }
.detail__meta { display: flex; gap: var(--space-4); flex-wrap: wrap; margin-top: var(--space-3); font-size: .9rem; color: var(--ink-subtle); }

.detail__body { font-size: .96rem; line-height: 1.7; overflow-wrap: break-word; }
.detail__body h2 { font-size: 1.2rem; margin-top: var(--space-5); }
.detail__body h3 { font-size: 1.05rem; margin-top: var(--space-4); }
.detail__body ul, .detail__body ol { padding-left: var(--space-5); margin-bottom: var(--space-4); }
.detail__body li { margin-bottom: var(--space-2); }
.detail__body img { border-radius: var(--radius); margin: var(--space-3) 0; }
.detail__body table { width: 100%; border-collapse: collapse; margin-bottom: var(--space-4); }
.detail__body td, .detail__body th { border: 1px solid var(--border); padding: var(--space-2) var(--space-3); }

.detail__aside { position: sticky; top: var(--space-4); }

.definition-list { margin: 0; font-size: .9rem; }
.definition-list dt { font-weight: 640; color: var(--ink-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.definition-list dd { margin: 2px 0 var(--space-3); color: var(--ink); }
.definition-list dd:last-child { margin-bottom: 0; }

/* --- Empty state ---------------------------------------------------------- */
.empty {
    text-align: center;
    padding: var(--space-8) var(--space-5);
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
}
.empty__icon { font-size: 2.4rem; margin-bottom: var(--space-3); opacity: .5; }
.empty h3 { margin-bottom: var(--space-2); }
.empty p { color: var(--ink-muted); max-width: 46ch; margin: 0 auto var(--space-4); }

/* --- Home page ------------------------------------------------------------ */
.section { padding: var(--space-7) 0; }
.section__header {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5);
}
.section__header p { margin: 0; color: var(--ink-muted); font-size: .94rem; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-6); }

.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--space-4); }
.feature { padding: var(--space-5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.feature__icon {
    width: 40px; height: 40px; border-radius: var(--radius);
    background: var(--blue-100); color: var(--blue-600);
    display: grid; place-items: center; font-size: 1.15rem; margin-bottom: var(--space-3);
}
.feature h3 { font-size: 1rem; }
.feature p { font-size: .9rem; color: var(--ink-muted); margin: 0; }

/* --- Auth pages ----------------------------------------------------------- */
.auth-page {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: var(--space-5);
    background: linear-gradient(160deg, var(--navy-900), var(--navy-700));
}
.auth-card { width: 100%; max-width: 452px; }
.auth-card .card { box-shadow: var(--shadow-lg); }
.auth-header { text-align: center; margin-bottom: var(--space-5); }
.auth-header .brand { justify-content: center; font-size: 1.5rem; }
.auth-header p { color: #b9cae2; margin: var(--space-2) 0 0; font-size: .93rem; }
.auth-footer { text-align: center; margin-top: var(--space-4); font-size: .9rem; color: #b9cae2; }
.auth-footer a { color: #fff; font-weight: 550; text-decoration: underline; }

.demo-hint {
    margin-top: var(--space-4); padding: var(--space-3);
    background: rgba(255, 255, 255, .09); border-radius: var(--radius);
    font-size: .84rem; color: #c8d8ee; text-align: center;
    border: 1px solid rgba(255, 255, 255, .14);
}
.demo-hint code { font-family: var(--mono); color: #fff; font-size: .84rem; }

/* --- Admin ---------------------------------------------------------------- */
.admin { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }

.admin__sidebar {
    background: var(--navy-900);
    color: #b9c9de;
    padding: var(--space-4) 0;
    display: flex; flex-direction: column;
}
.admin__brand { padding: var(--space-2) var(--space-5) var(--space-5); }
.admin__brand .brand { font-size: 1.05rem; }
.admin__brand-tag {
    display: inline-block;
    margin-top: var(--space-2);
    margin-left: 40px;          /* clears the 32px mark plus its gap */
    padding: 1px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .14);
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: #cfe0f7;
}
.admin__nav { flex: 1; padding: 0 var(--space-3); }
.admin__nav-label {
    padding: var(--space-4) var(--space-3) var(--space-2);
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .08em; color: #6c8099;
}
.admin__nav-link {
    display: flex; align-items: center; gap: var(--space-3);
    padding: 9px var(--space-3); border-radius: var(--radius);
    color: #b9c9de; font-size: .92rem; font-weight: 520; text-decoration: none;
    margin-bottom: 2px;
}
.admin__nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.admin__nav-link.is-active { background: var(--blue-600); color: #fff; }
.admin__nav-badge {
    margin-left: auto; background: rgba(255, 255, 255, .14);
    padding: 1px 7px; border-radius: 999px; font-size: .74rem; font-variant-numeric: tabular-nums;
}
.admin__sidebar-footer { padding: var(--space-4) var(--space-5) 0; border-top: 1px solid rgba(255, 255, 255, .1); font-size: .85rem; }

.admin__main { background: var(--surface-alt); min-width: 0; }
.admin__topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--space-4) var(--space-5);
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--space-4); flex-wrap: wrap;
    position: sticky; top: 0; z-index: 20;
}
.admin__topbar h1 { margin: 0; font-size: 1.3rem; }
.admin__content { padding: var(--space-5); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-5); }
.stat {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5);
}
.stat__label { font-size: .8rem; font-weight: 640; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-subtle); }
.stat__value { font-size: 1.95rem; font-weight: 700; letter-spacing: -.025em; margin: var(--space-1) 0 0; line-height: 1.1; }
.stat__meta { font-size: .84rem; color: var(--ink-muted); margin-top: var(--space-1); }
.stat__meta--up { color: var(--green-600); }
.stat__meta--down { color: var(--red-600); }

.toolbar {
    display: flex; align-items: center; gap: var(--space-3);
    flex-wrap: wrap; margin-bottom: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.toolbar .input, .toolbar .select { width: auto; min-width: 148px; padding-top: 8px; padding-bottom: 8px; }
.toolbar__search { flex: 1 1 230px; min-width: 190px !important; }
.toolbar__spacer { margin-left: auto; }

.bulk-bar {
    display: none;
    align-items: center; gap: var(--space-3); flex-wrap: wrap;
    padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4);
    background: var(--navy-800); color: #fff; border-radius: var(--radius-lg);
}
.bulk-bar.is-visible { display: flex; }
.bulk-bar__count { font-weight: 600; font-size: .93rem; }
.bulk-bar .select { width: auto; }

.run-log {
    font-family: var(--mono); font-size: .83rem; line-height: 1.65;
    background: var(--navy-900); color: #cfe0f7;
    padding: var(--space-4); border-radius: var(--radius);
    max-height: 340px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}

/* --- Avatars -------------------------------------------------------------- */
.avatar {
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--surface-sunk);
    overflow: hidden;
}
.avatar--initials { color: #fff; font-weight: 650; letter-spacing: .02em; line-height: 1; }

.site-nav__profile {
    display: inline-flex; align-items: center; gap: var(--space-2);
    padding: 4px 10px 4px 4px; border-radius: 999px;
    font-size: .92rem; font-weight: 550; color: #ccd8ea; text-decoration: none;
}
.site-nav__profile:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.site-nav__profile.is-active { background: rgba(255,255,255,.16); color: #fff; }

/* --- Mobile tab bar ------------------------------------------------------- */
/* Hidden by default; the media query at the bottom turns it on for phones. */
.tabbar { display: none; }

/* --- Food ----------------------------------------------------------------- */
.food-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: var(--space-3);
}

.food-tile {
    position: relative;
    display: block;
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--ink);
    transition: border-color .12s ease, box-shadow .12s ease, transform .12s ease;
}
.food-tile:hover { border-color: var(--blue-500); box-shadow: var(--shadow); text-decoration: none; }
.food-tile.is-active { border-color: var(--blue-600); background: var(--blue-050); box-shadow: inset 0 0 0 1px var(--blue-600); }
.food-tile__icon  { font-size: 1.7rem; display: block; line-height: 1; margin-bottom: var(--space-2); }
.food-tile__label { display: block; font-weight: 640; font-size: 1rem; margin-bottom: 2px; }
.food-tile__blurb { display: block; font-size: .84rem; color: var(--ink-subtle); line-height: 1.4; }
.food-tile__count {
    position: absolute; top: var(--space-3); right: var(--space-3);
    background: var(--surface-sunk); color: var(--ink-muted);
    border-radius: 999px; padding: 1px 9px;
    font-size: .76rem; font-weight: 640; font-variant-numeric: tabular-nums;
}

.recipe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
    gap: var(--space-4);
}

.recipe-card {
    position: relative;
    display: flex; flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color .12s ease, box-shadow .12s ease;
}
.recipe-card:hover { border-color: var(--blue-500); box-shadow: var(--shadow); }
.recipe-card--featured { border-color: var(--amber-600); }

.recipe-card__media {
    position: relative; display: block;
    aspect-ratio: 16 / 9;
    background: var(--navy-800);
    overflow: hidden;
}
.recipe-card__media img { width: 100%; height: 100%; object-fit: cover; }
.recipe-card__placeholder {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    font-size: 2.4rem; opacity: .65;
}
.recipe-card__play {
    position: absolute; inset: 0; margin: auto;
    width: 46px; height: 46px; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(11, 27, 51, .72); color: #fff;
    font-size: .95rem; padding-left: 3px;
    backdrop-filter: blur(2px);
}
.recipe-card__time {
    position: absolute; right: var(--space-2); bottom: var(--space-2);
    background: rgba(11, 27, 51, .82); color: #fff;
    border-radius: var(--radius-sm); padding: 2px 7px;
    font-size: .76rem; font-weight: 600;
}

.recipe-card__body { padding: var(--space-3) var(--space-4) var(--space-4); flex: 1; }
.recipe-card__title { font-size: 1rem; font-weight: 640; margin: 0 0 var(--space-2); line-height: 1.35; }
.recipe-card__title a { color: var(--navy-900); }
.recipe-card__title a::after { content: ""; position: absolute; inset: 0; }
.recipe-card__summary { font-size: .86rem; color: var(--ink-muted); margin: 0 0 var(--space-2); }
.recipe-card__meta {
    display: flex; gap: var(--space-3); flex-wrap: wrap;
    font-size: .82rem; color: var(--ink-subtle); margin-bottom: var(--space-2);
}
.recipe-card__cost { color: var(--teal-600); font-weight: 640; }
.recipe-card__source { font-size: .78rem; color: var(--ink-subtle); margin: 0 0 var(--space-2); }

.source-callout {
    padding: var(--space-5);
    background: var(--blue-050);
    border: 1px solid var(--blue-100);
    border-radius: var(--radius-lg);
}
.source-callout h2 { margin-top: 0; }
.recipe-card__tags { display: flex; gap: 5px; flex-wrap: wrap; }
.recipe-card__save { position: absolute; top: var(--space-2); left: var(--space-2); z-index: 2; }
.recipe-card__save .bookmark-btn { background: rgba(255,255,255,.92); border-color: transparent; }

/* Click-to-play video facade */
.video { position: relative; aspect-ratio: 16 / 9; background: var(--navy-900); }
.video iframe { width: 100%; height: 100%; border: 0; display: block; }
.video__facade {
    position: absolute; inset: 0;
    width: 100%; height: 100%; padding: 0;
    border: 0; cursor: pointer; background: var(--navy-900);
    display: block; overflow: hidden;
}
.video__facade img { width: 100%; height: 100%; object-fit: cover; opacity: .82; }
.video__play {
    position: absolute; inset: 0; margin: auto;
    width: 68px; height: 68px; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(11, 27, 51, .78); color: #fff;
    font-size: 1.5rem; padding-left: 5px;
    transition: transform .12s ease, background .12s ease;
}
.video__facade:hover .video__play { transform: scale(1.08); background: var(--blue-600); }
.video__hint {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: var(--space-3) var(--space-4);
    background: linear-gradient(to top, rgba(11,27,51,.9), transparent);
    color: #fff; font-size: .85rem; text-align: left;
}

.recipe-facts {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: var(--space-2);
    margin-top: var(--space-5);
    padding: var(--space-4) 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    text-align: center;
}
.recipe-fact__value { display: block; font-size: 1.15rem; font-weight: 700; letter-spacing: -.02em; }
.recipe-fact__label { display: block; font-size: .76rem; color: var(--ink-subtle); text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }

.ingredient-list { list-style: none; padding: 0; margin: 0; }
.ingredient-list li { border-bottom: 1px solid var(--border); }
.ingredient-list li:last-child { border-bottom: 0; }
.ingredient-list .checkbox { padding: var(--space-3) 0; font-size: .95rem; }
/* Ticking an ingredient greys it out while shopping or cooking. */
.ingredient-list input:checked + span { text-decoration: line-through; color: var(--ink-subtle); }

.method-list { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.method-list li {
    counter-increment: step;
    position: relative;
    padding: 0 0 var(--space-4) var(--space-7);
    font-size: .96rem; line-height: 1.65;
}
.method-list li::before {
    content: counter(step);
    position: absolute; left: 0; top: 0;
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--blue-100); color: var(--navy-700);
    font-size: .85rem; font-weight: 700;
}
.recipe-notes p { font-size: .93rem; color: var(--ink-muted); margin-bottom: var(--space-2); }

/* --- Profile -------------------------------------------------------------- */
.profile-header {
    display: flex; align-items: center; gap: var(--space-4);
    padding: var(--space-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
}
.profile-header__text { flex: 1; min-width: 0; }
.profile-header__name { font-size: 1.3rem; margin: 0 0 2px; }
.profile-header__email { font-size: .9rem; color: var(--ink-muted); margin: 0; overflow-wrap: anywhere; }
.profile-header__edit { flex-shrink: 0; align-self: flex-start; }

.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); margin-bottom: var(--space-5); }
.profile-stat {
    display: block; text-align: center; text-decoration: none;
    padding: var(--space-4) var(--space-2);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); color: var(--ink);
}
.profile-stat:hover { border-color: var(--blue-500); text-decoration: none; }
.profile-stat__value { display: block; font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.profile-stat__label { display: block; font-size: .78rem; color: var(--ink-subtle); margin-top: 2px; }

/* Grouped list rows — the iOS/Android settings pattern */
.menu-group { margin-bottom: var(--space-5); }
.menu-group__label {
    font-size: .74rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .07em; color: var(--ink-subtle);
    padding: 0 var(--space-2) var(--space-2);
}
.menu-group .menu-row:first-of-type { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.menu-group .menu-row:last-of-type  { border-radius: 0 0 var(--radius-lg) var(--radius-lg); border-bottom: 1px solid var(--border); }
.menu-group .menu-row:only-of-type  { border-radius: var(--radius-lg); }

.menu-row {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: 0;
    text-decoration: none; color: var(--ink);
}
.menu-row:hover { background: var(--blue-050); text-decoration: none; }
.menu-row__icon { font-size: 1.15rem; width: 26px; text-align: center; flex-shrink: 0; }
.menu-row__text { flex: 1; min-width: 0; }
.menu-row__title { display: block; font-weight: 550; font-size: .96rem; }
.menu-row__sub { display: block; font-size: .83rem; color: var(--ink-subtle); margin-top: 1px; line-height: 1.45; }
.menu-row__chevron { color: var(--border-strong); font-size: 1.3rem; flex-shrink: 0; }

.avatar-editor { display: flex; gap: var(--space-5); align-items: flex-start; flex-wrap: wrap; }
.avatar-editor .avatar { border: 3px solid var(--surface); box-shadow: var(--shadow); }

/* --- Utilities ------------------------------------------------------------ */
.muted { color: var(--ink-muted); }
.subtle { color: var(--ink-subtle); }
.small { font-size: .86rem; }
.tiny { font-size: .78rem; }
.strong { font-weight: 650; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.text-right { text-align: right; }
.text-center { text-align: center; }

.mt-0 { margin-top: 0; } .mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); } .mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); } .mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }

.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.flex-gap { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.flex-gap-sm { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }

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

.inline-form { display: inline; }

/* --- Responsive ----------------------------------------------------------- */
@media (max-width: 1024px) {
    .detail { grid-template-columns: 1fr; }
    .detail__aside { position: static; }
    .admin { grid-template-columns: 1fr; }
    .admin__sidebar { flex-direction: row; align-items: center; overflow-x: auto; padding: var(--space-2) var(--space-3); }
    .admin__brand { padding: 0 var(--space-3) 0 var(--space-2); }
    .admin__nav { display: flex; gap: var(--space-1); padding: 0; }
    .admin__nav-label, .admin__sidebar-footer, .admin__brand-tag { display: none; }
    .admin__nav-link { white-space: nowrap; margin-bottom: 0; }
}

@media (max-width: 900px) {
    .layout-sidebar { grid-template-columns: 1fr; }
    .filters { position: static; }
    .split { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    h1 { font-size: 1.6rem; }
    .hero { padding: var(--space-6) 0; }
    .hero h1 { font-size: 1.85rem; }
    .hero p { font-size: 1rem; }
    .hero__stats { gap: var(--space-5); }
    .field-row, .field-row--3 { grid-template-columns: 1fr; }
    .site-header__bar { min-height: 0; padding: var(--space-3) 0; }
    .result-card__top { flex-direction: column; gap: var(--space-2); }
    .admin__content { padding: var(--space-4) var(--space-3); }
    .recipe-facts { grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
    .profile-header { flex-wrap: wrap; }
}

/* ==========================================================================
   Mobile app shell
   Below 768px the site behaves like a native app: a fixed bottom tab bar
   replaces the top navigation links, and the footer is hidden because the
   tab bar already carries the navigation.
   ========================================================================== */
@media (max-width: 768px) {
    /* The top bar keeps only the wordmark; the tabs do the navigating. */
    .site-nav { display: none; }
    .site-header__bar { justify-content: center; min-height: 0; padding: var(--space-3) 0; }
    .site-footer { display: none; }

    .tabbar {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 100;
        background: var(--surface);
        border-top: 1px solid var(--border);
        /* Clear the iOS home indicator without a gap on other devices. */
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-shadow: 0 -1px 12px rgba(11, 27, 51, .07);
    }

    .tabbar__item {
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 3px;
        padding: 9px 2px 7px;
        min-height: 56px;                 /* comfortable tap target */
        color: var(--ink-subtle);
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
        transition: color .12s ease;
    }
    .tabbar__item:hover { text-decoration: none; }
    .tabbar__item:active { background: var(--surface-sunk); }
    .tabbar__item.is-active { color: var(--blue-600); }

    .tabbar__icon { display: block; width: 24px; height: 24px; }
    .tabbar__icon svg { width: 100%; height: 100%; display: block; }
    .tabbar__label { font-size: .68rem; font-weight: 600; letter-spacing: .01em; }

    /* A short bar above the active tab, the usual "you are here" cue. */
    .tabbar__item.is-active::before {
        content: "";
        position: absolute;
        top: 0;
        width: 26px; height: 3px;
        border-radius: 0 0 3px 3px;
        background: var(--blue-600);
    }
    .tabbar__item { position: relative; }

    /* Stop the tab bar covering the end of the page. */
    body { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }

    /* Sticky elements must sit above the tab bar, not under it. */
    .filters, .detail__aside { position: static; }

    /* Full-bleed cards read better on a narrow screen. */
    .page { padding-top: var(--space-4); }
    .food-tiles { grid-template-columns: repeat(2, 1fr); gap: var(--space-2); }
    .food-tile { padding: var(--space-3); }
    .food-tile__icon { font-size: 1.4rem; }
    .food-tile__label { font-size: .92rem; }
    .food-tile__blurb { display: none; }
    .recipe-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-3); }
    .recipe-card__title { font-size: .92rem; }
    .recipe-card__summary { display: none; }

    .profile-stats { gap: var(--space-2); }
    .profile-stat__value { font-size: 1.25rem; }

    /* Edge-to-edge list rows, as a phone settings screen would be. */
    .menu-row { border-left: 0; border-right: 0; border-radius: 0 !important; }
    .menu-group { margin-left: calc(var(--space-4) * -1); margin-right: calc(var(--space-4) * -1); }
    .menu-group__label { padding-left: var(--space-4); }

    /* Admin is still usable, but the tab bar must not overlap it. */
    .admin__main { padding-bottom: var(--space-6); }
}

@media (max-width: 380px) {
    .tabbar__label { font-size: .62rem; }
    .tabbar__icon { width: 22px; height: 22px; }
}

@media print {
    .site-header, .site-footer, .filters, .bookmark-btn, .detail__aside, .pagination { display: none; }
    body { background: #fff; }
}
