/* --- Design System --- */
:root {
    --primary: hsl(210, 100%, 60%);
    --primary-glow: hsla(210, 100%, 60%, 0.3);
    --secondary: hsl(260, 100%, 65%);
    
    --bg-dark: hsl(230, 40%, 4%);
    --bg-card: hsla(230, 30%, 8%, 0.7);
    --bg-sidebar: hsla(230, 30%, 5%, 0.85);
    
    --border: hsla(0, 0%, 100%, 0.06);
    --border-hover: hsla(0, 0%, 100%, 0.12);
    
    --text: hsl(210, 20%, 98%);
    --text-dim: hsl(210, 15%, 70%);
    --text-muted: hsl(210, 10%, 50%);
    
    --success: hsl(150, 80%, 50%);
    --warning: hsl(45, 100%, 55%);
    --danger: hsl(0, 85%, 60%);
    
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 12px 40px -12px rgba(0, 0, 0, 0.7);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', system-ui, sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
    background-image: 
        radial-gradient(at 0% 0%, hsla(210, 100%, 15%, 0.4) 0px, transparent 50%),
        radial-gradient(at 100% 100%, hsla(260, 100%, 10%, 0.3) 0px, transparent 50%);
}

#app-shell {
    display: flex;
    height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 3rem;
}

.brand-logo {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px var(--primary-glow);
}

.brand-logo i {
    color: white;
    width: 22px;
    height: 22px;
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    display: block;
}

.brand-tagline {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.nav-group {
    margin-bottom: 2.5rem;
}

.nav-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding-left: 0.75rem;
    margin-bottom: 0.75rem;
}

.nav-link {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    margin-bottom: 0.25rem;
}

.nav-link i {
    width: 20px;
    height: 20px;
}

.nav-link:hover {
    background: hsla(0, 0%, 100%, 0.04);
    color: var(--text);
    transform: translateX(4px);
}

.nav-link.active {
    background: hsla(210, 100%, 60%, 0.1);
    color: var(--primary);
}

.nav-link.active .nav-indicator {
    position: absolute;
    right: 12px;
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--primary);
}

.badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    box-shadow: 0 4px 10px hsla(0, 85%, 60%, 0.4);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.system-status {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

/* --- Main Content --- */
.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: transparent;
    overflow: hidden;
}

.top-bar {
    height: 80px;
    padding: 0 3rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
}

#view-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.text-muted { color: var(--text-muted); font-size: 0.85rem; }

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.clock-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-card);
    padding: 0.5rem 1.25rem;
    border-radius: 50px;
    border: 1px solid var(--border);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--primary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.username { font-size: 0.85rem; font-weight: 600; }
.role { font-size: 0.7rem; color: var(--text-muted); }

.view-port {
    flex: 1;
    padding: 3rem;
    overflow-y: auto;
}

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

.stat-card {
    background: var(--bg-card);
    padding: 1.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-5px);
    background: hsla(0, 0%, 100%, 0.03);
}

.stat-label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--text); }
.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.stat-icon.primary { background: var(--primary-glow); color: var(--primary); }
.stat-icon.warning { background: hsla(45, 100%, 55%, 0.15); color: var(--warning); }
.stat-icon.danger { background: hsla(0, 85%, 60%, 0.15); color: var(--danger); }
.stat-icon.success { background: hsla(150, 80%, 50%, 0.15); color: var(--success); }

/* --- Table --- */
.data-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}

