/* App chrome only.
   Ad previews get their own isolated stylesheets in assets/previews/ —
   nothing here may leak into a .ad-preview-frame, so keep every selector
   under the app-level classes below and never style bare elements globally. */

:root {
    --ink: #16181d;
    --ink-soft: #5b6070;
    --line: #e3e5ea;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --accent: #2f5bea;
    --accent-ink: #ffffff;
    --radius: 10px;
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

[x-cloak] {
    display: none !important;
}

/* Header */

.app-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 24px;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.app-brand {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ink);
    text-decoration: none;
}

.app-brand span {
    color: var(--accent);
}

.app-brand__logo {
    display: block;
    max-height: 28px;
    max-width: 200px;
}

.app-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-right: auto;
}

.app-nav__link {
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--ink-soft);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}

.app-nav__link:hover {
    background: var(--bg);
    color: var(--ink);
}

.app-logout {
    margin: 0;
}

.app-logout__btn {
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink-soft);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}

.app-logout__btn:hover {
    color: var(--ink);
    border-color: var(--ink-soft);
}

/* Flash messages */

.app-flashes {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 860px;
    margin: 20px auto 0;
    padding: 0 24px;
}

.flash {
    margin: 0;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 14px;
}

.flash--success {
    background: #e8f6ec;
    color: #1c7a3a;
}

.flash--error {
    background: #fdecec;
    color: #a52121;
}

/* Breadcrumbs */

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--ink-soft);
}

.breadcrumbs a {
    color: var(--ink-soft);
    text-decoration: none;
}

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

.breadcrumbs__current {
    color: var(--ink);
}

.breadcrumbs__sep {
    color: var(--line);
}

/* Main */

.app-main {
    flex: 1;
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 32px 24px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 28px;
}

.card--error {
    border-left: 3px solid var(--accent);
}

.card h1 {
    margin: 4px 0 12px;
    font-size: 28px;
    letter-spacing: -0.02em;
}

.card h2 {
    margin: 0 0 8px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-soft);
}

.eyebrow {
    margin: 0;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
}

.lede {
    margin: 0 0 24px;
    color: var(--ink-soft);
    max-width: 60ch;
}

.btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-ink);
    font: inherit;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover {
    filter: brightness(1.08);
}

/* Scaffold smoke tests — removed once real pages exist */

.scaffold-checks {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.scaffold-check {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    background: var(--bg);
}

.scaffold-check__out {
    margin: 12px 0 0;
    font-size: 14px;
    color: var(--ink-soft);
}

.footnote {
    margin: 24px 0 0;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    font-size: 13px;
    color: var(--ink-soft);
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px 5px;
}

.card--error code {
    background: var(--surface);
}

.trace {
    margin: 16px 0 0;
    padding: 14px;
    overflow-x: auto;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
}

/* Forms */

.card--narrow {
    max-width: 360px;
    margin: 0 auto;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
    color: var(--ink-soft);
}

.form-field input,
.form-field textarea,
.form-field select {
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    resize: vertical;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.form-field--checkbox {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.ad-group-form {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-top: 20px;
}

.ad-group-form .form-field {
    flex: 0 0 auto;
}

.table__actions {
    display: flex;
    gap: 4px;
    white-space: nowrap;
}

.share-link-input {
    width: 220px;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: 12px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
    color: var(--ink-soft);
}

.table__actions .btn {
    padding: 4px 9px;
}

.ad-group {
    padding: 16px 0;
    border-bottom: 1px solid var(--line);
}

.ad-group:last-of-type {
    border-bottom: none;
}

.ad-group__header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.ad-group__header strong {
    flex: 1;
}

.code-textarea {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    white-space: pre;
}

.preview-demo__controls {
    max-width: 200px;
}

.preview-demo__frame {
    margin-top: 20px;
}

.variation-grid__items {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 16px;
}

.variation-grid__item {
    flex: 0 0 auto;
}

/* Structured ad editors (RSA, Meta, LinkedIn) — shared layout/row/counter
   classes prefixed .editor-, plus per-type classes (.rsa-*) for markup that
   only the RSA form uses (pin selects, sitelinks, callouts). */

.editor-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 32px;
    align-items: start;
    margin-top: 16px;
    max-width: 100%;
}

/* The flexible track's item defaults to min-width: auto (its content's
   min-content size), which can exceed the track's minmax(0, 1fr) and blow
   out the grid regardless — the item itself needs the override too. Covers
   both structures used by the four structured editors: RSA nests
   .editor-live inside .editor-form; Meta/LinkedIn nest .editor-form inside
   .editor-live. */
.editor-layout > .editor-form,
.editor-layout > .editor-live {
    min-width: 0;
}

.editor-form h2 {
    margin: 24px 0 4px;
    font-size: 15px;
}

.editor-hint {
    font-weight: 400;
    font-size: 12px;
    color: var(--ink-soft);
}

.editor-field-row {
    display: flex;
    gap: 12px;
}

.editor-field-row .form-field {
    flex: 1;
    min-width: 0;
}

.editor-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.editor-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px 90px;
    gap: 8px;
    align-items: center;
}

.editor-row--nopin {
    grid-template-columns: minmax(0, 1fr) 48px;
}

.editor-row input {
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    font-size: 13px;
}

.editor-counter {
    font-size: 11px;
    color: var(--ink-soft);
    text-align: right;
    white-space: nowrap;
}

.editor-counter--over {
    color: #a52121;
    font-weight: 600;
}

.editor-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 4px;
}

