:root {
    --bg: #eef3fb;
    --bg-elevated: #ffffff;
    --bg-sidebar: #0b1730;
    --text: #162338;
    --text-muted: #5e6f89;
    --text-inverse: #e8efff;
    --border: #d6dfed;
    --primary: #1862d8;
    --primary-contrast: #f7fbff;
    --danger: #c63f4f;
    --success: #1f7e4b;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 8px 20px rgba(21, 38, 66, 0.08);
    --shadow-md: 0 14px 30px rgba(21, 38, 66, 0.1);
}

html[data-theme="dark"] {
    --bg: #0d1627;
    --bg-elevated: #152238;
    --bg-sidebar: #080f1f;
    --text: #e4ecf8;
    --text-muted: #9eb0ce;
    --text-inverse: #e7efff;
    --border: #2a3850;
    --primary: #4b8ff8;
    --primary-contrast: #edf5ff;
    --danger: #dd6f7b;
    --success: #52c88b;
    --shadow-sm: 0 12px 26px rgba(2, 8, 17, 0.42);
    --shadow-md: 0 18px 36px rgba(2, 8, 17, 0.5);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    background: radial-gradient(circle at top left, rgba(24, 98, 216, 0.09), transparent 40%), var(--bg);
    color: var(--text);
}

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

/* Layout */
.app-shell {
    display: flex;
    min-height: 100dvh;
}

.sidebar {
    width: 240px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--bg-sidebar) 95%, #0f2241 5%), var(--bg-sidebar));
    color: var(--text-inverse);
    border-right: 1px solid color-mix(in srgb, #fff 12%, transparent);
    padding: 0.85rem 0.72rem;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 0.72rem;
    transform: translateX(0);
    transition: transform 0.2s ease;
}

