/* iOS / Apple Store Theme Redesign */

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Base Variables & Theme (iOS Dark Mode by default to match existing logic) */
:root {
    --primary: #0A84FF; /* iOS Dark Mode Blue */
    --primary-hover: #007AFF;
    --app-bg: #000000;
    --panel-bg: #1C1C1E; /* iOS Dark Gray panels */
    --text-main: #FFFFFF;
    --text-muted: #8E8E93;
    --border-color: #38383A;
    --panel-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    
    --danger: #FF453A;
    --success: #32D74B;
    --warning: #FF9F0A;
    --transition: all 0.25s cubic-bezier(0.25, 1, 0.5, 1);
    --sidebar-width: 280px;
}

/* Light Theme Enhancements (iOS Light Mode) */
body.light-theme {
    --primary: #007AFF;
    --primary-hover: #005bb5;
    --app-bg: #F2F2F7;
    --panel-bg: #FFFFFF;
    --text-main: #000000;
    --text-muted: #8E8E93;
    --border-color: #C6C6C8;
    --panel-shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--app-bg);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Hide particles to respect clean Apple aesthetic */
canvas.particles-js-canvas-el {
    display: none !important;
}

/* Glassmorphism -> Solid Apple Cards */
.glass-panel {
    background: var(--panel-bg);
    border: none;
    border-radius: 22px;
    box-shadow: var(--panel-shadow);
}

/* Typography */
h1, h2, h3, h4 { color: var(--text-main); font-weight: 800; letter-spacing: -0.5px; }
p { color: var(--text-muted); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: 16px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    outline: none;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: rgba(142, 142, 147, 0.15); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Inputs */
.input-group {
    margin-bottom: 20px;
    position: relative;
    width: 100%;
}
.input-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}
.input-group i {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.2rem;
}
.input-group input {
    width: 100%;
    background: rgba(142, 142, 147, 0.12);
    border: none;
    padding: 16px 45px 16px 16px;
    border-radius: 14px;
    color: var(--text-main);
    font-size: 1rem;
    transition: var(--transition);
}
.input-group input:focus {
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.2);
    outline: none;
}
.input-group label + input {
    padding-right: 16px;
}

/* Custom iOS Date Input Styling */
input[type="date"].ios-date-input {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    font-weight: 700;
    color: var(--text-main);
}
/* Stretch the invisible native indicator across the entire input to make it fully clickable */
input[type="date"].ios-date-input::-webkit-calendar-picker-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* Page Containers */
.page-container {
    display: none;
    min-height: 100vh;
    width: 100%;
}
.page-container.active { display: flex; animation: fadeIn 0.4s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

/* Login Page */
#login-page {
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}
.login-box {
    margin: auto;
    width: 100%;
    max-width: 400px;
    padding: 40px;
    text-align: center;
}
.logo-container { margin-bottom: 40px; }
.logo-icon { font-size: 4rem; color: var(--primary); margin-bottom: 15px; }

/* App Title */
.ig-style-title {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 2.2rem;
    color: var(--text-main);
    margin-bottom: 5px;
    font-weight: 800;
    letter-spacing: -1px;
    background: none;
    -webkit-text-fill-color: var(--text-main);
}

/* Social Login */
.social-login-section { margin-top: 30px; }
.social-divider {
    position: relative;
    text-align: center;
    margin-bottom: 25px;
}
.social-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    border-top: 1px solid var(--border-color);
    z-index: 1;
}
.social-divider span {
    position: relative;
    padding: 0 15px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 2;
    background-color: var(--panel-bg);
}
.social-icons {
    display: flex;
    justify-content: center;
    gap: 15px;
}
.btn-social {
    width: 50px;
    height: 50px;
    border-radius: 14px;
    border: none;
    background: rgba(142, 142, 147, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--text-main);
    cursor: pointer;
    transition: var(--transition);
}
.btn-social:hover {
    transform: translateY(-2px);
    background: rgba(142, 142, 147, 0.2);
}

