/* Base app styles */
body {
    font-family: 'Inter', sans-serif;
    padding-top: 0; /* Reset in case it was set elsewhere */
    transition: padding-top 0.3s; /* Smooth transition for banner */
}

/* Fix for duplicated auth forms */
#auth-panels .hidden {
    display: none;
}

/* --- OFFLINE STATUS BAR --- */
#offline-status-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 40px;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    transform: translateY(-100%);
    transition: transform 0.3s ease-in-out, background-color 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#offline-status-bar.visible {
    transform: translateY(0);
}

/* Status Colors */
.status-offline {
    background-color: #ef4444; /* Red-500 */
    color: white;
}
.status-syncing {
    background-color: #eab308; /* Yellow-500 */
    color: white;
}
.status-online {
    background-color: #22c55e; /* Green-500 */
    color: white;
}

/* Adjust body padding when banner is visible to prevent overlap */
body.has-offline-banner {
    padding-top: 40px;
}

/* Custom styles for tables and buttons for a cleaner look */
.app-table {
    width: 100%;
    border-collapse: collapse;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #e5e7eb;
}
.app-table th, .app-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
}
.app-table th {
    background-color: #f9fafb;
    font-weight: 600;
    color: #374151;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.app-table td {
    font-size: 0.875rem;
    color: #4b5563;
}
.app-table tr:last-child td {
    border-bottom: 0;
}
.app-table tr:hover {
    background-color: #f9fafb;
}

/* Form inputs and buttons */
.app-input, .app-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.app-input:focus, .app-select:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px #e0e7ff;
}
.app-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 100px;
}
.app-textarea:focus {
     outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px #e0e7ff;
}


.app-button {
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: 600;
    color: white;
    background-color: #4f46e5; /* indigo-600 */
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: background-color 0.2s;
    border: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.app-button:hover {
    background-color: #4338ca; /* indigo-700 */
}
.app-button-secondary {
    background-color: #ffffff;
    color: #374151;
    border: 1px solid #d1d5db;
}
.app-button-secondary:hover {
    background-color: #f9fafb;
}
.app-button-icon {
    padding: 8px;
    background-color: #f3f4f6;
    color: #4b5563;
    border: 1px solid #d1d5db;
}
.app-button-icon:hover {
    background-color: #e5e7eb;
}
.app-button-danger {
    background-color: transparent;
    color: #ef4444;
    padding: 0;
    box-shadow: none;
}
.app-button-danger:hover {
    background-color: transparent;
    color: #dc2626;
}


/* Tabs */
.tab-button {
    padding: 8px 16px;
    border: 0;
    background: none;
    font-weight: 600;
    color: #6b7280;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}
.tab-button:hover {
    color: #374151;
}
.tab-button.active {
    color: #4f46e5;
    border-bottom-color: #4f46e5;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 9999px;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
}
.badge-pending {
    color: #995000;
    background-color: #ffedd5;
}
.badge-superadmin {
    color: #312e81;
    background-color: #e0e7ff;
}
.badge-admin {
    color: #166534;
    background-color: #dcfce7;
}
.badge-manager {
    color: #1d4ed8;
    background-color: #dbeafe;
}
.badge-lead_capturer {
    color: #581c87;
    background-color: #f3e8ff;
}
 .badge-user {
    color: #374151;
    background-color: #f3f4f6;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 50;
}
.modal-content {
    background: white;
    padding: 24px;
    border-radius: 8px;
    width: 100%;
    max-width: 600px;
    transform: translateY(20px);
    transition: transform 0.3s;
}
.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}
.modal-overlay.open .modal-content {
    transform: translateY(0);
}

/* Toast Notification */
#toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #22c55e;
    color: white;
    padding: 12px 20px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
    z-index: 100;
    font-weight: 600;
}
#toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Form Builder */
.form-builder-field {
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #ffffff;
    padding: 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.form-builder-field .drag-handle {
    cursor: move;
    color: #9ca3af;
}
.form-builder-field .drag-handle:hover {
    color: #374151;
}
.sortable-ghost {
    background: #eef2ff;
    opacity: 0.5;
    border-radius: 6px;
    border: 1px dashed #6366f1;
}

/* Embed Code Textarea */
#embed-code-textarea {
    font-family: monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    color: #312e81;
    background-color: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 6px;
    padding: 12px;
    width: 100%;
    min-height: 150px;
    white-space: pre;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* Star Rating */
#lqc-star-rating .star-icon.active {
    color: #f59e0b; /* A nice amber color */
}

/* --- Lead Management Table --- */
.lead-table-stars {
    display: flex;
    color: #f59e0b; /* Amber */
}

.lead-table-stars .star-filled {
    color: #f59e0b; /* Amber */
}

.lead-table-stars .star-empty {
    color: #d1d5db; /* Gray-300 */
}

/* Make note text wrap nicely */
.lead-table-notes {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.875rem;
    color: #4b5563;
}

