:root {
    --bg: #f5f7fb;
    --sidebar-bg: #111827;
    --sidebar-text: #9ca3af;
    --card: #ffffff;
    --ink: #111827;
    --muted: #6b7280;
    --accent: #0866ff;
    --accent-hover: #0052cc;
    --success: #198754;
    --warning: #b45309;
    --error: #dc3545;
    --border: #dfe5ef;
    --shadow: rgba(17, 24, 39, 0.08);
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

button, input, select { font: inherit; }
textarea { font: inherit; resize: vertical; }
option {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: var(--ink);
    background: #fff;
}
code { background: #eef2ff; border-radius: 5px; padding: 2px 5px; }

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

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 244px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--accent);
    font-weight: 800;
}

.brand strong { display: block; color: #fff; font-size: 18px; }
.brand span { display: block; font-size: 12px; }

.nav { display: grid; gap: 4px; }

.nav-link {
    border: 0;
    width: 100%;
    text-align: left;
    padding: 11px 12px;
    border-radius: 8px;
    background: transparent;
    color: var(--sidebar-text);
    cursor: pointer;
}

.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: rgba(8,102,255,0.18); color: #fff; }

.main {
    flex: 1;
    margin-left: 244px;
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(255,255,255,0.96);
    border-bottom: 1px solid var(--border);
    padding: 20px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
}

.topbar h1, .panel h2, .modal-head h2 { margin: 0; font-weight: 650; }
.topbar h1 { font-size: 24px; }
.topbar p, .panel-head p { margin: 4px 0 0; color: var(--muted); }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.content { padding: 24px 32px; }
.view { display: none; }
.view.active { display: block; }

.btn {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 13px;
    cursor: pointer;
    font-weight: 650;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: #fff; border-color: var(--border); color: var(--ink); }
.btn.ghost:hover { border-color: #b9c3d4; }
.btn.danger { background: #fff4f4; color: var(--error); border-color: #ffd0d0; }
.btn.danger:hover { border-color: #f59ca5; background: #ffe8e8; }
.btn.small { min-height: 32px; padding: 6px 9px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: wait; }

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric, .panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 26px var(--shadow);
}

.metric { padding: 18px; position: relative; }
.metric span { color: var(--muted); display: block; }
.metric strong { display: block; font-size: 28px; margin-top: 6px; }

.panel { padding: 18px; }
.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.scroll-hint {
    position: sticky;
    left: 0;
    display: inline-flex;
    align-items: center;
    margin-bottom: 8px;
    padding: 7px 10px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1e3a8a;
    font-size: 12px;
    font-weight: 700;
}

.scroll-hint::after {
    content: "→";
    margin-left: 8px;
    font-size: 15px;
}

.campaign-table-wrap {
    overflow-x: scroll;
    padding-bottom: 12px;
    scrollbar-color: var(--accent) #dbeafe;
    scrollbar-width: auto;
}

.campaign-table-wrap::-webkit-scrollbar {
    height: 14px;
}

.campaign-table-wrap::-webkit-scrollbar-track {
    background: #dbeafe;
    border-radius: 999px;
}

.campaign-table-wrap::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 999px;
    border: 3px solid #dbeafe;
}

.campaign-table { width: 100%; border-collapse: collapse; min-width: 1320px; }
.campaign-table th, .campaign-table td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.campaign-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.campaign-table td:last-child { min-width: 310px; }
.campaign-table tr:last-child td { border-bottom: 0; }
.campaign-table tr.clickable-row { cursor: pointer; }
.campaign-table tr.clickable-row:hover td,
.campaign-table tr.clickable-row.active td {
    background: #f8fbff;
}
.campaign-table tr.clickable-row.active td:first-child {
    box-shadow: inset 3px 0 0 var(--accent);
}

.status {
    display: inline-flex;
    border-radius: 999px;
    padding: 4px 9px;
    font-weight: 700;
    font-size: 12px;
}

.status.ACTIVE { color: #0f5132; background: #d1e7dd; }
.status.PAUSED { color: #664d03; background: #fff3cd; }
.status.UNKNOWN { color: #374151; background: #e5e7eb; }

.row-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.budget-pending {
    display: inline-flex;
    border-radius: 7px;
    padding: 3px 7px;
    color: #0646ad;
    background: #dbeafe;
    border: 1px solid #93c5fd;
    font-weight: 800;
}

.roas-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 800;
}

.roas-pill.good { color: #0f5132; background: #d1e7dd; }
.roas-pill.medium { color: #664d03; background: #fff3cd; }
.roas-pill.bad { color: #842029; background: #f8d7da; }

.split {
    display: grid;
    grid-template-columns: minmax(320px, .9fr) minmax(360px, 1.1fr);
    gap: 18px;
    align-items: start;
}

.campaign-cards, .logs, .user-list { display: grid; gap: 10px; }

.campaign-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 13px;
    background: #fff;
    cursor: pointer;
}

.campaign-card:hover, .campaign-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8,102,255,.12); }
.campaign-card strong { display: block; }
.campaign-card span { color: var(--muted); font-size: 13px; }

.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 16px 0;
}

.campaign-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f8fafc;
}

.campaign-tabs button {
    border: 0;
    border-radius: 8px;
    padding: 10px 12px;
    background: transparent;
    color: var(--muted);
    font-weight: 800;
    cursor: pointer;
}

.campaign-tabs button.active {
    color: #fff;
    background: var(--accent);
    box-shadow: 0 8px 18px rgba(8,102,255,.2);
}

.verdict-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    background: #f8fafc;
}

.verdict-card span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.verdict-card strong {
    display: block;
    margin-top: 4px;
    font-size: 20px;
}

.verdict-card p {
    margin: 6px 0 0;
    color: #334155;
}

.verdict-card.good { border-color: #badbcc; background: #f0fdf4; }
.verdict-card.warn { border-color: #facc15; background: #fefce8; }
.verdict-card.paused { border-color: #fed7aa; background: #fff7ed; }

.action-panel {
    display: grid;
    gap: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    background: #fff;
}

.action-panel span,
.action-panel small {
    display: block;
    color: var(--muted);
}

.action-panel strong {
    display: block;
    margin: 4px 0;
    font-size: 24px;
}

.soft-actions {
    justify-content: flex-start;
    margin-top: 12px;
}

.detail-metric {
    position: relative;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}

.detail-metric span { display: block; color: var(--muted); font-size: 12px; }
.detail-metric > span,
.metric > span {
    display: flex;
    align-items: center;
    gap: 6px;
}
.detail-metric strong { display: block; margin-top: 3px; font-size: 18px; }
.detail-metric.pending { border-color: #93c5fd; background: #eff6ff; }
.detail-metric.cap-ok { border-color: #badbcc; background: #f0fdf4; }
.detail-metric.cap-warn { border-color: #facc15; background: #fefce8; }
.detail-metric.cap-danger { border-color: #f5c2c7; background: #fff1f2; }
.detail-metric small { display: block; color: var(--accent); margin-top: 3px; }

.muted-value {
    color: var(--muted);
}

.global-budget {
    min-width: 150px;
}

.global-budget strong,
.global-budget span {
    display: block;
}

.global-budget span {
    color: var(--muted);
    font-size: 12px;
}

.progress {
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: #e5e7eb;
    margin-top: 6px;
}

.progress i {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--success);
}

.progress.warn i { background: #eab308; }
.progress.danger i { background: var(--error); }

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 0 0 14px;
}

.panel-subhead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 18px 0 10px;
}

.panel-subhead h3 {
    margin: 0;
    font-size: 15px;
}

.ads-subhead {
    max-width: 720px;
}

.empty-inline {
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--muted);
    padding: 12px;
    margin-bottom: 14px;
}

.meta-creatives {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 360px));
    gap: 12px;
    align-items: start;
    justify-content: start;
    margin-bottom: 14px;
}

.meta-creative {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.meta-creative.active {
    border-color: #8bd3a6;
    box-shadow: inset 4px 0 0 #16a34a;
}

.meta-creative.paused {
    border-color: #f0d47a;
    box-shadow: inset 4px 0 0 #d99800;
}

.meta-creative.processing {
    border-color: #93c5fd;
    box-shadow: inset 4px 0 0 #2563eb;
}

.meta-creative.danger {
    opacity: 0.72;
}

.meta-creative-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.meta-creative-top small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.meta-preview-frame {
    width: min(100%, 420px);
    max-height: 760px;
    overflow: auto;
    background: #fff;
}

.meta-preview-frame iframe {
    width: 100%;
    min-height: 720px;
    border: 0;
}

.meta-creative-media,
.creative-placeholder {
    width: 100%;
    aspect-ratio: 1.91 / 1;
    background: #0b1220;
    color: #fff;
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
}

.meta-creative img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.meta-creative-media em {
    display: none;
    padding: 18px;
    color: #cbd5e1;
    text-align: center;
    font-size: 13px;
    font-style: normal;
    line-height: 1.35;
}

.meta-creative-media.is-missing img {
    display: none;
}

.meta-creative-media.is-missing em {
    display: block;
}

.meta-creative-media.video-card {
    min-height: 170px;
    align-content: center;
    gap: 8px;
    padding: 18px;
    background: #111827;
}

.meta-creative-media.video-card strong {
    color: #fff;
    font-size: 18px;
}

.meta-creative-media.video-card em {
    display: block;
    max-width: 280px;
}

.meta-creative-media span {
    position: absolute;
    left: 10px;
    top: 10px;
    border-radius: 999px;
    padding: 4px 8px;
    background: rgba(15, 23, 42, 0.82);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}

.meta-creative > div:not(.creative-placeholder):not(.meta-creative-media):not(.meta-preview-frame) {
    padding: 10px;
}

.meta-creative strong,
.meta-creative span {
    display: block;
}

.meta-creative span,
.meta-creative p {
    color: var(--muted);
    font-size: 12px;
}

.meta-creative p {
    margin: 6px 0;
}

.meta-creative-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.meta-creative-body {
    display: grid;
    gap: 7px;
}

.meta-creative-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 4px;
}

.ad-status {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    border-radius: 999px;
    padding: 5px 10px;
    color: var(--ink);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.ad-status.active {
    background: #d7f3df;
    color: #146c43;
}

.ad-status.paused {
    background: #fff1bf;
    color: #7a5a00;
}

.ad-status.processing {
    background: #dbeafe;
    color: #1d4ed8;
}

.ad-status.danger {
    background: #ffdbe0;
    color: #8a2432;
}

.ad-status.neutral {
    background: #e8eef7;
    color: #46556b;
}

.link-button {
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}

.media-note {
    display: block;
    margin: 6px 0;
    color: #92400e;
    font-size: 12px;
}

.form-actions.soft-actions {
    justify-content: flex-start;
}

.ad-actions {
    max-width: 720px;
    justify-content: center;
}

.ad-actions .btn {
    width: min(100%, 360px);
}

.chart-card {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    padding: 10px;
    color: var(--accent);
}

.chart-card span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 6px;
}

.line-chart {
    display: block;
    width: 100%;
    height: auto;
    color: var(--accent);
}

.mini-spark {
    margin-top: 8px;
    color: var(--accent);
    opacity: .9;
}

.advice {
    margin: 16px 0 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 8px;
}

.advice li {
    border-left: 3px solid var(--accent);
    background: #f0f6ff;
    padding: 9px 11px;
    border-radius: 6px;
}

.help-box {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1e3a8a;
    border-radius: 8px;
    padding: 10px 12px;
    margin: 0 0 14px;
}

.budget-helper {
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 12px;
    background: #eff6ff;
    color: #1e3a8a;
}

.budget-helper strong,
.budget-helper span {
    display: block;
}

.budget-helper.warn {
    border-color: #facc15;
    background: #fefce8;
    color: #713f12;
}

.budget-helper.error {
    border-color: #f5c2c7;
    background: #fff1f2;
    color: #842029;
}

.budget-helper.muted {
    border-color: var(--border);
    background: #f8fafc;
    color: var(--muted);
}

.budget-helper-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.tip-wrap {
    position: relative;
    display: inline-flex;
}

.tip {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: var(--accent);
    display: inline-grid;
    place-items: center;
    padding: 0;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    cursor: help;
}

.tooltip {
    position: absolute;
    z-index: 60;
    left: 0;
    top: calc(100% + 8px);
    width: min(280px, 80vw);
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #111827;
    color: #fff;
    box-shadow: 0 16px 38px rgba(17, 24, 39, 0.24);
    font-size: 12px;
    line-height: 1.35;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity .15s ease, transform .15s ease, visibility .15s ease;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
}

.metric > .tooltip {
    left: 18px;
    top: 42px;
}

.metrics-grid .metric:nth-child(4n) > .tooltip {
    left: auto;
    right: 18px;
}

.detail-metric .tip-wrap .tooltip {
    left: 50%;
    right: auto;
    transform: translate(-50%, -4px);
}

.detail-metric .tip-wrap:hover .tooltip,
.detail-metric .tip-wrap:focus-within .tooltip {
    transform: translate(-50%, 0);
}

.detail-metric:nth-child(3n+1) .tip-wrap .tooltip {
    left: 0;
    right: auto;
    transform: translateY(-4px);
}

.detail-metric:nth-child(3n+1) .tip-wrap:hover .tooltip,
.detail-metric:nth-child(3n+1) .tip-wrap:focus-within .tooltip {
    transform: translateY(0);
}

.detail-metric:nth-child(3n) .tip-wrap .tooltip {
    left: auto;
    right: 0;
    transform: translateY(-4px);
}

.detail-metric:nth-child(3n) .tip-wrap:hover .tooltip,
.detail-metric:nth-child(3n) .tip-wrap:focus-within .tooltip {
    transform: translateY(0);
}

.has-tip:hover .tooltip,
.has-tip:focus-within .tooltip,
.tip-wrap:hover .tooltip,
.tip-wrap:focus-within .tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.tutorial-box {
    border: 1px solid #bfdbfe;
    background: #f8fbff;
    border-radius: 8px;
    padding: 12px 14px;
    color: #1f2937;
}

.tutorial-box strong {
    display: block;
    margin-bottom: 8px;
}

.tutorial-box ol {
    margin: 0;
    padding-left: 20px;
}

.tutorial-box li + li {
    margin-top: 6px;
}

.empty-state {
    min-height: 220px;
    display: grid;
    place-items: center;
    color: var(--muted);
    border: 1px dashed var(--border);
    border-radius: 8px;
}

.log-row, .user-row {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    background: #fff;
}

.log-row strong, .user-row strong { display: block; }
.log-row span, .user-row span { color: var(--muted); font-size: 12px; }

.settings-panel { max-width: 980px; }
.settings-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

label { display: grid; gap: 6px; font-weight: 650; }
.field-help {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.scale-field span {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 58px;
    gap: 10px;
    align-items: center;
}

.scale-field input[type="range"] {
    padding: 0;
    border: 0;
    box-shadow: none;
    accent-color: var(--accent);
}

.scale-field output {
    color: var(--ink);
    font-size: 13px;
    font-weight: 800;
    text-align: right;
    white-space: nowrap;
}

.source-image-state {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 8px 10px;
    background: #eff6ff;
    color: #1e3a8a;
    font-size: 12px;
    font-weight: 700;
}

.source-image-state[hidden] {
    display: none;
}

.video-copy-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-radius: 6px;
    padding: 3px 8px;
    background: #ede9fe;
    color: #5b21b6;
    font-size: 11px;
    font-weight: 700;
}

.meta-pages-list {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.meta-page-option {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
}

.meta-page-option:hover {
    border-color: var(--accent);
    background: #eff6ff;
}

.meta-page-option.selected {
    border-color: var(--accent);
    background: #e8f1ff;
    box-shadow: inset 4px 0 0 var(--accent);
}

.meta-page-option strong,
.meta-page-option span {
    display: block;
}

.meta-page-option span {
    color: var(--muted);
    font-size: 12px;
}
input, select, textarea {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 11px;
    background: #fff;
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    font-weight: 500;
    min-width: 0;
    width: 100%;
}

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, #6b7280 50%), linear-gradient(135deg, #6b7280 50%, transparent 50%);
    background-position: calc(100% - 18px) 52%, calc(100% - 12px) 52%;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 34px;
    line-height: 1.4;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(8,102,255,.14);
}

.wide { grid-column: 1 / -1; }
.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.alert {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 2000;
    width: min(420px, calc(100vw - 36px));
    margin: 0;
    border-radius: 8px;
    padding: 11px 13px;
    border: 1px solid var(--border);
    background: #fff;
    box-shadow: 0 16px 38px rgba(17, 24, 39, 0.18);
}

.alert.success { color: #0f5132; border-color: #badbcc; background: #d1e7dd; }
.alert.error { color: #842029; border-color: #f5c2c7; background: #f8d7da; }

dialog {
    border: 0;
    border-radius: 12px;
    width: min(520px, calc(100vw - 28px));
    padding: 0;
    box-shadow: 0 24px 80px rgba(0,0,0,.25);
}

dialog::backdrop { background: rgba(17,24,39,.45); }
.modal-form { padding: 24px; display: grid; gap: 14px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    cursor: pointer;
    display: grid;
    place-items: center;
    line-height: 1;
}

.creative-split {
    grid-template-columns: minmax(360px, .9fr) minmax(420px, 1.1fr);
    align-items: start;
}

.creative-split > .panel {
    max-height: calc(100vh - 136px);
    overflow: auto;
}

.creative-split > .panel:last-child {
    position: sticky;
    top: 18px;
}

.creative-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
#creativeCanvas {
    width: 100%;
    max-height: 560px;
    object-fit: contain;
    display: block;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #0b1220;
    margin-bottom: 14px;
}

#creativeCanvas.is-editing {
    cursor: grab;
}

#creativeCanvas.is-editing:active {
    cursor: grabbing;
}

#creativeCanvas[hidden] {
    display: none;
}

.library-title {
    margin: 18px 0 0;
    font-size: 18px;
}

.creative-library {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.creative-record {
    display: grid;
    grid-template-columns: 86px 1fr;
    gap: 12px;
    align-items: start;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    background: #fff;
}

.creative-record.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(8, 102, 255, 0.14);
    background: #f8fbff;
}

.creative-record img {
    width: 86px;
    height: 86px;
    object-fit: cover;
    border-radius: 6px;
    background: #111827;
}

.creative-record strong { display: block; }
.creative-record span { color: var(--muted); font-size: 12px; }
.creative-record p { margin: 6px 0 0; color: var(--muted); }
.creative-record .btn { margin-top: 8px; }

.launch-dialog {
    width: min(860px, calc(100vw - 28px));
}

.visual-preview-dialog {
    width: min(1180px, calc(100vw - 28px));
}

.visual-preview-modal {
    padding: 24px;
}

.visual-preview-layout {
    display: grid;
    grid-template-columns: minmax(360px, 1fr) minmax(280px, 360px);
    gap: 18px;
    align-items: start;
    margin-top: 16px;
}

.visual-preview-layout .fb-card {
    max-width: 640px;
}

.visual-preview-layout aside {
    max-height: min(680px, calc(100vh - 180px));
    overflow: auto;
    border-left: 1px solid var(--border);
    padding-left: 16px;
}

.visual-preview-layout h3 {
    margin: 0 0 10px;
}

.modal-library {
    margin-top: 0;
}

.wizard-steps {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
}

.wizard-step {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    padding: 8px;
    color: var(--muted);
    font-weight: 700;
    cursor: pointer;
}

.wizard-step.active {
    border-color: var(--accent);
    background: #eff6ff;
    color: var(--accent);
}

.wizard-panel {
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.wizard-panel.active {
    display: grid;
}

.wizard-block {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    background: #fff;
}

.wizard-block + .wizard-block {
    margin-top: 2px;
}

.wizard-block-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    margin-bottom: 12px;
}

.wizard-block-head strong {
    font-size: 16px;
}

.wizard-block-head span {
    color: var(--muted);
    font-size: 13px;
}

.wizard-mini-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.launch-form .modal-head p {
    margin: 4px 0 0;
    color: var(--muted);
}

.review-box {
    grid-column: 1 / -1;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    background: #fff;
}

.review-box dl {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 8px 12px;
    margin: 12px 0 0;
}

.review-box dt {
    color: var(--muted);
}

.review-box dd {
    margin: 0;
    font-weight: 700;
}

.launch-warnings {
    margin-top: 14px;
    border: 1px solid #facc15;
    border-radius: 8px;
    padding: 12px;
    background: #fefce8;
}

.launch-errors {
    margin-top: 14px;
    border: 1px solid #f5c2c7;
    border-radius: 8px;
    padding: 12px;
    background: #fff1f2;
    color: #842029;
}

.launch-warnings strong,
.launch-errors strong,
.launch-ok {
    display: block;
    font-weight: 800;
}

.launch-warnings ul,
.launch-errors ul {
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 8px;
}

.launch-warnings li b,
.launch-warnings li span {
    display: block;
}

.launch-warnings li span {
    color: #713f12;
    font-size: 13px;
}

.launch-ok {
    margin-top: 14px;
    color: #0f5132;
}

.audience-estimate {
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 10px 12px;
    background: #eff6ff;
    color: #1e3a8a;
}

.audience-estimate strong,
.audience-estimate span,
.audience-estimate small {
    display: block;
}

.audience-estimate small {
    margin-top: 4px;
}

.audience-budget-plans {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 10px 0 4px;
}

.budget-plan {
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: #fff;
    padding: 9px 10px;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.budget-plan:hover {
    border-color: var(--accent);
    background: #f8fbff;
}

.budget-plan span {
    color: var(--accent-strong);
    font-size: 18px;
    font-weight: 800;
}

.budget-plan small {
    color: var(--muted);
    font-size: 11px;
}

.audience-estimate.muted {
    color: var(--muted);
    background: #f8fafc;
    border-color: var(--border);
}

.inline-field {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.inline-field.three {
    grid-template-columns: minmax(0, 1fr) auto auto;
}

.launch-map {
    height: 280px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #eef2f7;
}

.selected-location {
    color: var(--muted);
    font-size: 13px;
}

.location-results {
    display: grid;
    gap: 6px;
}

.location-result {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    padding: 9px 10px;
    text-align: left;
    cursor: pointer;
}

.location-result:hover {
    border-color: var(--accent);
    background: #eff6ff;
}

.fb-card {
    max-width: 520px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}

.fb-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
}

.fb-avatar,
.fb-avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.fb-avatar {
    display: grid;
    place-items: center;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
}

.fb-avatar-img {
    object-fit: cover;
    border: 1px solid var(--border);
    background: #fff;
}

.fb-header strong,
.fb-header span {
    display: block;
}

.fb-header span,
.fb-link span,
.fb-actions {
    color: var(--muted);
    font-size: 12px;
}

.fb-message {
    padding: 0 12px 10px;
    margin: 0;
    color: #111827;
}

.fb-image {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    background: #0b1220;
}

.fb-link {
    display: grid;
    gap: 3px;
    padding: 10px 12px;
    background: #f3f4f6;
}

.fb-link strong {
    font-size: 16px;
}

.fb-link em {
    justify-self: start;
    margin-top: 4px;
    padding: 6px 10px;
    border-radius: 6px;
    background: #e5e7eb;
    font-style: normal;
    font-weight: 700;
}

.fb-actions {
    display: flex;
    justify-content: space-around;
    border-top: 1px solid var(--border);
    padding: 9px 12px;
    font-weight: 700;
}

@media (max-width: 900px) {
    .sidebar { position: static; width: 100%; height: auto; }
    .app-shell { display: block; }
    .main { margin-left: 0; }
    .topbar { align-items: flex-start; flex-direction: column; padding: 18px; }
    .content { padding: 18px; }
    .metrics-grid, .split, .form-grid, .creative-form, .charts-grid, .wizard-panel, .audience-budget-plans { grid-template-columns: 1fr; }
    .campaign-tabs { grid-template-columns: 1fr; }
    .creative-split > .panel {
        max-height: none;
        overflow: visible;
    }
    .creative-split > .panel:last-child {
        position: static;
    }
    .wizard-steps { grid-template-columns: 1fr; }
    .inline-field { grid-template-columns: 1fr; }
    .wizard-mini-grid { grid-template-columns: 1fr 1fr; }
    .wizard-block-head { display: grid; }
    .visual-preview-layout { grid-template-columns: 1fr; }
    .visual-preview-layout aside {
        border-left: 0;
        border-top: 1px solid var(--border);
        padding-left: 0;
        padding-top: 14px;
        max-height: none;
    }
    .detail-grid { grid-template-columns: 1fr 1fr; }
    .detail-metric .tip-wrap .tooltip {
        left: 0;
        right: auto;
        transform: translateY(-4px);
    }
    .detail-metric .tip-wrap:hover .tooltip,
    .detail-metric .tip-wrap:focus-within .tooltip {
        transform: translateY(0);
    }
    .detail-metric:nth-child(2n) .tip-wrap .tooltip {
        left: auto;
        right: 0;
    }
}

@media (max-width: 560px) {
    .detail-grid { grid-template-columns: 1fr; }
    .wizard-mini-grid { grid-template-columns: 1fr; }
    .detail-metric:nth-child(n) .tip-wrap .tooltip {
        left: 0;
        right: auto;
    }
    .row-actions .btn { flex: 1 1 84px; }
}

/* --- ecran de connexion --- */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; max-width: 430px; display: grid; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-error { color: var(--error); margin: 0; }
