:root {
    --bg: #FAF7F2;
    --panel: #FFFFFF;
    --ink: #2F2F2F;
    --muted: #6B6B6B;
    --line: #E7DFD2;
    --honey: #F2C97D;
    --pine: #4C7A69;
    --sand: #EADFCB;
    --sage: #BFD8C2;
    --danger: #B85C5C;
    --warning: #9B6B1D;
    --success: #2D7A58;
    --shadow: 0 10px 24px rgba(30, 30, 30, 0.08);
    --r: 12px;
}

:root[data-theme="dark"] {
    --bg: #1b1e20;
    --panel: #24282b;
    --ink: #ece6dc;
    --muted: #c6bcae;
    --line: #3b4248;
    --honey: #d9b36c;
    --pine: #6c9f8a;
    --sand: #2a2f33;
    --sage: #41584d;
    --danger: #c06b6b;
    --warning: #d29a47;
    --success: #4ea77d;
    --shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

:root[data-theme="dark"] .admin-sidebar {
    border-right-color: #3b4248;
}

:root[data-theme="dark"] .table-wrap,
:root[data-theme="dark"] .table thead th,
:root[data-theme="dark"] .ranked-list li,
:root[data-theme="dark"] .status-chip,
:root[data-theme="dark"] .form-section,
:root[data-theme="dark"] .admin-modal-panel,
:root[data-theme="dark"] .ai-result-item,
:root[data-theme="dark"] .admin-image-card {
    background: #212629;
    border-color: #3b4248;
    color: var(--ink);
}

:root[data-theme="dark"] .table th,
:root[data-theme="dark"] .table td {
    border-bottom-color: #333b40;
}

:root[data-theme="dark"] .admin-form input,
:root[data-theme="dark"] .admin-form select,
:root[data-theme="dark"] .admin-form textarea {
    background: #1d2124;
    border-color: #434b51;
    color: var(--ink);
}

:root[data-theme="dark"] .help,
:root[data-theme="dark"] p,
:root[data-theme="dark"] small {
    color: var(--muted);
}

:root[data-theme="dark"] .action-bar,
:root[data-theme="dark"] .settings-tabs .tabs,
:root[data-theme="dark"] .form-actions.sticky-actions,
:root[data-theme="dark"] .admin-mobile-topbar {
    background: rgba(27, 30, 32, 0.94);
    border-color: #3b4248;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Quicksand", "Trebuchet MS", sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.4;
}

h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p, small { color: var(--muted); }

.admin-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.admin-sidebar {
    background: var(--sand);
    padding: 20px 14px;
    border-right: 1px solid #dfd2bd;
}
.admin-sidebar h2 { margin: 0 10px 14px; font-size: 20px; }
.admin-sidebar nav { display: grid; gap: 6px; }
.admin-sidebar a {
    color: var(--ink);
    text-decoration: none;
    font-weight: 700;
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.admin-sidebar a::before {
    content: none;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    display: inline-block;
    margin-right: 8px;
    background: #b89f7d;
}
.admin-sidebar a.active {
    background: var(--pine);
    color: #fff;
}
.admin-sidebar a.active::before { background: #fff; }
.nav-badge {
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    line-height: 1;
}

.admin-main { padding: 24px; display: grid; gap: 16px; }

.admin-mobile-topbar,
.admin-nav-backdrop {
    display: none;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    max-height: 80px;
}
.admin-header h1 { margin: 0; font-size: 22px; line-height: 1.15; }
.action-bar {
    position: sticky;
    top: 8px;
    z-index: 4;
    background: rgba(250, 247, 242, 0.95);
    padding: 6px 8px;
    border-radius: 10px;
    border: 1px solid var(--line);
    backdrop-filter: blur(4px);
}

.card {
    background: var(--panel);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    padding: 16px;
    border: 1px solid #f1ece3;
}

.admin-cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.metrics-grid { margin-bottom: 4px; }
.metric-card h3 { font-size: 13px; letter-spacing: 0.2px; color: var(--muted); margin-bottom: 6px; }
.metric-value { margin: 0; font-size: 30px; font-weight: 800; color: var(--ink); }
.metric-delta { display: inline-block; margin-top: 6px; color: var(--pine); font-weight: 700; }

.btn {
    border: none;
    border-radius: 999px;
    padding: 10px 16px;
    min-height: 40px;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--honey);
    color: #232323;
}
.btn.small { min-height: 34px; padding: 7px 12px; font-size: 13px; }
.btn.secondary { background: var(--pine); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }

.admin-form { display: grid; gap: 10px; margin: 10px 0 16px; }
.admin-form.inline {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    max-height: 80px;
}
.admin-form.compact { margin: 0; }
.admin-form label { font-weight: 700; color: #383838; }
.admin-form input,
.admin-form select,
.admin-form textarea {
    width: 100%;
    min-height: 40px;
    border: 1px solid #ddd3c3;
    border-radius: 10px;
    padding: 10px;
    background: #fcfaf7;
    font-family: inherit;
}
.admin-form.inline input,
.admin-form.inline select,
.admin-form.inline textarea {
    width: auto;
    min-width: 130px;
    min-height: 36px;
    padding: 8px 10px;
    flex: 0 0 auto;
}
.admin-form.inline .btn {
    min-height: 36px;
    padding: 8px 12px;
    white-space: nowrap;
    flex: 0 0 auto;
}
.admin-form.inline.filter-compact {
    gap: 6px;
    padding: 6px 8px;
    margin: 8px 0 10px;
}
.admin-form.inline.filter-compact input,
.admin-form.inline.filter-compact select,
.admin-form.inline.filter-compact textarea {
    min-height: 32px;
    padding: 6px 8px;
    min-width: 118px;
    border-radius: 8px;
}
.admin-form.inline.filter-compact .btn {
    min-height: 32px;
    padding: 6px 10px;
}
.admin-form input:focus,
.admin-form select:focus,
.admin-form textarea:focus {
    outline: 2px solid #b8d8c5;
    border-color: #b8d8c5;
}
.help { margin-top: -4px; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.check-row { display: flex; gap: 14px; flex-wrap: wrap; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tab-btn { border: none; border-radius: 10px; background: var(--sage); color: #20372f; font-weight: 800; padding: 10px 14px; cursor: pointer; }
.tab-btn.active { background: var(--pine); color: #fff; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.settings-tabs .btn {
    min-height: 34px;
    padding: 7px 12px;
    font-size: 13px;
}
.settings-tabs .tabs {
    position: static;
    background: rgba(250, 247, 242, 0.96);
    padding: 6px;
    border-radius: 10px;
    border: 1px solid var(--line);
    margin-bottom: 0;
}
.settings-tabs {
    margin-top: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.settings-tabs .btn.small {
    min-height: 30px;
    padding: 5px 10px;
}
.settings-tabs .admin-form.inline .btn {
    min-height: 32px;
    padding: 6px 10px;
}

.status-badge {
    display: inline-flex;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
}
.status-pending, .status-warning { background: #F7E3B2; color: var(--warning); }
.status-paid, .status-success { background: #DAF0E4; color: var(--success); }
.status-shipped { background: #D2E7DE; color: #1e5d46; }
.status-failed, .status-error { background: #F5D9D9; color: #7b2d2d; }

.status-overview {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
}
.status-chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 12px; font-weight: 700; }
.status-overview .status-chip {
    border-radius: 10px;
    display: block;
    padding: 10px 12px;
}
.status-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #f2ece4; }

.ai-dropzone {
    position: relative;
    border: 2px dashed #cdbfa8;
    border-radius: 12px;
    background: #fcfaf7;
    padding: 22px;
    text-align: center;
    cursor: pointer;
}
.ai-dropzone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.ai-dropzone.is-dragover {
    border-color: var(--pine);
    background: #f4fbf7;
}

.ai-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}
.ai-result-item {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
    background: #fff;
}
.ai-result-item img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}
.ai-result-item figcaption {
    margin-top: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.table-wrap {
    width: 100%;
    overflow: auto;
    border-radius: var(--r);
    border: 1px solid #efe7da;
    background: #fff;
}

.admin-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 8px;
}

.admin-image-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px;
    background: #fff;
}

.admin-image-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
    margin-bottom: 8px;
}
.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}
.table.compact { min-width: 520px; }
.table th,
.table td { text-align: left; border-bottom: 1px solid #f0e8dd; padding: 12px; vertical-align: top; }
.admin-thumb {
    width: 62px;
    height: 62px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid #e9dfd2;
    display: block;
}
.table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #faf6f0;
    font-size: 13px;
    color: #4c4c4c;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.pagination { display: flex; gap: 8px; flex-wrap: wrap; }
.page-link {
    min-width: 36px;
    min-height: 36px;
    border-radius: 8px;
    border: 1px solid #e7ddcf;
    text-decoration: none;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
}
.page-link.active { background: var(--pine); color: #fff; border-color: var(--pine); }

.table-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline; }

.empty-state {
    text-align: center;
    display: grid;
    gap: 8px;
    justify-items: center;
    padding: 24px;
}
.empty-state.compact { padding: 10px; }

.ranked-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.ranked-list li {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 10px;
    align-items: center;
    background: #faf7f1;
    border: 1px solid #efe5d8;
    border-radius: 10px;
    padding: 8px 10px;
}
.ranked-list .rank { font-weight: 800; color: #555; }
.ranked-list .path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranked-list .views { font-weight: 800; color: #555; }

.review-stars-admin { letter-spacing: 1px; white-space: nowrap; }
.review-stars-admin .on { color: #d49b25; }
.review-stars-admin .off { color: #d0c6ac; }
.review-admin-text {
    margin: 6px 0 0;
    max-width: 520px;
    color: var(--muted);
    white-space: normal;
}

.admin-alert { padding: 10px 12px; border-radius: 10px; font-weight: 700; }
.admin-alert.success { background: #DAF0E4; color: #1f6047; }
.admin-alert.error { background: #F5D9D9; color: #7a2a2a; }
.save-banner { border-left: 4px solid #2D7A58; }
.inline-error { margin-bottom: 10px; }

.form-sectioned { gap: 16px; }
.form-section { background: #fff; border: 1px solid #efe6d9; border-radius: var(--r); padding: 16px; display: grid; gap: 10px; }
.section-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.form-actions.sticky-actions { position: sticky; bottom: 12px; z-index: 5; background: rgba(250,247,242,.95); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }

.variant-table input { min-height: 36px; }

.admin-form input:invalid,
.admin-form select:invalid,
.admin-form textarea:invalid {
    border-color: #d5a1a1;
}

.charts-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
}
.charts-grid .card { min-height: 320px; display: grid; grid-template-rows: auto 1fr; }
.charts-grid canvas { width: 100% !important; height: 240px !important; }
.charts-grid .card.funnel-card {
    grid-column: 1 / -1;
    width: 75%;
    min-height: 320px;
    margin: 0 auto;
}
.funnel-canvas-wrap {
    width: 100%;
    height: 210px;
    margin: 0 auto;
}
.card.funnel-card canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}
.funnel-canvas-wrap #chart-funnel {
    width: 100%;
    height: 100%;
}
.funnel-canvas-wrap .svg-funnel-js,
.funnel-canvas-wrap svg {
    width: 100% !important;
    height: 100% !important;
    display: block;
}
.funnel-canvas-wrap .svg-funnel-js__subLabels {
    display: none !important;
}
.funnel-canvas-wrap .svg-funnel-js__labels {
    display: flex;
    width: 100%;
}
.funnel-canvas-wrap .svg-funnel-js__labels .svg-funnel-js__label {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
    display: grid;
    justify-items: center;
    align-content: start;
    padding-top: 4px;
}
.funnel-canvas-wrap .svg-funnel-js__labels .label__title {
    font-size: 24px;
    font-weight: 800;
    color: #233b33;
}
.funnel-canvas-wrap .svg-funnel-js__labels .label__value {
    font-size: 13px;
    font-weight: 700;
    color: #2f2f2f;
}
.funnel-canvas-wrap .svg-funnel-js__labels .label__percentage {
    font-size: 12px;
    font-weight: 700;
    color: #4f5f58;
}

.order-timeline { display: flex; gap: 12px; flex-wrap: wrap; }
.timeline-step { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.timeline-step .dot { width: 12px; height: 12px; border-radius: 999px; background: #d9d1c3; }
.timeline-step.done { color: var(--ink); font-weight: 700; }
.timeline-step.done .dot { background: var(--pine); }
.timeline-step.failed .dot { background: var(--danger); }

.funnel-steps { display: grid; gap: 8px; }
.funnel-step { display: flex; justify-content: space-between; border: 1px solid #ebe2d6; border-radius: 8px; padding: 8px 10px; background: #fffdf9; }

.admin-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
}
.admin-modal[hidden] {
    display: none !important;
}
.admin-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(28, 27, 25, 0.45);
}
.admin-modal-panel {
    position: relative;
    width: min(760px, calc(100% - 24px));
    max-height: calc(100vh - 24px);
    overflow: auto;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e8ddcc;
    box-shadow: var(--shadow);
    padding: 16px;
}

@media (max-width: 980px) {
    .admin-mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        position: sticky;
        top: 0;
        z-index: 32;
        background: rgba(250, 247, 242, 0.98);
        border-bottom: 1px solid var(--line);
        padding: 8px 12px;
    }
    .admin-nav-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(20, 20, 20, 0.42);
        z-index: 24;
    }
    body.admin-nav-open { overflow: hidden; }
    body.admin-nav-open .admin-nav-backdrop { display: block; }

    .admin-shell { grid-template-columns: 1fr; }
    .admin-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(82vw, 280px);
        z-index: 30;
        overflow-y: auto;
        transform: translateX(-105%);
        transition: transform 0.22s ease;
        box-shadow: 10px 0 24px rgba(0, 0, 0, 0.18);
    }
    body.admin-nav-open .admin-sidebar {
        transform: translateX(0);
    }
    .admin-main { padding: 12px; }
    .admin-header { gap: 8px; }
    .action-bar { top: 4px; }
    .status-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .charts-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .charts-grid .card.funnel-card { width: 100%; }
    .funnel-canvas-wrap { width: 100%; }
    .charts-grid .card.funnel-card { min-height: 360px; }
    .funnel-canvas-wrap { height: 280px; }
}

@media (max-width: 640px) {
    .status-overview { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
    .charts-grid .card.funnel-card { min-height: 320px; }
    .funnel-canvas-wrap { height: 220px; }
    .funnel-canvas-wrap .svg-funnel-js__labels .label__title { font-size: 18px; }
}

/* Login card */
.login-card { max-width: 400px; margin: 80px auto; background: var(--panel); border-radius: var(--r); box-shadow: var(--shadow); padding: 24px; border: 1px solid #f1ece3; }
.login-card h1 { text-align: center; margin-bottom: 16px; }
.login-card form { display: grid; gap: 10px; }
.login-card label { font-weight: 700; }
.login-card input { width: 100%; min-height: 40px; border: 1px solid #ddd3c3; border-radius: 10px; padding: 10px; background: #fcfaf7; font-family: inherit; }

/* Category list */
.category-list { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 10px; }
.category-item { display: flex; gap: 8px; align-items: flex-start; background: #faf7f1; border: 1px solid #efe5d8; border-radius: 10px; padding: 10px; }
.category-item .admin-form { flex: 1; margin: 0; }

/* Promo builder */
.promo-builder {
    background: linear-gradient(180deg, #fdfaf4 0%, #fff 100%);
    border: 1px solid #e9dfd0;
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
}
.promo-grid-2,
.promo-grid-3,
.promo-grid-4 {
    display: grid;
    gap: 10px;
    margin-bottom: 10px;
}
.promo-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.promo-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.promo-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.promo-builder .checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 10px;
    border: 1px solid #ebdfd1;
    border-radius: 10px;
    background: #fff;
    font-weight: 600;
}
.promo-builder select[multiple] {
    min-height: 180px;
    background: #fff;
}
.promo-details-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.promo-details-grid > div {
    border: 1px solid #ece2d4;
    border-radius: 10px;
    background: #fffdf9;
    padding: 8px 10px;
}
.promo-details-grid p {
    margin: 4px 0 0;
    word-break: break-word;
}

:root[data-theme="dark"] .promo-builder {
    background: linear-gradient(180deg, #23282b 0%, #1f2427 100%);
    border-color: #3b4248;
}
:root[data-theme="dark"] .promo-builder .checkbox-row {
    border-color: #414b52;
    background: #1c2023;
}
:root[data-theme="dark"] .promo-details-grid > div {
    border-color: #414b52;
    background: #1f2427;
}

:root[data-theme="dark"] .category-item {
    background: #212629;
    border-color: #3b4248;
}

:root[data-theme="dark"] .funnel-step {
    background: #212629;
    border-color: #3b4248;
}

/* Form row */
.form-row { display: flex; gap: 8px; align-items: center; }
.form-row input { flex: 1; }

/* Sidebar hover/focus */
.admin-sidebar a:hover { background: rgba(76, 122, 105, 0.12); }
.admin-sidebar a:focus-visible { outline: 3px solid var(--pine); outline-offset: 2px; }

/* Admin max width */
.admin-main { max-width: 1400px; }

@media (max-width: 640px) {
    .promo-grid-2,
    .promo-grid-3,
    .promo-grid-4 {
        grid-template-columns: 1fr;
    }
    .promo-details-grid {
        grid-template-columns: 1fr;
    }
}

/* Print styles */
@media print {
    .admin-sidebar, .admin-mobile-topbar, .admin-nav-backdrop, .action-bar .btn { display: none !important; }
    .admin-shell { grid-template-columns: 1fr; }
    .admin-main { padding: 12px; }
}
