:root {
    color-scheme: light;
    --ink: #34464d;
    --ink-strong: #2a3a40;
    --muted: #718087;
    --line: #d8e2e3;
    --surface: #fff;
    --soft: #f3f7f6;
    --accent: #527f7d;
    --accent-hover: #416b69;
    --accent-soft: #e9f2f1;
    --success: #54745f;
    --success-bg: #eef6f0;
    --error: #8d6269;
    --error-bg: #faf2f3;
    --status: #5d7378;
    --code: #485c63;
    --input: #fff;
    --table-head: #f5f8f8;
    --row-hover: #f8fbfa;
    --topbar: rgba(255,255,255,.98);
    --shadow: 0 14px 35px rgba(47,69,75,.08);
    --chart-accent: #527f7d;
    --chart-secondary: #7f8fb0;
    --chart-danger: #b57b84;
    --chart-success: #6f997b;
    --chart-grid: #e3e9ea;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --ink: #d5def0;
    --ink-strong: #f4f7ff;
    --muted: #8c9ab6;
    --line: #24324d;
    --surface: #0d1627;
    --soft: #050b16;
    --accent: #4e8cff;
    --accent-hover: #75a7ff;
    --accent-soft: #152747;
    --success: #78c99b;
    --success-bg: #112a24;
    --error: #e89ba8;
    --error-bg: #311b25;
    --status: #111d32;
    --code: #09111f;
    --input: #101b2d;
    --table-head: #121e32;
    --row-hover: #111d30;
    --topbar: rgba(8,15,28,.98);
    --chart-accent: #5e96ff;
    --chart-secondary: #8d9fc5;
    --chart-danger: #d88998;
    --chart-success: #78c99b;
    --chart-grid: #24324d;
    --shadow: 0 18px 50px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--soft); color: var(--ink); font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 1.45; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
a { color: inherit; }
code, pre { font-family: Consolas, "Courier New", monospace; }

