:root {
    color-scheme: light;
    --bg: #fcf8f5;
    --bg-elevated: #ffffff;
    --surface: #ffffff;
    --surface-hover: #f7f2ed;
    --border: #e6ddd4;
    --border-light: #efe9e3;
    --text: #1a1a1a;
    --text-muted: #6b6560;
    --accent: #d53a3d;
    --accent-dark: #6e0006;
    --accent-glow: rgba(213, 58, 61, 0.14);
    --blue: #232323;
    --green: #428445;
    --red: #eb001b;
    --orange: #c45a2a;
    --radius: 14px;
    --shadow: 0 4px 24px rgba(26, 26, 26, 0.08);
    --font: 'Roboto', system-ui, sans-serif;
    --font-heading: 'Montserrat', 'Roboto', system-ui, sans-serif;
    --mono: ui-monospace, 'Cascadia Code', monospace;
    --sidebar-width: 280px;
    --header-height: 64px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

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

h1, h2, .section-title {
    font-family: var(--font-heading);
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { color: var(--accent); text-decoration: underline; }

code {
    font-family: var(--mono);
    font-size: 0.88em;
    background: rgba(110, 0, 6, 0.06);
    color: var(--accent-dark);
    padding: 0.15em 0.4em;
    border-radius: 4px;
}

/* ── Login ── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background:
        radial-gradient(ellipse 70% 50% at 50% -5%, rgba(213, 58, 61, 0.07), transparent),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 420px;
    margin: 1.5rem;
    padding: 2.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-light);
}

.brand-logo {
    height: 52px;
    width: auto;
    max-width: 220px;
    object-fit: contain;
}

.brand h1 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-muted);
}

.brand p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.login-form label {
    display: block;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.login-form input {
    display: block;
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.login-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.88rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: #fde0e4;
    border: 1px solid rgba(235, 0, 27, 0.25);
    color: #a80018;
}

.alert-warn {
    background: #fbf6ea;
    border: 1px solid rgba(224, 178, 82, 0.35);
    color: #8a6914;
}

/* ── Layout ── */
.app-header {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: var(--header-height);
    padding: 0.75rem 1.5rem;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.app-body {
    display: flex;
    flex: 1;
    min-height: 0;
    width: 100%;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

.sidebar-heading {
    margin: 1.25rem 0 0.5rem;
    padding: 0 0.75rem;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 600;
    font-family: var(--font-heading);
}

.sidebar-heading:first-child {
    margin-top: 0.25rem;
}

.sidebar-link {
    appearance: none;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    border: none;
    background: transparent;
    color: var(--text);
    border-radius: 10px;
    padding: 0.62rem 0.75rem;
    cursor: pointer;
    font: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
    background: var(--surface-hover);
}

.sidebar-link.active {
    background: rgba(110, 0, 6, 0.08);
    color: var(--accent-dark);
    font-weight: 600;
}

.sidebar-icon {
    width: 1.1rem;
    flex-shrink: 0;
    opacity: 0.55;
    font-size: 0.82rem;
    text-align: center;
}

.sidebar-link.active .sidebar-icon {
    opacity: 1;
}

.sidebar-count {
    margin-left: auto;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: 999px;
    padding: 0.1rem 0.45rem;
    font-variant-numeric: tabular-nums;
}

.sidebar-link.active .sidebar-count {
    color: var(--accent-dark);
    border-color: rgba(110, 0, 6, 0.15);
    background: rgba(110, 0, 6, 0.06);
}

.sidebar-footer {
    padding: 1rem 0.75rem;
    border-top: 1px solid var(--border-light);
    background: var(--bg);
}

.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 1.25rem;
    left: 1.25rem;
    z-index: 70;
    width: 48px;
    height: 48px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text);
}

.content {
    flex: 1;
    min-width: 0;
    padding: 1.5rem 2rem 2rem;
    width: 100%;
}

.content-view {
    width: 100%;
}

.content-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.content-header h2 {
    margin: 0 0 0.35rem;
    font-size: 1.35rem;
    font-weight: 700;
}

.content-lead {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
    max-width: 720px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-brand .brand-logo {
    height: 42px;
}

.header-brand-text span {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 400;
    font-family: var(--font);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.user-chip strong { color: var(--text); }

.section-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin: 0 0 0.75rem;
    font-weight: 600;
}

/* ── Buttons ── */
.btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
    padding: 0.55rem 1rem;
    text-decoration: none;
    cursor: pointer;
    font: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--surface-hover);
    border-color: #d5ccc3;
    text-decoration: none;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    color: var(--text);
    background: var(--surface-hover);
    border-color: transparent;
}

.btn-block { width: 100%; justify-content: center; }

.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }

