/* biome-ignore-all lint/style/noExcessiveLinesPerFile: one stylesheet by design (Canopy ADR 0010, tech-spec "Styling"); the layout links only /assets/styles.css. */

/*
 * Grove styles: one plain CSS file with custom properties (Canopy ADR 0010).
 * Brand tokens are provisional until design delivers Grove's: MobileFuse publisher greens.
 * No inline styles anywhere (CSP `style-src 'self'`).
 */

/* ---------- Tokens ---------- */
:root {
    /* Brand greens */
    --grove-950: #072a19;
    --grove-900: #0b3a23;
    --grove-800: #114d30;
    --grove-700: #17643e;
    --grove-600: #1d7a4b;
    --grove-500: #27965c;
    --grove-400: #4fb27c;
    --grove-200: #b9e2c9;
    --grove-100: #dcf1e4;
    --grove-50: #f1f9f4;
    --leaf: #9ed36a;
    --grove-green: var(--grove-700);

    /* Neutrals (slightly green-tinted) */
    --ink: #17201b;
    --ink-2: #3c4a42;
    --muted: #66746c;
    --line: #dfe5e1;
    --line-strong: #c7d0ca;
    --surface: #ffffff;
    --surface-2: #f6f8f7;
    --bg: #f3f5f4;

    /* Status */
    --ok: #1d7a4b;
    --ok-bg: #e2f4e9;
    --warn: #8a5a00;
    --warn-bg: #fff3d6;
    --warn-line: #f1cf7a;
    --danger: #b42318;
    --danger-bg: #fdecea;
    --info: #22577a;
    --info-bg: #e6f0f7;

    /* Aliases */
    --text: var(--ink);
    --accent: var(--grove-600);
    --accent-hover: var(--grove-700);
    --focus: 0 0 0 3px rgb(39 150 92 / 0.35);

    /* Type */
    --font-sans:
        "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
        sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --fs-xs: 0.75rem;
    --fs-sm: 0.8125rem;
    --fs-md: 0.875rem;
    --fs-lg: 1rem;
    --fs-xl: 1.375rem;
    --fs-2xl: 1.75rem;

    /* Shape */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgb(16 40 28 / 0.06);
    --shadow: 0 1px 3px rgb(16 40 28 / 0.08), 0 4px 16px rgb(16 40 28 / 0.06);
    --shadow-lg: 0 12px 40px rgb(16 40 28 / 0.18);

    --topbar-h: 56px;
    --content-max: 1360px;
}

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

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

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--fs-md);
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
    margin: 0 0 0.5rem;
    line-height: 1.25;
    color: var(--ink);
    letter-spacing: -0.01em;
}

h1 {
    font-size: var(--fs-2xl);
    font-weight: 700;
}

h2 {
    font-size: var(--fs-xl);
    font-weight: 650;
}

h3 {
    font-size: var(--fs-lg);
    font-weight: 650;
}

p {
    margin: 0 0 0.75rem;
}

a {
    color: var(--accent);
    text-underline-offset: 2px;
}

a:hover {
    color: var(--accent-hover);
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus);
    border-radius: var(--radius-sm);
}

code,
.mono {
    font-family: var(--font-mono);
    font-size: 0.92em;
}

[hidden] {
    /* biome-ignore lint/complexity/noImportantStyles: `hidden` must beat any class that sets display (.button, flex rows), which JS toggles. */
    display: none !important;
}

.visually-hidden {
    /* biome-ignore lint/complexity/noImportantStyles: standard sr-only pattern; a component's own position rule must not unhide it. */
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    /* biome-ignore lint/suspicious/useBaseline: deprecated but universally supported sr-only fallback, kept for older assistive tech. */
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.muted,
.hint {
    color: var(--muted);
}

.hint {
    font-size: var(--fs-sm);
}

/* ---------- Brand ---------- */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    color: inherit;
}

.brand:hover {
    color: inherit;
}

.brand-mark {
    flex: none;
    color: var(--grove-600);
}

.brand-mark-leaf {
    fill: #ffffff;
}

.brand-mark-leaf-alt {
    fill: var(--leaf);
}

.brand-mark-trunk {
    stroke: #ffffff;
    stroke-width: 2;
    stroke-linecap: round;
    fill: none;
}

