/* ============================================================
   CentralStore — Design System (Minimalist, Slate & Emerald Theme)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

:root {
    --primary: #059669; /* Emerald */
    --primary-bright: #34d399;
    --primary-dim: rgba(5, 150, 105, 0.08);
    --primary-glow: rgba(5, 150, 105, 0.15);
    
    --secondary: #2563eb; /* Cobalt Blue for Pharma / Health */
    --secondary-dim: rgba(37, 99, 235, 0.08);

    --bg-base: #f8fafc;
    --bg-card: #ffffff;
    --bg-elevated: #f1f5f9;
    --bg-surface: #e2e8f0;
    
    --border: rgba(5, 150, 105, 0.12);
    --border-subtle: rgba(148, 163, 184, 0.12);
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --red: #ef4444;
    --red-dim: rgba(239, 68, 68, 0.06);
    --amber: #f59e0b;
    --amber-dim: rgba(245, 158, 11, 0.08);
    
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.02);
    --shadow-card: 0 4px 20px rgba(148, 163, 184, 0.08), 0 2px 4px rgba(148, 163, 184, 0.03);
    --shadow-lg: 0 12px 36px rgba(15, 23, 42, 0.08);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode preferences */
.dark-theme {
    --bg-base: #0f172a;
    --bg-card: #1e293b;
    --bg-elevated: #334155;
    --bg-surface: #475569;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border-subtle: rgba(255, 255, 255, 0.06);
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.25);
}

/* Reset & Basics */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
    font-family: inherit;
    outline: none;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    transition: var(--transition);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 10px;
    opacity: 0.5;
}

/* Views display logic */
.view {
    display: none !important;
    height: 100vh;
    width: 100vw;
}
.view.active {
    display: flex !important;
}

/* ════════════════════════════════════════════════════════════
   LOGIN VIEW
   ════════════════════════════════════════════════════════════ */
#loginView {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 10% 20%, rgba(5, 150, 105, 0.05) 0%, transparent 40%),
                radial-gradient(circle at 90% 80%, rgba(37, 99, 235, 0.04) 0%, transparent 40%),
                var(--bg-base);
    position: relative;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    z-index: 10;
}

.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 24px;
}

.brand-icon {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.brand-icon span {
    font-size: 24px;
}

.brand-name {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 24px;
}

/* PIN Access */
.pin-container {
    margin: 20px 0;
}

.pin-dots {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 24px;
}

.pin-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 2px solid var(--border-subtle);
    transition: var(--transition);
}

.pin-dot.filled {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
    transform: scale(1.15);
}

.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 320px;
    margin: 0 auto;
}

.key-btn {
    height: 60px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.key-btn:hover {
    background: var(--bg-surface);
}

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

.key-btn.delete {
    color: var(--red);
    background: var(--red-dim);
}

.key-btn.submit {
    color: var(--primary);
    background: var(--primary-dim);
}

.login-toggle {
    margin-top: 24px;
    font-size: 13px;
    color: var(--secondary);
    text-decoration: none;
    font-weight: 600;
}

.login-form-group {
    text-align: left;
    margin-bottom: 16px;
}

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

.login-input {
    width: 100%;
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 14px;
}

.login-input:focus {
    border-color: var(--primary);
    background: var(--bg-card);
}

.btn-primary {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 4px 12px var(--primary-glow);
    margin-top: 10px;
}

.btn-primary:hover {
    background: #047857;
    transform: translateY(-1px);
}

/* ════════════════════════════════════════════════════════════
   MAIN APP SHELL
   ════════════════════════════════════════════════════════════ */
#appShell {
    flex-direction: column;
}

.topbar {
    height: 60px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    box-shadow: var(--shadow-sm);
    z-index: 100;
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.tenant-badge {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 700;
    background: var(--primary-dim);
    color: var(--primary);
}

.branch-select {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    font-size: 12px;
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 8px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--secondary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
}

.user-info {
    font-size: 12px;
    font-weight: 600;
}

.user-role {
    font-size: 10px;
    color: var(--text-muted);
}

.nav-link-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
}

.nav-link-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.nav-link-btn.active {
    background: var(--primary-dim);
    color: var(--primary);
}

