:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --text: #1a1d26;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --border: #e5e7eb;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

button, .btn, .product-btn, a.btn { touch-action: manipulation; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

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

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
    padding: 0.6rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); white-space: nowrap; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

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

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.page-header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.inline-form { display: inline; }

.btn-lg { padding: 0.85rem 1.25rem; font-size: 1rem; min-height: 48px; }
.btn-block { width: 100%; }

.form-group { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: 0.35rem; font-size: 0.9rem; }
input, select, textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    min-height: 44px;
    font-size: 16px;
}
textarea { min-height: auto; }

.card:has(table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
th, td { padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--border); text-align: left; }
th { font-size: 0.8rem; text-transform: uppercase; color: var(--muted); }

.stat { font-size: 1.75rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.875rem; }

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: var(--primary);
    color: #fff;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    min-height: 44px;
    line-height: 1.2;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.875rem; min-height: 36px; }

.topbar-start { display: flex; align-items: center; gap: 0.75rem; min-width: 0; flex-shrink: 0; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    margin-left: auto;
}

.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
}
.nav-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    margin: 0 auto;
    background: var(--text);
    border-radius: 1px;
}

.topbar-nav {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 0.75rem;
    min-width: 0;
}

.nav-primary {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-wrap: wrap;
    min-width: 0;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.7rem;
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
}
.nav-link:hover {
    background: var(--bg);
    text-decoration: none;
    color: var(--text);
}
.nav-link.is-active {
    background: #dbeafe;
    color: var(--primary);
    font-weight: 600;
}

.nav-dropdown { position: relative; }
.nav-dropdown-toggle,
.nav-user-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.7rem;
    border: none;
    border-radius: var(--radius);
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.nav-dropdown-toggle:hover,
.nav-user-toggle:hover { background: var(--bg); }
.nav-dropdown-toggle.is-active { background: #dbeafe; color: var(--primary); }

.nav-caret { font-size: 0.65rem; opacity: 0.7; }

.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 190px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 80;
    padding: 0.35rem;
}
.nav-dropdown.is-open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu .nav-link {
    display: block;
    width: 100%;
    text-align: left;
}

.nav-pos-btn { font-weight: 600; white-space: nowrap; }
.nav-pos-btn.is-active { box-shadow: inset 0 0 0 2px rgba(255,255,255,0.35); }

.nav-user-toggle { padding-right: 0.5rem; }
.nav-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}
.nav-user-menu { right: 0; left: auto; padding: 0.75rem; }
.nav-user-meta { margin-bottom: 0.75rem; }
.nav-user-meta strong { display: block; }
.nav-user-meta small { color: var(--muted); font-size: 0.8rem; word-break: break-all; }

