:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f9fafb;
    --text: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --green: #059669;
    --amber: #d97706;
    --red: #dc2626;
    --sidebar: #101928;
    --sidebar-muted: #98a2b3;
}

* {
    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;
    font-size: 15px;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
    max-width: 100%;
}

.app-shell > * {
    min-width: 0;
}

.sidebar {
    background: var(--sidebar);
    color: #fff;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px 24px;
    font-weight: 800;
    font-size: 18px;
    min-width: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: #fff;
    color: var(--sidebar);
}

.nav {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.nav a {
    color: var(--sidebar-muted);
    padding: 10px 12px;
    border-radius: 8px;
    font-weight: 650;
}

.nav a.active,
.nav a:hover {
    background: rgba(255, 255, 255, 0.09);
    color: #fff;
}

.sidebar-footer {
    display: grid;
    gap: 10px;
    margin-top: auto;
    padding: 18px 10px 0;
    color: var(--sidebar-muted);
    font-size: 13px;
}

.current-user {
    overflow-wrap: anywhere;
}

.nav-logout {
    width: 100%;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.12);
}

.nav-logout:hover {
    background: rgba(255, 255, 255, 0.14);
}

.main {
    padding: 28px;
    min-width: 0;
    max-width: 100%;
}

.page-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 22px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--muted);
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: 28px;
    line-height: 1.15;
}

h2 {
    font-size: 18px;
    margin-bottom: 14px;
}

.grid {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.grid > *,
.toolbar > *,
.field,
.mini-record,
details {
    min-width: 0;
}

.grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.stack-list {
    display: grid;
    gap: 12px;
}

.mini-record {
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.mini-record p {
    margin-bottom: 0;
}

.info-panel {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    border-radius: 8px;
    padding: 14px;
}

.scope-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
}

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

.stat strong {
    display: block;
    margin-top: 6px;
    color: var(--text);
    font-size: 30px;
}

.dashboard-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
}

.metric-card {
    display: grid;
    gap: 7px;
    align-content: start;
    color: var(--muted);
    overflow-x: hidden;
}

.metric-card span,
.metric-card small {
    overflow-wrap: anywhere;
}

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

.metric-card strong {
    color: var(--text);
    font-size: 34px;
    line-height: 1;
}

.metric-card.primary {
    border-color: #bfdbfe;
    background: #eff6ff;
}

.metric-card.alert {
    border-color: #fecaca;
}

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

.dashboard-panels {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-top: 18px;
}

.dashboard-latest {
    margin-top: 18px;
}

.bar-list {
    display: grid;
    gap: 13px;
}

.bar-row {
    display: grid;
    gap: 7px;
    min-width: 0;
}

.bar-heading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
}

.bar-heading span {
    overflow-wrap: anywhere;
}

.bar-heading strong {
    color: var(--text);
}

.bar-track {
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: #e5e7eb;
}

.bar-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--blue);
}

.bar-track.commercial span {
    background: var(--green);
}

.bar-track.creator span {
    background: var(--amber);
}

.timeline-bars {
    display: grid;
    grid-template-columns: repeat(14, minmax(22px, 1fr));
    gap: 8px;
    align-items: end;
    min-height: 180px;
}

.timeline-day {
    display: grid;
    grid-template-rows: auto 110px auto;
    gap: 6px;
    min-width: 0;
    text-align: center;
    color: var(--muted);
}

.timeline-day strong {
    color: var(--text);
    font-size: 12px;
}

.timeline-day div {
    display: flex;
    align-items: end;
    justify-content: center;
    min-height: 110px;
    border-radius: 999px;
    background: #f3f4f6;
    overflow: hidden;
}

.timeline-day div span {
    display: block;
    width: 100%;
    min-height: 2px;
    border-radius: inherit;
    background: var(--blue);
}

.timeline-day small {
    font-size: 11px;
    white-space: nowrap;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    min-width: 0;
}

.button,
button {
    appearance: none;
    border: 1px solid transparent;
    background: var(--blue);
    color: #fff;
    border-radius: 8px;
    padding: 9px 13px;
    font-weight: 750;
    cursor: pointer;
    font-size: 14px;
    text-align: center;
    white-space: normal;
}

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