.btn-icon {
    padding: 0.45rem;
    min-width: 36px;
    justify-content: center;
}

/* ── Cards & metrics ── */
.metrics-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    margin-bottom: 0;
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.15rem;
    position: relative;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(26, 26, 26, 0.04);
}

.metric-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--card-accent, var(--border));
}

.metric-card.accent-yellow { --card-accent: var(--accent); }
.metric-card.accent-blue { --card-accent: var(--accent-dark); }
.metric-card.accent-green { --card-accent: var(--green); }
.metric-card.accent-orange { --card-accent: var(--orange); }

.metric-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    font-weight: 600;
    font-family: var(--font-heading);
}

.metric-value {
    font-size: 1.85rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-heading);
}

.metric-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.status-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: var(--font-heading);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--orange);
    flex-shrink: 0;
}

.status-dot.ok {
    background: var(--green);
    box-shadow: 0 0 8px rgba(66, 132, 69, 0.4);
}

.panel-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 3px rgba(26, 26, 26, 0.04);
}

.panel-card-flush {
    padding: 0;
    overflow: hidden;
}

.panel-card-flush .table-wrap {
    border: none;
    border-radius: 0;
}

.panel-card-flush .tree-toolbar,
.panel-card-flush #category-tree-root {
    padding: 1rem 1.25rem;
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--border-light);
    background: var(--bg);
}

.panel-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.panel-card-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.cache-badge {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 0.25rem 0.6rem;
    background: var(--bg);
    border-radius: 999px;
    border: 1px solid var(--border);
}

/* ── Export table ── */
.export-table .export-name {
    font-weight: 600;
    white-space: nowrap;
    font-family: var(--font-heading);
}

.export-table .export-url {
    min-width: 280px;
}

.export-table .export-url code {
    display: block;
    word-break: break-all;
    white-space: normal;
    background: transparent;
    padding: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.export-table .export-count {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--text-muted);
    font-weight: 600;
}

.export-table .export-actions {
    white-space: nowrap;
    display: flex;
    gap: 0.35rem;
}

/* ── Table ── */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

table.data-table th,
table.data-table td {
    text-align: left;
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border-light);
}

table.data-table th {
    background: var(--bg);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    font-family: var(--font-heading);
}

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover td { background: var(--surface-hover); }

.table-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.65rem;
}

.table-footer .table-meta {
    margin-top: 0;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 0.85rem;
    flex-wrap: wrap;
}

.page-info {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 140px;
    text-align: center;
}

/* ── Category tree ── */
.tree-toolbar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 1rem;
}

.tree-search {
    flex: 1;
    min-width: 200px;
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
}

.tree-search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.category-tree {
    list-style: none;
    margin: 0;
    padding: 0;
}

.category-tree ul {
    list-style: none;
    margin: 0;
    padding-left: 1.35rem;
    border-left: 1px solid var(--border);
    margin-left: 0.65rem;
}

.tree-node {
    margin: 0.15rem 0;
}

.tree-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    border-radius: 6px;
    cursor: default;
}

.tree-row:hover { background: var(--surface-hover); }

.tree-toggle {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    width: 20px;
    height: 20px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 4px;
    font-size: 0.7rem;
}

.tree-toggle:hover { background: var(--border-light); color: var(--text); }
.tree-toggle.hidden { visibility: hidden; }

.tree-ref {
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--accent-dark);
    min-width: 5rem;
}

.tree-name {
    flex: 1;
    font-size: 0.88rem;
}

.tree-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.tree-badge.has-products {
    background: #e8f0e9;
    border-color: rgba(66, 132, 69, 0.3);
    color: var(--green);
}

.tree-children.collapsed { display: none; }

.tree-empty {
    color: var(--text-muted);
    font-size: 0.88rem;
    padding: 1.5rem;
    text-align: center;
}

/* ── Toast / error ── */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    max-width: 420px;
    padding: 0.85rem 1.1rem;
    background: var(--accent-dark);
    color: #fff;
    border-radius: var(--radius);
    font-size: 0.88rem;
    box-shadow: var(--shadow);
    z-index: 100;
    animation: slideIn 0.25s ease;
}

.toast[hidden] { display: none; }

@keyframes slideIn {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(252, 248, 245, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.loading-overlay[hidden] { display: none; }

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 960px) {
    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        z-index: 55;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: var(--shadow);
    }

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

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .content {
        padding: 1rem;
    }

    .cache-badge {
        display: none;
    }
}

@media (max-width: 640px) {
    .header-brand-text { display: none; }
    .metrics-grid { grid-template-columns: 1fr 1fr; }
    .header-brand .brand-logo { height: 34px; }
    .table-footer {
        flex-direction: column;
        align-items: stretch;
    }
    .export-table .export-actions {
        flex-direction: column;
    }
}