.nav-mobile-sections { display: none; }
.nav-section-label {
    margin: 0.75rem 0 0.35rem;
    padding: 0 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

body.nav-open { overflow: hidden; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #f3f4f6; color: #4b5563; }
.badge-suspended { background: #fee2e2; color: #991b1b; }
.badge-pending { background: #fef9c3; color: #854d0e; }

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: flex-start;
}

.inline-form { display: inline; margin: 0; }

.inline-form-details {
    display: inline-block;
    position: relative;
}

.inline-form-details summary {
    list-style: none;
    cursor: pointer;
}

.inline-form-details summary::-webkit-details-marker { display: none; }

.inline-form-panel {
    position: absolute;
    z-index: 10;
    right: 0;
    margin-top: 0.35rem;
    min-width: 16rem;
    padding: 0.75rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.inline-form-panel label { display: block; font-size: 0.875rem; }

.inline-form-panel input[type="password"] {
    width: 100%;
    margin-top: 0.25rem;
}

.checkbox-inline {
    display: flex !important;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.875rem;
}

.container-narrow {
    max-width: 40rem;
    margin: 2rem auto;
}

.alert-warning {
    background: #fef9c3;
    color: #854d0e;
    border: 1px solid #fde047;
    border-radius: 0.375rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.totp-setup {
    text-align: center;
    margin: 1rem 0;
}

.totp-secret {
    display: inline-block;
    padding: 0.35rem 0.5rem;
    background: #f3f4f6;
    border-radius: 0.25rem;
    font-size: 0.95rem;
    letter-spacing: 0.05em;
    word-break: break-all;
}

.nav-dropdown-link {
    display: block;
    padding: 0.5rem 0.75rem;
    color: inherit;
    text-decoration: none;
}

.nav-dropdown-link:hover {
    background: #f3f4f6;
}

.receipt-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.receipt-email-form .form-group {
    margin-bottom: 0.5rem;
}

.receipt-email-form input[type="email"] {
    width: 100%;
}

.help-icon {
    display: inline-flex;
    width: 1.1rem;
    height: 1.1rem;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--border);
    color: var(--muted);
    font-size: 0.75rem;
    cursor: help;
    margin-left: 0.25rem;
}

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

/* POS layout */
body.layout-pos { background: #111827; color: #f9fafb; padding-bottom: env(safe-area-inset-bottom, 0); }
.layout-pos .container { max-width: none; padding: 0.75rem; padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0)); }
.layout-pos .topbar { background: #1f2937; border-color: #374151; }
.layout-pos .brand, .layout-pos .nav-link, .layout-pos .nav-dropdown-toggle, .layout-pos .nav-user-toggle { color: #f9fafb; }
.layout-pos .nav-link:hover, .layout-pos .nav-dropdown-toggle:hover, .layout-pos .nav-user-toggle:hover { background: #374151; }
.layout-pos .nav-link.is-active, .layout-pos .nav-dropdown-toggle.is-active { background: #374151; color: #93c5fd; }
.layout-pos .nav-dropdown-menu { background: #1f2937; border-color: #374151; }
.layout-pos .btn-secondary { background: #374151; color: #f9fafb; border-color: #4b5563; }
.layout-pos .card { background: #1f2937; border-color: #374151; color: #f9fafb; }
.layout-pos input, .layout-pos select, .layout-pos textarea {
    background: #111827;
    border-color: #4b5563;
    color: #f9fafb;
}

.pos-layout { display: grid; grid-template-columns: 1fr 340px; gap: 1rem; align-items: start; }
.pos-catalog { min-width: 0; }
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}
.product-btn {
    text-align: left;
    cursor: pointer;
    border: 1px solid #374151;
    background: #1f2937;
    color: #f9fafb;
    padding: 0.85rem;
    border-radius: var(--radius);
    min-height: 72px;
    font: inherit;
}
.product-btn:active { transform: scale(0.98); }
.pos-search { width: 100%; padding: 0.75rem; margin-bottom: 0.5rem; font-size: 16px; }
.pos-barcode-input { margin-top: 0.35rem; }

.pos-cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.pos-cart-header h2 { margin: 0; }
.pos-cart-close { display: none; }

.cart-items-scroll { max-height: 40vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.cart-line { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.65rem 0; border-bottom: 1px solid #374151; }
.cart-qty { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.35rem; }
.cart-qty button {
    width: 36px;
    height: 36px;
    border: 1px solid #4b5563;
    border-radius: var(--radius);
    background: #374151;
    color: #f9fafb;
    font-size: 1.1rem;
    cursor: pointer;
}
.cart-totals div { display: flex; justify-content: space-between; padding: 0.15rem 0; }
.cart-total-row { font-size: 1.15rem; margin-top: 0.5rem; font-weight: 700; }
.pos-pay-buttons { display: grid; gap: 0.5rem; margin-top: 0.75rem; }
.discount-row { display: flex; gap: 0.35rem; margin: 0.5rem 0; flex-wrap: wrap; }
.discount-row select, .discount-row input { flex: 1; min-width: 80px; }
.order-notes { width: 100%; margin: 0.5rem 0; min-height: 64px; }
.split-payment-details { margin-top: 0.75rem; }
.stripe-hint { color: #9ca3af; }

.customer-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
    margin-bottom: 0.5rem;
}
.customer-row .pos-search { flex: 1; margin-bottom: 0; }
.customer-row .btn { flex-shrink: 0; align-self: stretch; white-space: nowrap; }

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.pos-mobile-bar {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0));
    background: #1f2937;
    border-top: 1px solid #374151;
    gap: 0.75rem;
    align-items: center;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.25);
}
.pos-mobile-summary { flex: 1; min-width: 0; }
.pos-mobile-summary strong { display: block; font-size: 1.2rem; }
.pos-mobile-summary span { color: #9ca3af; font-size: 0.85rem; }
.pos-mobile-bar .btn { flex-shrink: 0; min-width: 110px; }

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
    z-index: 200;
}
.modal[hidden] { display: none; }
.modal-content {
    width: 100%;
    max-width: 360px;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.parked-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    flex-wrap: wrap;
}
.parked-item-info {
    flex: 1;
    min-width: 0;
}
.parked-item-info small {
    display: block;
    color: var(--muted);
}
.parked-item-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}
.delete-parked-btn {
    min-width: 2rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    font-size: 1.1rem;
    line-height: 1;
}

.text-muted { color: var(--muted); margin-top: 0; }
.login-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}
.login-card-header h1 { margin: 0; }
.locale-switcher {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}
.locale-btn {
    min-width: 2.25rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}
.locale-btn.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
@media (max-width: 900px) {
    .topbar-actions > .locale-switcher { display: none; }
}
@media (min-width: 901px) {
    .nav-mobile-user .locale-switcher { display: none; }
}
.form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.settings-receipts-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    gap: 1rem;
    align-items: start;
}
.receipt-preview-card { position: sticky; top: 1rem; }
.receipt-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.receipt-preview-header h2 { margin: 0; font-size: 1.1rem; }
.receipt-preview-pane {
    background: #fafafa;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    min-height: 320px;
    overflow: auto;
}
.receipt-preview-pane.is-loading { opacity: 0.55; }
@media (max-width: 900px) {
    .settings-receipts-layout { grid-template-columns: 1fr; }
    .receipt-preview-card { position: static; }
}

.help-panel { position: fixed; right: 0; top: 0; bottom: 0; width: 280px; background: var(--surface); border-left: 1px solid var(--border); padding: 1rem; box-shadow: var(--shadow); z-index: 100; }
.help-panel[hidden] { display: none; }

.impersonation-banner { background: #fef3c7; color: #92400e; padding: 0.5rem 1.5rem; text-align: center; border-bottom: 1px solid #fcd34d; }
.checklist { list-style: none; padding: 0; }
.checklist li { padding: 0.35rem 0; }
.checklist li.done { color: var(--success); }
.progress-bar { height: 8px; background: var(--border); border-radius: 4px; margin-top: 0.75rem; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); transition: width 0.3s; }
.tour-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 200; }
.tour-tooltip { position: absolute; z-index: 201; max-width: 280px; }
.row-low-stock { background: #fef2f2; }
.report-filters { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; margin-bottom: 1rem; }
.export-links { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 1rem 0; }
.help-icon { display: inline-block; margin-left: 0.25rem; width: 1rem; height: 1rem; line-height: 1rem; text-align: center; border-radius: 50%; background: var(--border); font-size: 0.75rem; cursor: help; }

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-card { width: 100%; max-width: 400px; }

/* ---- Mobile ---- */
@media (max-width: 768px) {
    .container { padding: 1rem; }

    .topbar-inner {
        flex-wrap: nowrap;
        padding: 0.65rem 1rem;
        padding-top: calc(0.65rem + env(safe-area-inset-top, 0));
    }

    .nav-toggle { display: flex; }

    .topbar-nav {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(85vw, 320px);
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: calc(4rem + env(safe-area-inset-top, 0)) 1rem 1rem;
        background: var(--surface);
        border-right: 1px solid var(--border);
        box-shadow: var(--shadow);
        z-index: 100;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
    }
    .topbar-nav.is-open { display: flex; }

    .nav-primary { display: none !important; }
    .nav-mobile-sections { display: block; width: 100%; }

    .topbar-actions .nav-user-dropdown { display: none; }
    .topbar-actions .nav-pos-btn { display: none; }

    .nav-mobile-sections .nav-link {
        display: block;
        padding: 0.85rem 0.5rem;
        border-bottom: 1px solid var(--border);
        font-size: 1rem;
        min-height: 44px;
        border-radius: 0;
    }
    .nav-mobile-sections .nav-link.is-active {
        background: transparent;
        color: var(--primary);
        font-weight: 700;
    }

    .nav-mobile-user {
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid var(--border);
    }

    .layout-pos .topbar-nav {
        background: #1f2937;
        border-color: #374151;
    }
    .layout-pos .nav-mobile-sections .nav-link { border-color: #374151; }
    .layout-pos .nav-mobile-sections .nav-link.is-active { color: #93c5fd; }

    .help-panel {
        width: 100%;
        max-width: none;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
    }

    .grid-2, .grid-3 { grid-template-columns: 1fr; }

    .report-filters .form-group { flex: 1 1 100%; }
    .export-links .btn { flex: 1 1 auto; text-align: center; }

    h1 { font-size: 1.35rem; }

    /* POS mobile */
    .pos-layout { grid-template-columns: 1fr; }

    .pos-mobile-bar { display: flex; }

    .pos-cart {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        max-height: 85vh;
        margin: 0;
        border-radius: 16px 16px 0 0;
        z-index: 70;
        transform: translateY(100%);
        transition: transform 0.25s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
    }
    body.pos-cart-open .pos-cart { transform: translateY(0); }
    body.pos-cart-open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 65;
    }

    .pos-cart-close { display: inline-block; }
    .cart-items-scroll { max-height: 28vh; }

    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .layout-pos .container {
        padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0));
    }
}

@media (min-width: 769px) {
    .pos-cart-close { display: none !important; }
    .nav-toggle { display: none !important; }
    .nav-mobile-sections { display: none !important; }
    .topbar-nav { margin-left: 0.25rem; }
    .nav-user-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 480px) {
    .card { padding: 1rem; }
    .product-grid { grid-template-columns: repeat(2, 1fr); }
    table { min-width: 360px; font-size: 0.9rem; }
    th, td { padding: 0.5rem; }
}

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