/* AEO admin website: SharpQuest brand, light theme only. Everything is in this file: the Content-Security-Policy allows
   no inline styles. Fonts are served from /fonts (SIL Open Font License, see the OFL files there). */

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

@font-face {
    font-family: "Playfair Display";
    src: url("../fonts/playfair-display-latin.woff2") format("woff2");
    font-weight: 400 900;
    font-style: normal;
    font-display: swap;
}

:root {
    /* SharpQuest design system tokens */
    --brand-blue: #0078ab;
    --brand-blue-deep: #005a80;
    --brand-blue-soft: #e5f2f8;
    --brand-green: #bcdd57;
    --brand-green-ink: #4a6b12;
    --ink: #1f2a33;
    --muted: #5b6670;
    --surface: #ffffff;
    --surface-alt: #f3f7fa;
    --hairline: #d9e2e8;
    --danger: #b3261e;
    --danger-soft: #fbe9e7;
    --warn: #8a4b00;
    --warn-bar: #c26a00;
    --warn-soft: #fdf0dc;
    --ok-soft: #eef6d8;
    --focus: #0078ab;

    --font-sans: Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-display: "Playfair Display", Georgia, "Times New Roman", serif;
    --font-mono: ui-monospace, Consolas, "Cascadia Mono", monospace;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 16px;
    --space-4: 24px;
    --space-5: 32px;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;

    --sidebar-width: 248px;
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
    margin: 0;
    background: var(--surface-alt);
    color: var(--ink);
    font: 400 14px/22px var(--font-sans);
}

a { color: var(--brand-blue); text-decoration: none; }
a:hover { color: var(--brand-blue-deep); text-decoration: underline; }

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

h1, h2, h3 { color: var(--ink); }

h1 { font: 700 30px/38px var(--font-display); margin: 0; }
h2 { font: 700 20px/28px var(--font-display); margin: 0 0 var(--space-3); }
h3 { font-size: 15px; font-weight: 500; margin: 0 0 var(--space-2); }

p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

code { font-family: var(--font-mono); font-size: 13px; }

pre {
    margin: 0 0 12px;
    padding: 12px 14px;
    overflow-x: auto;
    background: var(--surface-alt);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
.url { word-break: break-all; }
.secret { word-break: break-all; font-weight: 700; }
.details { font-size: 12px; word-break: break-all; color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

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

/* ---------- Shell: sidebar + content ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    flex: 0 0 var(--sidebar-width);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-3);
    background: var(--surface);
    border-right: 1px solid var(--hairline);
}

.brand { display: flex; flex-direction: column; gap: 6px; padding: 0 var(--space-2); }
.brand:hover { text-decoration: none; }
.brand img { display: block; width: 176px; height: auto; }
.brand .product { font-size: 11px; line-height: 16px; font-weight: 700; letter-spacing: 0.1em; color: var(--muted); }

.sidenav { display: flex; flex-direction: column; gap: 2px; }

.sidenav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    color: var(--ink);
}

.sidenav a:hover { background: var(--surface-alt); text-decoration: none; }

.sidenav a[aria-current="page"] { background: var(--brand-blue-soft); color: var(--brand-blue-deep); font-weight: 500; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.side-foot {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding-top: var(--space-3);
    border-top: 1px solid var(--hairline);
}

.me { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: var(--radius-md); color: var(--ink); }
.me:hover { background: var(--surface-alt); text-decoration: none; }
.me .avatar {
    width: 32px;
    height: 32px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--brand-blue);
    color: #ffffff;
    font-size: 13px;
    font-weight: 700;
}
.me .who { display: flex; flex-direction: column; min-width: 0; line-height: 18px; }
.me .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .role { font-size: 12px; color: var(--muted); }

.side-foot form { margin: 0; }
.side-foot .btn { width: 100%; }

.content { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px var(--space-3);
    min-height: 56px;
    padding: 10px var(--space-5);
    background: var(--surface);
    border-bottom: 1px solid var(--hairline);
}

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.crumbs li + li::before { content: "/"; margin-right: 6px; color: var(--hairline); }
.crumbs [aria-current="page"] { color: var(--ink); font-weight: 500; }

.env {
    margin-left: auto;
    padding: 2px 10px;
    border-radius: var(--radius-sm);
    background: var(--brand-green);
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.page {
    width: 100%;
    max-width: 1320px;
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

/* Signed-out pages (sign in, invitations): a centred card, no sidebar. */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-4) var(--space-3); }