.admin-login-page { min-height: 100vh; display: grid; place-items: center; background: var(--soft); }
.login-shell { width: 100%; padding: 24px; }
.login-panel { width: min(100%, 400px); margin: 0 auto; padding: 34px; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: 6px; box-shadow: var(--shadow); }
.login-copy { margin: 18px 0 0; color: var(--muted); }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; background: var(--accent); color: #fff; border-radius: 4px; font-size: 21px; font-weight: 700; }
.brand-mark.small { width: 30px; height: 30px; font-size: 16px; }
.eyebrow { margin: 15px 0 4px; color: var(--accent); font-size: 11px; font-weight: 700; text-transform: uppercase; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: 0; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
.login-form, .stack-form { display: grid; gap: 14px; margin-top: 24px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
input, select, textarea { min-width: 0; width: 100%; padding: 9px 10px; color: var(--ink); background: var(--input); border: 1px solid var(--line); border-radius: 4px; outline: none; }
input, select { height: 40px; }
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(82,127,125,.13); }
input[readonly] { color: #647279; background: #f4f7f7; }

.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; padding: 8px 14px; border: 1px solid transparent; border-radius: 4px; cursor: pointer; font-weight: 700; text-decoration: none; white-space: nowrap; }
.button-primary { color: #fff; background: var(--accent); }
.button-primary:hover { background: var(--accent-hover); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-secondary { color: var(--ink); background: var(--surface); border-color: var(--line); }
.button-secondary:hover, .button-quiet:hover { border-color: #91aaa9; background: var(--accent-soft); }
.button-quiet { color: #526168; background: transparent; border-color: var(--line); }
.text-button { padding: 0; color: #567573; background: none; border: 0; cursor: pointer; text-decoration: underline; }
.text-button.danger { color: var(--error); }
.store-search-switch-form { display: flex; align-items: center; }
.admin-switch { display: inline-flex; grid-template-columns: none; align-items: center; gap: 7px; color: var(--muted); cursor: pointer; font-size: 11px; }
.admin-switch > input { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; opacity: 0; pointer-events: none; }
.admin-switch__track { position: relative; width: 38px; height: 22px; flex: 0 0 38px; border: 1px solid var(--line); border-radius: 11px; background: #aab6ba; transition: background .16s ease, border-color .16s ease; }
.admin-switch__track span { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(25,42,48,.25); transition: transform .16s ease; }
.admin-switch > input:checked + .admin-switch__track { border-color: var(--success); background: var(--success); }
.admin-switch > input:checked + .admin-switch__track span { transform: translateX(16px); }
.admin-switch > input:focus-visible + .admin-switch__track { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.admin-switch__text { min-width: 25px; color: var(--ink); }
.admin-icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--muted); cursor: pointer; }
.admin-icon-button:hover { border-color: currentColor; background: var(--error-bg); }
.admin-icon-button--danger { color: var(--error); }
.admin-icon-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.notice { margin: 14px 0; padding: 11px 13px; border: 1px solid; border-radius: 4px; }
.notice-error { color: var(--error); background: var(--error-bg); border-color: #dfc6ca; }
.notice-success { color: var(--success); background: var(--success-bg); border-color: #c7ddcc; }
.notice-warning { color: #76520a; background: #fff7dc; border-color: #e8cd78; }
.feed-change-warning strong { display: block; margin-bottom: 6px; }
.feed-change-warning p { margin: 5px 0 10px; }
.feed-change-warning form { margin-top: 12px; }

.topbar { position: sticky; top: 0; z-index: 10; background: var(--topbar); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1370px; min-height: 60px; margin: 0 auto; padding: 9px 24px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; }
.store-identity { display: grid; text-align: left; white-space: nowrap; }
.store-identity span { color: var(--muted); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.topbar-actions form { margin: 0; }
.theme-toggle { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 11px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; cursor: pointer; font: inherit; font-weight: 700; }
.theme-toggle:hover { color: var(--ink-strong); border-color: var(--accent); }
.theme-toggle-icon { position: relative; width: 17px; height: 17px; flex: 0 0 17px; border: 1.5px solid currentColor; border-radius: 50%; }
.theme-toggle-icon::after { position: absolute; inset: 3px; border-radius: 50%; background: currentColor; content: ''; }
html[data-theme="dark"] .theme-toggle-icon::after { inset: -2px -3px 3px 5px; background: var(--surface); }
.theme-toggle-login { position: fixed; z-index: 2; top: 18px; right: 18px; }

.dashboard { max-width: 1370px; margin: 0 auto; padding: 20px 24px 64px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding-bottom: 20px; }
.page-heading .eyebrow, .section-heading .eyebrow { margin-top: 0; }
.section-nav { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px 16px; }
.section-nav a { color: #627279; text-decoration: none; border-bottom: 1px solid transparent; }
.section-nav a:hover { color: var(--accent-hover); border-color: var(--accent); }
.section-nav a.active { color: var(--ink-strong); background: var(--accent-soft); }
.admin-menu-toggle, .admin-menu-backdrop { display: none; }
.admin-menu-heading { display: none; }
.admin-page-section { min-height: calc(100vh - 104px); border-top: 0; }
.compact-heading { margin-top: 28px; margin-bottom: 0; padding-top: 22px; border-top: 1px solid var(--line); }
.compact-form { margin-top: 14px; }
.feed-notification-note { margin: 0 0 14px; }
.feed-notification-grid { display: grid; grid-template-columns: repeat(2,minmax(220px,1fr)); gap: 10px; }
.feed-notification-card { min-width: 0; margin: 0; padding: 14px; display: grid; align-content: start; gap: 11px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
.feed-notification-card legend { padding: 0 6px; color: var(--ink-strong); font-weight: 700; }
.feed-notification-card p { margin: -3px 0 0; color: var(--muted); font-size: 11px; }
.feed-notification-card .toggle-label { height: auto; align-items: flex-start; font-size: 12px; }
.feed-source-field { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: end; gap: 9px; }
.feed-source-field label { min-width: 0; }
.feed-source-field .button { min-width: 142px; }
.feed-update-status { min-height: 20px; margin: -3px 0 0; color: var(--muted); font-size: 12px; }
.feed-update-status.is-success { color: var(--success); }
.feed-update-status.is-error { color: var(--error); }
.max-settings-layout { display: grid; grid-template-columns: minmax(0,1.15fr) minmax(300px,.85fr); gap: 18px; align-items: start; }
.max-settings-form, .max-instructions { padding: 19px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); }
.max-settings-form { margin-top: 0; }
.max-settings-form label small { color: var(--muted); font-weight: 400; }
.max-event-list { min-width: 0; margin: 2px 0; padding: 14px; display: grid; gap: 11px; border: 1px solid var(--line); border-radius: 5px; }
.max-event-list legend { padding: 0 6px; color: var(--ink-strong); font-weight: 700; }
.max-event-list label { grid-template-columns: 18px minmax(0,1fr); align-items: start; gap: 9px; }
.max-event-list input, .max-settings-form .toggle-label input { width: 16px; height: 16px; margin: 1px 0 0; }
.max-event-list span { display: grid; gap: 2px; }
.max-event-list strong { color: var(--ink-strong); }
.max-event-list small { color: var(--muted); font-weight: 400; }
.max-clear-token { color: var(--error); }
.max-instructions h3 { margin-bottom: 13px; }
.max-instructions ol { margin: 0; padding-left: 21px; display: grid; gap: 10px; }
.max-instructions li { padding-left: 3px; }
.max-instructions code { overflow-wrap: anywhere; }
.max-test-form { margin-top: 18px; }
.max-instructions .field-note { margin: 15px 0 0; }
.max-bot-state { margin: 15px 0 0; padding: 11px; background: var(--accent-soft); border-radius: 4px; }
.max-invite-result { margin: 18px 0; padding: 15px; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: end; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 5px; }
.max-users-table { margin-top: 18px; }
.muted-text { color: var(--muted); }

.section-block { padding: 27px 0 34px; border-top: 1px solid var(--line); scroll-margin-top: 68px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 17px; }
.section-copy { max-width: 700px; color: var(--muted); }
.period-form { display: grid; grid-template-columns: 140px 140px auto; align-items: end; gap: 9px; }
.period-presets { grid-column: 1/-1; display: flex; justify-content: flex-end; gap: 12px; }
.period-presets a { color: var(--accent); font-size: 11px; text-decoration: none; }
.period-presets a:hover { color: var(--accent-hover); text-decoration: underline; }
.metrics { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 10px; }
.metrics-wide { grid-template-columns: repeat(6,minmax(0,1fr)); }
.analytics-metrics { grid-template-columns: repeat(4,minmax(0,1fr)); }
.metric { min-height: 105px; padding: 16px; display: flex; flex-direction: column; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-radius: 5px; }
.metric span, .status-strip span { color: var(--muted); font-size: 12px; }
.metric strong { color: var(--ink-strong); font-size: 25px; line-height: 1; overflow-wrap: anywhere; }
.metric small { color: var(--muted); }
.metric-change { font-variant-numeric: tabular-nums; }
.metric-change.is-up { color: var(--success); }
.metric-change.is-down { color: var(--error); }
.metric-change.is-flat { color: var(--muted); }
.metric-change-inverse.is-up { color: var(--error); }
.metric-change-inverse.is-down { color: var(--success); }
.comparison-note { margin: 9px 0 0; color: var(--muted); font-size: 11px; text-align: right; }
.chart-grid { margin-top: 18px; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.chart-panel { min-width: 0; padding: 17px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); }
.chart-panel-wide { grid-column: 1/-1; }
.chart-heading { min-height: 44px; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.chart-heading > div:first-child { display: grid; gap: 2px; }
.chart-heading span { color: var(--muted); font-size: 11px; }
.chart-heading strong { color: var(--ink-strong); font-size: 15px; }
.chart-total { color: var(--ink-strong); font-size: 19px; font-weight: 700; }
.chart-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px 12px; color: var(--muted); font-size: 10px; }
.chart-legend i { width: 8px; height: 8px; margin-top: 2px; border-radius: 50%; background: var(--chart-accent); }
.chart-legend i.is-secondary { background: var(--chart-secondary); }
.chart-legend i.is-danger { background: var(--chart-danger); }
.chart-legend i.is-success { background: var(--chart-success); }
.admin-chart { position: relative; width: 100%; height: 230px; margin-top: 8px; overflow: hidden; }
.admin-chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.admin-chart .chart-grid-line { stroke: var(--chart-grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.admin-chart .chart-axis-label { fill: var(--muted); font-size: 10px; }
.admin-chart .chart-line { fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.admin-chart .chart-point { stroke: var(--surface); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.admin-chart .chart-bar { fill: var(--chart-accent); opacity: .82; }
.admin-chart .chart-empty { color: var(--muted); display: grid; height: 100%; place-items: center; font-size: 12px; }
.period-report { margin-top: 12px; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); }
.period-report-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 15px; border-bottom: 1px solid var(--line); }
.period-report-heading h3 { margin: 2px 0 0; font-size: 19px; }
.period-report-heading > span { color: var(--muted); font-size: 12px; }
.period-report-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 24px 34px; padding-top: 18px; }
.period-report h4 { margin: 0 0 11px; color: var(--ink-strong); font-size: 13px; }
.report-summary dl { margin: 0; display: grid; gap: 1px; }
.report-summary dl > div { padding: 7px 0; display: flex; align-items: baseline; justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--line); }
.report-summary dt { color: var(--muted); }
.report-summary dd { margin: 0; color: var(--ink-strong); font-weight: 700; text-align: right; }
.report-summary dd small { margin-left: 6px; font-weight: 600; }
.report-ranking ol { margin: 0; padding: 0; list-style: none; counter-reset: report-row; }
.report-ranking li { min-width: 0; padding: 7px 0; display: grid; grid-template-columns: 22px minmax(0,1fr) auto; gap: 8px; border-bottom: 1px solid var(--line); counter-increment: report-row; }
.report-ranking li::before { color: var(--muted); content: counter(report-row) '.'; }
.report-ranking li span { min-width: 0; overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
.report-ranking li strong { color: var(--ink-strong); font-variant-numeric: tabular-nums; }
.report-ranking li.empty { display: block; padding: 18px 0; text-align: left; }
.report-ranking li.empty::before { display: none; }
.report-ranking-zero { border-left: 2px solid var(--chart-danger); padding-left: 14px; }
.status-strip { margin-top: 10px; display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); background: var(--status); border-radius: 5px; overflow: hidden; }
.status-strip div { min-width: 0; padding: 14px 15px; display: grid; gap: 4px; border-right: 1px solid rgba(255,255,255,.18); }
.status-strip div:last-child { border: 0; }
.status-strip span { color: #d9e5e5; }
.status-strip strong { overflow-wrap: anywhere; color: #fff; font-size: 13px; }
.alert-list { margin-top: 10px; border: 1px solid #dfc6ca; background: var(--error-bg); }
.alert-list div { padding: 10px 12px; display: grid; grid-template-columns: 90px 1fr auto; gap: 12px; border-bottom: 1px solid #ead9dc; }
.alert-list div:last-child { border: 0; }
.alert-list time { color: var(--muted); font-size: 12px; }

.split-section { display: grid; grid-template-columns: minmax(0,1.5fr) minmax(300px,1fr); gap: 44px; }
.split-section > div { min-width: 0; }
.stack-form { margin-top: 0; }
.narrow-form { max-width: 480px; }
.field-note { margin: -3px 0 0; color: var(--muted); font-size: 12px; }
.form-footer { margin-top: 14px; }
.inline-editor { margin-bottom: 16px; display: grid; align-items: end; gap: 10px; }
.rule-editor { grid-template-columns: 1fr 1fr 1.5fr 90px auto; }
.boost-editor { grid-template-columns: 1.2fr 1fr 1fr 100px 90px auto; }
.rewrite-editor { grid-template-columns: minmax(280px,1.5fr) minmax(220px,1fr) 90px auto; }
.query-url-rule-editor, .query-url-rule-heading { grid-template-columns: minmax(280px,1.5fr) minmax(220px,1fr) minmax(150px,.65fr) 90px auto; }
.query-url-rule-heading { display: grid; gap: 10px; padding: 0 12px 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.query-url-rule-mode { justify-content: center; }
.query-url-rule-mobile-label { display: none; }
.rewrite-note { margin: 0 0 14px; }
.rewrite-list { display: grid; gap: 8px; margin-bottom: 18px; }
.rewrite-editor--saved { margin: 0; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; }
.rewrite-import { display: grid; grid-template-columns: minmax(300px,1.5fr) minmax(220px,1fr) auto; align-items: end; gap: 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.toggle-label { display: flex; align-items: center; gap: 7px; height: 40px; }
.toggle-label input { width: 17px; height: 17px; margin: 0; }
.query-notice-toggle { display: inline-flex; min-height: 28px; align-items: center; gap: 7px; cursor: pointer; }
.query-notice-toggle input { width: 17px; height: 17px; margin: 0; cursor: pointer; }
.query-notice-toggle input:disabled { cursor: wait; opacity: .65; }
.query-notice-toggle span { min-width: 28px; color: var(--muted); font-size: 12px; }
.query-notice-toggle.is-error span { color: var(--error); }
.editor-actions, .row-actions, .brand-footer { display: flex; align-items: center; gap: 11px; }
.editor-actions { align-self: end; }
.row-actions form { margin: 0; }

.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.subheading { min-height: 30px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.subheading a { color: var(--accent); font-size: 12px; }
.top-products-heading { margin-top: 22px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #e9eaec; vertical-align: top; }
th { color: var(--muted); background: var(--table-head); font-size: 11px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--row-hover); }
.query-cell { max-width: 420px; color: var(--ink-strong); font-weight: 700; overflow-wrap: anywhere; }
.empty { padding: 25px; color: var(--muted); text-align: center; }
.danger-table { border-left: 3px solid #c999a0; }
.action-cell { width: 1%; white-space: nowrap; }
.brand-table { max-height: 620px; overflow-y: auto; }
.compact-input { width: 90px; }
.brand-add-form { max-width: 720px; margin-bottom: 9px; display: grid; grid-template-columns: minmax(220px,1fr) 180px auto; align-items: end; gap: 10px; }
.brand-note { margin: 0 0 14px; }
.order-column { width: 112px; }
.brand-order-cell { display: flex; align-items: center; gap: 10px; }
.drag-handle { width: 32px; height: 32px; display: grid; place-items: center; padding: 0; color: #6b8584; background: var(--accent-soft); border: 1px solid #cbdcda; border-radius: 4px; cursor: grab; font-size: 19px; line-height: 1; touch-action: none; }
.drag-handle:hover, .drag-handle:focus { color: var(--accent-hover); border-color: #91aaa9; outline: none; }
.drag-handle:active { cursor: grabbing; }
.brand-position { min-width: 24px; color: var(--muted); font-variant-numeric: tabular-nums; }
.brand-name-input { min-width: 240px; height: 36px; }
.brand-row.is-dragging { opacity: .55; background: var(--accent-soft); }
.brand-row.is-dragging td { border-color: #bfd3d1; }
.brand-footer { margin-top: 14px; }
.brand-order-status { color: var(--muted); font-size: 12px; }
.hidden-form { display: none; }

.portfolio-topbar { grid-template-columns: auto 1fr auto; }
.portfolio-section h1 { font-size: 25px; }
.portfolio-alerts-section h1 { font-size: 25px; }
.portfolio-alert-list { display: grid; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; background: var(--surface); box-shadow: var(--shadow); }
.portfolio-alert-item { min-width: 0; padding: 12px 14px; display: grid; grid-template-columns: minmax(180px,.7fr) minmax(260px,1.8fr) auto auto; align-items: center; gap: 14px; border-bottom: 1px solid var(--line); border-left: 3px solid var(--error); }
.portfolio-alert-item:last-child { border-bottom: 0; }
.portfolio-alert-item.is-warning { border-left-color: #d2a527; }
.portfolio-alert-item > div { min-width: 0; display: grid; gap: 2px; }
.portfolio-alert-item strong, .portfolio-alert-item span { overflow-wrap: anywhere; }
.portfolio-alert-item small, .portfolio-alert-item time { color: var(--muted); font-size: 12px; }
.portfolio-alert-item .button { white-space: nowrap; }
.portfolio-managed-note { margin: 12px 0 0; }
.portfolio-summary { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); margin-bottom: 14px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); overflow: hidden; box-shadow: var(--shadow); }
.portfolio-summary div { min-width: 0; padding: 15px; display: grid; gap: 4px; border-right: 1px solid var(--line); }
.portfolio-summary div:last-child { border-right: 0; }
.portfolio-summary span { color: var(--muted); font-size: 11px; }
.portfolio-summary strong { color: var(--ink-strong); font-size: 21px; overflow-wrap: anywhere; }
.portfolio-table td > strong, .portfolio-table td > small { display: block; }
.portfolio-table td > small { max-width: 330px; margin-top: 3px; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.portfolio-actions { align-items: center; }
.status-badge { display: inline-flex; min-height: 25px; align-items: center; padding: 3px 8px; border: 1px solid; border-radius: 3px; font-size: 11px; font-weight: 700; }
.status-badge.is-ok { color: var(--success); border-color: #c7ddcc; background: var(--success-bg); }
.status-badge.is-error { color: var(--error); border-color: #dfc6ca; background: var(--error-bg); }
.status-badge.is-warning { color: #80600a; border-color: #e4d39e; background: #fff8df; }
.onboarding-result { display: grid; gap: 5px; }
.onboarding-result span, .onboarding-result small { display: block; }
.onboarding-result code { overflow-wrap: anywhere; }
.store-onboarding-form { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.store-onboarding-form fieldset { min-width: 0; margin: 0; padding: 18px; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); align-content: start; gap: 12px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
.store-onboarding-form legend { padding: 0 7px; color: var(--ink-strong); font-size: 14px; font-weight: 700; }
.store-onboarding-form textarea { min-height: 40px; }
.store-onboarding-footer { grid-column: 1/-1; display: flex; align-items: center; justify-content: space-between; gap: 20px; }

pre { max-height: 420px; overflow: auto; margin: 16px 0 0; padding: 15px; color: #edf3f3; background: var(--code); border: 1px solid #60747a; border-radius: 4px; font-size: 12px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.audit-list { max-height: 430px; overflow: auto; border-top: 1px solid var(--line); }
.audit-list > div { padding: 10px 0; display: grid; grid-template-columns: 160px 1fr auto; gap: 12px; border-bottom: 1px solid var(--line); }
.audit-list span { color: var(--muted); overflow-wrap: anywhere; }
.audit-list time { color: var(--muted); font-size: 11px; white-space: nowrap; }

html[data-theme="dark"] .metric,
html[data-theme="dark"] .login-panel,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .portfolio-alert-list,
html[data-theme="dark"] .portfolio-summary,
html[data-theme="dark"] .store-onboarding-form fieldset { box-shadow: var(--shadow); }
html[data-theme="dark"] th,
html[data-theme="dark"] td { border-color: var(--line); }
html[data-theme="dark"] input[readonly] { color: var(--muted); background: #0a1322; }
html[data-theme="dark"] .button-quiet { color: var(--muted); }
html[data-theme="dark"] .notice-success { border-color: #285442; }
html[data-theme="dark"] .notice-error,
html[data-theme="dark"] .alert-list { border-color: #633343; }
html[data-theme="dark"] .status-strip { border: 1px solid var(--line); }
html[data-theme="dark"] .status-badge.is-warning { color: #f0d783; border-color: #6d5c28; background: #2b2616; }

@media (min-width: 1121px) {
    .topbar { position: fixed; inset: 16px auto 16px 16px; width: 224px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
    .topbar-inner { width: 100%; min-height: 100%; padding: 18px; display: flex; flex-direction: column; align-items: stretch; gap: 20px; }
    .brand, .store-identity { padding-bottom: 17px; border-bottom: 1px solid var(--line); }
    .section-nav { display: flex; flex: 1 1 auto; flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; gap: 3px; }
    .section-nav a { padding: 8px 9px; border: 0; border-radius: 4px; }
    .section-nav a:hover, .section-nav a:focus-visible { color: var(--ink-strong); background: var(--accent-soft); outline: none; }
    .topbar-actions { margin-top: auto; align-items: stretch; flex-direction: column; }
    .topbar-actions .theme-toggle, .topbar-actions form, .topbar-actions .button { width: 100%; }
    .dashboard { width: calc(100% - 272px); max-width: 1370px; margin: 0 0 0 256px; padding: 20px 24px 64px; }
}

.admin-embed-page #security { grid-template-columns: 1fr; }
.embed-status { margin-top: 18px; padding: 14px; display: grid; gap: 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.embed-status span { color: var(--muted); }
.embed-status.is-ready { border-left: 3px solid var(--success); }
.embed-status.is-disabled { border-left: 3px solid var(--error); }
.origin-list { display: flex; flex-wrap: wrap; gap: 8px; }
.origin-list code { padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); }

.category-brand-settings { margin-top: 34px; padding-top: 30px; border-top: 1px solid var(--line); }
.category-brand-heading { margin-bottom: 8px; }
.category-brand-strategy { margin: 20px 0 24px; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.strategy-option { position: relative; display: block; cursor: pointer; }
.strategy-option input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.strategy-option span { min-height: 92px; padding: 15px 16px; display: grid; align-content: start; gap: 5px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); transition: border-color .16s ease, background-color .16s ease; }
.strategy-option strong { color: var(--ink-strong); font-size: 14px; }
.strategy-option small { color: var(--muted); line-height: 1.45; }
.strategy-option input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.strategy-option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.category-brand-strategy-status { grid-column: 1/-1; min-height: 20px; }
.category-brand-rules-layout { display: grid; gap: 24px; }
.category-brand-groups-table table { min-width: 920px; table-layout: fixed; }
.category-brand-groups-table th:first-child { width: 132px; }
.category-brand-groups-table th:nth-child(2) { width: 100px; }
.category-brand-groups-table th:nth-child(3) { width: 42%; }
.category-brand-groups-table tr.is-active td { background: var(--accent-soft); }
.category-brand-rule-open { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 750; cursor: pointer; }
.category-brand-rule-open:hover { text-decoration: underline; }
.category-brand-summary { color: var(--ink); font-size: 13px; line-height: 1.5; vertical-align: top; }
.category-brand-group-editor { padding-top: 22px; border-top: 1px solid var(--line); scroll-margin-top: 90px; }
.category-brand-group-heading { margin-bottom: 12px; display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.category-brand-group-heading h3 { margin: 2px 0 0; color: var(--ink-strong); font-size: 20px; }
.category-brand-group-heading > span { color: var(--muted); font-size: 13px; }
.category-brand-meta-fields { margin-bottom: 16px; display: grid; grid-template-columns: minmax(240px,1fr) minmax(170px,220px); gap: 12px; }
.category-brand-meta-fields label { display: grid; gap: 7px; color: var(--ink); font-size: 13px; font-weight: 700; }
.category-brand-meta-fields input { width: 100%; }
.category-brand-category-tags { margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.category-brand-category-tag { min-height: 32px; padding: 5px 5px 5px 9px; display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-muted); color: var(--ink); font-size: 12px; }
.category-brand-category-tag button { width: 24px; height: 24px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 19px; line-height: 1; cursor: pointer; }
.category-brand-category-tag button:hover { color: var(--error); }
.category-brand-category-add { margin-bottom: 16px; display: grid; grid-template-columns: minmax(260px,560px) auto; justify-content: start; gap: 8px; }
.category-brand-category-add select { width: 100%; }
.category-brand-table { max-height: 520px; overflow: auto; }
.category-brand-table table { min-width: 520px; }
.category-brand-row.is-dragging { opacity: .55; }
.category-brand-remove { width: 30px; height: 30px; border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.category-brand-remove:hover { color: var(--error); }
.category-brand-add { margin-top: 12px; display: grid; grid-template-columns: minmax(220px,420px) auto; justify-content: start; gap: 8px; }
.category-brand-add select { width: 100%; }

@media (max-width: 820px) {
    .category-brand-strategy { grid-template-columns: 1fr; }
    .category-brand-meta-fields { grid-template-columns: 1fr; }
    .category-brand-category-add { grid-template-columns: 1fr; }
    .category-brand-category-add .button { width: 100%; }
    .category-brand-add { grid-template-columns: 1fr; }
    .category-brand-add .button { width: 100%; }
}

@media (max-width: 1120px) {
    .topbar-inner { grid-template-columns: auto auto; gap: 10px 18px; }
    .topbar-inner .section-nav { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
    .metrics-wide { grid-template-columns: repeat(3,minmax(0,1fr)); }
    .analytics-metrics { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .rule-editor, .boost-editor, .rewrite-editor, .query-url-rule-editor, .rewrite-import { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .query-url-rule-heading { display: none; }
    .query-url-rule-mobile-label { display: inline; }
    .query-url-rule-mode { justify-content: flex-start; }
    .inline-editor .button { align-self: end; }
    .portfolio-summary { grid-template-columns: repeat(3,minmax(0,1fr)); }

    html.admin-menu-open, body.admin-menu-open { overflow: hidden; }
    .topbar { z-index: 40; }
    .topbar-inner { grid-template-columns: minmax(0,1fr) auto auto; }
    .admin-menu-toggle { min-height: 38px; display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink-strong); cursor: pointer; font: inherit; }
    .admin-menu-toggle span, .admin-menu-toggle span::before, .admin-menu-toggle span::after { width: 17px; height: 2px; display: block; border-radius: 2px; background: currentColor; content: ''; }
    .admin-menu-toggle span { position: relative; }
    .admin-menu-toggle span::before { position: absolute; top: -6px; left: 0; }
    .admin-menu-toggle span::after { position: absolute; top: 6px; left: 0; }
    .admin-menu-toggle b { font-size: 12px; }
    .topbar-inner .section-nav { position: fixed; z-index: 42; top: 0; bottom: 0; left: 0; width: min(320px,86vw); padding: max(24px,env(safe-area-inset-top)) 16px 24px; display: flex; grid-column: auto; grid-row: auto; flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; gap: 3px; overflow-x: hidden; overflow-y: auto; background: var(--surface); box-shadow: 18px 0 45px rgba(20,35,42,.18); transform: translateX(-105%); transition: transform .22s ease; }
    .topbar-inner .section-nav.is-open { transform: translateX(0); }
    .admin-menu-heading { margin-bottom: 10px; padding: 0 4px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
    .admin-menu-heading strong { color: var(--ink-strong); font-size: 16px; }
    .admin-menu-heading button { position: relative; width: 34px; height: 34px; padding: 0; border: 0; background: transparent; color: var(--ink); cursor: pointer; }
    .admin-menu-heading button::before, .admin-menu-heading button::after { position: absolute; top: 16px; left: 7px; width: 20px; height: 2px; border-radius: 2px; background: currentColor; content: ''; }
    .admin-menu-heading button::before { transform: rotate(45deg); }
    .admin-menu-heading button::after { transform: rotate(-45deg); }
    .topbar-inner .section-nav a { padding: 11px 12px; border: 0; border-radius: 4px; color: var(--ink); font-weight: 700; }
    .admin-menu-backdrop { position: fixed; z-index: 39; inset: 0; display: block; padding: 0; border: 0; background: rgba(19,31,38,.42); }
    .admin-menu-backdrop[hidden] { display: none; }
}

@media (max-width: 820px) {
    .section-heading { align-items: flex-start; flex-direction: column; }
    .portfolio-alert-item { grid-template-columns: 1fr; gap: 7px; }
    .portfolio-alert-item .button { justify-self: start; }
    .section-nav { justify-content: flex-start; }
    .split-section, .analytics-grid { grid-template-columns: 1fr; gap: 28px; }
    .metrics-wide { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .chart-grid, .period-report-grid { grid-template-columns: 1fr; }
    .chart-panel-wide { grid-column: auto; }
    .status-strip { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .status-strip div { border-bottom: 1px solid rgba(255,255,255,.18); }
    .store-onboarding-form { grid-template-columns: 1fr; }
    .feed-notification-grid { grid-template-columns: 1fr; }
    .max-settings-layout { grid-template-columns: 1fr; }
    .max-invite-result { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
    .topbar-inner { grid-template-columns: minmax(0,1fr) auto auto; gap: 8px; padding-inline: 15px; }
    .store-identity { display: grid; }
    .admin-menu-toggle { grid-column: 2; grid-row: 1; }
    .admin-menu-toggle b { display: none; }
    .topbar-actions { grid-column: 3; grid-row: 1; gap: 5px; }
    .topbar-actions [data-theme-label] { display: none; }
    .topbar-actions .theme-toggle { width: 38px; padding: 8px; }
    .topbar-actions .button { padding-inline: 9px; }
    .dashboard { padding: 22px 15px 48px; }
    .metrics-wide, .analytics-metrics, .status-strip, .rule-editor, .boost-editor, .rewrite-editor, .query-url-rule-editor, .rewrite-import, .brand-add-form { grid-template-columns: 1fr; }
    .chart-heading, .period-report-heading { align-items: flex-start; flex-direction: column; }
    .chart-legend { justify-content: flex-start; }
    .admin-chart { height: 205px; }
    .period-report { padding: 16px; }
    .report-summary dl > div { align-items: flex-start; flex-direction: column; gap: 3px; }
    .report-summary dd { text-align: left; }
    .metric { min-height: 90px; }
    .period-form { width: 100%; grid-template-columns: 1fr 1fr; }
    .period-form .button { grid-column: 1/-1; }
    .login-panel { padding: 27px 21px; }
    .alert-list div, .audit-list > div { grid-template-columns: 1fr; gap: 3px; }
    .row-actions { align-items: flex-start; flex-direction: column; }
    .brand-name-input { min-width: 180px; }
    .feed-source-field { grid-template-columns: 1fr; }
    .feed-source-field .button { width: 100%; }
    th, td { padding: 9px 10px; }
    .portfolio-summary, .store-onboarding-form fieldset { grid-template-columns: 1fr; }
    .portfolio-summary div { border-right: 0; border-bottom: 1px solid var(--line); }
    .portfolio-summary div:last-child { border-bottom: 0; }
    .store-onboarding-footer { align-items: stretch; flex-direction: column; }
}
