/* =============================================================================
   1. GLOBAL RESET & VARIABLES
   ============================================================================= */
:root {
    --bg: #000000;
    --surface: #1a1a1a;
    --surface-light: #2a2a2a;
    --border: #333333;
    --primary: #ffffff;
    --accent: #4CAF50; /* Green */
    --accent-dim: rgba(76, 175, 80, 0.1);
    --danger: #ff4444;
    --text-muted: #888888;
}

* {
    box-sizing: border-box;
    margin: 0; padding: 0;
    -webkit-tap-highlight-color: transparent;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    user-select: none; /* Disable text selection for App-like feel */
}

/* LOCK VIEWPORT: The key to "Native App" feel on Web */
body {
    position: fixed; /* Prevents whole-page bounce */
    width: 100%;
    height: 100dvh; /* Dynamic viewport height */
    background: var(--bg);
    overflow: hidden; /* No global scroll */
    color: var(--primary);
}

/* Re-enable text selection for inputs so users can edit */
input, textarea { user-select: text; }

/* Utilities */
.hidden { display: none !important; }
.spacer { flex-grow: 1; }

/* =============================================================================
   2. LAYER 1: CAMERA FEED
   ============================================================================= */
#camera-feed {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    z-index: 0;
}

#capture-canvas { display: none; }

/* =============================================================================
   2.5. LAYER 1.5: VISUAL EFFECTS (FLASH & ANIMATION)
   ============================================================================= */
#flash-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: white;
    z-index: 5; /* Above Camera, Below HUD */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease-out;
}

/* Dynamic class for flying photos */
.flying-photo {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    object-fit: cover;
    z-index: 6;
    pointer-events: none;
    transform-origin: bottom left; /* Shrinks towards bottom left */
    border-radius: 0;
    will-change: transform, opacity, border-radius;
}

/* =============================================================================
   3. LAYER 2: HUD (HEADS UP DISPLAY)
   ============================================================================= */
#app-hud {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 10;
    display: flex; flex-direction: column; justify-content: space-between;
    padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom) 20px;
    background: linear-gradient(180deg, rgba(0,0,0,0.6) 0%, transparent 15%, transparent 85%, rgba(0,0,0,0.8) 100%);
    pointer-events: none; /* Let clicks pass through to camera */
}

/* Enable pointer events on interactive children */
.hud-top, .hud-bottom, button, .control-side, .mode-switcher { pointer-events: auto; }

/* --- Top Bar --- */
.hud-top {
    display: flex; align-items: center; justify-content: space-between;
    padding-top: 10px; height: 60px;
}

.icon-btn {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: none; color: white;
    backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; cursor: pointer;
    transition: transform 0.1s;
}
.icon-btn:active { transform: scale(0.95); }

/* --- Bottom Controls --- */
.hud-bottom {
    display: flex; flex-direction: column; align-items: center; gap: 25px; padding-bottom: 20px;
}

/* Mode Switcher */
.mode-switcher {
    position: relative;
    background: rgba(0,0,0,0.5);
    border-radius: 25px;
    display: flex;
    width: 160px; height: 40px;
    border: 1px solid rgba(255,255,255,0.2);
}
.mode-text {
    flex: 1; text-align: center; line-height: 38px;
    font-size: 13px; font-weight: 600; color: var(--text-muted); z-index: 2;
    transition: color 0.2s;
    cursor: pointer;
}
.mode-text.active { color: white; }
.mode-switcher .slider {
    position: absolute; top: 4px; left: 4px;
    width: calc(50% - 4px); height: calc(100% - 8px);
    background: rgba(255,255,255,0.2);
    border-radius: 20px;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 1;
}

/* Shutter Area */
.shutter-area {
    display: flex; align-items: center; justify-content: center;
    width: 100%;
    position: relative;
    padding: 0 10px; /* Slight padding from edges */
}

.control-side {
    width: 80px; /* Generous touch target */
    height: 60px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px;
    cursor: pointer; opacity: 0.9;
    transition: opacity 0.2s, transform 0.1s;
    position: absolute;
}

/* Position left and right controls */
#bulk-toggle {
    left: 10px;
}

#btn-reset-scan {
    right: 10px;
}
.control-side:active { opacity: 0.6; transform: scale(0.95); }
.control-side.active { opacity: 1; }
/* The dot for the "Bulk Toggle" state */
.control-side.active .dot { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

.control-side.disabled {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(100%);
}

.label { font-size: 12px; font-weight: 600; text-align: center; }
.dot { width: 6px; height: 6px; background: #666; border-radius: 50%; transition: background 0.3s; margin-top: 5px; }

/* Icons inside control-side */
#bulk-icon-area, #submit-icon-area {
    display: flex; flex-direction: column; align-items: center;
    width: 100%;
}

/* Shutter Button */
#shutter-btn {
    width: 76px; height: 76px;
    border-radius: 50%;
    border: 4px solid white;
    background: transparent;
    position: relative;
    cursor: pointer;
    flex-shrink: 0; /* Don't shrink */
}
#shutter-btn::after {
    content: ''; position: absolute;
    top: 4px; left: 4px; right: 4px; bottom: 4px;
    background: white; border-radius: 50%;
    transition: transform 0.1s;
    z-index: 1;
}
#shutter-btn:active::after { transform: scale(0.9); }