.brand-word {
    font-size: 1.25rem;
    font-weight: 750;
    letter-spacing: -0.02em;
}

.brand-by {
    font-size: var(--fs-xs);
    font-weight: 500;
    opacity: 0.7;
    padding-left: 0.55rem;
    border-left: 1px solid currentColor;
    line-height: 1;
}

/* ---------- App shell (signed in) ---------- */
.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: linear-gradient(90deg, var(--grove-950), var(--grove-900) 55%, var(--grove-800));
    color: #ffffff;
    box-shadow:
        0 1px 0 rgb(255 255 255 / 0.04),
        var(--shadow-sm);
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    height: var(--topbar-h);
    padding: 0 1.25rem;
}

.topbar .brand-mark {
    color: var(--grove-500);
}

.topbar-nav {
    display: flex;
    align-items: stretch;
    gap: 0.15rem;
    height: 100%;
    overflow-x: auto;
    /* biome-ignore lint/suspicious/useBaseline: progressive enhancement; browsers without it just show the nav's scrollbar. */
    scrollbar-width: none;
    flex: 1 1 auto;
    min-width: 0;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 0 0.75rem;
    color: rgb(255 255 255 / 0.78);
    text-decoration: none;
    font-weight: 550;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    border-top: 3px solid transparent;
}

.nav-link:hover {
    color: #ffffff;
    background: rgb(255 255 255 / 0.06);
}

.nav-link[aria-current="page"] {
    color: #ffffff;
    border-bottom-color: var(--leaf);
}

.nav-link-internal {
    margin-left: auto;
    color: var(--leaf);
}

.account {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: none;
}

.account-name {
    font-weight: 550;
    color: rgb(255 255 255 / 0.9);
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewing-as {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--warn-bg);
    color: var(--warn);
    border-bottom: 1px solid var(--warn-line);
    font-weight: 550;
}

.viewing-as strong {
    color: #5c3c00;
}

.main {
    flex: 1 1 auto;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 1.75rem 1.5rem 3rem;
}

.main-bleed {
    max-width: none;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* ---------- Bare shell (signed out) ---------- */
.bare {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: radial-gradient(1200px 500px at 50% -10%, var(--grove-100), transparent 70%), var(--bg);
}

.bare-main {
    flex: 1 1 auto;
    width: 100%;
    max-width: 440px;
    margin: 0 auto;
    padding: 12vh 1.25rem 2rem;
}

.bare-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 1.75rem;
    color: var(--grove-900);
}

.bare-brand .brand-word {
    font-size: 1.6rem;
}

.bare-brand .brand-mark {
    width: 36px;
    height: 36px;
}

.bare-footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--muted);
    font-size: var(--fs-xs);
}

/* ---------- Surfaces ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.card-narrow {
    max-width: 440px;
    margin-left: auto;
    margin-right: auto;
}

.card-flush {
    padding: 0;
    overflow: hidden;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-header h1 {
    margin-bottom: 0.15rem;
}

.page-header p {
    margin: 0;
}

.empty {
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--muted);
    margin: 0;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
}

.empty-state-code {
    font-size: 3rem;
    font-weight: 800;
    color: var(--grove-200);
    margin: 0;
    line-height: 1;
}

/* ---------- Buttons & forms ---------- */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.25rem;
    padding: 0.45rem 0.95rem;
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    color: #ffffff;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition:
        background-color 0.12s ease,
        border-color 0.12s ease;
}

