/* ============================================================
   SCE HRMS Core — Global Stylesheet
   Version: 2.0 (Responsive Framework)
   ============================================================ */

/* --- CSS Reset & Base --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
}

body {
    background: #f4f6f9;
    color: #333;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    color: inherit;
}

/* --- App Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar Base --- */
.sidebar {
    width: 240px;
    background: #1f2937;
    color: #fff;
    padding: 20px;
}

.sidebar-brand {
    margin-bottom: 30px;
    border-bottom: 1px solid #374151;
    padding-bottom: 15px;
}

.sidebar-brand h2 {
    font-size: 22px;
    margin-bottom: 5px;
}

.sidebar-brand p {
    font-size: 12px;
    color: #d1d5db;
}

.sidebar-menu {
    list-style: none;
}

.sidebar-menu li {
    margin-bottom: 12px;
}

.sidebar-menu a {
    display: block;
    padding: 10px 12px;
    border-radius: 6px;
    transition: 0.3s;
}

.sidebar-menu a:hover {
    background: #374151;
}

/* --- Main Content --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* --- Topbar --- */
.topbar {
    background: #ffffff;
    padding: 18px 25px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* --- Page Content --- */
.page-content {
    padding: 25px;
}

/* --- Card --- */
.card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.card h2 {
    margin-bottom: 10px;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 12px;
    background: #e5e7eb;
    color: #111827;
}

.badge-green {
    background: #d1fae5;
    color: #065f46;
}

.badge-yellow {
    background: #fef3c7;
    color: #92400e;
}

.badge-red {
    background: #fee2e2;
    color: #991b1b;
}

.test-success {
    color: green;
    font-weight: bold;
}

.test-fail {
    color: red;
    font-weight: bold;
}

/* ============================================================
   RESPONSIVE FRAMEWORK — Comprehensive Breakpoints
   Breakpoints: 1200px, 1024px, 992px, 768px, 576px, 480px, 360px
   ============================================================ */

/* --- Sidebar Backdrop Overlay --- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.active {
    display: block;
    opacity: 1;
}

/* --- Topbar responsive --- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 999;
}
.topbar h1 {
    font-size: 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Table wrapper for horizontal scroll --- */
.table-wrapper-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

/* --- Sticky table header inside scrollable wrapper --- */
.table-wrapper-responsive table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
}

/* ============================================================
   RESPONSIVE: Container & Page Padding
   ============================================================ */
.container-fluid {
    width: 100%;
    padding: 0 25px;
}

@media (max-width: 992px) {
    .container-fluid {
        padding: 0 20px;
    }
}
@media (max-width: 768px) {
    .container-fluid {
        padding: 0 16px;
    }
}
@media (max-width: 480px) {
    .container-fluid {
        padding: 0 12px;
    }
}

/* --- Page content responsive padding --- */
@media (max-width: 992px) {
    .page-content {
        padding: 20px !important;
    }
}
@media (max-width: 768px) {
    .page-content {
        padding: 16px !important;
    }
}
@media (max-width: 480px) {
    .page-content {
        padding: 12px !important;
    }
}

/* --- Main content padding --- */
@media (max-width: 768px) {
    .main-content {
        padding: 0 !important;
    }
}

/* ============================================================
   RESPONSIVE: Typography
   ============================================================ */
@media (max-width: 768px) {
    h1 { font-size: 22px !important; }
    h2 { font-size: 20px !important; }
    h3 { font-size: 17px !important; }
}
@media (max-width: 480px) {
    h1 { font-size: 20px !important; }
    h2 { font-size: 18px !important; }
    h3 { font-size: 15px !important; }
}

/* --- Text truncation utility --- */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}
.text-wrap {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* --- Responsive image --- */
img {
    max-width: 100%;
    height: auto;
}

/* ============================================================
   RESPONSIVE: Grid System (Bootstrap-like)
   ============================================================ */
.row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -12px;
}
.row > [class*="col-"] {
    padding: 0 12px;
    box-sizing: border-box;
}
.col-md-3 { width: 25%; }
.col-md-4 { width: 33.333%; }
.col-md-6 { width: 50%; }
.col-md-8 { width: 66.666%; }
.col-md-12 { width: 100%; }
.col-sm-6 { width: 50%; }
.col-lg-6 { width: 50%; }
.col-lg-7 { width: 58.333%; }
.col-xl-6 { width: 50%; }