/* Grid POS View */
.pos-layout {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.pos-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 18px 24px;
    min-width: 0;
}

/* POS Toolbar (Search, Scanner, Scale indicator) */
.pos-toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    align-items: center;
}

.search-container {
    position: relative;
    flex: 1;
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 42px;
    border-radius: var(--radius);
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    font-size: 14px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.scanner-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: var(--amber-dim);
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: var(--radius);
    color: var(--amber);
    font-size: 12px;
    font-weight: 700;
}

.scale-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: var(--primary-dim);
    border: 1px solid rgba(5, 150, 105, 0.2);
    border-radius: var(--radius);
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

/* Catalog Products Grid */
.categories-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.category-tab {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--text-secondary);
}

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

.products-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    grid-auto-rows: max-content;
    align-content: start;
    gap: 14px;
    overflow-y: auto;
    padding-bottom: 24px;
}

/* Product Card Grid Item */
.product-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: relative;
    cursor: pointer;
    height: 110px;
}

.product-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-card);
    transform: translateY(-1px);
}

.product-card.rx::after {
    content: "Rx";
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--red);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    padding: 1px 5px;
    border-radius: 4px;
    text-transform: uppercase;
}

.product-card.granel::after {
    content: "Granel";
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--secondary);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    padding: 1px 5px;
    border-radius: 4px;
    text-transform: uppercase;
}

.product-name {
    font-weight: 700;
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    padding-right: 4px;
}

.product-card.rx .product-name,
.product-card.granel .product-name {
    padding-right: 46px; /* Space for the absolute top-right badge */
}

.product-sku {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.product-price-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 6px;
}

.product-price {
    font-weight: 800;
    color: var(--primary);
    font-size: 15px;
    line-height: 1.1;
}

.product-stock {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: right;
    line-height: 1.25;
}

.product-stock.low {
    color: var(--red);
    font-weight: 700;
}

/* POS Cart/Sidebar */
.pos-sidebar {
    width: 380px;
    border-left: 1px solid var(--border-subtle);
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.cart-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cart-title {
    font-weight: 800;
    font-size: 15px;
}

.client-select-row {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    gap: 8px;
    align-items: center;
}

.client-select {
    flex: 1;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    font-size: 12px;
    color: var(--text-primary);
}

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

.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.cart-item-info {
    flex: 1;
    min-width: 0;
    padding-right: 12px;
}

.cart-item-name {
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-item-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.cart-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.qty-btn {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
}

.qty-btn:hover {
    background: var(--bg-surface);
}

.cart-item-qty {
    font-weight: 700;
    font-size: 13px;
    min-width: 20px;
    text-align: center;
}

.cart-item-price {
    font-weight: 800;
    font-size: 13px;
    min-width: 60px;
    text-align: right;
}

.cart-item-remove {
    color: var(--red);
    cursor: pointer;
    font-size: 18px;
    margin-left: 8px;
}

/* Cart Summary & Checkout button */
.cart-summary {
    padding: 20px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
}

.summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.summary-row.total {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary);
    border-top: 1px solid rgba(0,0,0,0.06);
    padding-top: 8px;
    margin-bottom: 16px;
}

.btn-checkout {
    width: 100%;
    padding: 16px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    font-size: 15px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-checkout:hover {
    background: #047857;
}

/* Modals & Dialogs */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 480px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 28px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-content::-webkit-scrollbar {
    width: 6px;
}
.modal-content::-webkit-scrollbar-track {
    background: transparent;
}
.modal-content::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 18px;
    font-weight: 800;
}

.close-btn {
    cursor: pointer;
    font-size: 20px;
    color: var(--text-muted);
}

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

.form-col-full {
    grid-column: span 2;
}

/* Offline Banner */
.offline-banner {
    position: fixed;
    bottom: 16px;
    left: 16px;
    padding: 10px 16px;
    background: var(--red);
    color: #fff;
    border-radius: 30px;
    font-weight: 700;
    font-size: 12px;
    display: none;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    z-index: 1000;
}

.offline-banner.active {
    display: flex;
}

/* TPV Payment On-Screen Keypad */
.pos-keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 16px;
    background: var(--bg-elevated);
    padding: 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-subtle);
}