.button:hover {
    color: #ffffff;
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.button-primary {
    background: var(--accent);
}

.button-secondary {
    color: var(--ink-2);
    background: var(--surface);
    border-color: var(--line-strong);
}

.button-secondary:hover {
    color: var(--ink);
    background: var(--surface-2);
    border-color: var(--muted);
}

.button-quiet {
    color: var(--ink-2);
    background: transparent;
    border-color: var(--line-strong);
}

/* The top bar's quiet button sits on the dark brand bar (after the base rules, so specificity reads in order). */
.topbar .button-quiet {
    color: #ffffff;
    border-color: rgb(255 255 255 / 0.3);
    background: transparent;
}

.button-quiet:hover {
    color: var(--ink);
    background: var(--surface-2);
    border-color: var(--line-strong);
}

.topbar .button-quiet:hover {
    background: rgb(255 255 255 / 0.1);
    color: #ffffff;
}

.button-small {
    min-height: 1.85rem;
    padding: 0.25rem 0.7rem;
    font-size: var(--fs-sm);
}

.button[disabled],
.button[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
}

.link-button {
    padding: 0;
    font: inherit;
    color: var(--accent);
    background: none;
    border: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.viewing-as .link-button {
    color: #5c3c00;
    font-weight: 650;
}

.link-subtle {
    color: var(--accent);
    font-weight: 550;
    text-decoration: none;
}

.link-subtle:hover {
    text-decoration: underline;
}

.inline-form,
.form-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
textarea,
select {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.7rem;
    min-height: 2.25rem;
}

.input:focus,
input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--grove-500);
    box-shadow: var(--focus);
}

label {
    font-weight: 550;
    color: var(--ink-2);
}

/* ---------- Tables ---------- */
.toolbar {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.toolbar-filter {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1 1 18rem;
}

.input-search {
    width: 100%;
    max-width: 20rem;
    padding-left: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2366746c' stroke-width='2' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.6rem center;
}

.toolbar-count {
    font-size: var(--fs-sm);
    white-space: nowrap;
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.toast {
    position: absolute;
    right: 1rem;
    top: calc(100% + 0.5rem);
    z-index: 5;
    padding: 0.45rem 0.8rem;
    border-radius: var(--radius-sm);
    background: var(--grove-900);
    color: #ffffff;
    font-size: var(--fs-sm);
    box-shadow: var(--shadow);
}

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

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-md);
}

.data-table th,
.data-table td {
    padding: 0.6rem 1rem;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--line);
}

.data-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    color: var(--muted);
    font-size: var(--fs-xs);
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: var(--grove-50);
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.data-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.data-table .strong {
    font-weight: 600;
    color: var(--ink);
}

.data-table .nowrap,
.data-table .actions {
    white-space: nowrap;
}

.data-table .actions {
    text-align: right;
}

.cell-action {
    display: block;
    margin-top: 0.2rem;
    font-size: var(--fs-sm);
}

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    font-size: var(--fs-xs);
    font-weight: 650;
    text-transform: capitalize;
    white-space: nowrap;
    background: var(--surface-2);
    color: var(--ink-2);
    border: 1px solid var(--line);
}

.badge-active,
.badge-ads-ok {
    background: var(--ok-bg);
    color: var(--ok);
    border-color: transparent;
}

.badge-paused {
    background: var(--surface-2);
    color: var(--muted);
}

.badge-pending,
.badge-ads-missing_lines {
    background: var(--warn-bg);
    color: var(--warn);
    border-color: transparent;
}

.badge-ads-not_found {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: transparent;
}

.badge-ads-ok,
.badge-ads-missing_lines,
.badge-ads-not_found {
    text-transform: none;
}

/* ---------- Dialog ---------- */
.dialog {
    width: min(640px, calc(100vw - 2rem));
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    color: var(--ink);
}

.dialog::backdrop {
    background: rgb(7 42 25 / 0.45);
}

.dialog-body {
    padding: 1.5rem 1.5rem 0.5rem;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    padding: 0.75rem 1.5rem 1.25rem;
}

.code-block {
    display: block;
    width: 100%;
    margin: 0 0 0.75rem;
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    line-height: 1.6;
    background: var(--surface-2);
    /* biome-ignore lint/suspicious/useBaseline: progressive enhancement; browsers without it leave the textarea fixed-size. */
    resize: vertical;
    white-space: pre;
}

.copy-status {
    margin-left: 0.75rem;
    font-size: var(--fs-sm);
}

/* ---------- Rill embeds ---------- */
.rill-embed {
    flex: 1 1 auto;
    display: flex;
    min-height: 520px;
    height: calc(100vh - var(--topbar-h));
    background: var(--surface);
}

.viewing-as ~ .main .rill-embed {
    height: calc(100vh - var(--topbar-h) - 2.3rem);
}

.rill-embed-frame {
    display: block;
    flex: 1 1 auto;
    width: 100%;
    border: 0;
}

.embed-error {
    max-width: 560px;
    margin: 3rem auto;
    padding: 1.25rem 1.5rem;
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #f5c2bc;
    border-radius: var(--radius);
}

