:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #17202a;
    --muted: #667085;
    --line: #d9dee7;
    --primary: #2459d6;
    --primary-dark: #1d46a9;
    --green: #16784f;
    --red: #c0392b;
    --blue-soft: #edf3ff;
    --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-body {
    display: grid;
    place-items: center;
}

.login-shell {
    width: min(440px, calc(100% - 32px));
    padding: 32px 0;
}

.login-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 28px;
}

.login-panel h1 {
    margin-bottom: 8px;
}

.login-copy {
    margin-bottom: 18px;
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 14px;
}

.login-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.login-form .button {
    width: 100%;
}

button,
input,
select {
    font: inherit;
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0 56px;
}

.topbar {
    align-items: center;
}

.topbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 34px;
    line-height: 1.12;
}

h2 {
    font-size: 19px;
}

.topbar-actions,
.nav-actions,
.actions,
.webhook-box,
.custom-dates {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.control {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    padding: 0 12px;
    outline: none;
}

.control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(36, 89, 214, 0.14);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    padding: 0 15px;
    cursor: pointer;
    text-decoration: none;
    font-weight: 700;
    white-space: nowrap;
}

.button:hover {
    border-color: #b9c2d3;
}

.button.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

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

.button.subtle {
    background: #f9fafb;
}

.button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.custom-dates {
    margin-bottom: 18px;
    color: var(--muted);
}

.custom-dates label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
}

.notice {
    margin-bottom: 18px;
    border: 1px solid #bed0ff;
    border-radius: 8px;
    background: var(--blue-soft);
    color: #173b8f;
    padding: 12px 14px;
    font-weight: 700;
}

.notice.error {
    border-color: #f0c4be;
    background: #fff1ef;
    color: var(--red);
}

.overview-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 18px;
}

.overview-panel > div {
    display: grid;
    gap: 6px;
}

