:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-soft: #fff7ed;
    --text: #171923;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #e9422e;
    --primary-dark: #c92f1f;
    --orange: #ff8a1f;
    --yellow: #ffc83d;
    --green: #16a34a;
    --blue: #2563eb;
    --danger: #dc2626;
    --shadow: 0 14px 34px rgba(24, 24, 27, 0.08);
    --shadow-soft: 0 8px 20px rgba(24, 24, 27, 0.06);
    --radius: 8px;
    --sidebar-width: 260px;
}

body.dark {
    --bg: #111827;
    --surface: #182131;
    --surface-soft: #2a2118;
    --text: #f8fafc;
    --muted: #a8b3c4;
    --border: #2c3547;
    --shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
    --shadow-soft: 0 8px 20px rgba(0, 0, 0, 0.18);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Poppins", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    letter-spacing: 0;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

img {
    max-width: 100%;
    display: block;
}

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

.hidden {
    display: none !important;
}

.text-right {
    text-align: right;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 10% 15%, rgba(255, 200, 61, 0.32), transparent 30%),
        linear-gradient(135deg, #fff8ed 0%, #f6f7fb 58%, #fff1eb 100%);
}

.login-shell {
    width: min(980px, 100%);
    display: grid;
    grid-template-columns: 1fr 420px;
    align-items: stretch;
    gap: 24px;
}

.login-brand,
.login-card {
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid rgba(255, 255, 255, 0.65);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.login-brand {
    padding: 56px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #4b1b12;
    background:
        linear-gradient(135deg, rgba(233, 66, 46, 0.92), rgba(255, 138, 31, 0.82)),
        url("../images/logo-placeholder.svg") center/220px no-repeat;
}

.login-brand .brand-mark {
    width: 96px;
    height: 96px;
    border-radius: 22px;
    padding: 12px;
    background: #fff;
    box-shadow: var(--shadow-soft);
    margin-bottom: 24px;
}

.login-brand h1 {
    margin: 0;
    color: #fff;
    font-size: clamp(32px, 5vw, 52px);
    line-height: 1.05;
}

.login-brand p {
    margin: 12px 0 0;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
}

.login-card {
    padding: 34px;
    align-self: center;
}

.login-heading {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 24px;
}

.login-icon {
    width: 50px;
    height: 50px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--orange));
}

.login-heading h2,
.login-heading p {
    margin: 0;
}

.login-heading p {
    color: var(--muted);
    font-size: 14px;
}

.login-form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
    padding: 11px 12px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(233, 66, 46, 0.7);
    box-shadow: 0 0 0 4px rgba(233, 66, 46, 0.12);
}

.btn,
.icon-btn,
.nav-link,
.file-action {
    border: 0;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 15px;
    font-weight: 700;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.btn:hover,
.icon-btn:hover,
.nav-link:hover,
.file-action:hover {
    transform: translateY(-1px);
}

.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--orange));
    box-shadow: 0 10px 22px rgba(233, 66, 46, 0.24);
}

.btn-primary:hover {
    box-shadow: 0 14px 26px rgba(233, 66, 46, 0.3);
}

.btn-light,
.icon-btn,
.btn-ghost {
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
}

.btn-ghost {
    background: transparent;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
}

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

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

.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 18px;
    font-size: 14px;
}

.alert-danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background: #fff7ed;
    color: #9a3412;
    border: 1px solid #fed7aa;
}

.app-page {
    display: flex;
    overflow-x: hidden;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    padding: 18px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    z-index: 30;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 54px;
    margin-bottom: 18px;
    font-weight: 800;
}

.sidebar-logo img,
.topbar-brand img {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    object-fit: cover;
}

.sidebar-nav {
    display: grid;
    gap: 8px;
}

.nav-link {
    width: 100%;
    justify-content: flex-start;
    color: var(--muted);
    background: transparent;
    text-align: left;
}

