@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;700&family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;700&display=swap');

:root {
    --primary-color: #D4AF37;
    /* Soft Gold */
    --accent-color: #8C6239;
    /* Rich Bronze */
    --background-dark: #0B0B0B;
    /* Jet Black */
    --surface-dark: #2A2A2A;
    /* Charcoal Grey */
    --surface-light: #363636;
    --text-white: #F5F3EE;
    /* Warm Off-White */
    --text-muted: #A0A0A0;
    --danger-color: #C62828;
    --success-color: #2E7D32;
    --border-color: #3D3D3D;
    --border-radius: 10px;
    --input-bg: rgba(255, 255, 255, 0.05);
    /* Re-added for inline styles */
    --font-heading: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

body {
    font-family: var(--font-body);
    background-color: var(--background-dark);
    color: var(--text-white);
    line-height: 1.6;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

.container {
    width: 95%;
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 1rem;
}

#mobileMenuBtn {
    display: none;
    background: none;
    border: none;
    color: var(--text-white);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
}

@media (max-width: 768px) {
    #mobileMenuBtn {
        display: block;
    }
}

h1,
h2,
h3 {
    font-family: var(--font-heading);
    font-weight: 700;
}

h1 {
    font-size: 2.2rem;
    color: var(--text-white);
    letter-spacing: -0.5px;
}

/* Cards */
.card {
    background-color: var(--surface-dark);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    overflow-x: auto;
}

h2 {
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--accent-color);
    padding-bottom: 10px;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: #aaa;
}

input,
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-white);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: rgba(255, 255, 255, 0.08);
}

/* Buttons */
.action-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-family: var(--font-body);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: fit-content;
    max-width: 100%;
}

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

.btn-primary:hover {
    background-color: #e5c05b;
}

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

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

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

.btn-reset {
    background: linear-gradient(135deg, rgba(255, 152, 0, 0.1), rgba(255, 193, 7, 0.1));
    border: 1px solid rgba(255, 193, 7, 0.4);
    color: #ffc107;
}

.btn-reset:hover {
    background: linear-gradient(135deg, rgba(255, 152, 0, 0.2), rgba(255, 193, 7, 0.2));
    border-color: #ffc107;
    box-shadow: 0 0 15px rgba(255, 193, 7, 0.3);
    transform: translateY(-2px);
}

.btn-reset i {
    color: #ffc107;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    text-decoration: underline;
}

/* Footer */
footer {
    text-align: center;
    font-size: 0.8rem;
    color: #666;
    margin-top: 2rem;
}


/* Print Styles */
/* Print Styles (Thermal 80mm) */
@media print {
    @page {
        size: 80mm auto;
        margin: 0;
    }

    body {
        visibility: hidden;
        margin: 0;
        padding: 0;
        background: white;
    }

    /* Hide everything by default */
    .sidebar,
    #sidebar-container,
    header,
    .main-content,
    .pos-layout,
    .hide-print,
    button,
    .modal,
    dialog,
    .announcement-banner {
        display: none !important;
    }

    /* Only show the receipt */
    #receiptPrint,
    #receiptPrint * {
        visibility: visible !important;
        display: block !important;
    }

    #receiptLogo {
        margin: 0 auto !important;
    }

    /* Override flex/grid displays inside receipt */
    #receiptPrint .receipt-header,
    #receiptPrint .receipt-footer,
    #receiptPrint .receipt-table {
        display: block !important;
    }

    #receiptPrint table {
        display: table !important;
    }

    #receiptPrint tr {
        display: table-row !important;
    }

    #receiptPrint th,
    #receiptPrint td {
        display: table-cell !important;
    }

    #receiptPrint .flex-row-print {
        display: flex !important;
        justify-content: space-between !important;
    }

    #receiptPrint {
        position: absolute;
        left: 0;
        top: 0;
        width: 72mm;
        /* 80mm paper minus margins */
        margin: 0 auto;
        padding: 2mm 5mm;
        background: white;
        color: black;
        font-family: 'Courier New', Courier, monospace;
        /* Monospaced for receipt feel */
        font-size: 12px;
        line-height: 1.2;
    }

    /* Print Visuals */
    .receipt-header {
        text-align: center;
        margin-bottom: 5px;
        border-bottom: 1px dashed black;
        padding-bottom: 5px;
    }

    .receipt-table {
        width: 100%;
        border-collapse: collapse;
        margin: 5px 0;
        table-layout: fixed;
        /* Ensures strict adherence to column widths */
    }

    .receipt-table th {
        text-align: left;
        border-bottom: 1px solid black;
        font-size: 11px;
        padding: 4px 2px;
    }

    .receipt-table td {
        border: none;
        border: none;
        padding: 4px 2px;
        vertical-align: top;
    }

    /* Fixed Column Widths and Alignments */
    /* Column 1: Item */
    .receipt-table th:nth-child(1),
    .receipt-table td:nth-child(1) {
        width: 50%;
        text-align: left;
        word-wrap: break-word;
        /* Legacy support */
        overflow-wrap: break-word;
        /* Modern standard */
    }

    /* Column 2: Qty - Center Aligned */
    .receipt-table th:nth-child(2),
    .receipt-table tbody td:nth-child(2) {
        width: 15%;
        text-align: center !important;
    }

    /* Column 3: Total - Right Aligned */
    .receipt-table th:nth-child(3),
    .receipt-table tbody td:nth-child(3) {
        width: 35%;
        text-align: right !important;
    }

    .receipt-footer {
        border-top: 1px dashed black;
        margin-top: 10px;
        padding-top: 5px;
        text-align: center;
        font-size: 10px;
    }

    /* Utility to hide specific print elements */
    .no-print {
        display: none !important;
    }
}