.sidebar-brand {
    border-bottom: 1px solid color-mix(in srgb, #fff 12%, transparent);
    padding-bottom: 0.65rem;
}

.shop-logo {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    object-fit: cover;
    border: 1px solid color-mix(in srgb, #fff 25%, transparent);
    margin-bottom: 0.55rem;
}

.brand {
    font-size: 1.04rem;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.sidebar-nav {
    min-height: 0;
    overflow-y: auto;
    padding-right: 0.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
}

.nav-section {
    margin: 0.72rem 0 0.1rem;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: color-mix(in srgb, var(--text-inverse) 63%, #8ea9d8 37%);
}

.nav-link {
    display: block;
    padding: 0.46rem 0.56rem;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    color: color-mix(in srgb, var(--text-inverse) 86%, #8ea9d8 14%);
}

.nav-link:hover {
    background: color-mix(in srgb, #fff 8%, transparent);
    color: #fff;
}

.nav-link.is-active {
    background: color-mix(in srgb, #fff 16%, transparent);
    color: #fff;
    font-weight: 700;
}

.sidebar-footer {
    border-top: 1px solid color-mix(in srgb, #fff 12%, transparent);
    padding-top: 0.55rem;
    display: flex;
    flex-direction: column;
    gap: 0.46rem;
}

.user-meta {
    display: flex;
    flex-direction: column;
    gap: 0.08rem;
}

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

.sidebar .text-muted {
    color: color-mix(in srgb, var(--text-inverse) 74%, #90a8d5 26%);
}

.small {
    font-size: 0.82rem;
}

.app-main {
    margin-left: 240px;
    width: calc(100% - 240px);
    min-height: 100dvh;
}

.desktop-topbar {
    position: sticky;
    top: 0;
    z-index: 24;
    background: color-mix(in srgb, var(--bg-elevated) 94%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 0.95rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}

.topbar-kicker {
    margin: 0;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.topbar-title {
    margin: 0.15rem 0 0;
    font-size: 1rem;
}

.topbar-tools {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
}

.theme-icon {
    position: absolute;
    font-size: 14px;
    line-height: 1;
}

.theme-moon {
    opacity: 0;
}

html[data-theme="dark"] .theme-sun {
    opacity: 0;
}

html[data-theme="dark"] .theme-moon {
    opacity: 1;
}

.user-chip {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.15;
}

.user-chip span {
    font-size: 0.76rem;
    color: var(--text-muted);
}

.user-chip span:empty {
    display: none;
}

.mobile-topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 22;
    background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
    backdrop-filter: blur(9px);
    border-bottom: 1px solid var(--border);
    padding: 0.65rem 0.8rem;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.content-area {
    width: 100%;
    margin: 0;
    padding: 1rem 0.9rem 1.4rem;
}

/* Base Components */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 0.82rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.82rem;
}

.page-head h2,
.page-head-row h2 {
    margin: 0;
    font-size: 1.36rem;
}

.page-head p {
    margin: 0.4rem 0 0;
    color: var(--text-muted);
}

.page-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
    margin-bottom: 0.8rem;
}

.metric {
    margin: 0.28rem 0 0.8rem;
    font-size: 1.72rem;
    font-weight: 700;
}

.metric-label {
    margin: 0;
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.metric-value {
    margin: 0.22rem 0 0;
    font-size: 1.24rem;
    font-weight: 700;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.38rem;
}

label {
    font-size: 0.84rem;
    color: var(--text-muted);
}

input,
textarea,
select {
    width: 100%;
    padding: 0.56rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    color: var(--text);
    font: inherit;
}

.btn {
    border: 0;
    border-radius: var(--radius-md);
    padding: 0.48rem 0.74rem;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-sm {
    padding: 0.28rem 0.44rem;
    font-size: 0.72rem;
    border-radius: var(--radius-sm);
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-contrast);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

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

.sidebar .btn-ghost {
    border-color: color-mix(in srgb, #fff 14%, transparent);
    color: var(--text-inverse);
}

.full {
    width: 100%;
}

.inline-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.58rem;
}

.alert {
    border-radius: var(--radius-md);
    border: 1px solid;
    padding: 0.56rem 0.7rem;
    margin-bottom: 0.8rem;
    font-size: 0.84rem;
}

.alert-success {
    color: var(--success);
    border-color: color-mix(in srgb, var(--success) 35%, var(--border));
    background: color-mix(in srgb, var(--success) 8%, transparent);
}

.alert-danger {
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
    background: color-mix(in srgb, var(--danger) 8%, transparent);
}

/* Tables */
.form-card,
.table-card {
    overflow: hidden;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
}

.data-table th,
.data-table td {
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
    padding: 0.48rem;
    font-size: 0.82rem;
}

.data-table th {
    color: var(--text-muted);
    font-weight: 600;
}

.table-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 1rem;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.24rem;
    align-items: center;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.16rem 0.42rem;
    font-size: 0.7rem;
    font-weight: 700;
}

.status-active {
    background: color-mix(in srgb, var(--success) 18%, transparent);
    color: var(--success);
}

.status-inactive {
    background: color-mix(in srgb, var(--danger) 16%, transparent);
    color: var(--danger);
}

/* Filters */
.filter-card {
    margin-bottom: 0.75rem;
}

.filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.46rem;
    align-items: end;
}

.filters-row input,
.filters-row select {
    flex: 1 1 190px;
    min-width: 160px;
}

.filters-row .btn {
    flex: 0 0 auto;
}

/* POS */
.full-span {
    grid-column: 1 / -1;
}

.pos-table input,
.pos-table select {
    min-width: 92px;
}

.pos-density th,
.pos-density td {
    padding: 0.36rem;
    font-size: 0.74rem;
}

.pos-density input,
.pos-density select {
    padding: 0.24rem 0.3rem;
    font-size: 0.72rem;
    border-radius: 8px;
}

.pos-density .btn-sm {
    padding: 0.18rem 0.3rem;
    font-size: 0.64rem;
}

.totals-box {
    display: flex;
    flex-wrap: wrap;
    gap: 0.9rem;
    background: color-mix(in srgb, var(--bg-elevated) 92%, var(--primary) 8%);
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 0.55rem;
}

.pos-totals {
    justify-content: flex-end;
}

.pos-totals > div {
    min-width: 132px;
    text-align: right;
}

/* Sales */
.sales-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.65rem;
    margin-bottom: 0.75rem;
}

.metric-card {
    min-height: 84px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0.7rem;
}

.invoice-table-compact th,
.invoice-table-compact td {
    padding: 0.42rem;
    font-size: 0.78rem;
}

/* Settings */
.settings-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.settings-card {
    max-width: 600px;
}

.settings-card h3 {
    margin: 0 0 0.68rem;
}

.settings-actions {
    display: flex;
    justify-content: flex-end;
    grid-column: 1 / -1;
}

.settings-actions .btn {
    min-width: 152px;
}

/* Print */
.print-body {
    background: #fff;
    color: #111;
}

.print-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
}

.invoice-print-head {
    display: flex;
    justify-content: flex-end;
    gap: 0.4rem;
    margin-bottom: 0.7rem;
}

.invoice-sheet {
    border: 1px solid #d7deeb;
    border-radius: 12px;
    padding: 0.8rem;
}

.invoice-sheet-head {
    display: flex;
    justify-content: space-between;
    gap: 0.9rem;
    margin-bottom: 0.7rem;
}

.invoice-summary {
    margin-top: 0.7rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.8rem;
    flex-wrap: wrap;
}

/* Auth */
.auth-shell {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.auth-card {
    width: min(500px, 100%);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.1rem;
}

.auth-brand h1 {
    margin: 0 0 0.32rem;
}

.auth-brand p,
.help-text {
    margin-top: 0;
    color: var(--text-muted);
}

.auth-link {
    color: var(--primary);
    font-weight: 600;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 11, 22, 0.45);
    backdrop-filter: blur(2px);
    z-index: 50;
}

@media (min-width: 1024px) {
    .form-card .form-stack {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.8rem;
    }

    .form-card .field,
    .form-card textarea,
    .form-card button[type="submit"] {
        min-width: 0;
    }

    .form-card textarea,
    .form-card button[type="submit"],
    .form-card .full-span,
    .settings-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 920px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .app-main {
        margin-left: 0;
        width: 100%;
    }

    .desktop-topbar {
        display: none;
    }

    .mobile-topbar {
        display: flex;
    }

    .content-area {
        padding: 0.9rem 0.75rem 1.3rem;
    }

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

    body.sidebar-open .sidebar-overlay {
        display: block;
    }
}

@media (max-width: 720px) {
    .page-head-row {
        flex-direction: column;
        align-items: flex-start;
    }

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

    .filters-row input,
    .filters-row select,
    .filters-row .btn,
    .settings-actions .btn {
        width: 100%;
        min-width: 0;
    }

    .data-table {
        min-width: 560px;
    }

    .data-table th,
    .data-table td {
        font-size: 0.74rem;
        padding: 0.4rem;
    }

    .btn-sm {
        font-size: 0.68rem;
        padding: 0.22rem 0.36rem;
    }

    .status-badge {
        font-size: 0.64rem;
        padding: 0.14rem 0.34rem;
    }

    .invoice-sheet-head {
        flex-direction: column;
    }
}

@media print {
    .no-print {
        display: none !important;
    }

    .invoice-sheet {
        border: 0;
        padding: 0;
    }
}