.table-header {
    padding: 1.5rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.table-title { font-size: 1.1rem; font-weight: 700; }

.search-input {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    color: var(--text);
    width: 300px;
    outline: none;
    transition: var(--transition);
}

.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

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

.pos-table th {
    text-align: left;
    padding: 1.25rem 2rem;
    background: hsla(0, 0%, 100%, 0.02);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.pos-table td {
    padding: 1.25rem 2rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

.pos-table tr:last-child td { border-bottom: none; }
.pos-table tr:hover td { background: hsla(0, 0%, 100%, 0.01); }

.prod-cell { display: flex; align-items: center; gap: 1rem; }
.thumb-stack { display: flex; align-items: center; position: relative; width: 64px; }
.img-thumb {
    width: 40px; height: 40px;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid var(--bg-dark);
    background: var(--bg-dark);
}
.img-thumb.expiry { margin-left: -18px; border-color: var(--warning); z-index: 1; }

.tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}
.tag.valid { background: hsla(150, 80%, 50%, 0.15); color: var(--success); }
.tag.soon { background: hsla(45, 100%, 55%, 0.15); color: var(--warning); }
.tag.expired { background: hsla(0, 85%, 60%, 0.15); color: var(--danger); }

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: hsla(230, 40%, 2%, 0.8);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    visibility: hidden;
    transition: 0.3s ease;
}

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

.modal-box {
    width: 100%;
    max-width: 600px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 40px 100px rgba(0, 0, 0, 0.8);
    transform: translateY(20px) scale(0.95);
    transition: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

.close-modal { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.5rem; }

.modal-body { padding: 2rem; max-height: 70vh; overflow-y: auto; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

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

.form-group { display: flex; flex-direction: column; gap: 0.5rem; }
.form-group label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.form-group input, .form-group select {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    color: var(--text);
    outline: none;
}
.form-group input:focus { border-color: var(--primary); }

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-muted);
}
.upload-zone:hover { border-color: var(--primary); background: var(--primary-glow); color: var(--primary); }
.upload-zone i { width: 32px; height: 32px; }

.preview-area { position: relative; width: 100%; height: 120px; border-radius: 12px; overflow: hidden; }
.preview-area img { width: 100%; height: 100%; object-fit: cover; }
.remove-img { position: absolute; top: 8px; right: 8px; background: var(--danger); color: white; border: none; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; }

.modal-footer { padding: 1.5rem 2rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 1rem; }

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border: none;
}
.btn-primary { background: var(--primary); color: white; box-shadow: 0 4px 15px var(--primary-glow); }
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-2px); }
.btn-secondary { background: var(--border); color: var(--text); }

/* --- Toaster --- */
#toaster { position: fixed; bottom: 2rem; right: 2rem; display: flex; flex-direction: column; gap: 0.75rem; z-index: 2000; }
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: toastIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    backdrop-filter: blur(20px);
}
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* --- Responsive --- */
/* --- Mobile Toggle Defaults --- */
.menu-toggle, .mobile-close { display: none; }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .sidebar { width: 80px; padding: 2rem 0.75rem; align-items: center; }
    .brand-info, .nav-label, .nav-link span, .badge, .system-status span, .brand-tagline { display: none; }
    .top-bar { padding: 0 1.5rem; }
    .view-port { padding: 1.5rem; }
}

@media (max-width: 768px) {
    body { overflow-y: auto; overflow-x: hidden; height: auto; min-height: 100dvh; }
    #app-shell { height: auto; min-height: 100dvh; display: block; }
    
    .sidebar { 
        position: fixed; 
        left: -280px; 
        top: 0; 
        bottom: 0; 
        width: 280px; 
        transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        padding: 1.5rem;
        align-items: stretch;
        box-shadow: 20px 0 50px rgba(0,0,0,0.5);
        z-index: 1000;
    }
    
    .sidebar.active { left: 0; }
    
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        z-index: 999;
        display: none;
    }
    
    .sidebar-overlay.active { display: block; }
    
    .brand-info, .nav-label, .nav-link span, .badge, .system-status span, .brand-tagline { display: block; }
    .mobile-close { display: flex; align-items: center; justify-content: center; background: none; border: none; color: var(--text-muted); cursor: pointer; }
    .sidebar-header { justify-content: space-between; align-items: center; }
    
    .main-container { height: auto; min-height: 100vh; display: block; }
    
    .top-bar { 
        height: 70px; 
        padding: 0 1.25rem; 
        position: sticky; 
        top: 0; 
        z-index: 900;
        background: var(--bg-sidebar);
    }
    
    .menu-toggle { display: flex; align-items: center; justify-content: center; background: none; border: none; color: var(--text); font-size: 1.5rem; cursor: pointer; margin-right: 1rem; }
    
    .top-bar-right { display: none; }
    
    .view-port { padding: 1.25rem; overflow-y: visible; }
    
    .stats-grid { grid-template-columns: 1fr; gap: 1rem; }
    
    .data-card { 
        overflow-x: auto; 
        margin: 0 -0.25rem; 
        border-radius: var(--radius-sm);
    }
    
    .table-header { flex-direction: column; align-items: flex-start; gap: 1rem; padding: 1.25rem; }
    .search-input { width: 100%; }
    
    .pos-table th, .pos-table td { padding: 1rem 1.25rem; }
    
    .modal-box { 
        max-height: 90vh; 
        width: 95%; 
        margin: 0 auto; 
    }
    .modal-body { padding: 1.25rem; }
    .form-grid { grid-template-columns: 1fr; gap: 1rem; }
    .span-full { grid-column: auto; }
}

/* Fix for iOS Safari bottom bars */
@supports (-webkit-touch-callout: none) {
    .sidebar, .modal-overlay, #app-shell {
        height: -webkit-fill-available;
    }
}
