/* ==========================================================================
   GLOBAL FIXES & RESPONSIVE COMPATIBILITY
   iOS, Windows Browsers, and Mobile Responsiveness
   ========================================================================== */

/* 1. Prevent iOS Safari auto-zoom on inputs */
input[type="text"], 
input[type="password"], 
input[type="email"], 
input[type="number"], 
input[type="search"], 
input[type="tel"], 
input[type="url"], 
textarea, 
select,
.form-input {
    font-size: 16px !important;
}

/* 2. Remove default iOS/Windows styling for buttons and selects */
select, button, .btn, input[type="submit"], input[type="button"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* 3. Smooth scrolling for scrollable areas on iOS */
body, .main-content, .table-container, .modal-box, .content, .sidebar {
    -webkit-overflow-scrolling: touch;
}

/* 4. Remove tap highlight color on iOS for cleaner interactions */
* {
    -webkit-tap-highlight-color: transparent;
}

/* 5. Better font rendering on Windows and macOS */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 6. Fix Windows Edge clear button in inputs overlapping with custom UI */
input[type="text"]::-ms-clear,
input[type="text"]::-ms-reveal,
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear {
    display: none;
    width: 0;
    height: 0;
}

/* 7. Fix iOS Safari double tap to zoom issue on buttons */
button, .btn, a, summary {
    touch-action: manipulation;
}

/* ==========================================================================
   MOBILE RESPONSIVENESS OVERRIDES & SMART CSS GRID
   ========================================================================== */

/* SMART CSS GRID OVERRIDE (Replaces inline body { display: flex } in all PHP files) */
body:not(.login-page) {
    display: grid !important;
    grid-template-columns: 280px 1fr !important;
    transition: grid-template-columns 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    height: 100vh !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
}

body.sidebar-collapsed:not(.login-page) {
    grid-template-columns: 0px 1fr !important;
}

@media (max-width: 768px) {
    body:not(.login-page) {
        grid-template-columns: 1fr !important; /* Mobile collapses to 1 column */
    }
}


/* Employee Overview Cards */
.emp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; margin-bottom: 30px; }
.emp-card { background: #ffffff; padding: 20px 24px; border-radius: 12px; border: 1px solid #e2e8f0; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 16px; align-items: center; box-shadow: 0 1px 3px rgba(0,0,0,0.05); cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; }
.emp-card:hover { transform: translateY(-3px); box-shadow: 0 4px 15px rgba(0,0,0,0.02); }
.emp-title { color: #94a3b8; font-size: 11px; font-weight: 700; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.emp-val { font-size: 24px; font-weight: 800; color: #0f172a; }
.emp-icon { grid-column: 1; grid-row: 1 / span 2; width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; margin-bottom: 0; }

.text-muted { color: #64748b; }

/* ==========================================================================
   TABLET BREAKPOINT (≤ 1024px)
   Adjusts multi-column layouts to fewer columns on tablets
   ========================================================================== */
@media (max-width: 1024px) {
    /* Stats grid: 2 columns on tablet instead of auto-fit */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Employee grid: 2 columns on tablet */
    .emp-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Profile grid: stack to 1 column on tablet */
    .profile-grid {
        grid-template-columns: 1fr !important;
    }

    /* Filter grid: 2 columns on tablet */
    .filter-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    /* Dashboard sidebar+chart layout (inline 350px 1fr) → stack */
    [style*="grid-template-columns: 350px 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Layout grid (sidebar + content like public_holidays) → stack */
    .layout-grid {
        grid-template-columns: 1fr !important;
    }

    /* Reduce main content padding */
    .content {
        padding: 0 24px 30px 24px !important;
    }

    .topbar {
        padding: 20px 24px !important;
    }
}

/* ==========================================================================
   SMALL TABLET / LARGE MOBILE BREAKPOINT (≤ 768px)
   Compact layout for phones — stat cards stay 2-col, forms stack
   ========================================================================== */
@media (max-width: 768px) {
    /* Make tables horizontally scrollable if they overflow */
    .table-container, .card, .report-section {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        display: block;
    }
    
    table {
        min-width: 600px;
    }

    /* STAT CARDS: Keep 2 columns on mobile — they're compact enough */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
        margin-bottom: 16px !important;
    }

    /* EMPLOYEE CARDS: Keep 2 columns on mobile */
    .emp-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
        margin-bottom: 16px !important;
    }

    /* FORMS & WIDE CONTENT: Stack to 1 column */
    .grid-2, .form-row, .filter-grid, .layout-grid, .profile-grid {
        grid-template-columns: 1fr !important;
        display: grid !important;
    }

    /* Modal form grids (inline 1fr 1fr / repeat(2, 1fr)) → 1 column */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns: repeat(2, 1fr)"] {
        grid-template-columns: 1fr !important;
    }

    /* Calendar grid: shrink gaps but keep 7 columns */
    .calendar-grid {
        grid-template-columns: repeat(7, 1fr) !important;
        gap: 2px !important;
        font-size: 11px !important;
    }

    /* Premium stat cards: compact for mobile */
    .premium-stat-card {
        min-width: unset !important;
        width: 100% !important;
        padding: 16px !important;
        gap: 12px !important;
        border-radius: 12px !important;
    }

    .premium-stat-card .icon-box {
        width: 40px !important;
        height: 40px !important;
        border-radius: 10px !important;
        font-size: 18px !important;
    }

    .premium-stat-card .info-title {
        font-size: 11px !important;
    }

    .premium-stat-card .info-value {
        font-size: 17px !important;
    }

    /* Stat cards (non-premium) compact */
    .stat-card {
        padding: 14px 16px !important;
        column-gap: 10px !important;
        border-radius: 10px !important;
    }

    .stat-icon {
        width: 38px !important;
        height: 38px !important;
        font-size: 18px !important;
        border-radius: 10px !important;
    }

    .stat-value {
        font-size: 18px !important;
    }

    .stat-title {
        font-size: 10px !important;
    }

    /* Topbar */
    .topbar {
        padding: 15px 16px !important;
        flex-direction: row;
        align-items: center;
        gap: 10px;
    }

    .content {
        padding: 0 12px 20px 12px !important;
    }

    .page-title {
        font-size: 20px !important;
    }

    /* Modals should be full width with some margin */
    .modal-box {
        width: 92% !important;
        padding: 20px !important;
        margin: 20px auto;
    }

    /* Login container adjustments */
    .login-container {
        padding: 30px 20px !important;
        width: 90% !important;
    }

    /* Import grid: stack */
    .import-grid {
        flex-direction: column !important;
    }

    /* Reduce section spacing globally */
    .table-header {
        margin-bottom: 4px !important;
    }

    .table-title {
        font-size: 16px !important;
    }

    /* Refresh bar / live badge compact */
    .refresh-bar {
        font-size: 11px !important;
    }

    /* Employee/GL/TL Dashboard: info & action cards → wrap to 2-col grid */
    .info-cards, .action-cards {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .info-card {
        padding: 14px !important;
        gap: 10px !important;
        border-radius: 12px !important;
    }

    .info-icon {
        width: 36px !important;
        height: 36px !important;
    }

    .info-label {
        font-size: 10px !important;
    }

    .info-value {
        font-size: 15px !important;
    }

    .action-card {
        padding: 24px 14px !important;
        border-radius: 14px !important;
    }

    .timer-display {
        font-size: 32px !important;
    }

    .timer-subtext {
        font-size: 12px !important;
        margin-bottom: 20px !important;
    }

    .timer-circle {
        width: 60px !important;
        height: 60px !important;
        margin-bottom: 14px !important;
    }

    .timer-circle svg {
        width: 24px !important;
        height: 24px !important;
    }

    .btn-action {
        padding: 12px !important;
        font-size: 14px !important;
    }

    /* Topbar: wrap buttons below title on mobile */
    .topbar {
        flex-wrap: wrap !important;
    }

    .topbar-right {
        gap: 8px !important;
        flex-wrap: wrap !important;
    }

    .topbar-right .btn-primary,
    .topbar-right .btn-danger {
        padding: 8px 14px !important;
        font-size: 12px !important;
    }

    .avatar {
        width: 30px !important;
        height: 30px !important;
        font-size: 13px !important;
    }

    /* Status pill compact */
    .status-pill {
        font-size: 11px !important;
        padding: 4px 12px !important;
        margin-bottom: 16px !important;
    }

    /* Override request link */
    .info-action {
        font-size: 11px !important;
        top: 10px !important;
        right: 10px !important;
    }
}

/* ==========================================================================
   SMALL PHONE BREAKPOINT (≤ 480px)
   Extra compact for small screens
   ========================================================================== */
@media (max-width: 480px) {
    /* Stats grid: still 2 columns but even tighter */
    .stats-grid {
        gap: 8px !important;
        margin-bottom: 12px !important;
    }

    /* Action cards (timers) need full width on small phones */
    .action-cards {
        grid-template-columns: 1fr !important;
    }


    .emp-grid {
        gap: 8px !important;
    }

    /* Stat cards: extra compact */
    .stat-card, .premium-stat-card {
        padding: 12px !important;
        gap: 8px !important;
    }

    .premium-stat-card .icon-box,
    .stat-icon {
        width: 34px !important;
        height: 34px !important;
        font-size: 16px !important;
        border-radius: 8px !important;
    }

    .stat-value, .premium-stat-card .info-value {
        font-size: 16px !important;
    }

    .stat-title, .premium-stat-card .info-title {
        font-size: 9px !important;
        letter-spacing: 0.3px !important;
    }

    /* Calendar grid: tighter */
    .calendar-grid {
        gap: 1px !important;
        font-size: 10px !important;
    }

    /* Even tighter content padding */
    .content {
        padding: 0 8px 15px 8px !important;
    }

    .topbar {
        padding: 12px 8px !important;
    }

    .page-title {
        font-size: 18px !important;
    }

    /* Modal full width on small phones */
    .modal-box {
        width: 95% !important;
        padding: 16px !important;
        border-radius: 16px !important;
    }
}

.switch input:checked + .slider { background-color: #3b82f6 !important; }
.switch .slider:before { position: absolute; content: ''; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* ==========================================================================
   PREMIUM UI SHARED STYLES (LIGHT MODE DEFAULTS)
   ========================================================================== */
.profile-avatar { width: 40px; height: 40px; border-radius: 50%; background: #1e293b; color: #94a3b8; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 16px; border: 1px solid rgba(255,255,255,0.1); }
.premium-stat-card { background: #ffffff; border: 1px solid var(--border-light); border-radius: 16px; padding: 24px; display: flex; align-items: center; gap: 20px; color: var(--text-main-light); flex: 1; min-width: 280px; box-shadow: 0 4px 15px rgba(0,0,0,0.02); }
.premium-stat-card .icon-box { width: 50px; height: 50px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.premium-stat-card .info-area { flex: 1; }
.premium-stat-card .info-title { color: var(--text-muted-light); font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.premium-stat-card .info-value { font-size: 20px; font-weight: 700; color: var(--text-main-light); }

.premium-action-card { background: #ffffff; border-radius: 16px; border: 1px solid var(--border-light); padding: 30px; text-align: center; position: relative; box-shadow: 0 4px 15px rgba(0,0,0,0.03); }
.premium-action-card.lunch-card { border-left: 3px solid #ef4444; box-shadow: inset 20px 0 50px -30px rgba(239, 68, 68, 0.05); }
.premium-action-card.short-card { border-left: 3px solid #8b5cf6; box-shadow: inset 20px 0 50px -30px rgba(139, 92, 246, 0.05); }

.timer-circle { width: 80px; height: 80px; border-radius: 50%; margin: 0 auto 20px auto; display: flex; align-items: center; justify-content: center; position: relative; }
.lunch-card .timer-circle { background: radial-gradient(circle, rgba(239,68,68,0.15) 0%, rgba(0,0,0,0) 70%); border: 1px solid rgba(239, 68, 68, 0.2); color: #ef4444; }
.short-card .timer-circle { background: radial-gradient(circle, rgba(139,92,246,0.15) 0%, rgba(0,0,0,0) 70%); border: 1px solid rgba(139, 92, 246, 0.2); color: #a855f7; }
.progress-bar-container { width: 100%; height: 8px; background: #e2e8f0; border-radius: 4px; margin: 20px 0; overflow: hidden; display: flex; align-items: center; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #a855f7); width: 100%; }

.btn-premium { width: 100%; padding: 16px; font-size: 16px; font-weight: 700; border: none; border-radius: 12px; cursor: pointer; transition: 0.2s; }
.btn-red { background: linear-gradient(135deg, #ef4444, #dc2626); color: white; box-shadow: 0 4px 15px -3px rgba(239, 68, 68, 0.4); }
.btn-red:hover:not(:disabled) { box-shadow: 0 6px 20px -3px rgba(239, 68, 68, 0.6); transform: translateY(-2px); }
.btn-purple { background: linear-gradient(135deg, #8b5cf6, #7c3aed); color: white; box-shadow: 0 4px 15px -3px rgba(139, 92, 246, 0.4); }
.btn-purple:hover:not(:disabled) { box-shadow: 0 6px 20px -3px rgba(139, 92, 246, 0.6); transform: translateY(-2px); }
.btn-premium:disabled { background: #e2e8f0; color: #94a3b8; cursor: not-allowed; box-shadow: none; transform: none; }

.status-badge-dark { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 6px 16px; border-radius: 20px; font-weight: 600; font-size: 13px; margin-bottom: 24px; background: rgba(0, 0, 0, 0.04); border: 1px solid rgba(0,0,0,0.05); color: var(--text-muted-light); }
.timer-display-premium { font-size: 48px; font-weight: 800; margin-bottom: 5px; font-variant-numeric: tabular-nums; color: var(--text-main-light); }
.timer-label-premium { color: var(--text-muted-light); font-weight: 600; font-size: 14px; margin-bottom: 25px; }

/* ==========================================================================
   UTILITY CLASSES (To replace inline styles)
   ========================================================================== */
.bg-white { background-color: #ffffff; }
.bg-yellow-50 { background-color: #fffbeb; }
.bg-blue-50 { background-color: #eff6ff; }
.bg-green-50 { background-color: #f0fdf4; }
.bg-purple-50 { background-color: #fdf4ff; }
.bg-emerald-50 { background-color: #ecfdf5; }
.bg-red-50 { background-color: #fef2f2; }
.bg-amber-100 { background-color: #fef3c7; }
.bg-slate-200 { background-color: #e2e8f0; }
.bg-slate-100 { background-color: #f1f5f9; }
.bg-transparent { background-color: transparent; }
.bg-slate-800 { background-color: #1e293b; }
.bg-blue-600 { background-color: #2563eb; }

.text-blue-600 { color: #2563eb; }
.text-green-600 { color: #16a34a; }
.text-emerald-600 { color: #059669; }
.text-red-500 { color: #ef4444; }
.text-amber-600 { color: #d97706; }
.text-slate-600 { color: #475569; }
.text-slate-500 { color: #64748b; }
.text-white { color: #ffffff; }

/* ==========================================================================
   CUSTOM SLEEK SCROLLBARS (For dual scrollbar feature & general tables)
   ========================================================================== */
.table-scroll-wrapper::-webkit-scrollbar,
.top-scrollbar-wrapper::-webkit-scrollbar {
    height: 10px;
}

/* Light mode styles */
.table-scroll-wrapper::-webkit-scrollbar-track,
.top-scrollbar-wrapper::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 10px;
}
.table-scroll-wrapper::-webkit-scrollbar-thumb,
.top-scrollbar-wrapper::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
.table-scroll-wrapper::-webkit-scrollbar-thumb:hover,
.top-scrollbar-wrapper::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.25);
}

/* Dark mode styles */
body.dark-mode .table-scroll-wrapper::-webkit-scrollbar-track,
body.dark-mode .top-scrollbar-wrapper::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}
body.dark-mode .table-scroll-wrapper::-webkit-scrollbar-thumb,
body.dark-mode .top-scrollbar-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid transparent;
    background-clip: padding-box;
}
body.dark-mode .table-scroll-wrapper::-webkit-scrollbar-thumb:hover,
body.dark-mode .top-scrollbar-wrapper::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.25);
}