.editor-tab {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12px;
    cursor: pointer;
    background: var(--surface);
}

.editor-tab input {
    margin: 0;
}

.editor-tab:has(input:checked) {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.rsa-pin {
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    font-size: 12px;
}

.rsa-sitelink-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.rsa-sitelink-row input {
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    font-size: 12px;
}

.rsa-rows--callouts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
}

.rsa-callout-input {
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    font-size: 12px;
}

.editor-preview-pane {
    position: sticky;
    top: 16px;
}

.editor-preview-pane h2 {
    margin: 0 0 4px;
    font-size: 15px;
}

@media (max-width: 900px) {
    .editor-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .editor-preview-pane {
        position: static;
    }
}

.form-error {
    margin: 0;
    padding: 10px 12px;
    border-radius: 6px;
    background: #fdecec;
    color: #a52121;
    font-size: 14px;
}

/* Clients list / detail */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 4px;
}

.page-header h1 {
    margin: 0;
}

.inline-form {
    margin: 0;
}

.btn--muted {
    background: var(--surface);
    color: var(--ink-soft);
    border-color: var(--line);
}

.btn--muted:hover {
    color: var(--ink);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th,
.table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.table th {
    color: var(--ink-soft);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.table a {
    color: var(--ink);
    font-weight: 500;
    text-decoration: none;
}

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

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg);
    color: var(--ink-soft);
    font-size: 12px;
}

.card__section {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

.card__section h2 {
    margin: 0 0 4px;
    font-size: 16px;
}

.client-logo-preview {
    display: block;
    max-width: 160px;
    max-height: 80px;
    object-fit: contain;
    margin: 16px 0;
}

/* Asset picker */

.asset-picker {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}

.asset-picker__empty {
    margin: 0;
    color: var(--ink-soft);
    font-size: 14px;
}

.asset-picker__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
}

.asset-picker__thumb {
    aspect-ratio: 1;
    padding: 0;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    overflow: hidden;
    cursor: pointer;
}

.asset-picker__thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.asset-picker__thumb.is-selected {
    border-color: var(--accent);
}

.asset-picker__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.asset-picker__actions form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.asset-picker__actions input[type="url"] {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
    min-width: 220px;
}

/* Footer */

.app-footer {
    padding: 18px 24px;
    border-top: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-soft);
    font-size: 13px;
    text-align: center;
}

/* Public campaign review page (ad-preview-z51.2) */

.review-ad {
    padding: 16px 0;
    border-top: 1px solid var(--line);
}

.review-ad:first-of-type {
    border-top: none;
}

.review-ad__name {
    margin: 0 0 10px;
    font-weight: 500;
}

.review-device-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.review-device-tab {
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink-soft);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.review-device-tab--active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.review-rsa-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 24px;
    align-items: start;
}

.review-asset-inventory h3 {
    margin: 16px 0 6px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-soft);
}

.review-asset-inventory h3:first-child {
    margin-top: 0;
}

.review-asset-list {
    margin: 0;
    padding-left: 20px;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.review-asset-list .badge {
    margin-left: 6px;
}

/* Client feedback: comment threads + form (ad-preview-a2y.1) */

.comments-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.comments-section h2,
.comments-section h4 {
    margin: 0 0 10px;
    font-size: 15px;
}

.comments-section--ad {
    margin-top: 16px;
}

.comment-thread {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.comment {
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 8px;
}

.comment__meta {
    display: flex;
    gap: 8px;
    align-items: baseline;
    font-size: 12px;
    color: var(--ink-soft);
    margin-bottom: 4px;
}

.comment__author {
    font-weight: 500;
    color: var(--ink);
}

.comment__body {
    margin: 0;
    font-size: 14px;
    white-space: pre-line;
}

.comment-form {
    max-width: 480px;
}

/* Ad approve / request-changes (ad-preview-a2y.2) */

.review-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.review-section h4 {
    margin: 0 0 10px;
    font-size: 15px;
}

.review-status-list {
    list-style: none;
    margin: 0 0 14px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.review-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.review-status__author {
    font-weight: 500;
}

.review-status__time {
    color: var(--ink-soft);
}

.badge--approved {
    background: #e4f5ea;
    color: #1c7a3f;
}

.badge--needs_changes {
    background: #fdf1e0;
    color: #a5620a;
}

.review-form {
    max-width: 480px;
}

.review-form__actions {
    display: flex;
    gap: 8px;
}

.btn--approve {
    background: #1c7a3f;
}

/* Mobile */

@media (max-width: 640px) {
    .app-header {
        padding: 12px 16px;
    }

    .app-nav {
        order: 3;
        width: 100%;
        gap: 2px;
    }

    .app-nav__link {
        padding: 6px 8px;
        font-size: 13px;
    }

    .app-main {
        padding: 20px 16px;
    }

    .app-flashes {
        padding: 0 16px;
    }

    .card {
        padding: 20px;
    }

    .review-rsa-layout {
        grid-template-columns: 1fr;
    }
}

/* Print (ad-preview-z51.3) — a clean deck of the ad previews for Cmd+P.
   Only touches app chrome; renderer stylesheets are isolated per
   docs/ARCHITECTURE.md and print as-is. */

@media print {
    .app-header,
    .app-footer,
    .app-flashes,
    .breadcrumbs,
    .review-device-tabs,
    .comments-section,
    .btn {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .app-main {
        max-width: none;
        padding: 0;
    }

    .card {
        border: none;
        border-radius: 0;
        padding: 0;
    }

    .ad-group {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .review-ad {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