/* --- DESKTOP & WEB APP LAYOUT --- */
@media (min-width: 768px) {
    #app-page {
        display: flex;
        flex-direction: row;
        height: 100vh;
        background: var(--app-bg);
    }
    .sidebar {
        width: 280px;
        height: 100vh;
        background: var(--panel-bg);
        border-left: 1px solid var(--border-color); /* RTL */
        display: flex;
        flex-direction: column;
        z-index: 10;
        box-shadow: 2px 0 20px rgba(0,0,0,0.05);
    }
    .sidebar-header {
        display: flex; align-items: center; gap: 12px; padding: 25px 20px; border-bottom: 1px solid var(--border-color);
    }
    .sidebar-header h2 { font-size: 1.25rem; font-weight: 800; }
    .sidebar-header img { width: 32px; height: 32px; border-radius: 8px; }
    
    .user-info {
        padding: 20px; border-bottom: 1px solid var(--border-color);
        display: flex; align-items: center; gap: 15px;
    }
    .avatar {
        width: 45px; height: 45px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; flex-shrink: 0;
    }
    .user-info .details { display: flex; flex-direction: column; flex: 1; }
    .user-info .name { font-weight: 700; font-size: 1.05rem; }
    .user-info .role { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
    
    .sidebar-nav { flex: 1; padding: 20px 0; overflow-y: auto; }
    .sidebar-nav ul { list-style: none; display: flex; flex-direction: column; gap: 8px; padding: 0 15px; margin: 0; }
    .sidebar-nav li { margin: 0; }
    .sidebar-nav a { display: flex; align-items: center; gap: 15px; padding: 14px 15px; border-radius: 14px; color: var(--text-muted); text-decoration: none; font-weight: 600; font-size: 1rem; transition: 0.2s; }
    .sidebar-nav a:hover, .sidebar-nav a.active { background: rgba(10, 132, 255, 0.1); color: var(--primary); }
    .sidebar-nav i { font-size: 1.4rem; }
    
    .sidebar-footer { padding: 20px; border-top: 1px solid var(--border-color); text-align: center; }
    .sidebar-footer .btn { width: 100%; display: flex; justify-content: center; padding: 14px; border-radius: 16px; font-size: 1rem; }
    
    .main-content {
        flex: 1;
        overflow-y: auto;
        padding: 30px 40px;
        display: flex;
        flex-direction: column;
    }
    .topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
    .content-wrapper { flex: 1; }
}

/* Notification Bell Styles */
.notif-bell {
    position: relative;
    cursor: pointer;
    background: rgba(255, 68, 68, 0.1);
    color: var(--danger);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.3);
    border: 1px solid rgba(255, 68, 68, 0.2);
}
.notif-bell .bell-dot {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 10px;
    height: 10px;
    background: var(--danger);
    border-radius: 50%;
    border: 2px solid var(--card-bg);
}

/* Animations */
@keyframes shakeBell {
    0%, 100% { transform: rotate(0deg); }
    10%, 30%, 50%, 70%, 90% { transform: rotate(-10deg); }
    20%, 40%, 60%, 80% { transform: rotate(10deg); }
}
.bx-tada { animation: shakeBell 0.5s ease-in-out infinite; }

/* --- LOGIC-BASED APP VARIATIONS --- */
body.is-mobile-app .sidebar { display: none !important; }
body.is-mobile-app .main-content { margin-left: 0 !important; width: 100%; padding-bottom: 90px; }
body.is-mobile-app .bottom-nav { display: flex !important; }

body.is-web-app .bottom-nav { display: none !important; }
body.is-web-app #app-page { display: grid; grid-template-columns: var(--sidebar-width) 1fr; height: 100vh; overflow: hidden; }
body.is-web-app .sidebar { display: flex !important; width: var(--sidebar-width); height: 100vh; border-left: 1px solid var(--border-color); }
body.is-web-app .main-content { overflow-y: auto; padding: 40px; }

/* Bottom Nav Styling (Mobile App Only) */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(70px + env(safe-area-inset-bottom));
    background: rgba(28, 28, 30, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    display: none;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 1000;
}
body.light-theme .bottom-nav { background: rgba(255, 255, 255, 0.85); }

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 700;
    gap: 4px;
    flex: 1;
    transition: var(--transition);
}
.nav-item i { font-size: 1.6rem; }
.nav-item.active { color: var(--primary); transform: translateY(-2px); }
.nav-item.active i { transform: scale(1.1); }

/* Layout adjustments */
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 15px; }

/* Products Grid */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); /* Smaller min-width for mobile */
    gap: 15px;
}
.product-card {
    background: var(--panel-bg);
    border: none;
    border-radius: 20px;
    box-shadow: var(--panel-shadow);
    overflow: hidden;
    transition: var(--transition);
    position: relative;
    padding: 12px;
    display: flex;
    flex-direction: column;
}
.product-card:active { transform: scale(0.96); }
.product-image {
    width: 100%;
    height: 120px;
    background: transparent;
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 12px;
}
.product-image img { width: 100%; height: 100%; object-fit: contain; }
.product-image i { font-size: 3rem; color: rgba(142,142,147,0.3); }

.status-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 800;
    z-index: 2;
}
.status-in-stock { background: rgba(52, 199, 89, 0.15); color: var(--success); }
.status-out-stock { background: rgba(255, 59, 48, 0.15); color: var(--danger); }
.status-low-stock { background: rgba(255, 149, 0, 0.15); color: var(--warning); }

.product-details { padding: 0; display: flex; flex-direction: column; flex: 1; }
.product-title { font-size: 1rem; font-weight: 800; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-main); }
.stock-info {
    display: flex;
    justify-content: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}
.stock-item { display: flex; align-items: baseline; gap: 4px; }
.stock-val { font-size: 0.85rem; font-weight: 800; color: var(--text-muted); }
.stock-lbl { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }

