:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --accent: #7c3aed;
    --secondary: #64748b;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --bg: #f7f8fb;
    --card: #ffffff;
    --text: #0f172a;
    --border: #e6e9f0;
    --sidebar-width: 260px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 4px 16px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 20px 60px rgba(15, 23, 42, 0.16);
    --transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Login */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 20% 20%, #6366f1 0%, transparent 45%),
                radial-gradient(circle at 80% 80%, #7c3aed 0%, transparent 45%),
                linear-gradient(135deg, var(--primary), var(--primary-dark));
    padding: 20px;
}

.login-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 44px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.4);
}

.login-card h1 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.login-card .subtitle {
    text-align: center;
    color: var(--secondary);
    margin-bottom: 4px;
}

.login-credit {
    text-align: center;
    color: var(--secondary);
    font-size: 0.78rem;
    opacity: 0.7;
    margin-bottom: 26px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

select.form-control {
    cursor: pointer;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition), filter var(--transition);
    text-decoration: none;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover:not(:disabled) {
    filter: brightness(0.92);
    transform: translateY(-1px);
}

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

.btn-danger:hover:not(:disabled) {
    filter: brightness(0.92);
    transform: translateY(-1px);
}

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

.btn-outline:hover:not(:disabled) {
    background: var(--bg);
    border-color: var(--primary);
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1.1rem;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-block {
    width: 100%;
}

.icon-inline {
    display: inline-flex;
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
}

.icon-inline svg {
    width: 100%;
    height: 100%;
}

/* App Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #151b2e 0%, #0f1424 100%);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    position: relative;
    padding: 22px 24px;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-collapse-btn {
    display: none;
    position: absolute;
    top: 20px;
    right: 14px;
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.65);
    cursor: pointer;
}

.sidebar-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.sidebar-brand span {
    color: #818cf8;
}

.sidebar-brand-sub {
    font-size: 0.68rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.35);
    margin-top: 3px;
}

.sidebar-nav {
    padding: 16px 12px;
    flex: 1 1 auto;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.65);
    text-decoration: none;
    transition: all var(--transition);
    font-size: 0.92rem;
    font-weight: 500;
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.06);
    color: white;
}

.sidebar-nav a.active {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.sidebar-nav .nav-icon {
    width: 19px;
    height: 19px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-nav .nav-icon svg {
    width: 100%;
    height: 100%;
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.85rem;
}

.sidebar-scroll-hint {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 73px;
    height: 28px;
    background: linear-gradient(to bottom, transparent, #0f1424);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition);
    z-index: 1;
}

.sidebar-scroll-hint.visible {
    opacity: 1;
}

.sidebar-footer .user-name {
    font-weight: 600;
    color: white;
}

.sidebar-footer .store-name {
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.8rem;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 28px 32px;
    min-height: 100vh;
    transition: margin-left 0.25s ease;
}

/* Collapsible sidebar (desktop only — mobile keeps its own off-canvas
   open/close behavior below, unaffected by this). */
@media (min-width: 769px) {
    .sidebar-collapse-btn {
        display: flex;
    }

    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-collapsed .main-content {
        margin-left: 0;
        padding-top: 64px;
    }

    body.sidebar-collapsed .sidebar-toggle {
        display: flex;
    }
}

.main-content.pos-main {
    padding: 16px;
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 200;
    width: 42px;
    height: 42px;
    align-items: center;
    justify-content: center;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    color: var(--text);
    cursor: pointer;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 90;
}

.sidebar-overlay.show {
    display: block;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card-header {
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.card-body {
    padding: 22px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.dashboard-grid > .card {
    min-width: 0;
}

/* Stat Cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 22px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), transform var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.stat-card .stat-value {
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stat-card .stat-sub {
    font-size: 0.8rem;
    color: var(--secondary);
    margin-top: 4px;
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    position: relative;
}

.table-scroll-hint {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 28px;
    background: linear-gradient(to right, transparent, rgba(15, 23, 42, 0.12));
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition);
}

.table-scroll-hint.visible {
    opacity: 1;
}

.actions-cell {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
}

.actions-cell .btn {
    padding: 5px 8px;
    font-size: 0.78rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th,
table td {
    padding: 12px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--secondary);
}

table tbody tr {
    transition: background var(--transition);
}

table tbody tr:hover {
    background: var(--primary-light);
}

table tbody tr:last-child td {
    border-bottom: none;
}


/* POS Screen */
.pos-container {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    height: calc(100vh - 100px);
}

.pos-products {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
}

.pos-search {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.pos-search input {
    width: 100%;
    padding: 12px 16px;
    font-size: 1.1rem;
    font-family: inherit;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
}

.pos-search input:focus {
    outline: none;
    border-color: var(--primary);
}

.pos-categories {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.pos-categories .cat-btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--card);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 500;
    transition: all var(--transition);
}

.pos-categories .cat-btn.active,
.pos-categories .cat-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pos-product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    overflow-y: auto;
    padding: 4px;
    flex: 1;
}

.product-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.product-card:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.18);
    transform: translateY(-2px);
}

.product-card .product-image {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.product-card .product-name {
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.product-card .product-price {
    color: var(--primary);
    font-weight: 700;
    font-size: 1rem;
}

.product-card .product-stock {
    font-size: 0.75rem;
    color: var(--secondary);
    margin-top: 4px;
}

.product-card .product-stock.low {
    color: var(--danger);
}

.product-card.has-variants {
    cursor: default;
}

.product-card.has-variants:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--border);
}

.product-variant-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
}

.variant-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text);
    transition: all var(--transition);
}