.embed-error p:last-child {
    margin-bottom: 0;
}

/* ---------- HTMX (its own indicator styles are off: CSP) ---------- */
.htmx-indicator {
    opacity: 0;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
    transition: opacity 200ms ease-in;
}

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
    .brand-by,
    .account-name {
        display: none;
    }

    .topbar-inner {
        gap: 0.75rem;
        padding: 0 0.75rem;
    }

    .main {
        padding: 1.25rem 1rem 2rem;
    }

    .toolbar-actions .button {
        flex: 1 1 auto;
    }
}

/* auth pages (owned by the identity work stream: login, "Login As…", user settings) */
.auth-card,
.auth-message {
    max-width: 420px;
    margin: 8vh auto 0;
    padding: 32px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.auth-card h1,
.auth-message h1 {
    margin: 0 0 8px;
    font-size: var(--fs-xl);
}
.auth-lede {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: var(--fs-md);
}
.login-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.login-form label {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--ink-2);
}
.login-form input[type="email"],
.login-form input[type="password"],
.login-as-search input[type="search"],
.settings-api-key {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 12px;
    margin-bottom: 8px;
    font: inherit;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.login-form input:focus-visible,
.login-as-search input:focus-visible,
.settings-api-key:focus-visible {
    outline: none;
    box-shadow: var(--focus);
    border-color: var(--accent);
}
.login-form .login-remember {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
    margin: 4px 0 8px;
}
.login-form button[type="submit"] {
    padding: 10px 16px;
    font: inherit;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.login-form button[type="submit"]:hover {
    background: var(--accent-hover);
}
.login-forgot {
    margin: 12px 0 0;
    font-size: var(--fs-sm);
    text-align: center;
}
.login-error {
    margin: 0 0 12px;
    padding: 10px 12px;
    color: var(--danger);
    background: var(--danger-bg);
    border-radius: var(--radius-sm);
    font-size: var(--fs-md);
    overflow-wrap: anywhere;
}
.auth-notice {
    margin: 0 0 12px;
    padding: 10px 12px;
    color: var(--ok);
    background: var(--ok-bg);
    border-radius: var(--radius-sm);
    font-size: var(--fs-md);
}
/* A Dashboard validation message under its field. */
.field-error {
    margin: -4px 0 8px;
    color: var(--danger);
    font-size: var(--fs-sm);
}
.login-form input[aria-invalid="true"] {
    border-color: var(--danger);
}
.login-as {
    max-width: 720px;
}
.login-as-list {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}
.login-as-list li + li {
    border-top: 1px solid var(--line);
}
.login-as-choice button {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    align-items: baseline;
    width: 100%;
    padding: 12px 16px;
    font: inherit;
    text-align: left;
    background: none;
    border: 0;
    cursor: pointer;
}
.login-as-choice button:hover,
.login-as-choice button:focus-visible {
    background: var(--grove-50);
    outline: none;
}
.login-as-name {
    font-weight: 600;
}
.login-as-email,
.login-as-company,
.login-as-more,
.login-as-empty {
    color: var(--muted);
    font-size: var(--fs-sm);
}
.settings {
    max-width: 640px;
}
.settings-fields {
    display: grid;
    grid-template-columns: minmax(96px, max-content) 1fr;
    gap: 12px 24px;
    margin: 16px 0;
    padding: 20px 24px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.settings-fields dt {
    font-weight: 600;
    color: var(--ink-2);
}
.settings-fields dd {
    margin: 0;
    overflow-wrap: anywhere;
}
.settings-empty {
    color: var(--muted);
}
.settings-api-key {
    margin: 0;
    font-family: var(--font-mono);
}
.settings-note {
    color: var(--muted);
    font-size: var(--fs-sm);
}
.settings-password {
    margin: 24px 0 0;
    padding: 20px 24px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.settings-password h2 {
    margin: 0 0 12px;
    font-size: var(--fs-lg);
}
@media (max-width: 520px) {
    .auth-card,
    .auth-message {
        margin-top: 16px;
        padding: 20px;
    }
    .settings-fields {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .settings-fields dd {
        margin-bottom: 8px;
    }
}
/* end auth pages */