.overview-label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.overview-panel strong {
    font-size: 24px;
    line-height: 1.2;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.panel,
.account-chooser,
.metric,
.data-section {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel {
    padding: 18px;
}

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.panel-title strong {
    border-radius: 999px;
    background: #eef2f7;
    color: #344054;
    padding: 5px 10px;
    font-size: 12px;
}

.status-copy {
    min-height: 44px;
    margin-bottom: 14px;
    color: var(--muted);
    line-height: 1.45;
}

.webhook-box {
    margin-bottom: 12px;
}

.webhook-url {
    flex: 1;
    min-width: 260px;
}

.account-chooser,
.data-section {
    padding: 18px;
    margin-bottom: 18px;
}

.section-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.section-heading p {
    color: var(--muted);
    font-size: 14px;
    max-width: 620px;
}

.account-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.account-option {
    display: grid;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.account-option.selected {
    border-color: var(--primary);
    background: var(--blue-soft);
}

.account-option strong {
    font-size: 15px;
}

.account-option span {
    color: var(--muted);
    font-size: 13px;
}

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

.metric {
    min-height: 136px;
    padding: 18px;
    display: grid;
    align-content: space-between;
    gap: 12px;
}

.metric-primary {
    grid-column: span 1;
}

.metric span {
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.metric strong {
    font-size: 30px;
    line-height: 1.1;
}

.skeleton-text {
    position: relative;
    color: transparent !important;
    overflow: hidden;
}

.skeleton-text::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 6px;
    background: linear-gradient(90deg, #eef1f5 0%, #f8fafc 50%, #eef1f5 100%);
    background-size: 220% 100%;
    animation: shimmer 1.1s linear infinite;
}

@keyframes shimmer {
    from {
        background-position: 100% 0;
    }

    to {
        background-position: -100% 0;
    }
}

.metric small {
    color: var(--muted);
    line-height: 1.35;
}

.positive {
    color: var(--green);
}

.negative {
    color: var(--red);
}

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    border-bottom: 1px solid #eef1f5;
    padding: 13px 10px;
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

td {
    font-size: 14px;
}

td:nth-child(n+2),
th:nth-child(n+2) {
    text-align: right;
}

.empty {
    color: var(--muted);
    text-align: center !important;
    padding: 28px 10px;
}

.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 26px;
    border-radius: 999px;
    background: #eef2f7;
    color: #344054;
    padding: 0 9px;
    font-size: 12px;
    font-weight: 800;
}

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

.settings-panel {
    min-height: 320px;
}

.settings-list {
    display: grid;
    gap: 14px;
    margin: 0 0 18px;
}

.settings-list div {
    display: grid;
    gap: 5px;
}

.settings-list dt {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.settings-list dd {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.tracking-config {
    display: grid;
    gap: 14px;
}

.field-label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.code-field {
    width: 100%;
    min-height: 78px;
    padding-top: 10px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    line-height: 1.45;
}

.helper-copy {
    margin-top: 7px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

@media (max-width: 860px) {
    .shell {
        width: min(100% - 22px, 1180px);
        padding-top: 20px;
    }

    .topbar,
    .section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-actions {
        width: 100%;
    }

    .topbar-actions .control,
    .topbar-actions .button {
        flex: 1;
    }

    .status-grid,
    .metrics-grid,
    .overview-panel,
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .metric {
        min-height: 112px;
    }

    h1 {
        font-size: 28px;
    }
}

/* Dashboard visual system */
:root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --text: #56566f;
    --muted: #858597;
    --line: #e6e7ee;
    --primary: #4b61df;
    --primary-dark: #394dc4;
    --green: #4c9550;
    --red: #c85b63;
    --blue-soft: #eef1ff;
    --shadow: 0 10px 28px rgba(49, 52, 79, 0.07);
}

html[data-theme="dark"] {
    --bg: #171923;
    --surface: #232632;
    --text: #eef0f7;
    --muted: #aeb3c4;
    --line: #353a4b;
    --primary: #7c8cff;
    --primary-dark: #6675e8;
    --green: #79c77d;
    --red: #ef858c;
    --blue-soft: #293251;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

body {
    background: var(--bg);
    color: var(--text);
    transition: background-color .2s ease, color .2s ease;
}

.shell {
    width: min(1440px, calc(100% - 48px));
    padding: 24px 0 56px;
}

.hero-card,
.summary-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.hero-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 104px;
    margin-bottom: 22px;
    padding: 22px 26px;
}

.hero-card h1 {
    color: var(--text);
    font-size: clamp(25px, 3vw, 34px);
    font-weight: 750;
    letter-spacing: 0;
}

.hero-card .eyebrow {
    margin-bottom: 5px;
    color: var(--primary);
    font-size: 12px;
}

.hero-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.menu-wrap {
    position: relative;
}

.site-menu {
    position: absolute;
    z-index: 20;
    top: calc(100% + 8px);
    right: 0;
    display: grid;
    min-width: 190px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.site-menu[hidden] {
    display: none;
}

.site-menu a,
.site-menu button {
    display: block;
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    padding: 12px 14px;
    text-align: left;
    text-decoration: none;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.site-menu > :last-child {
    border-bottom: 0;
}

.site-menu a:hover,
.site-menu button:hover {
    background: var(--blue-soft);
    color: var(--primary);
}

.connections-panel[hidden] {
    display: none;
}

.connections-panel {
    margin-top: -2px;
}

.user-chip {
    display: grid;
    gap: 2px;
    min-width: 110px;
    padding-right: 8px;
    text-align: right;
}

.user-name {
    color: var(--text);
    font-size: 16px;
    font-weight: 800;
}

.user-role {
    color: var(--muted);
    font-size: 13px;
}

.icon-button {
    display: inline-grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 20px;
}

.icon-button svg,
.topbar-menu svg {
    display: block;
    pointer-events: none;
}

.icon-button:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.summary-card {
    margin-bottom: 22px;
    overflow: hidden;
}

.summary-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 24px 26px 20px;
    border-bottom: 1px solid var(--line);
}

.section-kicker {
    margin-bottom: 5px;
    color: var(--text);
    font-size: 21px;
    font-weight: 800;
}

.summary-head h2 {
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}

.summary-meta {
    display: flex;
    align-items: center;
    gap: 16px;
}

.summary-updated {
    color: var(--muted);
    white-space: nowrap;
}

.summary-card .button.primary {
    min-width: 132px;
    min-height: 46px;
    border-radius: 8px;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 22px;
    padding: 25px 26px 28px;
}

.filter-grid label,
.custom-dates label {
    display: grid;
    gap: 9px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
}

.control {
    min-height: 48px;
    border-color: var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.filter-grid .control {
    width: 100%;
    font-size: 16px;
}

.control:disabled {
    color: var(--text);
    opacity: .85;
}

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

.metric {
    min-height: 138px;
    border-radius: 12px;
    padding: 24px 26px;
    box-shadow: var(--shadow);
}

.metric span {
    color: var(--text);
    font-size: 16px;
    font-weight: 700;
}

.metric strong {
    color: var(--text);
    font-size: clamp(25px, 2.5vw, 36px);
    font-weight: 800;
    letter-spacing: 0;
}

.metric-positive span,
.metric-positive strong,
.metric strong.positive {
    color: var(--green);
}

.metric strong.negative {
    color: var(--red);
}

.panel,
.account-chooser,
.data-section {
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.notice {
    border-radius: 10px;
    background: var(--blue-soft);
    color: var(--primary);
}

html[data-theme="dark"] .notice.error {
    background: #432b31;
    color: var(--red);
}

html[data-theme="dark"] .panel-title strong,
html[data-theme="dark"] .pill,
html[data-theme="dark"] .button.subtle {
    background: #2d3241;
    color: var(--muted);
}

html[data-theme="dark"] th,
html[data-theme="dark"] td {
    border-color: var(--line);
}

.data-section {
    padding: 22px 24px;
}

.meta-toolbar {
    display: flex;
    align-items: end;
    gap: 16px;
    padding: 22px 26px 26px;
}

.meta-toolbar label {
    display: grid;
    gap: 8px;
    min-width: 220px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.analysis-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 22px;
    border-bottom: 1px solid var(--line);
}

.analysis-tab {
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--muted);
    padding: 10px 14px 12px;
    cursor: pointer;
    font-weight: 800;
}

.analysis-tab.active {
    border-bottom-color: var(--primary);
    color: var(--primary);
}

.meta-analysis-table {
    min-width: 1500px;
    table-layout: auto;
}

.meta-analysis-table th:first-child,
.meta-analysis-table td:first-child {
    min-width: 96px;
    text-align: center;
}

.meta-analysis-table td:nth-child(2) {
    width: 260px;
    min-width: 260px;
    text-align: left;
}

.meta-analysis-table th:nth-child(2) {
    text-align: left;
}

.meta-analysis-table td:nth-child(2) small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

.meta-analysis-table th:nth-child(1),
.meta-analysis-table td:nth-child(1) {
    position: sticky;
    z-index: 2;
    background: var(--surface);
}

.meta-analysis-table th:nth-child(1),
.meta-analysis-table td:nth-child(1) {
    left: 0;
}

.campaign-name-cell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 30px;
    align-items: center;
    gap: 6px;
}

.campaign-name-cell strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.campaign-name-cell .icon-button {
    width: 30px;
    height: 30px;
    font-size: 16px;
}

.campaign-budget-type,
.campaign-budget {
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    padding: 5px 8px;
    font: inherit;
}

.budget-control {
    display: grid;
    grid-template-columns: 92px 112px 28px;
    gap: 6px;
    align-items: center;
}

.campaign-budget {
    width: 112px;
}

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

.modal-backdrop[hidden] {
    display: none;
}

.modal-backdrop {
    position: fixed;
    z-index: 50;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, .48);
    padding: 20px;
}

.modal {
    width: min(440px, 100%);
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 24px 70px rgba(0, 0, 0, .24);
    padding: 22px;
}

.modal-head,
.modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-head {
    margin-bottom: 20px;
}

.modal .field-label {
    display: block;
    margin-bottom: 7px;
}

.modal .control {
    width: 100%;
}

.modal-actions {
    justify-content: flex-end;
    margin-top: 20px;
}

@media (max-width: 980px) {
    .filter-grid,
    .metrics-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 680px) {
    .shell {
        width: min(100% - 24px, 1440px);
        padding-top: 12px;
    }

    .hero-card,
    .summary-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .hero-card {
        padding: 20px;
    }

    .hero-actions,
    .summary-meta {
        justify-content: flex-start;
        width: 100%;
    }

    .user-chip {
        order: -1;
        text-align: left;
    }

    .filter-grid,
    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .summary-head,
    .filter-grid {
        padding-left: 20px;
        padding-right: 20px;
    }

    .summary-meta .button {
        flex: 1;
    }

    .meta-toolbar {
        align-items: stretch;
        flex-direction: column;
        padding-left: 20px;
        padding-right: 20px;
    }

    .meta-toolbar label {
        min-width: 0;
    }
}

/* Clay visual system */
:root {
    --bg: #fffaf0;
    --surface: #fffdf7;
    --text: #0a0a0a;
    --muted: #6a6a6a;
    --line: #e5e5e5;
    --primary: #0a0a0a;
    --primary-dark: #1f1f1f;
    --green: #17824a;
    --red: #d84343;
    --blue-soft: #f1edfD;
    --shadow: 0 8px 0 rgba(10, 10, 10, .04), 0 18px 40px rgba(10, 10, 10, .06);
}

html[data-theme="dark"] {
    --bg: #0a1a1a;
    --surface: #1a2a2a;
    --text: #ffffff;
    --muted: #a0a0a0;
    --line: #344646;
    --primary: #ffffff;
    --primary-dark: #e5e5e5;
    --green: #72d39a;
    --red: #ff8b7f;
    --blue-soft: #273b3b;
    --shadow: 0 12px 30px rgba(0, 0, 0, .24);
}

body {
    background: var(--bg);
    color: var(--text);
}

.shell {
    width: min(1440px, calc(100% - 48px));
    padding-top: 24px;
}

.hero-card,
.summary-card,
.panel,
.account-chooser,
.data-section,
.overview-panel {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.hero-card {
    min-height: 88px;
    padding: 18px 24px;
}

.brand-mark {
    display: grid;
    width: 52px;
    height: 52px;
    flex: 0 0 52px;
    place-items: center;
    border-radius: 12px;
    background: #0a0a0a;
    color: #fffaf0;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: .5px;
}

html[data-theme="dark"] .brand-mark {
    background: #fffaf0;
    color: #0a1a1a;
}

.hero-copy {
    margin-right: auto;
}

.hero-card h1 {
    font-size: clamp(25px, 3vw, 34px);
    font-weight: 700;
}

.eyebrow {
    color: var(--muted);
    letter-spacing: 1.5px;
}

.button {
    min-height: 44px;
    border-radius: 12px;
    padding: 0 18px;
    font-size: 14px;
    font-weight: 700;
}

.button.primary {
    border-color: #0a0a0a;
    background: #0a0a0a;
    color: #fff;
}

html[data-theme="dark"] .button.primary {
    border-color: #fffaf0;
    background: #fffaf0;
    color: #0a1a1a;
}

.button.subtle,
.control {
    background: var(--surface);
}

.summary-card,
.data-section,
.panel {
    box-shadow: var(--shadow);
}

.summary-head,
.section-heading {
    padding-left: 24px;
    padding-right: 24px;
}

.filter-grid {
    margin: 0 20px 20px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-soft, #faf5e8);
    padding: 18px;
}

.control {
    border-radius: 10px;
}

.metric {
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.metric:nth-child(1) { border-top: 4px solid #ff4d8b; }
.metric:nth-child(2) { border-top: 4px solid #1a3a3a; }
.metric:nth-child(3) { border-top: 4px solid #b8a4ed; }
.metric:nth-child(4) { border-top: 4px solid #ffb084; }

.data-section {
    padding: 24px;
}

th {
    color: var(--muted);
    letter-spacing: 1px;
}

th, td {
    border-bottom-color: var(--line);
}

.site-menu {
    border-radius: 12px;
    border-color: var(--line);
    background: var(--surface);
}

.site-menu a,
.site-menu button {
    padding: 13px 16px;
}

.modal {
    border-radius: 16px;
}

.login-body {
    background: var(--bg);
}

.login-panel {
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 32px;
}

.login-panel h1 {
    font-size: 32px;
    font-weight: 700;
}

/* Performance workspace template */
:root {
    --bg: #080d16;
    --surface: #101824;
    --surface-2: #0d1521;
    --surface-soft: #131e2d;
    --text: #eef3fb;
    --muted: #8e9caf;
    --line: #29384e;
    --primary: #7180ff;
    --primary-dark: #5f6ef1;
    --green: #58d982;
    --red: #ff6670;
    --blue-soft: #142545;
    --shadow: 0 20px 50px rgba(0, 0, 0, .22);
}

html[data-theme="light"] {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-soft: #f2f5fa;
    --text: #172236;
    --muted: #647188;
    --line: #dbe3ef;
    --primary: #5668e8;
    --primary-dark: #4659d7;
    --green: #278d51;
    --red: #db4e59;
    --blue-soft: #edf1ff;
    --shadow: 0 18px 42px rgba(26, 44, 72, .08);
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #080d16;
    --surface: #101824;
    --surface-2: #0d1521;
    --surface-soft: #131e2d;
    --text: #eef3fb;
    --muted: #8e9caf;
    --line: #29384e;
    --primary: #7180ff;
    --primary-dark: #5f6ef1;
    --green: #58d982;
    --red: #ff6670;
    --blue-soft: #142545;
    --shadow: 0 20px 50px rgba(0, 0, 0, .22);
}

body, .control, button, select, input, textarea { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { background: var(--bg); color: var(--text); }

.app-body { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100vh; background: var(--bg); }
.app-sidebar { position: sticky; top: 0; display: flex; flex-direction: column; width: 210px; height: 100vh; padding: 20px 12px 14px; border-right: 1px solid var(--line); background: var(--surface-2); }
.sidebar-brand { display: flex; align-items: center; gap: 12px; min-height: 62px; padding: 0 10px 18px; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: 19px; letter-spacing: .2px; }
.sidebar-brand .brand-mark { width: 42px; height: 42px; flex-basis: 42px; border-radius: 11px; background: linear-gradient(135deg, #4f45c8, #211a67); color: #fff; }
.sidebar-nav { display: grid; gap: 5px; padding-top: 20px; }
.sidebar-nav a { display: flex; align-items: center; gap: 12px; min-height: 43px; padding: 0 12px; border: 1px solid transparent; border-radius: 9px; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 700; }
.sidebar-nav a span { width: 20px; color: #aeb9ce; text-align: center; font-size: 17px; }
.sidebar-nav a:hover, .sidebar-nav a.active { border-color: #344b7d; background: #16274a; color: #b7c1ff; }
.sidebar-nav a.active span { color: #8190ff; }
.sidebar-spacer { flex: 1; }
.sidebar-user { display: flex; align-items: center; gap: 9px; min-height: 52px; padding: 10px 7px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.sidebar-user strong, .sidebar-user small { display: block; }
.sidebar-user strong { color: var(--text); font-size: 12px; }
.sidebar-user small { margin-top: 2px; }
.avatar { display: grid; width: 29px; height: 29px; place-items: center; border-radius: 50%; background: #5b40a7; color: #fff; font-size: 12px; font-weight: 800; }
.sidebar-caret { margin-left: auto; font-size: 18px; }
.app-shell { width: auto; min-width: 0; margin: 0; padding: 24px 26px 54px; }
.app-topbar { display: flex; align-items: center; justify-content: space-between; gap: 22px; min-height: 62px; margin-bottom: 18px; }
.topbar-title { min-width: 0; }
.topbar-title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: clamp(25px, 3vw, 34px); letter-spacing: -.7px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-icon { width: 40px; height: 40px; flex: 0 0 40px; border-color: var(--line); background: var(--surface); }
.topbar-menu { width: 40px; min-height: 40px; padding: 0; font-size: 16px; letter-spacing: 2px; }
.sync-status { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border: 1px solid rgba(65, 203, 129, .25); border-radius: 999px; background: rgba(44, 143, 91, .12); color: var(--green); font-size: 12px; font-weight: 800; white-space: nowrap; }
.sync-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(88, 217, 130, .12); }
.privacy-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }
.privacy-toggle.is-active { border-color: rgba(113, 128, 255, .45); background: var(--blue-soft); color: var(--primary); }
.privacy-mask { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; white-space: nowrap; }
html[data-private-names="hidden"] .privacy-mask { position: relative; color: transparent !important; }
html[data-private-names="hidden"] .privacy-mask::after { position: absolute; inset: 0 auto auto 0; max-width: 100%; overflow: hidden; color: var(--text); content: attr(data-private-label); text-overflow: ellipsis; white-space: nowrap; }
.hero-card { display: none; }
.summary-card, .data-section, .panel, .account-chooser, .overview-panel { border: 1px solid var(--line); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow); }
.summary-card { overflow: hidden; }
.summary-head { min-height: 72px; border-bottom: 1px solid var(--line); }
.summary-head h2, .section-heading h2 { font-size: 16px; }
.section-kicker { color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .2px; text-transform: none; }
.filter-grid { margin: 0; border: 0; border-radius: 0; background: var(--surface); padding: 17px 18px 18px; }
.filter-grid label, .meta-toolbar label { color: var(--muted); font-size: 12px; font-weight: 800; }
.control { min-height: 40px; border-color: var(--line); border-radius: 8px; background: var(--surface-2); color: var(--text); }
.control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(113, 128, 255, .16); }
.button { min-height: 40px; border-color: var(--line); border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: 13px; }
.button:hover { border-color: #52678a; }
.button.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-dark); }
.button.subtle { background: var(--surface-2); }
.notice { border-color: #4c63a7; border-radius: 9px; background: #172746; color: #b9c5ff; }
.notice.error { border-color: #7c3e4b; background: #3b2029; color: #ff9da1; }
.connections-panel { margin-top: 14px; }
.metrics-grid { gap: 10px; margin-top: 14px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric { min-height: 112px; border-color: var(--line); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow); }
.metric span { color: var(--muted); font-size: 12px; font-weight: 800; }
.metric strong { margin-top: 13px; color: var(--text); font-size: clamp(25px, 3vw, 34px); letter-spacing: -.7px; }
.metric-positive strong { color: var(--green); }
.data-section { margin-top: 14px; padding: 16px; }
.section-heading { margin-bottom: 13px; }
.section-heading p, .helper-copy { color: var(--muted); font-size: 12px; line-height: 1.5; }
.table-wrap { border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); }
table { min-width: 760px; }
th { color: var(--muted); font-size: 10px; letter-spacing: .7px; }
td { color: var(--text); font-size: 12px; }
th, td { border-bottom-color: var(--line); }
.site-menu { min-width: 155px; border-color: var(--line); border-radius: 9px; background: var(--surface); box-shadow: var(--shadow); }
.site-menu a, .site-menu button { color: var(--text); }
.site-menu a:hover, .site-menu button:hover { background: var(--surface-soft); }
.account-chooser { margin-top: 14px; }
.meta-analysis-card { margin-top: 0; }
.meta-toolbar { border-top: 1px solid var(--line); padding-top: 15px; }
.analysis-tabs { gap: 3px; border-bottom-color: var(--line); }
.analysis-tab { color: var(--muted); }
.analysis-tab.active { border-bottom-color: var(--primary); color: #aeb8ff; }
.modal { border-color: var(--line); background: var(--surface); box-shadow: var(--shadow); }

@media (max-width: 980px) {
    .app-body { grid-template-columns: 70px minmax(0, 1fr); }
    .app-sidebar { width: 70px; padding-left: 9px; padding-right: 9px; }
    .sidebar-brand { justify-content: center; padding-left: 0; padding-right: 0; }
    .sidebar-brand strong, .sidebar-nav a:not(.active) { font-size: 0; }
    .sidebar-nav a { justify-content: center; padding: 0; }
    .sidebar-nav a span { margin: 0; }
    .sidebar-user { justify-content: center; padding-left: 0; padding-right: 0; }
    .sidebar-user > span:not(.avatar) { display: none; }
    .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .topbar-actions .user-chip { display: none; }
}

@media (max-width: 620px) {
    .app-body { display: block; }
    .app-sidebar { position: static; display: block; width: 100%; height: auto; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
    .sidebar-brand { width: max-content; min-height: 42px; padding: 0; border: 0; }
    .sidebar-brand .brand-mark { width: 34px; height: 34px; flex-basis: 34px; }
    .sidebar-brand strong { display: inline; font-size: 17px; }
    .sidebar-nav, .sidebar-spacer, .sidebar-user { display: none; }
    .app-shell { padding: 18px 12px 36px; }
    .app-topbar { align-items: flex-start; margin-bottom: 14px; }
    .topbar-title h1 { font-size: 23px; }
    .sync-status { padding: 6px; font-size: 0; }
    .sync-status i { display: block; }
    .metrics-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .metric { min-height: 96px; padding: 14px; }
    .metric strong { font-size: 23px; }
    .summary-head, .section-heading { padding-left: 16px; padding-right: 16px; }
    .filter-grid { grid-template-columns: 1fr 1fr; padding: 14px; }
    .data-section { padding: 12px; }
}

/* Automation workspace */
.automation-page { max-width: 1500px; }
.automation-intro { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 14px; padding: 20px 22px; border: 1px solid var(--line); border-radius: 11px; background: linear-gradient(105deg, var(--surface), var(--surface-soft)); box-shadow: var(--shadow); }
.automation-intro h2 { margin: 3px 0 5px; font-size: 20px; letter-spacing: -.3px; }
.automation-intro p:not(.section-kicker) { max-width: 650px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.automation-intro .button { display: inline-flex; gap: 8px; }
.automation-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.automation-stats article { display: flex; align-items: center; justify-content: space-between; min-height: 70px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.automation-stats span { color: var(--muted); font-size: 11px; font-weight: 800; }
.automation-stats strong { color: var(--text); font-size: 24px; }
.automation-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 10px; }
.automation-tabs { display: flex; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.automation-tab { min-height: 32px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 0 12px; cursor: pointer; font-size: 11px; font-weight: 800; }
.automation-tab.active { background: var(--primary); color: #fff; }
.automation-search { display: flex; align-items: center; gap: 7px; width: min(260px, 100%); min-height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); }
.automation-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 12px; }
.automation-list { display: grid; gap: 8px; }
.automation-rule { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 13px; min-height: 88px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.automation-rule.is-inactive { opacity: .66; }
.rule-icon { display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid #354e83; border-radius: 9px; background: #182746; font-size: 16px; }
.rule-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.rule-heading h3 { margin: 0 0 4px; color: var(--text); font-size: 14px; }
.rule-type { color: var(--muted); font-size: 10px; font-weight: 800; }
.rule-status { flex: 0 0 auto; padding: 4px 8px; border: 1px solid transparent; border-radius: 999px; font-size: 10px; font-weight: 800; }
.rule-status.is-active { border-color: rgba(88,217,130,.3); background: rgba(88,217,130,.12); color: var(--green); }
.rule-status.is-inactive { border-color: var(--line); background: var(--surface-soft); color: var(--muted); }
.rule-targets { margin: 0 0 7px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rule-targets strong { color: var(--text); }
.rule-meta { display: flex; gap: 14px; color: var(--muted); font-size: 10px; }
.rule-actions { display: flex; gap: 5px; }
.rule-actions .icon-button { width: 30px; height: 30px; min-height: 30px; padding: 0; border-radius: 7px; }
.rule-more-wrap { position: relative; }
.rule-more-menu { position: absolute; z-index: 20; top: calc(100% + 5px); right: 0; display: grid; min-width: 130px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.rule-more-menu button { display: flex; align-items: center; gap: 7px; min-height: 31px; border: 0; border-radius: 5px; background: transparent; color: var(--text); padding: 0 9px; cursor: pointer; text-align: left; font-size: 11px; }
.rule-more-menu button:hover { background: var(--surface-soft); color: var(--primary); }
.empty-state { display: grid; justify-items: center; gap: 5px; padding: 48px 20px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); text-align: center; font-size: 12px; }
.empty-state strong { color: var(--text); font-size: 14px; }
.automation-modal { width: min(650px, calc(100% - 28px)); max-height: calc(100vh - 28px); overflow: auto; }
.automation-form { display: grid; gap: 12px; }
.automation-form > label, .automation-form .form-grid-2 > label, .automation-subsection > label { display: grid; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 800; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.automation-form .control { width: 100%; min-height: 38px; font-size: 12px; }
.modal-tabs { display: flex; gap: 4px; margin: 2px 0 3px; padding-bottom: 7px; border-bottom: 1px solid var(--line); }
.modal-tab { min-height: 30px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 0 12px; cursor: pointer; font-size: 11px; font-weight: 800; }
.modal-tab.active { background: var(--blue-soft); color: var(--primary); }
.product-target-fields { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.product-target-fields > label { display: grid; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 800; }
.automation-targets { min-height: 120px !important; height: 120px !important; padding: 7px; }
.automation-targets option { padding: 6px; border-radius: 4px; }
.field-hint { color: var(--muted); font-size: 10px; font-weight: 500; }
.automation-subsection { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.subsection-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.subsection-title strong { color: var(--text); font-size: 11px; }
.subsection-title span { color: var(--muted); font-size: 10px; }
.weekday-field { margin: 0; padding: 0; border: 0; }
.weekday-field legend { margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 800; }
.weekday-list { display: flex; flex-wrap: wrap; gap: 6px; }
.weekday-list label { display: inline-flex; align-items: center; gap: 5px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); font-size: 10px; font-weight: 700; }
.weekday-list input { accent-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
@media (max-width: 640px) { .automation-intro, .automation-toolbar { align-items: stretch; flex-direction: column; } .automation-stats { grid-template-columns: 1fr; } .automation-search { width: 100%; } .automation-rule { grid-template-columns: 34px minmax(0, 1fr); } .rule-actions { grid-column: 2; } .form-grid-2 { grid-template-columns: 1fr; } }

/* Compact controls and settings polish */
.app-topbar h1 { font-size: 28px; letter-spacing: -.35px; }
.summary-head { min-height: 66px; padding-top: 16px; padding-bottom: 14px; }
.summary-head .section-kicker { margin-bottom: 2px; font-size: 14px; color: var(--text); }
.summary-head h2 { font-size: 12px; }
.summary-card .summary-meta { gap: 12px; }
.refresh-button { width: 38px; height: 38px; min-height: 38px; padding: 0; border-radius: 9px; background: var(--primary); color: #fff; font-size: 22px; line-height: 1; }
.refresh-button:hover { background: var(--primary-dark); }
.refresh-button.is-loading span { display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.filter-grid { grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; padding: 14px 18px 16px; }
.filter-grid label { gap: 6px; font-size: 11px; }
.filter-grid .control { min-height: 38px; height: 38px; font-size: 13px; }
.custom-dates { display: grid; grid-template-columns: repeat(2, minmax(150px, 210px)); gap: 12px; margin: 0; padding: 0 18px 16px; }
.custom-dates label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 800; }
.custom-dates .control { width: 100%; min-height: 38px; height: 38px; font-size: 13px; }
.settings-grid { align-items: start; gap: 12px; }
.settings-panel { min-height: 0; padding: 16px; }
.settings-panel .panel-title { margin-bottom: 10px; }
.settings-panel .panel-title > span { font-size: 14px; font-weight: 800; }
.settings-panel .panel-title strong { padding: 4px 8px; font-size: 10px; }
.settings-list { gap: 9px; margin-bottom: 13px; }
.settings-list dt { font-size: 10px; letter-spacing: .5px; }
.settings-list dd { font-size: 13px; }
.settings-panel .helper-copy { font-size: 11px; }
.settings-panel .field-label { margin-top: 9px; font-size: 10px; }
.settings-panel .control { min-height: 36px; height: 36px; font-size: 12px; }
.settings-panel .button { min-height: 34px; padding: 0 12px; font-size: 11px; }
.settings-panel .actions { margin-top: 10px; }
.settings-panel .webhook-url { min-width: 0; width: 100%; }
.settings-panel .webhook-box { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.settings-panel .webhook-box .button { align-self: stretch; }
.settings-grid + .data-section { margin-top: 14px; }
.data-section h2 { font-size: 15px; }
.data-section .section-heading p { font-size: 11px; }
.table-wrap th { padding-top: 10px; padding-bottom: 10px; }
.table-wrap td { padding-top: 10px; padding-bottom: 10px; }
.status-pill { border: 1px solid transparent; }
.status-positive { border-color: rgba(88, 217, 130, .3); background: rgba(88, 217, 130, .13); color: var(--green); }
.status-negative { border-color: rgba(255, 102, 112, .32); background: rgba(255, 102, 112, .13); color: var(--red); }
.status-attention { border-color: rgba(242, 171, 69, .34); background: rgba(242, 171, 69, .14); color: #e9ae4c; }
.status-neutral { border-color: var(--line); background: var(--surface-soft); color: var(--muted); }
.settings-section { margin-bottom: 18px; }
.settings-section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin: 0 2px 10px; }
.settings-section-heading .section-kicker { margin-bottom: 2px; color: var(--primary); font-size: 11px; letter-spacing: .8px; text-transform: uppercase; }
.settings-section-heading h2 { font-size: 17px; letter-spacing: -.15px; }
.settings-section-heading > p { max-width: 360px; margin: 0; color: var(--muted); font-size: 11px; text-align: right; }
.settings-connections-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.settings-controls-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.settings-controls-grid .settings-panel { min-height: 238px; }
.settings-panel .settings-list dd .control { width: 100%; }
.settings-panel .panel-title strong { white-space: nowrap; }
.settings-panel .field-label { display: grid; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 800; }
.settings-panel .field-label + .control { margin-bottom: 5px; }
.settings-panel textarea.control { height: auto; min-height: 72px; padding: 9px 10px; }
.settings-panel .actions { align-items: center; }
.settings-preferences-section { margin-top: 2px; }
.timezone-panel { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.timezone-copy { display: flex; align-items: flex-start; gap: 11px; max-width: 650px; }
.timezone-copy strong { display: block; margin-bottom: 4px; color: var(--text); font-size: 13px; }
.timezone-copy .helper-copy { margin: 0; }
.preference-icon { display: grid; width: 34px; height: 34px; flex: 0 0 34px; place-items: center; border: 1px solid #354e83; border-radius: 9px; background: #182746; color: #aeb8ff; font-size: 17px; }
.timezone-form { display: flex; align-items: end; gap: 10px; min-width: min(100%, 400px); }
.timezone-form .field-label { flex: 1; }
.timezone-form .button { flex: 0 0 auto; }
@media (max-width: 720px) { .timezone-panel { align-items: stretch; flex-direction: column; gap: 14px; } .timezone-form { align-items: stretch; flex-direction: column; min-width: 0; } }

@media (max-width: 900px) {
    .settings-controls-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
    .settings-connections-grid, .settings-controls-grid { grid-template-columns: 1fr; }
    .settings-controls-grid .settings-panel { min-height: 0; }
    .settings-section-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
    .settings-section-heading > p { text-align: left; }
}

@media (max-width: 620px) {
    .app-topbar h1 { font-size: 22px; }
    .filter-grid { grid-template-columns: 1fr 1fr; }
    .custom-dates { grid-template-columns: 1fr 1fr; padding-left: 14px; padding-right: 14px; }
}

/* Meta analysis controls */
.meta-toolbar { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; }
.meta-toolbar label { display: grid; min-width: 210px; gap: 6px; }
.meta-toolbar .button { min-height: 38px; }
.meta-selection-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 0 0 16px; }
.meta-selection-bar[hidden] { display: none; }
.meta-selection-pill { display: inline-flex; align-items: center; max-width: min(100%, 420px); min-height: 32px; gap: 7px; border: 1px solid var(--line); border-radius: 8px; background: var(--blue-soft); color: var(--text); padding: 6px 9px; cursor: pointer; font-size: 12px; font-weight: 800; }
.meta-selection-pill span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.meta-selection-pill svg { flex: 0 0 auto; width: 14px; height: 14px; }
.meta-analysis-table tbody tr.is-selectable { cursor: pointer; }
.meta-analysis-table tbody tr.is-selectable:hover td { background: var(--blue-soft); }
.meta-analysis-table tbody tr.is-selected td { background: var(--blue-soft); box-shadow: inset 0 1px 0 var(--primary), inset 0 -1px 0 var(--primary); }
.meta-analysis-table tbody tr.is-selected td:first-child { box-shadow: inset 3px 0 0 var(--primary), inset 0 1px 0 var(--primary), inset 0 -1px 0 var(--primary); }
.meta-custom-dates { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; padding: 0 18px 16px; border-top: 1px solid var(--line); }
.meta-custom-dates[hidden] { display: none; }
.meta-custom-dates label { display: grid; min-width: 180px; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 800; }
.meta-custom-dates .control { width: 100%; min-height: 38px; height: 38px; font-size: 13px; }
.meta-analysis-table th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.meta-analysis-table th[data-sort]::after { content: '↕'; display: inline-block; margin-left: 5px; color: var(--muted); opacity: .65; }
.meta-analysis-table th[data-sort].is-sorted::after { content: attr(data-direction); color: var(--primary); opacity: 1; }
.meta-analysis-table th[data-sort]:hover { color: var(--primary); }
.entity-status-switch { position: relative; display: inline-flex; width: 34px; height: 20px; align-items: center; border: 0; border-radius: 999px; background: var(--line); padding: 0; cursor: pointer; transition: background .15s ease, box-shadow .15s ease; vertical-align: middle; }
.entity-status-switch span { width: 14px; height: 14px; margin-left: 3px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s ease; }
.entity-status-switch.is-on { background: var(--primary); }
.entity-status-switch.is-on span { transform: translateX(14px); }
.entity-status-switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.entity-status-switch:disabled { opacity: .72; cursor: wait; }
.entity-status-switch.is-loading { box-shadow: 0 0 0 3px rgba(113, 128, 255, .16); }
.budget-submit { width: 28px; min-width: 28px; height: 28px; min-height: 28px; border-color: transparent; background: transparent; color: var(--muted); padding: 0; opacity: .72; }
.budget-submit:hover { border-color: var(--line); background: var(--surface-soft); color: var(--primary); opacity: 1; }
.budget-submit:disabled { opacity: .55; cursor: wait; }
.budget-submit[hidden] { display: none; }
.budget-submit.is-loading svg { animation: icon-spin .8s linear infinite; }
@keyframes icon-spin { to { transform: rotate(360deg); } }
@media (max-width: 620px) {
    .meta-toolbar label { min-width: min(100%, 210px); flex: 1 1 180px; }
    .meta-custom-dates { display: grid; grid-template-columns: 1fr 1fr; padding-left: 14px; padding-right: 14px; }
    .meta-custom-dates label { min-width: 0; }
}

/* Automation rules table */
.automation-panel { overflow: visible; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.automation-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 76px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.automation-panel-head h2 { margin: 0 0 3px; color: var(--text); font-size: 18px; }
.automation-panel-head p { margin: 0; color: var(--muted); font-size: 11px; }
.automation-panel-actions { display: flex; align-items: center; gap: 8px; }
.automation-panel-actions .button { min-height: 34px; font-size: 11px; }
.automation-toolbar { margin: 0; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.automation-tabs { border: 0; background: transparent; padding: 0; }
.automation-tab { border-radius: 6px; }
.automation-list { display: block; }
.automation-table-wrap { overflow: visible; }
.automation-table { width: 100%; min-width: 0; border-collapse: collapse; table-layout: auto; }
.automation-table th { padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .45px; text-align: left; text-transform: uppercase; }
.automation-table th:nth-child(1) { width: 82px; text-align: center; }
.automation-table th:nth-child(2) { width: 21%; }
.automation-table th:nth-child(3) { width: 18%; }
.automation-table th:nth-child(4) { width: 21%; }
.automation-table th:nth-child(5) { width: 18%; }
.automation-table th:nth-child(6) { width: 14%; }
.automation-table th:nth-child(7) { width: 58px; text-align: center; }
.automation-table td { padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--text); vertical-align: middle; }
.automation-table tr:last-child td { border-bottom: 0; }
.automation-table tr.is-inactive td { opacity: .58; }
.automation-table td strong, .automation-table td small { display: block; overflow-wrap: anywhere; word-break: break-word; }
.automation-table td strong { color: var(--text); font-size: 11px; font-weight: 800; }
.automation-table td small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.automation-table td:first-child { text-align: center; }
.automation-table td:last-child { text-align: center; }
.rule-switch { position: relative; display: inline-flex; width: 34px; height: 20px; align-items: center; border: 0; border-radius: 999px; background: var(--line); padding: 0; cursor: pointer; transition: background .15s ease; }
.rule-switch span { width: 14px; height: 14px; margin-left: 3px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s ease; }
.rule-switch.is-on { background: var(--primary); }
.rule-switch.is-on span { transform: translateX(14px); }
.automation-table .rule-more-wrap { display: inline-block; }
.automation-table .rule-more { width: 28px; height: 28px; min-height: 28px; padding: 0; }
.automation-table .rule-more-menu { right: 0; }
.rule-more-menu[hidden] { display: none !important; }
.automation-history-table { width: 100%; min-width: 1120px; border-collapse: collapse; }
.automation-history-table th { padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .45px; text-align: left; text-transform: uppercase; }
.automation-history-table td { padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--text); vertical-align: top; font-size: 11px; }
.automation-history-table tr:last-child td { border-bottom: 0; }
.automation-history-table td strong, .automation-history-table td small { display: block; overflow-wrap: anywhere; word-break: break-word; }
.automation-history-table td strong { color: var(--text); font-size: 11px; font-weight: 800; }
.automation-history-table td small { margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.automation-history-table .status-pill { display: inline-flex; margin-bottom: 2px; }
.automation-modal .form-grid-2 { grid-template-columns: 1fr; }
.automation-modal .modal-tabs { margin-top: 2px; }
.automation-modal [hidden] { display: none !important; }
.help-icon { display: inline-grid; width: 15px; height: 15px; place-items: center; border: 1px solid var(--muted); border-radius: 50%; color: var(--muted); cursor: help; font-size: 10px; font-weight: 800; }
.tooltip-trigger { position: relative; }
.tooltip-trigger::after { position: absolute; z-index: 80; bottom: calc(100% + 8px); left: 50%; display: none; width: 230px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); color: var(--text); content: attr(data-tooltip); padding: 8px 9px; font-size: 10px; font-weight: 500; line-height: 1.4; text-align: left; transform: translateX(-50%); }
.tooltip-trigger:hover::after, .tooltip-trigger:focus-visible::after { display: block; }
@media (max-width: 640px) {
    .automation-panel-head { align-items: stretch; flex-direction: column; }
    .automation-panel-actions { justify-content: flex-end; }
    .automation-toolbar { align-items: stretch; flex-direction: column; }
    .automation-search { width: 100%; }
    .automation-table-wrap { overflow-x: auto; }
    .automation-table { min-width: 980px; }
}

/* Reports workspace */
.reports-page { max-width: 1680px; }
.reports-filters { margin-bottom: 12px; }
.reports-filter-grid { grid-template-columns: 1.2fr 1fr 1fr 1fr; }
.reports-kpi-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.report-kpi { display: grid; align-content: space-between; min-height: 106px; padding: 15px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow); }
.report-kpi span { color: var(--muted); font-size: 11px; font-weight: 800; }
.report-kpi strong { margin-top: 9px; overflow-wrap: anywhere; color: var(--text); font-size: 28px; line-height: 1; letter-spacing: 0; }
.report-kpi small { margin-top: 9px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.report-kpi:nth-child(1) { border-top: 3px solid #8a72ff; }
.report-kpi:nth-child(2) { border-top: 3px solid var(--green); }
.report-kpi:nth-child(3) { border-top: 3px solid #4f8cff; }
.report-kpi:nth-child(4) { border-top: 3px solid #f5c84b; }
.report-kpi:nth-child(5) { border-top: 3px solid #5bc0de; }
.report-kpi:nth-child(6) { border-top: 3px solid #b8a4ed; }
.report-kpi.danger { border-top: 3px solid var(--red); }
.reports-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.report-card { min-height: 258px; padding: 15px; border: 1px solid var(--line); border-radius: 11px; background: linear-gradient(180deg, var(--surface), var(--surface-2)); box-shadow: var(--shadow); }
.report-card-wide { grid-column: span 2; }
.report-card-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; min-height: 38px; margin-bottom: 10px; }
.report-card-head h2 { margin: 0; color: var(--text); font-size: 15px; letter-spacing: 0; }
.report-card-head span { color: var(--muted); font-size: 10px; font-weight: 800; text-align: right; }
.report-highlight { color: #b7c1ff !important; }
.bar-chart { display: grid; grid-template-columns: repeat(24, minmax(8px, 1fr)); align-items: end; gap: 6px; height: 210px; padding: 4px 0 0; border-bottom: 1px solid var(--line); }
.bar-chart.compact { grid-template-columns: repeat(31, minmax(5px, 1fr)); gap: 4px; }
.bar-chart.weekday { grid-template-columns: repeat(7, minmax(22px, 1fr)); gap: 9px; }
.chart-column { position: relative; display: grid; grid-template-rows: 22px minmax(0, 1fr) 18px; align-items: end; min-width: 0; height: 100%; }
.chart-value { align-self: end; overflow: hidden; color: var(--text); font-size: 9px; font-weight: 900; line-height: 1.1; text-align: center; text-overflow: clip; white-space: nowrap; writing-mode: vertical-rl; transform: rotate(180deg); opacity: .9; }
.bar-chart.weekday .chart-value { font-size: 10px; writing-mode: horizontal-tb; transform: none; }
.chart-bar { width: 100%; min-height: 2px; border-radius: 5px 5px 2px 2px; background: linear-gradient(180deg, #8a72ff, #5445ce); box-shadow: inset 0 1px 0 rgba(255,255,255,.22); }
.chart-column:hover .chart-bar { filter: brightness(1.16); box-shadow: 0 0 0 1px rgba(255,255,255,.18), 0 8px 22px rgba(113,128,255,.22); }
.bar-chart.compact .chart-bar { background: linear-gradient(180deg, #74dd86, #318b51); }
.bar-chart.weekday .chart-bar { background: linear-gradient(180deg, #f5c84b, #ce8d1e); }
.chart-column span { overflow: hidden; color: var(--muted); font-size: 10px; line-height: 18px; text-align: center; text-overflow: clip; white-space: nowrap; }
.horizontal-chart { display: grid; gap: 11px; padding-top: 3px; }
.horizontal-row { position: relative; display: grid; grid-template-columns: minmax(120px, 1fr) minmax(160px, 2fr) 70px; align-items: center; gap: 10px; }
.horizontal-row span { overflow: hidden; color: var(--text); font-size: 11px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.horizontal-row strong { color: var(--green); font-size: 11px; text-align: right; }
.horizontal-track { height: 12px; overflow: hidden; border-radius: 999px; background: var(--surface-soft); }
.horizontal-track i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #62ce72, #b8e35f); }
.horizontal-track i.is-negative { background: linear-gradient(90deg, #d65b5b, #f5a45f); }
.rank-list { display: grid; gap: 9px; }
.rank-row { position: relative; min-height: 46px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.rank-row > div { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rank-row strong { overflow-wrap: anywhere; color: var(--text); font-size: 12px; }
.rank-row span { flex: 0 0 auto; color: var(--muted); font-size: 10px; font-weight: 800; text-align: right; }
.rank-row i { position: absolute; inset: auto auto 0 0; display: block; height: 3px; border-radius: 0 999px 999px 0; background: var(--primary); }
.report-card .empty-state { min-height: 174px; border-color: var(--line); }
.reports-campaigns-section { margin-top: 10px; }
.reports-campaigns-table { min-width: 980px; }
.reports-campaigns-table th:first-child,
.reports-campaigns-table td:first-child { text-align: left; }
.reports-campaigns-table td:first-child strong,
.reports-campaigns-table td:first-child small { display: block; max-width: 430px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reports-campaigns-table td:first-child small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.reports-campaigns-table tbody tr:hover td { background: rgba(113, 128, 255, .07); }
.reports-campaigns-table .campaign-tooltip-cell { position: relative; }
.chart-column::after,
.horizontal-row::after,
.rank-row::after,
.reports-campaigns-table .campaign-tooltip-cell::after { position: absolute; z-index: 30; bottom: calc(100% + 9px); left: 50%; display: none; width: max-content; max-width: 280px; border: 1px solid #3d5072; border-radius: 8px; background: #09111e; box-shadow: 0 18px 42px rgba(0,0,0,.32); color: #eef3fb; content: attr(data-tooltip); padding: 9px 10px; font-size: 11px; font-weight: 700; line-height: 1.45; text-align: left; white-space: pre-line; transform: translateX(-50%); pointer-events: none; }
.chart-column::before,
.horizontal-row::before,
.rank-row::before,
.reports-campaigns-table .campaign-tooltip-cell::before { position: absolute; z-index: 31; bottom: calc(100% + 3px); left: 50%; display: none; width: 10px; height: 10px; background: #09111e; border-right: 1px solid #3d5072; border-bottom: 1px solid #3d5072; content: ""; transform: translateX(-50%) rotate(45deg); pointer-events: none; }
.reports-campaigns-table .campaign-tooltip-cell::after,
.reports-campaigns-table .campaign-tooltip-cell::before { left: min(220px, 85%); }
.chart-column:hover::after,
.chart-column:hover::before,
.horizontal-row:hover::after,
.horizontal-row:hover::before,
.rank-row:hover::after,
.rank-row:hover::before,
.reports-campaigns-table tbody tr:hover .campaign-tooltip-cell::after,
.reports-campaigns-table tbody tr:hover .campaign-tooltip-cell::before,
.reports-campaigns-table .campaign-tooltip-cell:hover::after,
.reports-campaigns-table .campaign-tooltip-cell:hover::before { display: block; }
.horizontal-row::after,
.rank-row::after { bottom: calc(100% + 8px); }

@media (max-width: 1180px) {
    .reports-kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .reports-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .report-card-wide { grid-column: span 2; }
}

@media (max-width: 720px) {
    .reports-filter-grid { grid-template-columns: 1fr 1fr; }
    .reports-kpi-grid, .reports-grid { grid-template-columns: 1fr; }
    .report-card-wide { grid-column: span 1; }
    .report-card { min-height: 230px; padding: 12px; }
    .report-kpi strong { font-size: 23px; }
    .bar-chart { gap: 3px; height: 190px; }
    .bar-chart.compact { gap: 2px; }
    .chart-value { font-size: 8px; }
    .horizontal-row { grid-template-columns: minmax(88px, 1fr) minmax(90px, 1.3fr) 58px; gap: 7px; }
    .rank-row > div { align-items: flex-start; flex-direction: column; gap: 4px; }
    .rank-row span { text-align: left; }
}

/* Responsive navigation and screen polish */
.mobile-nav-toggle,
.sidebar-close {
    display: none;
}

.sidebar-backdrop[hidden] {
    display: none;
}

.sidebar-head {
    display: contents;
}

.table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.topbar-actions {
    min-width: 0;
}

.summary-updated,
.sync-status,
.user-chip {
    min-width: 0;
}

.control,
.button,
select,
input,
textarea {
    max-width: 100%;
}

.metric strong,
.report-kpi strong,
.settings-list dd {
    overflow-wrap: anywhere;
}

@media (max-width: 1180px) {
    .app-body {
        grid-template-columns: 86px minmax(0, 1fr);
    }

    .app-sidebar {
        width: 86px;
    }

    .sidebar-brand strong,
    .sidebar-user > span:not(.avatar),
    .sidebar-caret {
        display: none;
    }

    .sidebar-brand {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    .sidebar-nav a {
        justify-content: center;
        padding: 0;
        font-size: 0;
    }

    .sidebar-nav a span {
        width: auto;
        margin: 0;
        font-size: 17px;
    }
}

@media (min-width: 721px) and (max-width: 1180px) {
    .sidebar-nav a {
        position: relative;
    }

    .sidebar-nav a::after {
        position: absolute;
        z-index: 40;
        left: calc(100% + 10px);
        top: 50%;
        display: none;
        width: max-content;
        max-width: 180px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--surface);
        box-shadow: var(--shadow);
        color: var(--text);
        content: attr(aria-label);
        padding: 7px 9px;
        font-size: 11px;
        font-weight: 800;
        transform: translateY(-50%);
        white-space: nowrap;
    }

    .sidebar-nav a:hover::after,
    .sidebar-nav a:focus-visible::after {
        display: block;
    }
}

@media (max-width: 900px) {
    .app-shell {
        padding-left: 18px;
        padding-right: 18px;
    }

    .app-topbar {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 12px;
    }

    .topbar-title {
        flex: 1 1 320px;
    }

    .topbar-title h1 {
        white-space: normal;
    }

    .topbar-actions {
        justify-content: flex-end;
        flex: 1 1 auto;
    }

    .summary-head,
    .automation-panel-head,
    .section-heading,
    .settings-section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .summary-meta,
    .automation-panel-actions,
    .actions,
    .webhook-box {
        width: 100%;
    }

    .filter-grid,
    .reports-filter-grid,
    .metrics-grid,
    .settings-connections-grid,
    .settings-controls-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .reports-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .reports-grid {
        grid-template-columns: 1fr;
    }

    .report-card-wide {
        grid-column: span 1;
    }
}

@media (max-width: 720px) {
    body.sidebar-open {
        overflow: hidden;
    }

    .app-body {
        display: block;
        min-width: 0;
    }

    .mobile-nav-toggle {
        position: fixed;
        z-index: 70;
        top: 12px;
        left: 12px;
        display: inline-grid;
        width: 42px;
        height: 42px;
        place-items: center;
        border: 1px solid var(--line);
        border-radius: 10px;
        background: var(--surface);
        box-shadow: var(--shadow);
        color: var(--text);
        cursor: pointer;
        font-size: 22px;
        line-height: 1;
    }

    .sidebar-backdrop {
        position: fixed;
        z-index: 60;
        inset: 0;
        display: block;
        background: rgba(8, 13, 22, .62);
        backdrop-filter: blur(2px);
    }

    .app-sidebar {
        position: fixed;
        z-index: 80;
        inset: 0 auto 0 0;
        display: flex;
        width: min(82vw, 310px);
        height: 100dvh;
        padding: 16px 14px 14px;
        border-right: 1px solid var(--line);
        border-bottom: 0;
        background: var(--surface-2);
        box-shadow: 24px 0 60px rgba(0, 0, 0, .28);
        transform: translateX(-105%);
        transition: transform .2s ease;
    }

    body.sidebar-open .app-sidebar {
        transform: translateX(0);
    }

    .sidebar-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        min-height: 48px;
        padding-bottom: 14px;
        border-bottom: 1px solid var(--line);
    }

    .sidebar-brand {
        justify-content: flex-start;
        min-height: 42px;
        padding: 0;
        border: 0;
    }

    .sidebar-brand strong {
        display: inline;
        font-size: 18px;
    }

    .sidebar-brand .brand-mark {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
    }

    .sidebar-close {
        display: inline-grid;
        width: 38px;
        height: 38px;
        place-items: center;
        border: 1px solid var(--line);
        border-radius: 10px;
        background: var(--surface);
        color: var(--text);
        cursor: pointer;
        font-size: 24px;
        line-height: 1;
    }

    .sidebar-nav {
        display: grid;
        gap: 7px;
        padding-top: 16px;
    }

    .sidebar-nav a,
    .sidebar-nav a:not(.active) {
        justify-content: flex-start;
        min-height: 46px;
        padding: 0 12px;
        font-size: 14px;
    }

    .sidebar-nav a span {
        width: 24px;
    }

    .sidebar-spacer {
        display: block;
    }

    .sidebar-user {
        display: flex;
    }

    .sidebar-user > span:not(.avatar),
    .sidebar-caret {
        display: block;
    }

    .app-shell {
        width: 100%;
        padding: 74px 12px 34px;
    }

    .app-topbar {
        min-height: 0;
        margin-bottom: 12px;
    }

    .topbar-title {
        flex-basis: calc(100% - 54px);
        min-width: 0;
        padding-left: 54px;
    }

    .app-topbar h1,
    .topbar-title h1 {
        overflow: visible;
        font-size: 22px;
        line-height: 1.14;
        text-overflow: clip;
        white-space: normal;
    }

    .eyebrow {
        font-size: 10px;
    }

    .topbar-actions {
        justify-content: flex-start;
        width: 100%;
        gap: 8px;
    }

    .sync-status {
        max-width: 100%;
        white-space: normal;
    }

    .topbar-actions .user-chip {
        display: none;
    }

    .site-menu {
        position: fixed;
        top: 64px;
        right: 12px;
        left: 12px;
        width: auto;
        min-width: 0;
    }

    .summary-card,
    .data-section,
    .panel,
    .account-chooser,
    .automation-panel,
    .report-card,
    .report-kpi {
        border-radius: 10px;
    }

    .summary-head,
    .filter-grid,
    .custom-dates,
    .data-section,
    .automation-panel-head,
    .automation-toolbar,
    .panel,
    .account-chooser {
        padding-left: 12px;
        padding-right: 12px;
    }

    .summary-head {
        gap: 10px;
    }

    .summary-meta {
        align-items: stretch;
        justify-content: space-between;
        gap: 8px;
    }

    .summary-updated {
        white-space: normal;
    }

    .filter-grid,
    .reports-filter-grid,
    .metrics-grid,
    .reports-kpi-grid,
    .settings-grid,
    .settings-connections-grid,
    .settings-controls-grid,
    .status-grid,
    .overview-panel,
    .account-list,
    .custom-dates,
    .meta-custom-dates,
    .automation-stats {
        grid-template-columns: 1fr;
    }

    .custom-dates,
    .meta-custom-dates {
        padding-bottom: 12px;
    }

    .metrics-grid {
        gap: 9px;
    }

    .metric,
    .report-kpi {
        min-height: 92px;
        padding: 13px;
    }

    .metric strong,
    .report-kpi strong {
        font-size: 22px;
        letter-spacing: 0;
    }

    .metric span,
    .report-kpi span {
        font-size: 11px;
    }

    .section-heading {
        gap: 6px;
        margin-bottom: 10px;
    }

    .section-heading p,
    .settings-section-heading > p {
        max-width: none;
        text-align: left;
    }

    .actions,
    .webhook-box,
    .automation-panel-actions,
    .timezone-form,
    .meta-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .actions .button,
    .webhook-box .button,
    .automation-panel-actions .button,
    .timezone-form .button,
    .meta-toolbar .button {
        width: 100%;
    }

    .webhook-url {
        min-width: 0;
        width: 100%;
    }

    .analysis-tabs,
    .automation-tabs,
    .modal-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .analysis-tab,
    .automation-tab,
    .modal-tab {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .automation-table-wrap,
    .table-wrap {
        margin-left: -1px;
        margin-right: -1px;
    }

    .automation-table {
        min-width: 860px;
    }

    .modal-backdrop {
        align-items: end;
        padding: 10px;
    }

    .modal,
    .automation-modal {
        width: 100%;
        max-height: calc(100dvh - 20px);
        border-radius: 12px;
    }
}

@media (max-width: 420px) {
    .app-shell {
        padding-left: 10px;
        padding-right: 10px;
    }

    .topbar-actions {
        gap: 7px;
    }

    .topbar-icon,
    .topbar-menu,
    .refresh-button {
        width: 38px;
        height: 38px;
        min-height: 38px;
        flex-basis: 38px;
    }

    .sync-status {
        flex: 1 1 100%;
        justify-content: center;
    }

    .report-card {
        min-height: 220px;
    }

    .bar-chart {
        height: 170px;
    }

    .horizontal-row {
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
    }

    .horizontal-row strong {
        text-align: left;
    }
}
