/* ================================================================
   HR MANAGEMENT SYSTEM — MODERN RESPONSIVE CSS
   Global rules that make every page look great on PC, iPad & Mobile
   ================================================================ */

/* ----------------------------------------------------------------
   1. BOX-SIZING & ROOT OVERFLOW GUARD
   ---------------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%; /* Prevent iOS font inflation */
}

body {
    overflow-x: hidden;
    min-height: 100dvh; /* dynamic viewport height (handles mobile browser chrome) */
}

/* ----------------------------------------------------------------
   2. FLUID TYPOGRAPHY  (clamp scales between viewport widths)
   ---------------------------------------------------------------- */
:root {
    --fs-xs:   clamp(0.7rem,   1.5vw, 0.8rem);
    --fs-sm:   clamp(0.8rem,   1.8vw, 0.875rem);
    --fs-base: clamp(0.875rem, 2vw,   1rem);
    --fs-md:   clamp(1rem,     2.5vw, 1.125rem);
    --fs-lg:   clamp(1.125rem, 3vw,   1.375rem);
    --fs-xl:   clamp(1.25rem,  3.5vw, 1.75rem);
    --fs-2xl:  clamp(1.5rem,   4vw,   2.25rem);

    --tap-target: 44px; /* WCAG 2.5.5 minimum touch target */
    --header-height: 72px;
}

/* ----------------------------------------------------------------
   3. RESPONSIVE IMAGES & MEDIA
   ---------------------------------------------------------------- */
img, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* ----------------------------------------------------------------
   4. TABLES — Horizontal scroll wrapper on small screens
   ---------------------------------------------------------------- */
.table-responsive-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--company-card-radius, 0.75rem);
    box-shadow: 0 0 0 1px var(--company-border-light, #e3e6f0);
}

/* Auto-wrap any raw .table that isn't already inside a .table-responsive */
@media (max-width: 767.98px) {
    .card-body > .table,
    .page-body > .table,
    section > .table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Allow wrapping cells that don't need nowrap */
    .table td.text-wrap,
    .table th.text-wrap {
        white-space: normal;
    }
}

/* ----------------------------------------------------------------
   5. RESPONSIVE CARDS & GRIDS
   ---------------------------------------------------------------- */

/* Stat / KPI card grids */
.stats-grid,
.kpi-grid,
.summary-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
}

/* Action-card grids (e.g. quick links) */
.action-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr));
}

@media (max-width: 575.98px) {
    .stats-grid,
    .kpi-grid,
    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.625rem;
    }

    .action-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
}

/* ----------------------------------------------------------------
   6. PAGE HEADER  (title + action buttons row)
   ---------------------------------------------------------------- */
.page-header,
.employee-page-header,
.department-page-header,
.position-page-header,
.payroll-page-header,
.attendance-page-header {
    flex-wrap: wrap;
    gap: 0.75rem;
}

@media (max-width: 575.98px) {
    .page-header,
    .employee-page-header,
    .department-page-header,
    .position-page-header,
    .payroll-page-header,
    .attendance-page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .employee-page-title,
    .page-title {
        font-size: var(--fs-xl);
    }

    .employee-actions,
    .page-actions,
    .header-actions-group {
        width: 100%;
        flex-wrap: wrap;
    }

    .employee-actions .btn,
    .page-actions .btn,
    .header-actions-group .btn {
        flex: 1 1 auto;
        min-height: var(--tap-target);
        justify-content: center;
    }
}

/* ----------------------------------------------------------------
   7. BUTTONS — Touch-friendly minimum size
   ---------------------------------------------------------------- */