/* Sidebar */
#sidebar-container {
    width: 250px;
    flex-shrink: 0;
    background-color: var(--surface-dark);
    border-right: 1px solid var(--border-color);
    transition: transform 0.3s ease;
    z-index: 2000;
    overflow-y: auto;
}

@media (max-width: 768px) {
    #sidebar-container {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        width: 280px;
        box-shadow: 10px 0 20px rgba(0, 0, 0, 0.5);
        display: flex;
        flex-direction: column;
    }

    #sidebar-container.active {
        transform: translateX(0);
    }

    /* Sidebar Overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        z-index: 1999;
    }

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

.sidebar {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    min-height: 100%;
}

.sidebar-header {
    margin-bottom: 2.5rem;
    color: var(--primary-color);
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.nav-links {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    overflow-y: auto;
}

.nav-links li:last-child {
    margin-top: auto;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.3s ease;
    font-size: 0.95rem;
    font-weight: 500;
}

.nav-links a:hover {
    background-color: rgba(212, 175, 55, 0.05);
    color: var(--primary-color);
    padding-left: 25px;
}

.nav-links a.active {
    background-color: rgba(212, 175, 55, 0.1);
    color: var(--primary-color);
    border-left: 3px solid var(--primary-color);
    border-radius: 0 8px 8px 0;
}

.main-content {
    flex-grow: 1;
    padding: 2rem;
    overflow-y: auto;
}

@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
        padding-top: 1.5rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .hide-mobile {
        display: none !important;
    }

    /* POS Modal Specific Fixes */
    #historyModal {
        width: 98% !important;
        padding: 1.2rem !important;
    }

    #historyFlexContainer {
        height: 85vh !important;
    }

    #historyListColumn {
        height: 200px !important;
    }
}

#historyFlexContainer {
    display: flex;
    flex-direction: column;
}

#historyListColumn {
    width: 100%;
    border-right: none !important;
    border-bottom: 1px solid var(--border-color);
}

#historyDetails {
    width: 100%;
}

.close-modal-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.8rem;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

.close-modal-btn:hover {
    background: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
}

@media (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background-color: var(--surface-dark);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.stat-card .icon {
    width: 50px;
    height: 50px;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--primary-color);
}

.stat-card.alert .icon {
    color: var(--danger-color);
}

.stat-card .info h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-card .info p {
    font-family: var(--font-mono);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-white);
    margin: 0;
}

/* Stat Card Links */
.stat-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card-link:hover {
    transform: translateY(-4px);
}

.stat-card-link:hover .stat-card {
    border-color: var(--primary-color);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.4);
}

.stat-card-link:hover .icon {
    background-color: rgba(0, 123, 255, 0.1);
}

/* Tables */
.data-table-container {
    overflow-x: auto;
    margin-top: 1rem;
}

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

.data-table th {
    text-align: left;
    padding: 12px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--border-color);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid #333;
    font-size: 0.95rem;
    word-break: break-word;
}

.data-table tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.03);
}

.data-table tr:hover {
    background-color: rgba(212, 175, 55, 0.08);
    /* Highlight with primary color tint */
    transition: background-color 0.2s ease;
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-warning {
    background-color: rgba(255, 193, 7, 0.2);
    color: #ffc107;
}

.badge-success {
    background-color: rgba(40, 167, 69, 0.2);
    color: #28a745;
}

/* POS Layout */
.pos-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
    height: calc(100vh - 4rem);
}

