/* ===== CSS VARIABLES & RESET ===== */
:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --success: #0d904f;
    --success-light: #e6f4ea;
    --warning: #e37400;
    --warning-light: #fef7e0;
    --danger: #d93025;
    --danger-light: #fce8e6;
    --bg: #f1f3f4;
    --surface: #ffffff;
    --text: #202124;
    --text-secondary: #5f6368;
    --border: #dadce0;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --nav-width: 280px;
    --bar-height: 56px;
}

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

body {
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* ===== APP BAR ===== */
.app-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--bar-height);
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    padding: 0 8px;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.menu-btn, .icon-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.menu-btn:active, .icon-btn:active {
    background: rgba(255,255,255,0.2);
}

.app-title {
    flex: 1;
    font-size: 20px;
    font-weight: 500;
    margin-left: 8px;
}

.app-bar-actions {
    display: flex;
    gap: 4px;
}

/* ===== SEARCH BAR ===== */
.search-bar {
    position: fixed;
    top: var(--bar-height);
    left: 0;
    right: 0;
    background: var(--surface);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 99;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
}

.search-bar.hidden {
    transform: translateY(-100%);
    pointer-events: none;
}

.search-bar input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    padding: 8px 0;
    background: transparent;
}

/* ===== SIDE NAVIGATION ===== */
.nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    opacity: 1;
    transition: opacity 0.3s;
}

.nav-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.side-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--nav-width);
    background: var(--surface);
    z-index: 201;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.side-nav.open {
    transform: translateX(0);
}

.nav-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 32px 20px 20px;
}

.nav-logo {
    font-size: 40px;
    margin-bottom: 8px;
}

.nav-header h2 {
    font-size: 22px;
    font-weight: 600;
}

.nav-header p {
    font-size: 13px;
    opacity: 0.8;
    margin-top: 4px;
}

.nav-menu {
    list-style: none;
    padding: 8px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background 0.2s, color 0.2s;
    font-size: 14px;
    font-weight: 500;
}

.nav-item:active {
    background: var(--primary-light);
}

.nav-item.active {
    color: var(--primary);
    background: var(--primary-light);
}

.nav-item svg {
    flex-shrink: 0;
}

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 16px;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-top: var(--bar-height);
    padding: 16px;
    padding-bottom: 80px;
    min-height: calc(100vh - var(--bar-height));
}

.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

/* ===== STATS GRID ===== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
}

.stat-icon {
    font-size: 28px;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.stat-primary .stat-value { color: var(--primary); }
.stat-success .stat-value { color: var(--success); }
.stat-warning .stat-value { color: var(--warning); }
.stat-danger .stat-value { color: var(--danger); }

/* ===== SECTION CARD ===== */
.section-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

/* ===== CATEGORY LIST ===== */
.category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.category-item:last-child {
    border-bottom: none;
}

.category-name {
    font-size: 14px;
    font-weight: 500;
}

.category-count {
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
}

/* ===== FILTER BAR ===== */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: center;
}

.filter-bar select {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 14px;
    color: var(--text);
    outline: none;
    appearance: auto;
}

.btn-fab-small {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
}

.btn-fab-small:active {
    transform: scale(0.95);
}

/* ===== PRODUCT LIST ===== */
.product-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.product-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    position: relative;
}

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

.product-card.low-stock {
    border-left: 4px solid var(--warning);
}

.product-card.out-of-stock {
    border-left: 4px solid var(--danger);
}

.product-avatar {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.product-info {
    flex: 1;
    min-width: 0;
}

.product-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.product-stock {
    text-align: right;
    flex-shrink: 0;
}

.stock-badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
}

.stock-ok {
    background: var(--success-light);
    color: var(--success);
}

.stock-low {
    background: var(--warning-light);
    color: var(--warning);
}

.stock-out {
    background: var(--danger-light);
    color: var(--danger);
}

/* ===== SCAN PAGE ===== */
.scan-container {
    max-width: 500px;
    margin: 0 auto;
}

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

.scan-header h3 {
    font-size: 20px;
    margin-bottom: 4px;
}

.scan-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.qr-reader {
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
    min-height: 100px;
}

#qrReader video {
    border-radius: var(--radius);
}

.scan-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}

.scan-result {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    animation: fadeIn 0.3s;
}

.scan-result h4 {
    margin-bottom: 12px;
    color: var(--primary);
}

/* ===== LOW STOCK LIST ===== */
.low-stock-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.low-stock-item:last-child {
    border-bottom: none;
}

.low-stock-info {
    flex: 1;
}

.low-stock-name {
    font-size: 14px;
    font-weight: 500;
}

.low-stock-category {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ===== BUTTONS ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.15s, opacity 0.15s;
}

.btn:active {
    transform: scale(0.97);
}

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

.btn-secondary {
    background: var(--bg);
    color: var(--text);
}

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

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

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

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transition: opacity 0.3s;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-small {
    max-width: 400px;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
    border-radius: 20px 20px 0 0;
}

.modal-header h3 {
    font-size: 18px;
}

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

.modal-body {
    padding: 20px;
}

/* ===== FORM STYLES ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--primary);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ===== STOCK ADJUSTER ===== */
.stock-product-name {
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 8px;
}

.stock-current {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.stock-adjuster {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 16px;
}

.btn-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface);
    font-size: 24px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-minus:active {
    background: var(--danger-light);
    border-color: var(--danger);
    color: var(--danger);
}

.btn-plus:active {
    background: var(--success-light);
    border-color: var(--success);
    color: var(--success);
}

.stock-adjuster input {
    width: 80px;
    text-align: center;
    font-size: 28px;
    font-weight: 700;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    outline: none;
}

.stock-type-toggle {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}

.toggle-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn.active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

/* ===== QR MODAL ===== */
.qr-modal-body {
    text-align: center;
}

.qr-product-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.qr-canvas {
    margin: 0 auto 12px;
    display: flex;
    justify-content: center;
}

.qr-canvas canvas, .qr-canvas img {
    max-width: 200px;
    border-radius: 8px;
}

.barcode-canvas {
    display: block;
    margin: 0 auto 16px;
    max-width: 250px;
}

/* ===== DETAIL VIEW ===== */
.detail-section {
    margin-bottom: 16px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--text-secondary);
}

.detail-value {
    font-weight: 600;
    text-align: right;
}

.detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.detail-actions .btn {
    flex: 1;
    justify-content: center;
    min-width: 0;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #323232;
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    z-index: 999;
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== UTILITY ===== */
.hidden {
    display: none !important;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 600px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .main-content {
        max-width: 800px;
        margin-left: auto;
        margin-right: auto;
    }
    
    .modal {
        border-radius: var(--radius);
        max-height: 80vh;
    }
    
    .modal-overlay {
        align-items: center;
    }
    
    @keyframes slideUp {
        from { transform: translateY(40px); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    body * {
        visibility: hidden;
    }
    
    #qrModal, #qrModal * {
        visibility: visible;
    }
    
    #qrModal {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: white;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .modal-header, .form-actions {
        display: none !important;
    }
}

/* Product action buttons row */
.product-actions-row {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.product-action-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background 0.2s;
}

.product-action-btn:active {
    background: var(--bg);
}
