* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', 'Segoe UI', Roboto, sans-serif;
}

:root {
    --primary-color: #0d6efd;
    /* Blue banner */
    --primary-hover: #0b5ed7;
    --navbar-bg: #003366;
    /* Rich Navy Blue */
    --navbar-text: rgba(255, 255, 255, 0.7);
    --navbar-text-hover: #ffffff;
    --bg-main: #f8f9fa;
    /* Light gray */
    --text-main: #212529;
    --text-muted: #6c757d;
    --card-bg: #ffffff;
    --border-color: #dee2e6;
    --success: #198754;
    --danger: #dc3545;
    --warning: #ffc107;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
}

/* Typography */
h1,
h2,
h3,
h4 {
    color: var(--text-main);
    font-weight: 600;
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.text-center {
    text-align: center;
}

/* Utilities */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

.d-flex {
    display: flex;
}

.justify-between {
    justify-content: space-between;
}

.justify-center {
    justify-content: center;
    flex-wrap: wrap;
}

.align-center {
    align-items: center;
}

.mt-4 {
    margin-top: 1.5rem;
}

.mb-4 {
    margin-bottom: 1.5rem;
}

.w-100 {
    width: 100%;
}

.p-0 {
    padding: 0 !important;
}

/* Navbar (Top) */
.navbar {
    background-color: var(--navbar-bg);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
    margin-right: 2rem;
}

.navbar-nav {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    flex-direction: row;
}

.nav-item {
    margin-right: 0.5rem;
}

.nav-link {
    color: var(--navbar-text);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: color 0.2s ease;
}

.nav-link:hover,
.nav-link.active {
    color: var(--navbar-text-hover);
}

.navbar-user {
    color: var(--navbar-text);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Layout */
.main-content {
    padding: 2rem 15px;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Custom Welcome Banner */
.welcome-banner {
    background-color: var(--primary-color);
    color: white;
    padding: 3rem 2rem;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(13, 110, 253, 0.2);
}

.welcome-banner h1 {
    color: white;
    font-size: 2rem;
    font-weight: 700;
    margin-top: 0.5rem;
    margin-bottom: 0;
}

.welcome-banner p {
    font-size: 1rem;
    opacity: 0.9;
    margin-bottom: 0;
}

/* Cards */
.card,
.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 1.5rem;
}

/* Login Page Specific */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background-color: var(--navbar-bg);
    /* Match navbar for login screen */
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: white;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h2 {
    color: var(--text-main);
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-main);
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 0.6rem 1rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 1rem;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    font-weight: 500;
    text-align: center;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-warning {
    background-color: var(--warning);
    color: #000;
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

.btn-icon {
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    border: 1px solid transparent;
}

.alert-danger {
    background: #f8d7da;
    border-color: #f5c2c7;
    color: #842029;
}

.alert-success {
    background: #d1e7dd;
    border-color: #badbcc;
    color: #0f5132;
}

/* Tables - Auto-sizing for content */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    table-layout: auto; /* Content-based column widths */
    border-collapse: collapse;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 0.5rem 0.4rem; /* Reduced padding */
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    white-space: nowrap; /* Prevent text wrap in cells */
}

.table th {
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.02);
}

/* Matrix/Presensi table optimizations */
.table-matrix {
    font-size: 0.85rem;
}

.table-matrix th,
.table-matrix td {
    padding: 0.4rem 0.2rem !important;
    min-width: 28px; /* Fits 'OFF', auto-expands for content */
    max-width: 40px;
}

.table-matrix th.col-nama,
.table-matrix td.col-nama { /* Name column - match jadwal shift */
    width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    height: auto;
    vertical-align: middle;
    padding: 0.5rem 10px !important;
    font-size: 0.75rem;
    text-align: left;
}

.table-matrix th:nth-child(n+5),
.table-matrix td:nth-child(n+5) { /* Day columns */
    min-width: 28px;
}

.table tbody tr:hover td,
.table tbody tr:focus-within td {
    background-color: #dbeafe !important; /* Very visible light blue indicator */
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 0, 0, .02);
}

/* Badges */
.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
}

.badge-success {
    background: var(--success);
}

.badge-danger {
    background: var(--danger);
}

.badge-warning {
    background: var(--warning);
    color: #000;
}

/* Clock Display */
.live-clock {
    font-size: 3.5rem;
    font-weight: 700;
    text-align: center;
    margin: 1rem 0;
    color: var(--text-main);
}

.live-date {
    text-align: center;
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

/* Grid Layouts */
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    padding: 1.5rem;
    border-radius: 8px;
    background: white;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.stat-card h3 {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card .value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    border-radius: 8px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: var(--text-main);
    text-decoration: none;
    cursor: pointer;
}

.modal-body {
    padding: 1.5rem;
}

/* DataTables Overrides - Compact */
.dataTables_wrapper {
    font-size: 0.88rem;
}

.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.35rem 0.6rem; /* Smaller */
    margin-left: 0.5rem;
    outline: none;
    font-size: 0.88rem;
}