@media (max-width: 992px) {
    .col-md-3, .col-md-4, .col-md-6, .col-md-8 {
        width: 50% !important;
    }
}
@media (max-width: 768px) {
    .row > [class*="col-"] {
        width: 100% !important;
    }
    .row {
        margin: 0 -8px;
    }
    .row > [class*="col-"] {
        padding: 0 8px;
    }
}

/* ============================================================
   RESPONSIVE: Dashboard Card Grid
   ============================================================ */
.main-content .dashboard-card-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
    gap: 24px !important;
}

@media (max-width: 1200px) {
    .main-content .dashboard-card-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
@media (max-width: 768px) {
    .main-content .dashboard-card-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
}

/* ============================================================
   RESPONSIVE: KPI / Stats Cards Grid
   ============================================================ */
@media (max-width: 1024px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
@media (max-width: 576px) {
    .kpi-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    .kpi-card {
        padding: 16px !important;
    }
    .kpi-val {
        font-size: 20px !important;
    }
    .kpi-bg-icon {
        font-size: 2.5rem !important;
    }
}

/* ============================================================
   RESPONSIVE: Charts Grid
   ============================================================ */
@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
}
@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
}

/* ============================================================
   RESPONSIVE: Tables
   ============================================================ */
@media (max-width: 768px) {
    table {
        font-size: 12px !important;
    }
    table th,
    table td {
        padding: 8px 10px !important;
        white-space: nowrap;
    }
    table th {
        font-size: 10px !important;
    }
}

/* Generic table responsive wrapper */
.table-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    border-radius: 12px;
}
.table-scroll-wrap table {
    min-width: auto;
}

/* Table with forced min-width should be wrapped */
.table-fixed-width {
    width: 100%;
}

/* ============================================================
   RESPONSIVE: Forms — Table-based forms to stacked
   ============================================================ */
@media (max-width: 768px) {
    .form-table,
    .form-table tbody,
    .form-table tr,
    .form-table td {
        display: block !important;
        width: 100% !important;
    }
    .form-table td {
        padding: 8px 0 !important;
    }
    .form-table td .form-label,
    .form-table td .form-input,
    .form-table td select,
    .form-table td input,
    .form-table td textarea {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* Generic form controls responsive */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        max-width: 100% !important;
        font-size: 14px !important;
    }
}

/* ============================================================
   RESPONSIVE: Modals
   ============================================================ */
@media (max-width: 768px) {
    .modal-content,
    .modal-dialog {
        width: 95% !important;
        max-width: 95% !important;
        margin: 10px auto !important;
    }
    .modal-body {
        padding: 16px !important;
        max-height: 70vh;
        overflow-y: auto;
    }
    .modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }
    .modal-footer .btn {
        flex: 1 1 45%;
        min-height: 44px;
    }
}

/* ============================================================
   RESPONSIVE: Buttons
   ============================================================ */