.nav-link i {
    width: 22px;
    text-align: center;
}

.nav-link.active,
.nav-link:hover {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--orange));
    box-shadow: 0 10px 22px rgba(233, 66, 46, 0.2);
}

.nav-logout {
    margin-top: auto;
    color: var(--danger);
}

.app-shell {
    width: calc(100% - var(--sidebar-width));
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 74px;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    background: rgba(246, 247, 251, 0.88);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

body.dark .topbar {
    background: rgba(17, 24, 39, 0.88);
}

.mobile-menu-btn {
    display: none;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-brand strong,
.topbar-brand span {
    display: block;
}

.topbar-brand span {
    color: var(--muted);
    font-size: 12px;
}

.topbar-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

.clock-box,
.user-chip {
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    box-shadow: 0 4px 12px rgba(17, 24, 39, 0.03);
    font-size: 13px;
}

.user-chip {
    display: grid;
    gap: 0;
    align-content: center;
    min-width: 140px;
}

.user-chip small {
    color: var(--muted);
}

.content {
    padding: 24px;
}

.page-section {
    display: none;
    animation: fadeIn 0.22s ease;
}

.page-section.active {
    display: block;
}

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

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.section-heading h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.2;
}

.section-heading p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.button-row,
.backup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card,
.panel,
.product-card,
.cart-panel,
.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.stat-card {
    padding: 18px;
    display: grid;
    gap: 10px;
    min-height: 136px;
}

.stat-card .stat-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--muted);
    font-size: 13px;
}

.stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--primary);
}

.stat-icon.orange { background: var(--orange); }
.stat-icon.yellow { background: #d97706; }
.stat-icon.green { background: var(--green); }
.stat-icon.blue { background: var(--blue); }
.stat-icon.red { background: var(--danger); }

.stat-card strong {
    font-size: clamp(20px, 2.5vw, 28px);
    line-height: 1.1;
}

.stat-card small {
    color: var(--muted);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.span-2 {
    grid-column: span 2;
}

.panel {
    padding: 18px;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}

.panel-header h2 {
    margin: 0;
    font-size: 17px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    vertical-align: middle;
}

th {
    color: var(--muted);
    text-align: left;
    font-weight: 700;
    white-space: nowrap;
}

td {
    color: var(--text);
}

.compact-list {
    display: grid;
    gap: 10px;
}

.compact-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius);
    background: var(--surface-soft);
    border: 1px solid #fed7aa;
}

.compact-item strong,
.compact-item span {
    display: block;
}

.compact-item span,
.stock-note {
    color: var(--muted);
    font-size: 12px;
}

.cashier-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 18px;
    align-items: start;
}

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

.product-card {
    position: relative;
    min-height: 180px;
    padding: 18px;
    display: grid;
    align-content: space-between;
    gap: 18px;
    overflow: hidden;
}

.product-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 5px;
    background: linear-gradient(90deg, var(--primary), var(--orange), var(--yellow));
}

.product-card h3 {
    margin: 0;
    font-size: 18px;
    line-height: 1.3;
}

.product-card .price {
    font-size: 24px;
    font-weight: 800;
    color: var(--primary);
}

.product-card .stock-note {
    margin-top: 4px;
}

.cart-panel {
    position: sticky;
    top: 92px;
    padding: 18px;
}

.cart-items {
    display: grid;
    gap: 12px;
    min-height: 160px;
    max-height: 44vh;
    overflow-y: auto;
    padding-right: 4px;
}