.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--primary-color);
}

.dataTables_wrapper .dataTables_length select {
    font-size: 0.88rem;
    padding: 0.2rem 0.4rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.3em 0.6em;
    font-size: 0.85rem;
    border-radius: 4px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: var(--primary-color) !important;
    color: white !important;
    border: 1px solid var(--primary-hover) !important;
}

.dt-buttons .dt-button {
    font-size: 0.85rem !important;
    padding: 0.4rem 0.8rem !important;
    margin-right: 0.5rem;
}

table.dataTable.no-footer {
    border-bottom: 1px solid var(--border-color);
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
        gap: 1rem;
    }
    
    .navbar > .d-flex {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        gap: 1rem;
    }
    
    .navbar-brand {
        margin-right: 0;
        margin-bottom: 0.5rem;
    }
    
    .navbar-nav {
        flex-wrap: wrap;
        width: 100%;
        gap: 0.5rem;
    }
    
    .navbar-user {
        width: 100%;
        justify-content: flex-end;
        padding-top: 0.5rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .page-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 1rem;
        margin-bottom: 1.5rem !important;
    }
    
    .page-header form {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.75rem;
        width: 100%;
    }
    
    .page-header form select,
    .page-header form button {
        width: 100% !important;
        margin-bottom: 0 !important;
    }
    
    .page-header form .d-flex {
        flex-direction: column;
        width: 100%;
    }
    
    .main-content {
        padding: 1rem !important;
    }
    
    .welcome-banner {
        padding: 1.5rem 1rem;
    }
    
    .welcome-banner h1 {
        font-size: 1.5rem;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
    
    .modal-content {
        width: 95% !important;
        margin: 10% auto;
    }
    
    .card-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1rem;
    }
    
    .card-header > div {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
    }
    
    .card-header .btn {
        margin-right: 0 !important;
        flex: 1 1 auto;
        text-align: center;
    }

    .modal-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .modal-header > div {
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-items: center;
    }
    
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length {
        text-align: left !important;
        margin-bottom: 1rem;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
        margin-left: 0;
    }
    
    .dt-buttons {
        text-align: left !important;
        margin-bottom: 1rem;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .dt-buttons .dt-button {
        margin-right: 0;
        flex: 1 1 auto;
    }
}

/* Fix table-matrix sticky columns on mobile & tablet */
@media (max-width: 992px) {
    /* For attendance.php (uses nth-child) */
    .table-matrix th:nth-child(1), .table-matrix td:nth-child(1) {
        width: 40px !important; min-width: 40px !important; max-width: 40px !important;
        left: 0 !important;
        position: sticky !important; z-index: 15 !important;
    }
    .table-matrix th:nth-child(3), .table-matrix td:nth-child(3) {
        width: 220px !important; min-width: 220px !important; max-width: 220px !important;
        left: 40px !important;
        position: sticky !important; z-index: 14 !important;
        white-space: normal !important; /* Allow wrapping */
        line-height: 1.3 !important;
    }
    
    /* Perusahaan, Scan, NIK, Bagian -> STATIC (Bisa digeser/scroll ke kiri lalu menghilang) */
    .table-matrix th:nth-child(2), .table-matrix td:nth-child(2),
    .table-matrix th:nth-child(4), .table-matrix td:nth-child(4),
    .table-matrix th:nth-child(5), .table-matrix td:nth-child(5),
    .table-matrix th:nth-child(6), .table-matrix td:nth-child(6) {
        position: static !important;
        z-index: auto !important;
        width: auto !important; min-width: 100px !important; max-width: 200px !important;
    }

    /* For schedules.php (uses classes) */
    .table-matrix .col-no {
        width: 40px !important; min-width: 40px !important; max-width: 40px !important;
        left: 0 !important;
        position: sticky !important; z-index: 15 !important;
    }
    .table-matrix .col-nama {
        width: 220px !important; min-width: 220px !important; max-width: 220px !important;
        left: 40px !important;
        position: sticky !important; z-index: 14 !important;
        white-space: normal !important;
        line-height: 1.3 !important;
    }
    .table-matrix .col-scan,
    .table-matrix .col-bagian {
        position: static !important;
        z-index: auto !important;
        width: auto !important; min-width: 100px !important; max-width: 200px !important;
    }
    
    /* Ensure thead stays sticky vertically */
    .table-matrix thead th {
        position: sticky !important;
        top: 0;
        z-index: 20 !important;
    }
    /* Ensure top-left corners have highest z-index */
    .table-matrix thead th:nth-child(1),
    .table-matrix thead th:nth-child(3),
    .table-matrix thead .col-no,
    .table-matrix thead .col-nama {
        z-index: 30 !important;
    }
}