@media (max-width: 576px) {
    .btn-group, .button-group {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
}

/* Ensure touch-friendly button sizes */
@media (pointer: coarse) {
    .sidebar-btn,
    .sidebar-link-manual,
    a[data-sidebar-decorated="true"],
    .action-btn,
    .btn-login,
    .emp-add-btn,
    button,
    .btn {
        min-height: 44px;
    }
}

/* ============================================================
   RESPONSIVE: Calendar
   ============================================================ */
@media (max-width: 768px) {
    .calendar-grid {
        font-size: 12px !important;
    }
    .calendar-grid th,
    .calendar-grid td {
        padding: 4px !important;
        font-size: 11px !important;
    }
}

/* ============================================================
   RESPONSIVE: Charts (Canvas)
   ============================================================ */
canvas {
    max-width: 100%;
    height: auto !important;
}

/* ============================================================
   RESPONSIVE: Tabs (scrollable on mobile)
   ============================================================ */
@media (max-width: 768px) {
    .nav-tabs,
    .nav-pills,
    .tab-nav {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        scrollbar-width: none;
    }
    .nav-tabs::-webkit-scrollbar,
    .nav-pills::-webkit-scrollbar,
    .tab-nav::-webkit-scrollbar {
        display: none;
    }
}

/* ============================================================
   RESPONSIVE: Breadcrumb
   ============================================================ */
.breadcrumb {
    flex-wrap: wrap;
    gap: 4px;
}

/* ============================================================
   RESPONSIVE: Dropdown
   ============================================================ */
.dropdown-menu {
    max-height: 60vh;
    overflow-y: auto;
    max-width: 95vw;
}

/* ============================================================
   RESPONSIVE: Notification Dropdown
   ============================================================ */
@media (max-width: 768px) {
    .notif-dropdown {
        width: 260px !important;
        right: -10px !important;
    }
}
@media (max-width: 480px) {
    .notif-dropdown {
        width: 240px !important;
        right: -20px !important;
    }
}

/* ============================================================
   RESPONSIVE: Emp Master Container
   ============================================================ */
@media (max-width: 768px) {
    .emp-master-container {
        padding: 16px !important;
    }
    .emp-header-card {
        padding: 16px !important;
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    .emp-add-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================================
   RESPONSIVE: Form Card
   ============================================================ */
@media (max-width: 768px) {
    .form-card {
        padding: 20px !important;
        max-width: 100% !important;
    }
}

/* ============================================================
   RESPONSIVE: Page Header (flex with button)
   ============================================================ */
@media (max-width: 768px) {
    .page-header,
    .emp-header-card,
    .dash-header {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    .page-header a,
    .page-header button,
    .page-header form {
        width: 100%;
    }
}

/* ============================================================
   RESPONSIVE: Sidebar scroll for long menus
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        max-height: 100vh;
        overflow-y: auto;
        padding-bottom: 40px;
    }
}

/* ============================================================
   RESPONSIVE: Stat Card
   ============================================================ */
@media (max-width: 768px) {
    .stat-card {
        padding: 16px !important;
    }
    .stat-number {
        font-size: 22px !important;
    }
    .stat-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 18px !important;
    }
}

/* ============================================================
   RESPONSIVE: TSA Card
   ============================================================ */
@media (max-width: 768px) {
    .tsa-hero {
        padding: 12px 16px !important;
    }
    .tsa-stat {
        min-width: 60px !important;
        padding: 8px 10px !important;
    }
    .tsa-stat-num {
        font-size: 18px !important;
    }
}

/* ============================================================
   RESPONSIVE: Action Buttons (wrap on small screens)
   ============================================================ */
@media (max-width: 576px) {
    .action-btn {
        display: inline-flex !important;
        margin-bottom: 4px;
        font-size: 10px !important;
        padding: 5px 10px !important;
    }
}

/* ============================================================
   RESPONSIVE: Search Box & Table Header
   ============================================================ */
@media (max-width: 768px) {
    .search-box {
        width: 100% !important;
        max-width: 100% !important;
    }
    .table-header {
        flex-direction: column !important;
        gap: 10px !important;
        align-items: stretch !important;
    }
    .table-header > div:last-child {
        display: flex !important;
        gap: 8px !important;
        flex-wrap: wrap;
    }
}

/* ============================================================
   RESPONSIVE: Login Page
   ============================================================ */
@media (max-width: 480px) {
    .login-card {
        padding: 24px !important;
        margin: 12px !important;
        border-radius: 12px !important;
    }
    .login-header h1 {
        font-size: 22px !important;
    }
    .login-footer {
        flex-direction: column !important;
        gap: 8px !important;
        text-align: center;
    }
}

/* ============================================================
   RESPONSIVE: Employee Table min-width adjustments
   ============================================================ */
@media (max-width: 768px) {
    .emp-table {
        min-width: 800px !important;
    }
}

/* ============================================================
   RESPONSIVE: Fix inline style overflow on small screens
   ============================================================ */
@media (max-width: 768px) {
    [style*="padding: 32px"] {
        padding: 16px !important;
    }
    [style*="padding: 40px"] {
        padding: 16px !important;
    }
    [style*="padding: 0 40px"] {
        padding: 0 16px !important;
    }
    [style*="padding: 0 32px"] {
        padding: 0 16px !important;
    }
    [style*="min-width: 1400px"] {
        min-width: 800px !important;
    }
    [style*="min-width: 1100px"] {
        min-width: 700px !important;
    }
    [style*="min-width: 700px"] {
        min-width: 500px !important;
    }
    [style*="max-width: 900px"] {
        max-width: 100% !important;
    }
    [style*="max-width: 1600px"] {
        max-width: 100% !important;
    }
    [style*="max-width: 240px"] {
        max-width: 100% !important;
        width: 100% !important;
    }
    [style*="max-width: 260px"] {
        max-width: 100% !important;
        width: 100% !important;
    }
}

/* ============================================================
   RESPONSIVE: Hero / Gradient Headers
   ============================================================ */
@media (max-width: 768px) {
    .rg-hero,
    .ts-hero,
    [style*="linear-gradient(135deg"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        padding: 20px 16px !important;
    }
    .rg-stat,
    .ts-stat {
        min-width: auto !important;
    }
}

/* ============================================================
   RESPONSIVE: Filter Forms (stack on mobile)
   ============================================================ */
@media (max-width: 768px) {
    .dr-filter-form,
    .rg-filter form,
    [style*="display:flex"][style*="gap:12px"][style*="flex-wrap:wrap"] {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .dr-filter-form input,
    .dr-filter-form select,
    .dr-filter-form button {
        width: 100% !important;
    }
}

/* ============================================================
   RESPONSIVE: Review Panels
   ============================================================ */
@media (max-width: 768px) {
    .rg-review-grid,
    .rg-review-panel [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    .rg-actions {
        flex-direction: column !important;
    }
    .rg-actions .btn,
    .rg-actions a,
    .rg-actions button {
        width: 100% !important;
        justify-content: center;
    }
}

/* ============================================================
   RESPONSIVE: Review Panel Override Grids
   ============================================================ */
@media (max-width: 768px) {
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================================
   RESPONSIVE: Payslip Module
   ============================================================ */
@media (max-width: 768px) {
    .payslip-card,
    [style*="border-radius: 16px"][style*="overflow: hidden"] {
        margin-bottom: 16px;
    }
}

/* ============================================================
   RESPONSIVE: Invoice Module
   ============================================================ */
@media (max-width: 992px) {
    .invoice-card,
    .inv-stat-card {
        margin-bottom: 16px;
    }
}
@media (max-width: 768px) {
    .inv-filter-form {
        flex-direction: column !important;
    }
    .inv-filter-form > * {
        width: 100% !important;
    }
    .inv-actions {
        flex-wrap: wrap;
        gap: 8px;
    }
    .inv-actions .btn,
    .inv-actions a {
        flex: 1 1 45%;
        min-height: 44px;
    }
    .invoice-action-group {
        flex-wrap: wrap;
        gap: 6px !important;
    }
    .invoice-action-group .btn,
    .invoice-action-group .action-btn {
        flex: 0 0 auto;
    }
}
@media (max-width: 576px) {
    .invoice-action-group {
        flex-direction: column;
        align-items: stretch;
    }
    .invoice-action-group .btn,
    .invoice-action-group .action-btn {
        width: 100% !important;
        justify-content: center;
    }
}

/* ============================================================
   RESPONSIVE: Timesheet Calendar Grid
   ============================================================ */
@media (max-width: 768px) {
    .ts-cal {
        grid-template-columns: 1fr !important;
        padding: 12px !important;
    }
    .ts-day-col {
        min-height: auto !important;
    }
    .ts-nav {
        flex-direction: column;
        align-items: stretch;
    }
    .ts-nav-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================================
   RESPONSIVE: Leave Request Forms
   ============================================================ */
@media (max-width: 768px) {
    [style*="grid-template-columns: repeat(auto-fit, minmax(220px"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns: repeat(auto-fit, minmax(240px"] {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================================
   RESPONSIVE: Holiday Table
   ============================================================ */
@media (max-width: 768px) {
    [style*="min-width:700px"] {
        min-width: 500px !important;
    }
}

/* ============================================================
   RESPONSIVE: Attendance Widget
   ============================================================ */
@media (max-width: 768px) {
    .attendance-main-card {
        padding: 20px !important;
    }
    [style*="display:flex; justify-content:space-between"][style*="gap:16px"] {
        flex-direction: column !important;
    }
}

/* ============================================================
   RESPONSIVE: Dash Cards Grid (flex-based)
   ============================================================ */
@media (max-width: 768px) {
    .dash-cards-grid {
        gap: 16px !important;
    }
    .dash-card-item {
        min-width: 0 !important;
        flex: 1 1 100% !important;
        padding: 20px 16px !important;
    }
    .dash-card-item .dash-card-emoji {
        font-size: 28px !important;
        margin-bottom: 6px !important;
    }
    .dash-card-item .dash-card-title {
        font-size: 15px !important;
    }
    .dash-card-item .dash-card-subtitle {
        font-size: 10px !important;
    }
    .dash-card-item .dash-card-desc {
        font-size: 12px !important;
    }
    .dash-card-item .dash-card-btn {
        font-size: 12px !important;
        padding: 8px 16px !important;
    }
}
@media (max-width: 576px) {
    .dash-welcome h2 {
        font-size: 18px !important;
    }
    .dash-card-item {
        min-width: 0 !important;
        flex: 1 1 100% !important;
    }
}

/* ============================================================
   RESPONSIVE: Payslip Admin Dashboard (Bootstrap override)
   ============================================================ */
@media (max-width: 768px) {
    .main-content {
        padding: 0 !important;
    }
    .action-card-btn {
        min-height: 44px;
        padding: 12px 16px;
    }
}

/* ============================================================
   RESPONSIVE: Hierarchy / Roles / Audit / Compliance Tables
   ============================================================ */
@media (max-width: 768px) {
    [style*="width:100%; border-collapse:collapse"] {
        font-size: 12px !important;
    }
}

/* ============================================================
   RESPONSIVE: Flex Wrapping for Header Sections
   ============================================================ */
@media (max-width: 768px) {
    [style*="display:flex"][style*="justify-content:space-between"][style*="align-items:center"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px;
    }
    [style*="display:flex"][style*="justify-content:space-between"][style*="align-items:center"] > * {
        width: 100%;
    }
}

/* ============================================================
   RESPONSIVE: Button Groups in Forms
   ============================================================ */
@media (max-width: 768px) {
    [style*="display:flex"][style*="gap:"][style*="margin-top"] {
        flex-wrap: wrap;
    }
    [style*="display:flex"][style*="gap:"][style*="margin-top"] > * {
        min-height: 44px;
    }
}

/* ============================================================
   RESPONSIVE: Generic Full-Width Fix
   ============================================================ */
@media (max-width: 768px) {
    [style*="max-width: 900px"] {
        max-width: 100% !important;
    }
    [style*="max-width: 1200px"] {
        max-width: 100% !important;
    }
    [style*="max-width: 1600px"] {
        max-width: 100% !important;
    }
    [style*="max-width: 1000px"] {
        max-width: 100% !important;
    }
}

/* ============================================================
   RESPONSIVE: Body Overflow Prevention
   ============================================================ */
html {
    scroll-behavior: smooth;
}

body {
    overflow-x: hidden;
}

/* ============================================================
   RESPONSIVE: Print Styles
   ============================================================ */
@media print {
    .sidebar, .topbar, .sidebar-toggle, .sidebar-backdrop {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    body {
        overflow: visible !important;
    }
    .table-wrapper-responsive {
        overflow: visible !important;
    }
    .table-wrapper-responsive table {
        min-width: auto !important;
    }
}
