/* ============================================================
   HRPro Solutions — Global Responsive Stylesheet
   responsive.css
   Covers: Mobile, Tablet, Laptop, Desktop (320px → 1920px+)
   ============================================================ */

/* ── 1. CSS Custom Properties & Base Reset ──────────────────── */
:root {
    --sidebar-w: 260px;
    --topbar-h:  70px;
    --navy:      #0a1628;
    --navy-mid:  #112240;
    --navy-light:#1a3a5c;
    --cyan:      #00c8e0;
    --cyan-dark: #0099b0;
    --blue-mid:  #1e6faa;
    --blue-light:#5ab4e5;
    --white:     #ffffff;
    --gray-100:  #f0f6ff;
    --gray-200:  #e2eaf6;
    --gray-400:  #94a3b8;
    --gray-600:  #64748b;
    --danger:    #ef4444;
    --success:   #10b981;
    --touch-min: 44px; /* minimum touch target size */
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    max-width: 100%;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

img, video, svg {
    max-width: 100%;
    height: auto;
}

/* ── 2. Sidebar — Collapsible Mobile/Tablet ─────────────────── */

/* Hamburger toggle button — hidden on desktop */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 200;
    background: var(--navy);
    border: none;
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
    flex-direction: column;
    gap: 5px;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.sidebar-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--white);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.sidebar-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.sidebar-toggle.open span:nth-child(2) { opacity: 0; }
.sidebar-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 99;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.show { display: block; }

/* ── 3. Dashboard Layout — Responsive Body & Content ──────── */
.main-content {
    transition: margin-left 0.3s ease;
    min-width: 0;
    width: 100%;
}
.page-body {
    min-width: 0;
    width: 100%;
}

/* ── 4. Topbar Responsive ───────────────────────────────────── */
.topbar {
    padding: 0 24px;
}

.topbar-left h1 {
    font-size: clamp(1rem, 2.5vw, 1.4rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60vw;
}

.topbar-left p {
    font-size: clamp(0.75rem, 1.5vw, 1.05rem);
}

/* ── 5. Page Body Padding ───────────────────────────────────── */
.page-body {
    padding: clamp(16px, 3vw, 32px);
}

/* ── 6. Stats Grid — Responsive Cards ──────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
    gap: clamp(12px, 2vw, 20px);
    margin-bottom: clamp(20px, 3vw, 32px);
}

.stat-card {
    padding: clamp(16px, 2vw, 24px);
}

.stat-value {
    font-size: clamp(1.4rem, 3vw, 2rem);
}

/* ── 7. Info Banner Responsive ─────────────────────────────── */
.info-banner {
    flex-direction: row;
    flex-wrap: wrap;
    padding: clamp(18px, 3vw, 28px) clamp(20px, 3vw, 32px);
}

.info-banner .banner-icon {
    font-size: clamp(32px, 5vw, 48px);
}

.info-banner h2 {
    font-size: clamp(1.1rem, 2.5vw, 1.5rem);
}

/* ── 8. Responsive Tables ───────────────────────────────────── */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
}

.table-wrap table,
.data-table {
    width: 100%;
    min-width: 600px; /* prevents column squish */
    border-collapse: collapse;
}

/* Responsive card-style table on small screens */
.table-responsive-card {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── 9. Action / Feature Cards Grid ────────────────────────── */
.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr));
    gap: clamp(12px, 2vw, 16px);
}

.action-card {
    padding: clamp(16px, 2.5vw, 22px) clamp(14px, 2vw, 20px);
}

/* ── 10. Forms — Mobile Friendly ───────────────────────────── */
.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="tel"],
select,
textarea {
    width: 100%;
    min-height: var(--touch-min);
    font-size: max(16px, 1rem); /* prevents iOS zoom on focus */
}

.form-group,
.mb-3,
.form-field {
    margin-bottom: clamp(14px, 2vw, 22px);
}

/* Buttons — touch friendly */
.btn,
button[type="submit"],
.btn-login,
.btn-primary,
.btn-secondary,
.btn-danger {
    min-height: var(--touch-min);
    padding: 10px 20px;
    font-size: clamp(0.9rem, 1.8vw, 1rem);
    cursor: pointer;
    touch-action: manipulation;
}

/* ── 11. Typography — Fluid Scaling ────────────────────────── */
h1 { font-size: clamp(1.4rem, 3vw, 2rem); }
h2 { font-size: clamp(1.2rem, 2.5vw, 1.6rem); }
h3 { font-size: clamp(1.05rem, 2vw, 1.3rem); }
h4 { font-size: clamp(0.95rem, 1.8vw, 1.1rem); }
p, li { font-size: clamp(0.875rem, 1.5vw, 1rem); }

/* Remove empty stat icons globally */
.stat-icon, .icon-box { display: none !important; }

/* ── 12. Utility: Prevent horizontal overflow ───────────────── */
.no-overflow {
    overflow-x: hidden;
    max-width: 100%;
}