.btn {
    min-height: var(--tap-target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Icon-only buttons keep a square tap target */
.btn-icon {
    width: var(--tap-target);
    height: var(--tap-target);
    padding: 0;
    border-radius: 50%;
}

/* ----------------------------------------------------------------
   8. FORMS — Readable on mobile
   ---------------------------------------------------------------- */
@media (max-width: 575.98px) {
    .form-label {
        font-size: var(--fs-sm);
        margin-bottom: 0.25rem;
    }

    .form-control,
    .form-select {
        font-size: var(--fs-base);
        min-height: var(--tap-target);
        border-radius: var(--company-radius-md, 8px) !important;
    }

    .form-check-input {
        width: 1.25em;
        height: 1.25em;
        margin-top: 0.1em;
    }

    /* Stack paired form groups (e.g. From / To date) on tiny screens */
    .form-row-inline {
        flex-direction: column;
    }
}

/* Prevent iOS zoom on focus (font-size < 16px) */
@media (max-width: 767.98px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ----------------------------------------------------------------
   9. MODALS — Full-screen on small phones
   ---------------------------------------------------------------- */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        min-height: 100dvh;
        align-items: flex-end;
    }

    .modal-content {
        border-radius: 20px 20px 0 0 !important;
        border-bottom-left-radius: 0 !important;
        border-bottom-right-radius: 0 !important;
        max-height: 92dvh;
        overflow-y: auto;
    }

    .modal-header {
        padding: 1rem 1.25rem 0.75rem;
    }

    .modal-body {
        padding: 1rem 1.25rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer {
        padding: 0.75rem 1.25rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* Blazored Modal on mobile */
    .blazored-modal-container {
        align-items: flex-end !important;
    }
}

/* ----------------------------------------------------------------
   10. CARDS — Better mobile padding
   ---------------------------------------------------------------- */
@media (max-width: 575.98px) {
    .card {
        border-radius: 12px !important;
    }

    .card-body {
        padding: 0.875rem !important;
    }

    .card-header,
    .card-footer {
        padding: 0.625rem 0.875rem !important;
    }
}

/* ----------------------------------------------------------------
   11. DROPDOWN MENUS — Prevent off-screen overflow
   ---------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .dropdown-menu {
        max-height: 60dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ----------------------------------------------------------------
   12. BADGES & PILLS — Readable small size
   ---------------------------------------------------------------- */
.badge {
    font-size: var(--fs-xs);
    padding: 0.3em 0.6em;
}

/* ----------------------------------------------------------------
   13. SCROLLBAR STYLING  (Chrome/Edge/Safari)
   ---------------------------------------------------------------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 100px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* ----------------------------------------------------------------
   14. OVERSCROLL BEHAVIOUR
   ---------------------------------------------------------------- */
body {
    overscroll-behavior-y: none; /* Prevent pull-to-refresh on native wrappers */
}

.modal-body,
.mobile-nav,
.nav-dropdown-menu {
    overscroll-behavior: contain;
}

/* ----------------------------------------------------------------
   15. FOCUS-VISIBLE — Keyboard accessibility
   ---------------------------------------------------------------- */
:focus-visible {
    outline: 2px solid var(--company-primary-500, #4f46e5);
    outline-offset: 3px;
    border-radius: 4px;
}

/* Remove focus ring when using mouse/touch */
:focus:not(:focus-visible) {
    outline: none;
}

/* ----------------------------------------------------------------
   16. PRINT STYLES
   ---------------------------------------------------------------- */
@media print {
    .top-nav-header,
    .mobile-menu-toggle,
    .mobile-nav,
    .mobile-nav-overlay,
    .notification-bell,
    .user-profile-dropdown,
    .no-print {
        display: none !important;
    }

    .main-content {
        padding: 0 !important;
    }

    body {
        font-size: 12pt;
        color: #000;
        background: #fff;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        break-inside: avoid;
    }

    .table {
        font-size: 10pt;
    }

    a[href]::after {
        content: none !important;
    }
}

/* ----------------------------------------------------------------
   17. RTL SUPPORT ADDITIONS
   ---------------------------------------------------------------- */
[dir="rtl"] .mobile-nav {
    left: auto;
    right: env(safe-area-inset-right, 0);
    transform: translateX(110%);
    border-right: none;
    border-left: 1px solid rgba(0, 0, 0, 0.05);
}

[dir="rtl"] .mobile-nav.open {
    transform: translateX(0);
    box-shadow: -4px 0 32px rgba(0, 0, 0, 0.18);
}

/* ----------------------------------------------------------------
   18. ANIMATION PERFORMANCE
   ---------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ----------------------------------------------------------------
   19. RESPONSIVE UTILITY HELPERS
   ---------------------------------------------------------------- */

/* Stack flex items vertically on mobile */
@media (max-width: 575.98px) {
    .flex-stack-mobile {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .flex-stack-mobile > * {
        width: 100% !important;
    }
}

/* Hide on specific breakpoints */
@media (max-width: 575.98px)  { .hide-xs { display: none !important; } }
@media (max-width: 767.98px)  { .hide-sm { display: none !important; } }
@media (max-width: 1023.98px) { .hide-md { display: none !important; } }

/* Truncate long text to one line */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ----------------------------------------------------------------
   20. HEADER HEIGHT VARIABLE — used by sticky elements
   ---------------------------------------------------------------- */
:root {
    --header-height: 72px;
}

/* Sticky page sub-headers sit just below the top nav */
.sticky-below-header {
    position: sticky;
    top: var(--header-height);
    z-index: 900;
    background: var(--company-bg-primary, #fff);
}

/* ----------------------------------------------------------------
   21. TABLE CELLS — better readability on small screens
   ---------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .table th,
    .table td {
        padding: 0.5rem 0.625rem !important;
        font-size: var(--fs-sm);
    }
}

/* ----------------------------------------------------------------
   22. EMPLOYEE / HR SPECIFIC RESPONSIVE PATCHES
   ---------------------------------------------------------------- */

/* Salary & payroll numbers should not wrap */
.no-wrap {
    white-space: nowrap;
}

/* Stat card numbers scale down smoothly */
.stat-value,
.kpi-value {
    font-size: clamp(1.25rem, 4vw, 2rem);
    font-weight: 700;
    line-height: 1.1;
}

/* Search bars full-width on mobile */
@media (max-width: 575.98px) {
    .search-bar,
    .filter-bar {
        width: 100% !important;
    }

    .search-bar input {
        width: 100%;
    }
}