.variant-btn span {
    color: var(--primary);
    font-weight: 700;
}

.variant-btn:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--primary-light);
}

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

.pos-cart {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pos-cart-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.pos-cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.cart-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--secondary);
}

.cart-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.cart-item .item-name {
    flex: 1;
    font-size: 0.9rem;
}

.cart-item .item-price {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
}

.cart-item .item-qty {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cart-item .item-qty button {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-item .item-qty span {
    min-width: 24px;
    text-align: center;
    font-weight: 600;
}

.cart-item .item-qty .qty-input {
    width: 44px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 6px;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text);
    -moz-appearance: textfield;
}

.cart-item .item-qty .qty-input::-webkit-outer-spin-button,
.cart-item .item-qty .qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.cart-item .item-remove {
    color: var(--danger);
    cursor: pointer;
    padding: 4px;
}

.pos-cart-summary {
    padding: 16px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.cart-summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.cart-summary-row.total {
    font-size: 1.25rem;
    font-weight: 700;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid var(--border);
}

.discount-controls {
    display: flex;
    gap: 6px;
}

.discount-controls input {
    width: 64px;
    padding: 4px 6px;
    font-size: 0.85rem;
}

.discount-controls select {
    width: 56px;
    padding: 4px 4px;
    font-size: 0.85rem;
}

.pos-cart-actions {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

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

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--card);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: scale(0.97) translateY(4px);
    transition: transform var(--transition);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--secondary);
    line-height: 1;
    transition: color var(--transition);
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 22px;
}

.modal-footer {
    padding: 16px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Payment Modal */
.payment-methods {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.payment-method-btn {
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: all var(--transition);
}

.payment-method-btn.active,
.payment-method-btn:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.amount-tendered-input {
    font-size: 1.5rem;
    text-align: center;
    font-weight: 700;
}

.change-display {
    text-align: center;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-top: 16px;
}

.change-display .change-amount {
    font-size: 2rem;
    font-weight: 700;
    color: var(--success);
}

/* Receipt */
.receipt {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    max-width: 300px;
    margin: 0 auto;
    padding: 20px;
}

.receipt-header {
    text-align: center;
    margin-bottom: 16px;
}

.receipt-header h3 {
    font-size: 1.1rem;
}

.receipt-items {
    border-top: 1px dashed var(--border);
    border-bottom: 1px dashed var(--border);
    padding: 12px 0;
    margin: 12px 0;
}

.receipt-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.receipt-totals {
    margin-top: 12px;
}

.receipt-total-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.receipt-total-row.grand-total {
    font-weight: 700;
    font-size: 1rem;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 11px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

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

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

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

/* Responsive */
@media (max-width: 1024px) {
    .pos-container {
        grid-template-columns: 1fr;
        height: auto;
    }

    .pos-cart {
        max-height: 500px;
    }
}

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

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

    .main-content {
        margin-left: 0;
        padding: 64px 20px 20px;
    }

    .main-content.pos-main {
        padding: 64px 16px 16px;
    }

    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .sidebar-toggle {
        display: flex;
    }

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

/* Print */
@media print {
    @page {
        size: var(--receipt-width) auto;
        margin: 0;
    }

    body * {
        visibility: hidden;
    }

    .receipt, .receipt * {
        visibility: visible;
    }

    .receipt {
        position: absolute;
        left: 0;
        top: 0;
        width: var(--receipt-width);
        padding: 3mm;
        font-size: 10px;
        line-height: 1.35;
    }

    .receipt-header h3 {
        font-size: 13px;
    }
}