.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* ── 13. Flex/Grid Helpers ──────────────────────────────────── */
.flex-wrap-mobile { flex-wrap: wrap; }
.full-width-mobile { width: 100%; }

/* ============================================================
   BREAKPOINTS
   ── XS: < 480px   (Small phones — iPhone SE, Galaxy A)
   ── SM: 480–767px (Larger phones)
   ── MD: 768–1023px (Tablet — iPad)
   ── LG: 1024–1279px (Laptop)
   ── XL: 1280px+  (Desktop)
   ============================================================ */

/* ── DESKTOP (1280px+) ──────────────────────────────────────── */
@media (min-width: 1280px) {
    .sidebar {
        transform: translateX(0) !important;
    }
    .main-content {
        margin-left: var(--sidebar-w) !important;
    }
    .sidebar-toggle {
        display: none !important;
    }
}

/* ── LAPTOP (1024px – 1279px) ───────────────────────────────── */
@media (min-width: 1024px) and (max-width: 1279px) {
    :root { --sidebar-w: 240px; }
    .page-body { padding: 24px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
}

/* ── TABLET (768px – 1023px) ────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
    :root { --sidebar-w: 220px; }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .actions-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .info-banner {
        flex-direction: column;
        text-align: center;
    }

    .info-banner .banner-icon {
        align-self: center;
    }

    .page-body { padding: 20px; }
}

/* ── MOBILE (< 768px) ───────────────────────────────────────── */
@media (max-width: 767px) {
    .sidebar-toggle { display: flex; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 150;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0 !important;
    }

    .topbar {
        padding-left: 70px; /* space for hamburger */
    }

    .topbar-left h1 { font-size: 1.1rem; }
    .topbar-left p  { display: none; }

    .topbar-badge { display: none; }

    .top-user-name { display: none; }

    /* Inherited rules from mobile block */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .stat-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 12px 16px;
    }

    .stat-value { font-size: 1.35rem !important; margin-bottom: 2px; }
    .stat-label { font-size: 0.8rem !important; }

    /* Shrink buttons to be compact but clickable */
    .btn, button[type="submit"], .btn-sm {
        padding: 6px 12px !important;
        font-size: 0.8rem !important;
        min-height: 36px !important;
    }

    .actions-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .action-card { padding: 16px 14px; }
    .action-card .a-icon { font-size: 24px; }
    .action-card .a-title { font-size: 0.95rem; }
    .action-card .a-desc { font-size: 0.85rem; }

    .topbar {
        padding: 0 12px 0 60px;
        height: 60px;
    }

    .topbar-right { gap: 10px; }

    .page-body { padding: 16px 12px; }

    .section-title { font-size: 1.05rem; }

    /* Dropdown menu — full width on mobile */
    .dropdown-menu {
        right: -10px;
        width: 220px;
    }

    .info-banner {
        padding: 18px 16px;
        border-radius: 10px;
    }

    .info-banner h2 { font-size: 1.1rem; }
    .info-banner p  { font-size: 0.85rem; }
}

