:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #1a1f26;
    --muted: #6b7280;
    --border: #e2e5e9;
    --accent: #2563eb;
    --accent-soft: #eaf1ff;
    --danger: #dc2626;
    --success: #16a34a;
}

:root[data-theme="dark"] {
    --bg: #17191c;
    --surface: #24272b;
    --text: #f2f3f5;
    --muted: #9aa0a6;
    --border: #34383d;
    --accent: #4f8cff;
    --accent-soft: #1d2a42;
    --danger: #f87171;
    --success: #34d399;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #17191c;
        --surface: #24272b;
        --text: #f2f3f5;
        --muted: #9aa0a6;
        --border: #34383d;
        --accent: #4f8cff;
        --accent-soft: #1d2a42;
        --danger: #f87171;
        --success: #34d399;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    padding-bottom: 96px;
}

.hidden { display: none !important; }

/* ---- Loading / error screens ------------------------------------- */

.loading-screen, .error-screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    padding: 24px;
}

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

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

.error-emoji { font-size: 40px; margin: 0; }

.retry-button {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
}

/* ---- App shell ----------------------------------------------------- */

#app { padding: 16px; }

.app-header { margin-bottom: 20px; }
.app-header h1 { font-size: 20px; margin: 0; }

.field { margin-bottom: 20px; position: relative; }

.field-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 8px;
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
}

.field input[type="text"] {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
}

.dropdown-list {
    position: absolute;
    z-index: 10;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-top: 6px;
    max-height: 220px;
    overflow-y: auto;
    display: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.dropdown-list.open { display: block; }

.dropdown-item {
    padding: 14px;
    cursor: pointer;
    font-size: 15px;
}

.dropdown-item:hover { background: var(--accent-soft); }

/* ---- Category cards ------------------------------------------------ */

.category-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 12px;
    overflow: hidden;
}

.category-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

.category-icon { font-size: 20px; }
.category-name { flex: 1; }

.category-count {
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 999px;
}

.chevron {
    color: var(--muted);
    transition: transform 0.2s ease;
}

.category-card.open .chevron { transform: rotate(180deg); }

.category-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.product-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s ease;
    min-height: 48px;
}

.product-row:active { background: var(--accent-soft); }
.product-row.selected { background: var(--accent-soft); }

.product-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.product-name { font-size: 15px; }
.product-price { font-size: 13px; color: var(--muted); }

.stepper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
}

.stepper-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

.stepper-value {
    min-width: 20px;
    text-align: center;
    font-size: 15px;
    font-weight: 600;
}

/* ---- Summary --------------------------------------------------------- */

.summary {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
}

.summary h3 { margin: 0 0 12px; font-size: 15px; }

.summary-empty { color: var(--muted); font-size: 14px; }

.summary-item {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.summary-totals {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    font-size: 15px;
}

.advance-row { color: var(--muted); font-size: 14px; }

.balance-row {
    font-weight: 700;
    color: var(--accent);
    border-top: 1px dashed var(--border);
    padding-top: 8px;
    margin-top: 4px;
}

.advance-inputs {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.advance-inputs input {
    flex: 1;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
}

/* ---- Toast ------------------------------------------------------------ */

.toast {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    padding: 14px;
    border-radius: 12px;
    text-align: center;
    font-size: 14px;
    color: #fff;
    transform: translateY(120%);
    transition: transform 0.25s ease;
    z-index: 100;
}

.toast.show { transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