.cart-empty {
    display: grid;
    place-items: center;
    min-height: 150px;
    color: var(--muted);
    text-align: center;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.cart-item {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

.cart-item-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.cart-item h4 {
    margin: 0;
    font-size: 14px;
}

.qty-control {
    display: grid;
    grid-template-columns: 36px 1fr 36px;
    gap: 8px;
    align-items: center;
}

.qty-control input {
    text-align: center;
    padding: 7px;
    min-height: 36px;
}

.qty-btn {
    min-height: 36px;
    padding: 0;
}

.cart-total {
    margin: 16px 0;
    padding: 16px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, rgba(233, 66, 46, 0.1), rgba(255, 138, 31, 0.13));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.cart-total strong {
    font-size: 24px;
    color: var(--primary);
}

.payment-selector {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.payment-option {
    min-height: 46px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-weight: 800;
}

.payment-option.active {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(135deg, var(--primary), var(--orange));
}

.cart-actions {
    display: grid;
    gap: 10px;
}

.filter-bar,
.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.form-grid.panel {
    margin-bottom: 16px;
}

.filter-bar .btn {
    align-self: stretch;
}

.align-end {
    align-self: end;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 26px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.badge-danger {
    color: #991b1b;
    background: #fee2e2;
}

.badge-success {
    color: #166534;
    background: #dcfce7;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.pagination {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

.pagination button {
    min-width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-weight: 700;
}

.pagination button.active {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.settings-grid {
    display: grid;
    grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
    gap: 16px;
}

.settings-form {
    display: grid;
    gap: 13px;
}

.file-action {
    position: relative;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
}

.file-action input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.48);
    backdrop-filter: blur(3px);
    z-index: 60;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: grid;
    place-items: center;
    padding: 18px;
}

.modal-card {
    width: min(720px, 100%);
    max-height: min(86vh, 760px);
    overflow-y: auto;
    padding: 18px;
}

.modal-header,
.modal-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.modal-header {
    margin-bottom: 16px;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
}

.modal-actions {
    justify-content: flex-end;
    margin-top: 18px;
}

.toast-stack {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 90;
    display: grid;
    gap: 10px;
    width: min(360px, calc(100vw - 36px));
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 14px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    animation: toastIn 0.2s ease;
}

.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--orange); }

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

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.5);
}

body.dark .loading-overlay {
    background: rgba(17, 24, 39, 0.55);
}

.loader {
    width: 46px;
    height: 46px;
    border: 4px solid rgba(233, 66, 46, 0.18);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.receipt-print {
    display: none;
}

.receipt-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    margin: 0 auto 4px;
}

.receipt-line {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.receipt-sep {
    border-top: 1px dashed #111;
    margin: 6px 0;
}

@media (max-width: 1180px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid,
    .cashier-layout,
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: span 1;
    }

    .cart-panel {
        position: static;
    }
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.22s ease;
    }

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

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

    .mobile-menu-btn {
        display: inline-flex;
    }

    .topbar {
        align-items: flex-start;
    }

    .topbar-meta {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .filter-bar,
    .form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 680px) {
    .login-shell {
        grid-template-columns: 1fr;
    }

    .login-brand {
        padding: 30px;
    }

    .content,
    .topbar {
        padding: 16px;
    }

    .topbar-brand span,
    .clock-box {
        display: none;
    }

    .section-heading {
        display: grid;
    }

    .stats-grid,
    .filter-bar,
    .form-grid,
    .product-grid {
        grid-template-columns: 1fr;
    }

    .payment-selector {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: span 1;
    }

    .user-chip {
        min-width: 110px;
    }
}

@media print {
    @page {
        size: 58mm auto;
        margin: 0;
    }

    body * {
        visibility: hidden !important;
    }

    #receiptPrintArea,
    #receiptPrintArea * {
        visibility: visible !important;
    }

    #receiptPrintArea {
        display: block !important;
        position: absolute;
        inset: 0 auto auto 0;
        width: 58mm;
        padding: 4mm;
        background: #fff;
        color: #111;
        font-family: Arial, sans-serif;
        font-size: 10.5px;
        line-height: 1.35;
    }

    #receiptPrintArea h1,
    #receiptPrintArea p {
        margin: 0;
        text-align: center;
    }

    #receiptPrintArea h1 {
        font-size: 13px;
    }
}