.card {
    width: 100%;
    max-width: 440px;
    padding: var(--space-5);
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.card .logo { display: block; width: 200px; height: auto; margin-bottom: var(--space-2); }
.card h1 { font-size: 26px; line-height: 34px; }
.card form { margin: 0; }
.card .btn { width: 100%; height: 44px; }
.page > .card { margin: var(--space-4) auto; }

/* ---------- Page heading ---------- */

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3); }
.page-head .lead { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.page-actions form { margin: 0; }

/* ---------- Grid (Bootstrap-like 12 columns) ---------- */

.row { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--space-4); }
.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }

.auto-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-3); }

.stack { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }

/* ---------- Panels ---------- */

.panel {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    padding: 20px var(--space-4);
}

.panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: -20px calc(-1 * var(--space-4)) 20px;
    padding: 14px var(--space-4);
    border-bottom: 1px solid var(--hairline);
}

.panel-head h2 { margin: 0; }
.panel-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.panel.danger-zone { border-color: #f0c4c0; }
.panel.danger-zone h2 { color: var(--danger); }

/* A table that fills its panel edge to edge. */
.panel > .table-wrap:first-child { margin-top: -20px; }
.panel > .table-wrap { margin-left: calc(-1 * var(--space-4)); margin-right: calc(-1 * var(--space-4)); }
.panel > .table-wrap:last-child { margin-bottom: -20px; }
.panel > .panel-head + .table-wrap { margin-top: -20px; }
.panel > .table-wrap + p { margin-top: 16px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }

.table-card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius-md); overflow: hidden; }

table { width: 100%; border-collapse: collapse; }

th, td { padding: 12px; text-align: left; vertical-align: middle; }
th:first-child, td:first-child { padding-left: var(--space-4); }
th:last-child, td:last-child { padding-right: var(--space-4); }

thead th {
    position: sticky;
    top: 0;
    background: var(--surface-alt);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    border-bottom: 1px solid var(--hairline);
}

tbody tr + tr td { border-top: 1px solid var(--hairline); }
tbody tr:hover td { background: #f8fbfc; }

td .sub { display: block; font-size: 12px; line-height: 16px; color: var(--muted); }
td.url, td .url { max-width: 380px; }

.empty { padding: 40px var(--space-4); text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-weight: 500; }

.table-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px var(--space-4);
    border-top: 1px solid var(--hairline);
    font-size: 13px;
    color: var(--muted);
}

/* ---------- Pills and badges ---------- */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 1px 10px;
    border-radius: 11px;
    font-size: 12px;
    line-height: 20px;
    font-weight: 500;
    white-space: nowrap;
}

.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.pill-ok { background: var(--ok-soft); color: var(--brand-green-ink); }
.pill-running { background: var(--brand-blue-soft); color: var(--brand-blue-deep); }
.pill-waiting, .pill-neutral { background: var(--surface-alt); color: var(--muted); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-bad { background: var(--danger-soft); color: var(--danger); }

.tag {
    display: inline-block;
    padding: 1px 8px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
    font-size: 12px;
    line-height: 20px;
    font-weight: 500;
    white-space: nowrap;
}

.count { margin-left: auto; padding: 0 8px; border-radius: 9px; background: var(--surface); color: var(--brand-blue-deep); font-size: 12px; line-height: 18px; font-weight: 500; }
.sidenav a:not([aria-current]) .count { background: var(--brand-blue-soft); }

/* ---------- Buttons ---------- */

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 16px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--ink);
    font: 500 14px/1 var(--font-sans);
    white-space: nowrap;
    cursor: pointer;
}

button:hover, .btn:hover { border-color: var(--brand-blue); color: var(--ink); text-decoration: none; }

button.primary, .btn.primary { background: var(--brand-blue); border-color: var(--brand-blue); color: #ffffff; }
button.primary:hover, .btn.primary:hover { background: var(--brand-blue-deep); border-color: var(--brand-blue-deep); color: #ffffff; }

button.danger, .btn.danger { color: var(--danger); border-color: #e6a9a3; }
button.danger:hover, .btn.danger:hover { background: var(--danger); border-color: var(--danger); color: #ffffff; }

button.small, .btn.small { height: 32px; padding: 0 12px; font-size: 13px; }

button.link { height: auto; padding: 0; border: 0; background: none; color: var(--brand-blue); }
button.link:hover { text-decoration: underline; }

/* ---------- Forms ---------- */

.form { display: flex; flex-direction: column; gap: var(--space-3); max-width: 600px; margin: 0; }

.form.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-3) 20px; max-width: none; align-items: end; }
.form.grid > .wide, .form.grid > fieldset, .form.grid > p { grid-column: 1 / -1; }
.form.grid > button { justify-self: start; }

.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }

.form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; font-weight: 400; color: var(--ink); }

.form .hint { margin: 0; font-size: 13px; color: var(--muted); }