.button.secondary,
button.secondary {
    background: #fff;
    color: var(--text);
    border-color: var(--line);
}

.button.secondary:hover,
button.secondary:hover {
    background: var(--surface-soft);
}

.button.danger,
button.danger {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}

.button.danger:hover,
button.danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

.table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    overflow-wrap: normal;
}

.table td a,
.table td code,
.table td .muted {
    overflow-wrap: anywhere;
}

.table th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

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

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 3px 9px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 12px;
    font-weight: 800;
}

.badge.ready,
.badge.completed,
.badge.ai_ready,
.badge.theme_ready,
.badge.products_ready,
.badge.products_improved,
.badge.store_analyzed,
.badge.analyzed {
    background: #ecfdf5;
    color: #047857;
}

.badge.failed {
    background: #fef2f2;
    color: #b91c1c;
}

.badge.processing,
.badge.analyzing_store,
.badge.improving_products,
.badge.ai_processing,
.badge.theme_generating,
.badge.products_syncing,
.badge.pushing_to_shopify {
    background: #fff7ed;
    color: #c2410c;
}

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

.shop-form {
    max-width: 640px;
}

.field {
    display: grid;
    gap: 7px;
}

label {
    font-weight: 750;
}

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    background: #fff;
    color: var(--text);
}

textarea {
    min-height: 130px;
    resize: vertical;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 9px;
}

.checkbox-row input {
    width: auto;
}

.flash {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    background: #fff;
}

.flash.success {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.flash.error {
    border-color: #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.flash.warning {
    border-color: #fed7aa;
    background: #fff7ed;
    color: #9a3412;
}

.json-block,
pre {
    overflow: auto;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #0b1020;
    color: #d1e7ff;
    padding: 14px;
    font-size: 12px;
    line-height: 1.5;
}

.steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 8px;
}

.step {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 10px;
    color: var(--muted);
    font-weight: 750;
    font-size: 13px;
}

.step.done {
    border-color: #bbf7d0;
    color: #047857;
    background: #f0fdf4;
}

details {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 12px;
}

summary {
    cursor: pointer;
    font-weight: 800;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--bg);
}

.auth-panel {
    width: min(100%, 420px);
}

.auth-card {
    display: grid;
    gap: 18px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 16px 44px rgba(16, 24, 40, 0.12);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 18px;
}

@media (max-width: 960px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        gap: 12px;
        width: 100%;
        overflow: hidden;
    }

    .brand {
        padding-bottom: 8px;
    }

    .nav {
        display: flex;
        gap: 8px;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 4px;
        scrollbar-width: thin;
    }

    .nav a {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .sidebar-footer {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 12px;
        padding-top: 6px;
    }

    .nav-logout {
        width: auto;
        white-space: nowrap;
    }

    .grid.cols-3,
    .grid.cols-2,
    .steps,
    .dashboard-metrics,
    .dashboard-panels {
        grid-template-columns: 1fr;
    }

    .page-header {
        display: grid;
    }
}

@media (max-width: 560px) {
    body {
        font-size: 14px;
    }

    .sidebar {
        padding: 16px;
    }

    .main {
        padding: 18px;
    }

    .page-header {
        gap: 14px;
        margin-bottom: 18px;
    }

    h1 {
        font-size: 26px;
    }

    .card {
        padding: 14px;
    }

    .toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar > *,
    .toolbar form,
    .toolbar select,
    .toolbar .button,
    .toolbar button {
        width: 100%;
    }

    .table .toolbar {
        align-items: center;
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .table .toolbar > *,
    .table .toolbar form,
    .table .toolbar .button,
    .table .toolbar button {
        width: auto;
    }

    .auth-page {
        padding: 16px;
    }

    .auth-card {
        padding: 20px;
    }

    .timeline-bars {
        overflow-x: auto;
        grid-template-columns: repeat(14, 30px);
        padding-bottom: 4px;
    }
}

@media (max-width: 420px) {
    .sidebar-footer {
        grid-template-columns: 1fr;
    }

    .nav-logout {
        width: 100%;
    }
}