/* ── SMALL PHONES (< 480px) ─────────────────────────────────── */
@media (max-width: 479px) {
    html {
        font-size: 13px !important;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .actions-grid {
        grid-template-columns: 1fr;
    }

    .topbar-right .topbar-badge { display: none; }

    .table-wrap table,
    .data-table {
        min-width: 480px;
    }

    .btn, button[type="submit"] {
        width: 100%;
        text-align: center;
    }

    /* Stack button groups vertically */
    .btn-group,
    .btn-row {
        flex-direction: column;
        gap: 10px;
    }
}

/* ── reCAPTCHA mobile scaling ─────────────────────────────── */
@media (max-width: 400px) {
    .g-recaptcha {
        transform: scale(0.85);
        -webkit-transform: scale(0.85);
        transform-origin: 0 0;
        -webkit-transform-origin: 0 0;
    }
    .captcha-container {
        overflow: hidden;
        justify-content: flex-start;
        padding-left: 5px;
        height: 66px;
    }
}

/* ── Update Profile & Forms ─────────────────────────────────── */
@media (max-width: 767px) {
    .form-row,
    .row {
        flex-direction: column;
    }

    .col, .col-md-6, .col-lg-4, .col-sm-6 {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }

    /* Panel cards */
    .panel-card {
        padding: 18px 14px;
        border-radius: 12px;
    }
}

/* ── Chart Cards ────────────────────────────────────────────── */
@media (max-width: 1023px) {
    .charts-grid,
    .two-col-grid,
    .grid-2 {
        grid-template-columns: 1fr !important;
    }

    .chart-card {
        min-height: 260px;
    }
}

/* ── Sidebar scrollbar styling ──────────────────────────────── */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* ── Touch-friendly nav items in sidebar ────────────────────── */
.nav-item {
    min-height: var(--touch-min);
    padding: 13px 20px;
}

/* ── Keyboard accessibility ─────────────────────────────────── */
:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ============================================================
   GLOBAL INTERNAL PAGES RESPONSIVENESS OVERRIDES
   Fixes overflowing tables, oversized cards, and rigid grids 
   across all roles (Admin, HR, Payroll, Employee).
   ============================================================ */

/* ── TABLET (max-width: 1023px) ──────────────────────────────── */
@media (max-width: 1023px) {
    /* Ensure tables can scroll horizontally without breaking layout */
    .table-responsive, .table-container, .table-wrap,
    .data-table-container, .admin-activity-feed, .list-card,
    .log-container, .report-container, .table-card {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        width: 100% !important;
        display: block; /* Required for table containers to scroll */
    }

    /* Give tables a minimum width on tablet so columns don't squish too much */
}

/* ── TABLET STRICTLY (768px - 1023px) ────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
    table, .data-table {
        min-width: 600px; 
        width: 100% !important;
    }
}

/* ── MOBILE (max-width: 767px) ───────────────────────────────── */
@media (max-width: 767px) {
    /* 0. Scale down all typography proportionally for mobile */
    html {
        font-size: 14px !important;
    }

    /* 1. Force main containers to 100% width, overriding fixed max-widths */
    .form-card, .config-card, .settings-container, .settings-card,
    .payslip-container, .modal-content, .card, .profile-card,
    .branding-dashboard, .timeline-panel, .panel-content {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        padding: 16px !important; /* Reduce excessive padding on mobile */
    }

    /* 2. Break horizontal layout grids into vertical stacks */
    .grid, .grid-2, .grid-3, .grid-4, .role-grid, .settings-grid,
    .dashboard-grid, .field-row, .field-row-3, .form-row, .row,
    .flex-row, .d-flex, .nav-grid, .info-grid, .action-grid,
    .admin-charts-grid, .charts-row, .profile-layout, .row-grid, .card-head,
    .summary-row, .attendance-summary, .record-bar {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 16px !important; /* Consistent gap when stacked */
        padding: 0 !important; /* Remove excessive layout padding */
    }

    /* Keep card-head and record-bar aligned properly on mobile */
    .card-head, .record-bar { align-items: flex-start !important; }
    .card-head button, .record-bar button, .record-bar div { width: 100% !important; justify-content: center !important; }

    /* Ensure children of stacked flex/grids take full width */
    .grid > *, .grid-2 > *, .grid-3 > *, .grid-4 > *,
    .role-grid > *, .settings-grid > *, .field-row > *,
    .field-row-3 > *, .form-row > *, .flex-row > *,
    .row-grid > *, .summary-row > *, .attendance-summary > * {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Scale down specific summary values not caught by .stat-value */
    .s-val { font-size: 1.4rem !important; }
    .s-lbl { font-size: 0.85rem !important; }

    /* 3. Force inputs and form controls to fit viewport */
    input[type="text"], input[type="email"], input[type="password"],
    input[type="number"], input[type="date"], select, textarea,
    .form-control, .salary-input, .field input, .field select, .f-group {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    /* 4. Fix specific oversized internal UI components */
    .totals-box {
        float: none !important;
        width: 100% !important;
    }

    .timeline-feed::before {
        left: 10px !important; /* Adjust timeline bar for mobile padding */
    }
    .timeline-dot {
        left: -20px !important;
    }

    /* 5. Chart responsivenes */
    canvas {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* 6. Fix topbar actions overflowing */
    .topbar {
        padding: 0 16px !important;
    }
    .topbar-right {
        gap: 10px !important;
    }

    /* 7. GLOBAL MOBILE TABLE STACKING (No Swiping Required!) */
    table, .data-table, .report-table {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100vw !important;
        overflow: hidden !important;
    }
    thead { display: none !important; }
    tbody, tr, td, th { display: block !important; width: 100% !important; box-sizing: border-box !important; }
    tr { margin-bottom: 16px !important; border: 1px solid var(--gray-200) !important; border-radius: 12px !important; padding: 16px !important; background: white !important; box-shadow: 0 2px 4px rgba(0,0,0,0.02) !important; overflow: hidden !important; }
    
    td { 
        padding: 10px 0 !important; 
        border: none !important; 
        display: flex !important; 
        flex-direction: column !important; 
        align-items: flex-start !important; 
        text-align: left !important; 
        border-bottom: 1px solid var(--gray-100) !important; 
        gap: 6px !important;
        word-break: break-word !important;
        white-space: normal !important;
    }
    td:last-child { border-bottom: none !important; }
    td::before { 
        content: attr(data-label); 
        font-weight: 700 !important; 
        color: var(--gray-600) !important; 
        font-size: 0.75rem !important; 
        text-transform: uppercase !important; 
        margin-right: 0 !important; 
        margin-bottom: 2px !important;
        text-align: left !important;
    }
    
    /* Ensure action buttons wrap cleanly in the stacked td */
    td > div, td > form, td > button, td > a {
        display: inline-flex;
        flex-wrap: wrap;
        justify-content: flex-start !important;
        gap: 6px;
        white-space: normal !important;
        max-width: 100% !important;
    }
}