.inline-form { display: flex; flex-flow: row wrap; align-items: flex-end; gap: 12px; max-width: none; }
.inline-form label { flex: 1 1 260px; }

input, select, textarea {
    font: 400 14px/20px var(--font-sans);
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
    padding: 9px 10px;
    min-height: 40px;
}

input:hover, select:hover, textarea:hover { border-color: #b7c6d0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus); }

input[type="checkbox"] { min-height: 0; width: 16px; height: 16px; accent-color: var(--brand-blue); }
input[type="file"] { padding: 7px 10px; }

textarea { resize: vertical; }

fieldset { margin: 0; padding: 12px 16px; border: 1px solid var(--hairline); border-radius: var(--radius-md); display: flex; flex-wrap: wrap; gap: 8px 24px; }
legend { padding: 0 6px; font-size: 13px; font-weight: 500; color: var(--muted); }

.filters { padding: var(--space-3) 20px; }
.filters.form.grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }

.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.actions form { margin: 0; }

/* ---------- Messages ---------- */

.notice, .alert {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin: 0;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid #b3d7e8;
    background: var(--brand-blue-soft);
    color: var(--brand-blue-deep);
}

.alert { border-color: #f0c4c0; background: var(--danger-soft); color: var(--danger); }

/* ---------- Definition lists ---------- */

dl.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px 24px; margin: 0; }
dl.grid > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
dl.grid dt { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
dl.grid dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Dashboard tiles ---------- */

.tile {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    color: var(--ink);
}

a.tile:hover { border-color: var(--brand-blue); text-decoration: none; color: var(--ink); }

.tile .label { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.tile .value { font-size: 32px; line-height: 40px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .note { font-size: 13px; color: var(--muted); }

.tile.warn { border-color: #f0c4c0; }
.tile.warn .label, .tile.warn .value { color: var(--danger); }

.tile.good .note { color: var(--brand-green-ink); }

/* ---------- Usage meters (budget, allowance) ---------- */

.usage { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.usage span { font-size: 13px; font-variant-numeric: tabular-nums; }

meter {
    width: 100%;
    height: 6px;
    border: 0;
    border-radius: 3px;
    background: var(--surface-alt);
    appearance: none;
}

meter::-webkit-meter-bar { height: 6px; border: 0; border-radius: 3px; background: var(--surface-alt); }
meter::-webkit-meter-optimum-value { border-radius: 3px; background: var(--brand-blue); }
meter::-webkit-meter-suboptimum-value, meter::-webkit-meter-even-less-good-value { border-radius: 3px; background: var(--warn-bar); }
meter::-moz-meter-bar { border-radius: 3px; background: var(--brand-blue); }
meter:-moz-meter-sub-optimum::-moz-meter-bar, meter:-moz-meter-sub-sub-optimum::-moz-meter-bar { background: var(--warn-bar); }

/* ---------- Sub navigation (agency pages) ---------- */

.subnav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 0;
    padding: 0;
    border-bottom: 1px solid var(--hairline);
}

.subnav a {
    padding: 10px 14px;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-weight: 500;
}

.subnav a:hover { color: var(--ink); text-decoration: none; }
.subnav a[aria-current="page"] { color: var(--brand-blue-deep); border-bottom-color: var(--brand-blue); }

/* ---------- Pager ---------- */

.pager { display: flex; align-items: center; gap: 8px; }
.pager .btn { height: 32px; padding: 0 12px; font-size: 13px; }
.pager .btn[aria-disabled="true"] { color: var(--muted); pointer-events: none; opacity: 0.6; }

/* ---------- Narrow screens ---------- */

@media (max-width: 1100px) {
    .col-8, .col-6, .col-4 { grid-column: span 12; }
    .col-3 { grid-column: span 6; }
}

@media (max-width: 900px) {
    .shell { flex-direction: column; }
    .sidebar { flex: none; gap: var(--space-3); padding: var(--space-3); border-right: 0; border-bottom: 1px solid var(--hairline); }
    .sidenav { flex-direction: row; flex-wrap: wrap; }
    .side-foot { flex-direction: row; flex-wrap: wrap; align-items: center; margin-top: 0; }
    .side-foot .btn { width: auto; }
    .topbar, .page { padding-left: var(--space-3); padding-right: var(--space-3); }
    .col-3 { grid-column: span 12; }
    .panel { padding-left: var(--space-3); padding-right: var(--space-3); }
    .panel-head { margin-left: calc(-1 * var(--space-3)); margin-right: calc(-1 * var(--space-3)); padding-left: var(--space-3); padding-right: var(--space-3); }
    .panel > .table-wrap { margin-left: calc(-1 * var(--space-3)); margin-right: calc(-1 * var(--space-3)); }
}