/* Counter Badge INSIDE Shutter */
#counter-badge {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #000; /* Black text on white shutter */
    font-size: 26px;
    font-weight: 800;
    z-index: 10;
    pointer-events: none; /* Let clicks pass to button */
}

/* =============================================================================
   4. LAYER 3: OVERLAYS (MODALS/PAGES)
   ============================================================================= */
.overlay {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: #111;
    z-index: 100;
    display: flex; flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.overlay.visible { transform: translateY(0); }

/* --- Header --- */
.overlay-header {
    flex-shrink: 0; height: 60px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; border-bottom: 1px solid var(--border);
    background: #111;
    padding-top: env(safe-area-inset-top);
    position: relative; 
    z-index: 20; 
}
.overlay-header h2 { font-size: 18px; font-weight: 600; }
.close-overlay { background: none; border: none; color: white; font-size: 20px; padding: 10px; cursor: pointer; }
.icon-btn-text { background: none; border: none; color: white; font-size: 16px; display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* --- Body (Scrollable) --- */
.overlay-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* iOS Momentum */
    padding: 20px;
    background: #111;
    position: relative;
}
.center-content { display: flex; flex-direction: column; justify-content: center; }

/* --- Footer --- */
.overlay-footer {
    flex-shrink: 0;
    padding: 15px 20px;
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: #111;
}
/* For buttons stuck to bottom inside relative containers */
.fixed-bottom { position: absolute; bottom: 0; left: 0; width: 100%; z-index: 50; }

/* --- Form Styles --- */
.auth-box { display: flex; flex-direction: column; gap: 15px; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 11px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 5px; }

input, textarea {
    width: 100%; background: var(--surface); border: 1px solid var(--border);
    color: white; padding: 12px; border-radius: 8px; font-size: 16px;
    resize: none; transition: border 0.2s;
}
input:focus, textarea:focus { border-color: var(--accent); outline: none; }

/* Buttons */
.primary-btn {
    width: 100%; padding: 14px; background: white; color: black;
    border: none; border-radius: 8px; font-weight: bold; font-size: 16px;
    cursor: pointer;
}
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary-btn { 
    background: var(--surface); color: white; padding: 10px; 
    border-radius: 8px; border: none; cursor: pointer; width: 100%;
}

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

.link-text { text-align: center; color: var(--text-muted); font-size: 14px; margin-top: 10px; text-decoration: underline; cursor: pointer; }
.error-text { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }

/* --- AUTH: Google Button & Divider --- */
.google-btn {
    width: 100%; padding: 12px;
    background: white; color: #333;
    border: 1px solid #ddd; border-radius: 8px;
    font-weight: 600; font-size: 16px;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    margin-bottom: 10px; cursor: pointer;
}
.google-btn:active { background: #f1f1f1; }

.divider {
    display: flex; align-items: center; text-align: center;
    margin: 15px 0; color: #555; font-size: 12px;
}
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid #333; }
.divider span { padding: 0 10px; }

/* --- DASHBOARD: User Identity Section --- */
.user-identity-section {
    display: flex; align-items: center; gap: 15px;
    padding: 25px 20px;
    background: #151515;
    border-bottom: 1px solid var(--border);
}

.user-avatar {
    width: 48px; height: 48px;
    background: var(--surface);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 20px;
    border: 1px solid var(--border);
}

.user-details { display: flex; flex-direction: column; justify-content: center; }
.user-details .label { font-size: 11px; text-transform: uppercase; color: #666; margin-bottom: 4px; font-weight: 600; }
.user-details h3 { font-size: 16px; color: white; font-weight: 500; word-break: break-all; }

/* --- DASHBOARD: Menu --- */
.menu-list { display: flex; flex-direction: column; }
.menu-item {
    background: none; border: none; border-bottom: 1px solid var(--border);
    color: white; padding: 20px; text-align: left; font-size: 17px;
    display: flex; align-items: center; gap: 15px; cursor: pointer;
}
.menu-item i { width: 25px; text-align: center; color: var(--text-muted); }
.menu-item.destructive { color: var(--danger); }
.menu-item.destructive i { color: var(--danger); }

/* =============================================================================
   5. EMAIL SETTINGS UI
   ============================================================================= */

/* Toggle Switch */
.toggle-container { display: flex; align-items: center; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; touch-action: manipulation; z-index: 10;}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #333; transition: .4s; border-radius: 24px; }
.switch .slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
.switch input:checked + .slider { background-color: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* Template List */
.settings-intro { padding: 20px; color: var(--text-muted); font-size: 14px; text-align: center; }

.template-card {
    background: var(--surface);
    margin: 10px 0;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.2s;
}
.template-card:active { background: var(--surface-light); }

.template-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.template-header h4 {
    flex: 1;
    font-size: 16px;
    color: white;
    font-weight: 600;
}

.status-indicator {
    font-size: 11px;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 4px;
    background: #333;
    color: #888;
}

.template-card.active .status-indicator {
    background: var(--accent);
    color: white;
}

.template-actions {
    display: flex; /* Always visible for better UX */
    flex-direction: row;
    gap: 10px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.action-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid #444;
    background: transparent;
    color: white;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

.btn-activate { background: rgba(255,255,255,0.1); }
.template-card.active .btn-activate { border-color: var(--accent); color: var(--accent); }

/* Active State for Template */
.template-card.active { border-color: var(--accent); background: var(--accent-dim); }
.template-card h4 { font-size: 16px; margin-bottom: 5px; color: white; font-weight: 600; }
.template-card p {
    font-size: 13px;
    color: var(--text-muted);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Show 2 lines of preview */
    -webkit-box-orient: vertical;
    line-height: 1.4;
    max-height: 2.8em; /* 2 lines * 1.4 line-height */
}
.check-icon { position: absolute; top: 15px; right: 15px; color: var(--accent); display: none; }
.template-card.active .check-icon { display: block; }

/* =============================================================================
   6. LAYER 4: MODALS & SPINNERS
   ============================================================================= */
.modal-backdrop {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); z-index: 200;
    display: flex; align-items: center; justify-content: center;
}

.modal-box {
    background: var(--surface); width: 80%; max-width: 320px;
    padding: 24px; border-radius: 12px; text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions button { flex: 1; }

.spinner-box { text-align: center; color: var(--accent); }
.spinner-box i { font-size: 40px; margin-bottom: 15px; }

/* =============================================================================
   7. ENTERPRISE ADMIN PANEL
   ============================================================================= */

/* User Type Badge */
.user-type-badge {
    display: inline-block;
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 4px;
    margin-top: 4px;
}

.user-type-badge.admin {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.user-type-badge.sub-account {
    background: #333;
    color: #888;
}

/* Sub-accounts List */
.sub-accounts-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sub-account-card {
    background: var(--surface);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s;
}

.sub-account-card:active {
    background: var(--surface-light);
}

.sub-account-card.inactive {
    opacity: 0.5;
    border-style: dashed;
}

.sub-account-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sub-account-info .username {
    font-size: 16px;
    font-weight: 600;
    color: white;
}

.sub-account-info .status {
    font-size: 12px;
    color: var(--text-muted);
}

.sub-account-info .status.online {
    color: var(--accent);
}

.sub-account-actions {
    display: flex;
    gap: 8px;
}

.sub-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sub-action-btn:active {
    transform: scale(0.9);
}

.sub-action-btn.toggle {
    color: var(--accent);
}

.sub-action-btn.toggle.off {
    color: var(--danger);
}

.sub-action-btn.edit {
    color: #888;
}

.sub-action-btn.export {
    width: auto;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    gap: 6px;
    background: rgba(76, 175, 80, 0.15);
    color: var(--accent);
}

.sub-action-btn.export:hover {
    background: rgba(76, 175, 80, 0.25);
}

/* Template assignment dropdown for sub-accounts */
.sub-account-template {
    flex: 1;
    margin: 0 15px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sub-account-template label {
    font-size: 12px;
    color: #888;
}

.template-dropdown {
    width: 100%;
    padding: 8px 12px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.template-dropdown:focus {
    outline: none;
    border-color: var(--accent);
}

/* Update sub-account-card layout to accommodate new elements */
.sub-account-card {
    background: var(--surface);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: all 0.2s;
}

.sub-account-card > div:first-child {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ============================================ */
/* Distributor Dashboard Styles */
/* ============================================ */

.distributor-stats {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.stat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.stat-header i {
    font-size: 20px;
}

.stat-header span {
    color: #fff;
    font-size: 14px;
    font-weight: 500;
}

.stat-numbers {
    display: flex;
    gap: 10px;
}

.stat-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.stat-item.wide {
    flex: 2;
}

.stat-label {
    color: #888;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    color: #fff;
    font-size: 20px;
    font-weight: 600;
}

.account-creation-section {
    background: var(--surface);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.account-type-toggle {
    display: flex;
    gap: 10px;
}

.account-type-btn {
    flex: 1;
    padding: 12px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: #888;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.account-type-btn i {
    font-size: 16px;
}

.account-type-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.account-type-btn:hover:not(.active) {
    border-color: var(--accent);
    color: #fff;
}

.account-form {
    animation: fadeIn 0.3s ease;
}

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

.info-box {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.info-box i {
    color: var(--accent);
    margin-top: 2px;
}