.pos-left,
.pos-right {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.cart-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.cart-items {
    flex-grow: 1;
    overflow-y: auto;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    margin: 1rem 0;
    padding: 1rem 0;
}

.cart-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    border-bottom: 1px solid #333;
}

/* POS UI Refinements */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    overflow-y: auto;
    padding: 5px;
    height: calc(100vh - 250px);
}

.product-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 1.2rem;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s, border-color 0.2s;
    user-select: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 140px;
}

.product-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-5px);
    border-color: var(--primary-color);
}

.product-card:active {
    transform: scale(0.95);
}

.product-card .item-name {
    font-weight: 500;
    font-size: 1rem;
    margin-bottom: 8px;
    color: var(--text-light);
}

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

.product-card .item-stock {
    font-size: 0.75rem;
    color: #888;
    margin-top: 5px;
}

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

/* Category Filters */
.category-strip {
    display: flex;
    gap: 0.8rem;
    overflow-x: auto;
    padding: 10px 0;
    margin-bottom: 1rem;
    white-space: nowrap;
    scrollbar-width: thin;
}

.category-btn {
    padding: 8px 24px;
    border-radius: 20px;
    background: var(--surface-dark);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.category-btn.active {
    background: var(--primary-color);
    color: #000;
    border-color: var(--primary-color);
    font-weight: 600;
}

/* Cart Improvements */
.cart-qty-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid #444;
    background: #2c2c2c;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.cart-qty-btn:hover {
    background: #444;
}

/* Responsive Customization */
@media (max-width: 768px) {
    .pos-layout {
        height: auto;
        display: block;
    }

    .pos-right {
        margin-top: 2rem;
    }

    .product-grid {
        height: 60vh;
    }
}

/* Global Dialog Styles */
dialog {
    margin: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--surface-dark);
    color: var(--text-white);
    padding: 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    max-width: 450px;
    width: 90%;
    outline: none;
}

@media (max-width: 480px) {
    dialog {
        padding: 1.5rem;
    }
}

dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
}

dialog h3 {
    margin-bottom: 1.5rem;
    color: var(--primary-color);
    font-size: 1.5rem;
}

dialog p {
    margin-bottom: 1.5rem;
    color: var(--text-muted);
}

/* Legacy Modal Styles (Centering for existing div-based popups) */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 3000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal.active {
    display: flex !important;
}

.modal-content,
.modal>.card {
    background: var(--surface-dark) !important;
    padding: 2.5rem !important;
    border-radius: var(--border-radius) !important;
    width: 90% !important;
    max-width: 600px !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7) !important;
    margin: auto !important;
}

@media (max-width: 480px) {

    .modal-content,
    .modal>.card {
        padding: 1.5rem !important;
    }
}

/* Announcement Banner */
/* Announcement Banner */
.announcement-banner {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    max-width: 350px;
    pointer-events: auto;
    /* Allow clicking links/close */
}

.announcement-banner.visible {
    opacity: 1;
    transform: translateY(0);
}

.announcement-content {
    background: linear-gradient(135deg, var(--surface-dark), #1a1a1a);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px 25px 15px 15px;
    color: var(--text-white);
    font-weight: 500;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Variant Colors - Subtle Accents */
.announcement-info .announcement-content {
    border-left: 4px solid var(--primary-color);
    /* Gold */
}

.announcement-warning .announcement-content {
    border-left: 4px solid var(--accent-color);
    /* Bronze */
}

.announcement-success .announcement-content {
    border-left: 4px solid var(--success-color);
    /* Green */
}

/* Close Button */
.announcement-close {
    position: absolute;
    top: -10px;
    right: -10px;
    background: white;
    color: #333;
    border: 2px solid #fff;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    transition: transform 0.2s;
}

.announcement-close:hover {
    transform: scale(1.1);
    background: #f8f9fa;
}

/* Content Elements */
.announcement-img {
    width: 100%;
    max-height: 150px;
    object-fit: cover;
    border-radius: 4px;
    display: block;
}

.announcement-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.announcement-link:hover .announcement-text {
    text-decoration: underline;
}

/* Idle Screensaver Mode */
body.idle-active::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9998;
    pointer-events: none;
    /* Let clicks pass through to document listener */
}

body.idle-active .announcement-banner {
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    transform: translate(-50%, -50%) scale(1.2) !important;
    max-width: 90%;
    width: 500px;
    z-index: 9999;
}

body.idle-active .announcement-banner .announcement-content {
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    border: 2px solid var(--primary-color);
}