/* App Store Style GET Button */
.product-card .btn-primary {
    background: rgba(0, 122, 255, 0.1);
    color: var(--primary);
    border-radius: 18px;
    font-weight: 800;
    padding: 8px 12px;
    font-size: 0.9rem;
    box-shadow: none;
    width: 100%;
}

/* Tables */
.table-responsive { width: 100%; overflow-x: auto; border-radius: 20px; padding: 5px; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 600px; text-align: right; }
.data-table th, .data-table td { padding: 14px 15px; border-bottom: 1px solid var(--border-color); font-size:0.9rem;}
.data-table th { background: transparent; color: var(--text-muted); font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.data-table tr:last-child td { border-bottom: none; }
.tbl-img { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; background: rgba(142,142,147,0.1); display: flex; align-items: center; justify-content: center; }
.action-btns { display: flex; gap: 8px; }
.action-btn { background: rgba(142, 142, 147, 0.1); border: none; color: var(--primary); font-size: 1.1rem; cursor: pointer; transition: 0.2s; padding: 6px 10px; border-radius: 10px; }
.action-btn.del { color: var(--danger); }

/* User Management */
.users-container { display: grid; grid-template-columns: 1fr; gap: 20px; }
.add-user-panel, .users-list-panel { padding: 20px; }
.user-count-badge { padding: 6px 12px; background: rgba(0, 122, 255, 0.1); color: var(--primary); border-radius: 12px; font-weight: 800; font-size: 0.85rem; }
.user-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 10px;
    background: transparent;
    border-bottom: 1px solid var(--border-color);
}
.user-item:last-child { border-bottom: none; }
.user-item-info { display: flex; align-items: center; gap: 12px; }
.user-item-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }

/* Modals & Alerts */
.bell-container { position: relative; font-size: 1.5rem; color: var(--text-main); cursor: pointer; display: flex; align-items: center; justify-content: center;}
.bell-badge { position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff; font-size: 0.7rem; width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; }

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: flex-end; /* Mobile Bottom Sheet */
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: 0.3s;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal-content {
    width: 100%;
    max-width: 600px;
    padding: 30px 25px calc(30px + env(safe-area-inset-bottom));
    background: var(--panel-bg);
    border-radius: 30px 30px 0 0;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.2);
    transform: translateY(100%);
    transition: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-overlay.active .modal-content { transform: translateY(0); }
.modal-title { margin-bottom: 20px; text-align: center; font-size: 1.4rem; font-weight: 800; }
.modal-actions { display: flex; gap: 15px; margin-top: 25px; }
.modal-actions button { flex: 1; }
.withdraw-info { text-align: center; margin-bottom: 20px; }
.product-name { display: block; font-size: 1.3rem; font-weight: 800; margin-bottom: 5px; }
.badge { padding: 4px 10px; border-radius: 10px; font-size: 0.85rem; font-weight: 700; background: rgba(142, 142, 147, 0.2); }

/* Toasts */
.toast {
    position: fixed;
    top: calc(20px + env(safe-area-inset-top)); /* iOS safe area */
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: rgba(28, 28, 30, 0.85);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    padding: 15px 25px;
    border-radius: 30px;
    color: #fff;
    font-weight: 600;
    z-index: 3000;
    opacity: 0;
    transition: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    text-align: center;
    white-space: nowrap;
}
body.light-theme .toast { background: rgba(255, 255, 255, 0.95); color: #000; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

.filters-bar { display: flex; flex-direction: column; background: transparent; box-shadow: none; padding: 0; gap:10px;}
.filters-bar .input-group { width: 100%; margin-bottom: 5px; }

@media print {
    body * { visibility: hidden !important; }
    #print-receipt, #print-receipt * { visibility: visible !important; color: #000 !important; background: transparent !important; }
    #print-receipt { display: block !important; position: absolute; left: 0; top: 0; width: 100%; padding: 20px; font-family: sans-serif; }
    body { background: #fff !important; }
}

/* User Dropdown Menu */
.user-dropdown-menu {
    position: absolute;
    top: calc(100% + 5px);
    left: 20px;
    right: 20px;
    background: var(--panel-bg);
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    padding: 10px;
    display: none;
    flex-direction: column;
    z-index: 100;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s, transform 0.3s;
    border: 1px solid var(--border-color);
}
.user-dropdown-menu.show {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}
.user-dropdown-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    border-radius: 12px;
    color: var(--text-main);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: var(--transition);
}
.user-dropdown-menu a:hover {
    background: rgba(142, 142, 147, 0.15);
}
.user-dropdown-menu a i {
    font-size: 1.3rem;
}
.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 5px 0;
}

/* Theme Toggle Button Specifics */
#theme-toggle {
    background: rgba(142, 142, 147, 0.15);
    border: none;
    font-size: 1.4rem;
    color: var(--text-main);
    cursor: pointer;
    transition: var(--transition);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}
#theme-toggle:hover { background: rgba(142, 142, 147, 0.25); }