/* Wrapper to make the editor look like one input */
.editor-wrapper {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.editor-wrapper:focus-within {
    border-color: #6366f1; /* indigo-500 */
    box-shadow: 0 0 0 3px #e0e7ff; /* indigo-100 ring */
}

/* Variable Chips (Pills) */
.var-chip {
    display: inline-flex;
    align-items: center;
    font-size: 0.70rem; /* text-xs/sm mix */
    font-weight: 600;
    color: #4338ca; /* indigo-700 */
    background-color: #e0e7ff; /* indigo-100 */
    padding: 3px 10px;
    border-radius: 9999px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    user-select: none;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.var-chip:hover {
    background-color: #4f46e5; /* indigo-600 */
    color: white;
}

.var-chip:active {
    transform: translateY(1px);
}

/* ==========================================
   MOBILE RESPONSIVENESS (Card View + Scanner Fix)
   ========================================== */

@media (max-width: 768px) {

    /* --- 1. Responsive Tables (Card View) --- */
    /* Force table to not behave like a table anymore */
    .app-table, .app-table thead, .app-table tbody, .app-table th, .app-table td, .app-table tr { 
        display: block; 
    }

    /* Hide headers (but keep for accessibility/screen readers if needed) */
    .app-table thead tr { 
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .app-table tr { 
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        margin-bottom: 1rem;
        background: white;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    }

    .app-table td { 
        border-bottom: 1px solid #f3f4f6;
        position: relative;
        padding-left: 1rem;
        padding-right: 1rem;
        text-align: left;
        white-space: normal !important; /* Force text wrap */
        word-break: break-word;
    }

    .app-table tr:last-child td {
        border-bottom: none;
    }

    /* Specific adjustments for Actions column to look like a footer */
    .app-table td:last-child {
        background-color: #f9fafb;
        border-top: 1px solid #e5e7eb;
        display: flex;
        justify-content: flex-end;
        border-bottom-left-radius: 8px;
        border-bottom-right-radius: 8px;
    }
    
    /* Make checkboxes larger on mobile */
    input[type="checkbox"] {
        transform: scale(1.2);
    }

    /* --- 2. Scanner Overlay Mobile Fixes --- */
    #lqc-scanner-screen {
        display: flex !important;
        flex-direction: column;
        height: 100vh;
        height: 100dvh; /* Dynamic Viewport Height for mobile browsers */
        padding: 1rem;
        background-color: #000 !important; /* Dark background for focus */
    }

    /* Force the scanner box to take available space but not overflow */
    #lqc-qr-reader {
        flex-grow: 1;
        width: 100% !important;
        max-width: none !important;
        border: 2px solid #4f46e5;
        border-radius: 12px;
        margin: 0 !important;
        background: #000;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
    }
    
    #lqc-qr-reader video {
        object-fit: cover;
        width: 100%;
        height: 100%;
        border-radius: 8px;
    }

    /* Pin text/header to top */
    #lqc-scanner-screen > div:first-child {
        margin-bottom: 1rem;
        color: white;
    }
    #lqc-scanner-header { color: white !important; }
    #lqc-scanner-subheader { color: #9ca3af !important; }

    /* Pin Close button to bottom safely */
    #lqc-back-to-selection-btn {
        width: 100%;
        margin-top: 1rem;
        padding: 16px; /* Fat finger target */
        background-color: #ef4444; /* Red for visibility */
        color: white;
        border: none;
        font-size: 1rem;
    }

    /* --- 3. Navigation & Modal Tweaks --- */
    
    /* Allow tabs to scroll horizontally smoothly */
    nav[id$="-tabs"] {
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px; /* Space for scrollbar */
    }
    
    /* Increase modal inputs for touch */
    .modal-content input, 
    .modal-content select, 
    .modal-content button {
        min-height: 44px; /* iOS standard touch target */
    }
    
    /* Ensure modal fits on small screens with keyboard open */
    .modal-content {
        max-height: 85vh;
        overflow-y: auto;
    }
}

/* ==========================================
   PHASE 2: CHECK-IN STATION STYLES
   ========================================== */

/* The main container for the Check-in UI */
#checkin-screen {
    /* Smooth transitions for background color changes (Green/Red/Yellow) */
    transition: background-color 0.3s ease-in-out;
}

/* Typography Improvements */
#checkin-state-success h1,
#checkin-state-error h1 {
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Badge Canvas for Printing 
   Hidden in UI but styled for rasterization/screenshot 
*/
#hidden-print-container {
    position: fixed;
    top: -9999px;
    left: -9999px;
    z-index: -100;
    pointer-events: none;
}

#badge-canvas {
    background: white;
    /* Brother DK-2205 (62mm) 
       Approx 300-400px width is standard for decent resolution
    */
    width: 350px; 
    height: auto;
    min-height: 180px;
    color: black;
    /* Ensure crisp text for thermal printing */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Line clamping utilities */
.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;            /* Added standard property */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;            /* Added standard property */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ==========================================
   PRINT HYGIENE
   ========================================== */
@media print {
    /* Hide everything in the main app window if someone tries to print the dashboard manually */
    body > * {
        display: none !important;
    }
    
    /* Only allow the badge canvas to be visible if we were to print via browser dialog
       (Though we use QZ Tray, this is a safety fallback) */
    #hidden-print-container {
        position: absolute;
        top: 0;
        left: 0;
        display: block !important;
    }
    
    #badge-canvas {
        display: block !important;
        visibility: visible !important;
    }
}