.keypad-btn {
    height: 52px;
    font-size: 18px;
    font-weight: 700;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    user-select: none;
    outline: none;
}

.keypad-btn:active {
    transform: scale(0.96);
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.keypad-btn:hover {
    background: var(--bg-surface);
    border-color: var(--text-muted);
}

/* PWA Update Banner Styling */
.pwa-update-banner {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px) saturate(190%);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
    padding: 16px 20px;
    z-index: 2000;
    max-width: 380px;
    width: calc(100vw - 48px);
    display: none; /* controlled by JS */
    animation: slideUpIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.pwa-update-banner.active {
    display: block;
}

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

.pwa-update-content {
    display: flex;
    align-items: center;
    gap: 14px;
}

.pwa-update-icon {
    font-size: 28px;
    color: var(--primary);
    animation: rotateLoop 4s linear infinite;
}

@keyframes rotateLoop {
    from { transform: rotate(0deg); }
    to { transform: rotate(-360deg); }
}

.pwa-update-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pwa-update-title {
    font-size: 14px;
    font-weight: 800;
    color: #fff;
}

.pwa-update-text span {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.75);
}

.btn-update-install {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 800;
    border-radius: var(--radius-sm);
    cursor: pointer;
    box-shadow: 0 4px 12px var(--primary-glow);
    transition: all 0.2s ease;
}

.btn-update-install:hover {
    background: #047857;
    transform: translateY(-1px);
}

/* Mobile Bottom Navigation Bar */
.mobile-nav-bar {
    display: none;
}

@media (max-width: 768px) {
    .mobile-nav-bar {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 62px;
        background: var(--bg-card);
        border-top: 1px solid var(--border-subtle);
        z-index: 900;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.04);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .mobile-nav-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        color: var(--text-muted);
        font-size: 11px;
        font-weight: 700;
        gap: 4px;
        cursor: pointer;
        transition: color 0.15s ease;
    }

    .mobile-nav-tab.active {
        color: var(--primary);
    }

    .mobile-nav-tab .material-symbols-outlined {
        font-size: 22px;
    }

    .mobile-cart-badge {
        position: absolute;
        top: -6px;
        right: -10px;
        background: var(--red);
        color: #fff;
        font-size: 9px;
        font-weight: 800;
        min-width: 16px;
        height: 16px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
    }

    /* POS Layout Adjustments */
    .pos-layout {
        flex-direction: column !important;
        height: calc(100vh - 62px - env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Hide topbar sub-elements on mobile for clean screen spacing */
    .topbar {
        padding: 8px 12px !important;
        height: 52px !important;
        justify-content: space-between;
    }
    
    .topbar-left h2, 
    .topbar-left .tenant-badge, 
    .topbar-right button:not(#shiftManagerBtn),
    .topbar-right .user-profile {
        display: none !important;
    }
    
    .topbar-right {
        gap: 6px !important;
    }

    /* Tabbed views navigation toggling */
    .pos-layout.show-catalog .pos-main {
        display: flex !important;
    }
    
    .pos-layout.show-catalog .pos-sidebar {
        display: none !important;
    }

    .pos-layout.show-cart .pos-main {
        display: none !important;
    }
    
    .pos-layout.show-cart .pos-sidebar {
        display: flex !important;
        width: 100% !important;
        height: 100% !important;
    }

    .pos-main {
        padding: 10px 12px 24px 12px !important;
        overflow-y: auto;
    }

    /* Responsive grid updates for mobile screens */
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important;
        gap: 10px !important;
        padding-bottom: 30px !important;
    }

    .product-card {
        height: 105px !important;
        padding: 10px !important;
    }

    .product-name {
        font-size: 11px !important;
        line-height: 1.2 !important;
    }

    .product-price {
        font-size: 13px !important;
    }

    .product-stock {
        font-size: 9px !important;
    }
    
    .categories-tabs {
        margin-bottom: 10px !important;
        gap: 6px !important;
    }
    
    .category-tab {
        padding: 6px 12px !important;
        font-size: 11px !important;
    }

    /* General modal responsive fixes */
    .modal-content {
        padding: 20px !important;
        max-height: 88vh !important;
    }
}


