/* ===================================
   DESIGN TOKENS & VARIABLES
=================================== */
:root {
    /* Brand Palette */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: rgba(37, 99, 235, 0.1);
    --primary-glow: rgba(37, 99, 235, 0.25);

    /* Neutrals */
    --text-main: #0f172a;
    --text-sub: #334155;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    /* Backgrounds */
    --bg-main: #f0f4ff;
    --bg-card: #ffffff;
    --bg-subtle: #f8fafc;
    --bg-hover: #f1f5f9;

    /* Borders */
    --border: #e2e8f0;
    --border-focus: var(--primary);

    /* Status Colors */
    --success: #059669;
    --success-light: rgba(5, 150, 105, 0.1);
    --warning: #d97706;
    --warning-light: rgba(217, 119, 6, 0.1);
    --danger: #dc2626;
    --danger-light: rgba(220, 38, 38, 0.1);
    --info: #2563eb;
    --info-light: rgba(37, 99, 235, 0.1);

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.1), 0 4px 8px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 50px rgba(0,0,0,0.12), 0 8px 20px rgba(0,0,0,0.06);

    /* Radii */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-xl: 20px;
    --r-2xl: 28px;

    /* Transitions */
    --ease: all 0.2s ease;
    --ease-bounce: all 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* ===================================
   RESET & BASE
=================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Cairo', system-ui, -apple-system, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none !important;
}

/* ===================================
   VIEWS
=================================== */
.view {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease;
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    min-height: 100vh;
}

.view.active {
    opacity: 1;
    visibility: visible;
    position: relative;
    z-index: 10;
}

/* ===================================
   GLOBAL LOADER
=================================== */
#global-loader {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loader-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===================================
   TYPOGRAPHY
=================================== */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.3; }

/* ===================================
   FORM ELEMENTS
=================================== */
input, select, button, textarea {
    font-family: inherit;
    font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="date"],
input[type="number"],
select {
    width: 100%;
    padding: 0.65rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--r-md);
    background: var(--bg-card);
    color: var(--text-main);
    transition: var(--ease);
    outline: none;
}

input[type="date"] {
    position: relative;
    -webkit-appearance: none; /* Fix iOS rendering */
    appearance: none;
    min-height: 45px; /* Prevent shrinking on iOS */
    box-sizing: border-box;
    text-align: start; /* Fix centered default on iOS */
    max-width: 100%;
}


input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

input:disabled, select:disabled {
    background: var(--bg-subtle);
    color: var(--text-faint);
    cursor: not-allowed;
}

/* ===================================
   BUTTONS
=================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--r-md);
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: var(--ease);
    white-space: nowrap;
    line-height: 1;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: 0 4px 16px var(--primary-glow);
    transform: translateY(-1px);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-sub);
    border: 1.5px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--border);
    border-color: var(--text-faint);
}

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-sub);
}
.btn-outline:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-logout {
    background: transparent;
    color: var(--danger);
    border: 1.5px solid rgba(220,38,38,0.2);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}
.btn-logout:hover:not(:disabled) {
    background: var(--danger-light);
    border-color: var(--danger);
}

.btn-glass {
    background: rgba(255,255,255,0.25);
    backdrop-filter: blur(10px);
    border: 1.5px solid rgba(255,255,255,0.4);
    color: white;
    padding: 0.55rem;
    border-radius: var(--r-md);
}
.btn-glass:hover {
    background: rgba(255,255,255,0.35);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    min-width: 38px;
    height: 38px;
}

.btn-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===================================
   LOGIN VIEW
=================================== */
#login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(145deg, #1e40af 0%, #2563eb 40%, #7c3aed 100%);
    padding: 2rem 1rem;
    position: relative;
    overflow: hidden;
}

/* Decorative background shapes */
.login-bg-shapes {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.shape {
    position: absolute;
    border-radius: 50%;
    background: rgba(255,255,255,0.04);
}

.shape-1 {
    width: 500px; height: 500px;
    top: -200px; right: -150px;
    background: rgba(255,255,255,0.06);
}

.shape-2 {
    width: 350px; height: 350px;
    bottom: -100px; left: -100px;
    background: rgba(255,255,255,0.04);
}

.shape-3 {
    width: 200px; height: 200px;
    top: 40%; left: 60%;
    background: rgba(124, 58, 237, 0.2);
    filter: blur(60px);
}

/* Login top controls */
.login-top-controls {
    position: absolute;
    top: 1.25rem;
    left: 1.25rem;
    right: 1.25rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    z-index: 20;
}

/* Login wrapper */
.login-wrapper {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
    max-width: 440px;
}

/* Company header above card */
.login-company-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    color: white;
    animation: fadeSlideDown 0.5s ease;
}

@keyframes fadeSlideDown {
    from { opacity: 0; transform: translateY(-15px); }
    to   { opacity: 1; transform: translateY(0); }
}

.company-logo-large {
    width: 56px; height: 56px;
    background: rgba(255,255,255,0.18);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: var(--r-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.company-name-header {
    display: flex;
    flex-direction: column;
}

.company-label {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    text-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.company-subtitle {
    font-size: 0.8rem;
    opacity: 0.8;
    font-weight: 400;
}

/* Login card */
.login-card {
    background: var(--bg-card);
    border-radius: var(--r-2xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    padding: 2.5rem;
    position: relative;
    overflow: hidden;
    animation: fadeSlideUp 0.5s ease 0.1s both;
}

@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.login-card-glow {
    position: absolute;
    top: -60px; left: 50%;
    transform: translateX(-50%);
    width: 200px; height: 120px;
    background: var(--primary-glow);
    filter: blur(40px);
    pointer-events: none;
}

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

.logo-box {
    width: 60px; height: 60px;
    background: linear-gradient(135deg, var(--primary), #6d28d9);
    color: white;
    border-radius: var(--r-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    box-shadow: 0 8px 20px var(--primary-glow);
}

.login-header h1 {
    font-size: 1.5rem;
    color: var(--text-main);
    margin-bottom: 0.4rem;
}

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

/* Input with icon */
.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.45rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-sub);
}

.input-wrapper {
    position: relative;
}

.input-wrapper input {
    padding: 0 2.75rem;
}

.input-icon {
    position: absolute;
    right: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
    transition: color 0.2s;
}

.input-wrapper:focus-within .input-icon {
    color: var(--primary);
}

.btn-toggle-password {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 5px;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: color 0.2s;
}
.btn-toggle-password:hover {
    color: var(--text);
}
[dir="rtl"] .btn-toggle-password { left: 0.5rem; }
[dir="ltr"] .btn-toggle-password { right: 0.5rem; }

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.75rem;
}

.form-actions .btn {
    flex: 1;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
}

.login-help {
    margin-top: 1.25rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0.85rem 1rem;
    background: var(--bg-subtle);
    border-radius: var(--r-md);
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    line-height: 1.5;
}

.login-help svg { flex-shrink: 0; margin-top: 1px; }

/* Powered by badge */
.powered-by {
    color: rgba(255,255,255,0.7);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    animation: fadeSlideUp 0.5s ease 0.2s both;
}

.powered-by strong {
    color: rgba(255,255,255,0.95);
    font-weight: 700;
}

/* ===================================
   APP HEADER
=================================== */
.app-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 40;
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1440px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

/* Brand section */
.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    min-width: 0;
}

.header-logo {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--primary), #6d28d9);
    border-radius: var(--r-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 2px 8px var(--primary-glow);
}

.header-brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.header-company-name {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-app-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    white-space: nowrap;
}

/* Right side of header */
.header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-subtle);
    border: 1.5px solid var(--border);
    border-radius: 999px;
    padding: 0.35rem 0.9rem 0.35rem 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-sub);
}

.user-avatar {
    width: 28px; height: 28px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    flex-shrink: 0;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    border: 1.5px solid var(--border);
    border-radius: var(--r-md);
    padding: 0.2rem;
    background: var(--bg-subtle);
}

.ctrl-btn {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem 0.6rem;
    border-radius: var(--r-sm);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: var(--ease);
    font-family: inherit;
}

.ctrl-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.lang-text-label {
    font-size: 0.75rem;
    font-weight: 700;
}

/* ===================================
   APP MAIN CONTENT
=================================== */
.app-main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.75rem 2rem;
}

/* Controls bar */
.controls-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    background: var(--bg-card);
    padding: 1rem 1.25rem;
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    align-items: flex-end;
    border: 1px solid var(--border);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.control-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.control-group input[type="date"] {
    width: 200px;
}

.search-group {
    flex: 1;
    min-width: 250px;
    position: relative;
    justify-content: flex-end;
}

.search-icon {
    position: absolute;
    right: 0.85rem;
    bottom: 0.75rem;
    color: var(--text-faint);
    pointer-events: none;
}

.search-group input {
    padding-right: 2.5rem;
}

.action-buttons {
    display: flex;
    align-items: flex-end;
}

/* ===================================
   STATS CARDS
=================================== */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.25rem 1.5rem;
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--ease);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    border-radius: 0 4px 4px 0;
}

.stat-blue::before  { background: var(--info); }
.stat-red::before   { background: var(--danger); }
.stat-amber::before { background: var(--warning); }
.stat-green::before { background: var(--success); }
.stat-primary::before { background: var(--primary); }

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.clickable-card {
    cursor: pointer;
}
.clickable-card.card-active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-alpha);
    transform: translateY(-2px);
}

.stat-card .stat-icon {
    width: 46px; height: 46px;
    border-radius: var(--r-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-blue .stat-icon  { background: var(--info-light);    color: var(--info); }
.stat-red .stat-icon   { background: var(--danger-light);  color: var(--danger); }
.stat-amber .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-green .stat-icon { background: var(--success-light); color: var(--success); }

.stat-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
}

/* ===================================
   TABLE CONTAINER
=================================== */
.table-container {
    background: var(--bg-card);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
    max-height: calc(100vh - 380px);
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-actions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-subtle);
}

.table-filters-group {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.multi-select {
    display: inline-block;
    position: relative;
    min-width: 175px;
}

.multi-select-anchor {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    cursor: pointer;
    padding: 0.4rem 0.75rem;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
    user-select: none;
}

.multi-select-anchor::after {
    content: "▼";
    font-size: 0.6rem;
    color: var(--text-muted);
}

.multi-select-items {
    display: none;
    position: absolute;
    top: 110%;
    left: 0;
    width: 100%;
    max-height: 250px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 100;
    list-style: none;
    padding: 0.5rem;
    margin: 0;
}

.multi-select.open .multi-select-items {
    display: block;
}

.multi-select-items li {
    padding: 0.3rem 0;
}

.multi-select-items label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-main);
    cursor: pointer;
    line-height: 1.2;
}

.multi-select-items input[type="checkbox"] {
    cursor: pointer;
    width: 14px;
    height: 14px;
}

.save-actions {
    display: flex;
    gap: 0.75rem;
}

/* Table */
.employees-table {
    width: 100%;
    border-collapse: collapse;
    text-align: start; /* auto: right in Arabic (RTL), left in English (LTR) */
}

.employees-table th,
.employees-table td {
    padding: 0.9rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.employees-table th:nth-child(1) { min-width: 40px; }
.employees-table th:nth-child(2) { min-width: 50px; }
.employees-table th:nth-child(3) { min-width: 200px; }
.employees-table th:nth-child(4) { min-width: 130px; }
.employees-table th:nth-child(5) { min-width: 130px; }
.employees-table th:nth-child(6) { min-width: 120px; }
.employees-table th:nth-child(7) { min-width: 100px; }
.employees-table th:nth-child(8) { min-width: 140px; }

/* Sticky name column for horizontal scroll — desktop & tablet only */
@media (min-width: 769px) {
    html[dir="rtl"] .employees-table td:nth-child(3),
    html[dir="rtl"] .employees-table th:nth-child(3) {
        position: sticky;
        right: 0;
        z-index: 5;
        background: var(--bg-card);
        box-shadow: -2px 0 6px rgba(0,0,0,0.06);
    }
    
    html[dir="ltr"] .employees-table td:nth-child(3),
    html[dir="ltr"] .employees-table th:nth-child(3) {
        position: sticky;
        left: 0;
        z-index: 5;
        background: var(--bg-card);
        box-shadow: 2px 0 6px rgba(0,0,0,0.06);
    }

    html[dir="rtl"] .employees-table th:nth-child(3),
    html[dir="ltr"] .employees-table th:nth-child(3) {
        background: var(--bg-subtle);
        z-index: 25;
    }
    body.dark-theme .employees-table td:nth-child(3) {
        background: var(--bg-card);
    }
    body.dark-theme .employees-table th:nth-child(3) {
        background: var(--bg-subtle);
    }
}

.employees-table th {
    background: var(--bg-subtle);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 20;
}

.employees-table tbody tr {
    transition: background 0.15s;
}

.employees-table tbody tr:last-child td {
    border-bottom: none;
}

.employees-table tbody tr:hover {
    background: var(--bg-hover);
}

/* Row states */
tr.row-dirty {
    background: rgba(217, 119, 6, 0.04);
}
tr.row-dirty:hover {
    background: rgba(217, 119, 6, 0.08);
}

/* Table Inputs */
.td-status select {
    padding: 0.35rem 0.6rem;
    font-size: 0.875rem;
    width: 100%;
    min-width: 100px;
    border-radius: var(--r-sm);
    font-weight: 600;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.td-status select.status-present {
    background-color: var(--success-light);
    color: var(--success);
    border-color: rgba(5, 150, 105, 0.3);
}

.td-status select.status-absent {
    background-color: var(--danger-light);
    color: var(--danger);
    border-color: rgba(220, 38, 38, 0.3);
}

.td-overtime input {
    padding: 0.35rem 0.6rem;
    font-size: 0.875rem;
    width: 100%;
    min-width: 80px;
    border-radius: var(--r-sm);
    text-align: center;
}

/* Employee name emphasis */
.emp-name {
    font-weight: 700;
    color: var(--text-main);
    display: block;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    max-width: 250px;
}

.emp-id {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
}

/* ===================================
   BADGES
=================================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-default {
    background: rgba(100, 116, 139, 0.1);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.2);
}

.badge-draft {
    background: var(--info-light);
    color: var(--info);
    border: 1px solid rgba(37, 99, 235, 0.2);
}

.badge-dirty {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid rgba(217, 119, 6, 0.25);
}

.badge-remove {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.badge-submitted {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid rgba(5, 150, 105, 0.2);
}

/* ===================================
   EMPTY STATE
=================================== */
.empty-state {
    padding: 5rem 2rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-icon {
    width: 80px; height: 80px;
    background: var(--bg-hover);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
    color: var(--text-faint);
}

.empty-state p {
    font-size: 0.95rem;
    font-weight: 500;
}

/* ===================================
   TOAST NOTIFICATIONS
=================================== */
#toast-container {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    pointer-events: none;
}

.toast {
    min-width: 300px;
    max-width: 380px;
    background: var(--bg-card);
    border-radius: var(--r-lg);
    padding: 0.9rem 1.1rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    transform: translateX(-110%);
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: all;
    border: 1px solid var(--border);
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast-icon { flex-shrink: 0; margin-top: 1px; }

.toast-content { flex: 1; min-width: 0; }

.toast h4 {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.15rem;
}

.toast p {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.toast-success {
    border-right: 3px solid var(--success);
}
.toast-success .toast-icon { color: var(--success); }

.toast-error {
    border-right: 3px solid var(--danger);
}
.toast-error .toast-icon { color: var(--danger); }

/* ===================================
   BULK ACTIONS BAR
=================================== */
.bulk-actions-bar {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(400px);
    background: var(--bg-card);
    padding: 0.75rem 1.25rem;
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 100;
}

.bulk-actions-bar.show {
    transform: translateX(-50%) translateY(0) !important;
}

.bulk-selected-count {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.bulk-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
}

.bulk-inputs {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.bulk-inputs select,
.bulk-inputs input {
    height: 36px;
    padding: 0 0.7rem;
    width: auto;
    font-size: 0.875rem;
}

.bulk-inputs .btn {
    height: 36px;
    padding: 0 1.1rem;
    font-size: 0.875rem;
}

/* ===================================
   CHECKBOX
=================================== */
.row-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
    border-radius: 4px;
}

/* ===================================
   SORTING HEADERS
=================================== */
.employees-table th.sortable {
    cursor: pointer;
}

.employees-table th.sortable:hover {
    color: var(--primary);
}

.sort-icon {
    display: inline-block;
    width: 0; height: 0;
    margin: 0 0.4rem;
    vertical-align: middle;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    opacity: 0.25;
    transition: opacity 0.15s;
}

.sortable.asc .sort-icon {
    border-bottom: 5px solid currentColor;
    opacity: 1;
}

.sortable.desc .sort-icon {
    border-top: 5px solid currentColor;
    opacity: 1;
}

/* ===================================
   DARK THEME
=================================== */
body.dark-theme {
    --text-main:  #f1f5f9;
    --text-sub:   #cbd5e1;
    --text-muted: #94a3b8;
    --text-faint: #64748b;
    --bg-main:    #0b1120;
    --bg-card:    #131c30;
    --bg-subtle:  #1a2540;
    --bg-hover:   #1e2d48;
    --border:     #233046;
}

body.dark-theme #login-view {
    background: linear-gradient(145deg, #0b1120 0%, #1a2540 40%, #1e1045 100%);
}

body.dark-theme .login-card {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

body.dark-theme input[type="date"],
body.dark-theme input[type="number"],
body.dark-theme select {
    background: var(--bg-card);
    border-color: var(--border);
    color: var(--text-main);
}

/* ===================================
   MAIN TABS NAVIGATION
 =================================== */
.main-tabs {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    display: flex;
    gap: 2rem;
    position: sticky;
    top: 64px;
    z-index: 35;
    box-shadow: var(--shadow-sm);
}

.main-tab-btn {
    padding: 1rem 0;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-muted);
    border: none;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: var(--ease);
}

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

.main-tab-btn.active {
    color: var(--primary);
}

.main-tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary);
    border-radius: 3px 3px 0 0;
}

/* ===================================
   TAB SECTIONS
 =================================== */
.tab-section {
    display: block;
}

.tab-section.hidden {
    display: none !important;
}

/* ===================================
   TIMESHEET TAB SPECIFIC
 =================================== */

/* TS Filters */
.ts-filters-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.ts-filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 200px;
    flex: 1;
}

.ts-filter-group label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
}

.ts-select-wrapper {
    position: relative;
}

.ts-filter-actions {
    display: flex;
    gap: 0.75rem;
}

/* TS Report Area */
.ts-report-area {
    background: white;
    border-radius: var(--r-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    margin-bottom: 2rem;
    min-height: 500px;
    color: #1a1a1a; /* Fixed dark text for print consistency */
}

/* TS Header for Printing */
.ts-print-header {
    text-align: center;
    margin-bottom: 2rem;
}

.ts-print-logo {
    max-height: 60px;
    margin-bottom: 0.5rem;
}

.ts-print-title {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    color: #000;
}

.ts-company-name-print {
    display: none; /* Only visible in A4 clone/print */
    font-weight: 800;
}

/* TS Emp Info Grid */
.ts-emp-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 2rem;
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.ts-info-row {
    display: flex;
    gap: 0.5rem;
}

.ts-info-label {
    font-weight: 800;
    min-width: 140px;
}

.ts-info-value {
    color: #333;
}

/* TS Summary Bar */
.ts-summary-bar {
    display: flex;
    justify-content: space-around;
    padding: 1.25rem;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: var(--r-md);
    margin-bottom: 2rem;
}

.ts-summary-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.ts-s-val {
    font-size: 1.5rem;
    font-weight: 800;
}

.ts-s-lbl {
    font-size: 0.75rem;
    font-weight: 700;
    color: #64748b;
}

.ts-s-present .ts-s-val { color: #059669; }
.ts-s-absent  .ts-s-val { color: #dc2626; }
.ts-s-holiday .ts-s-val { color: #2563eb; }
.ts-s-woh     .ts-s-val { color: #d97706; }
.ts-s-ot      .ts-s-val { color: #9333ea; }

/* TS Dual Table */
.ts-dual-table-wrap {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.ts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    border: 1px solid #1a1a1a;
}

.ts-table th, .ts-table td {
    border: 1px solid #1a1a1a;
    padding: 0.4rem 0.5rem;
    text-align: center;
}

.ts-table th {
    background: #f1f5f9;
    font-weight: 800;
}

.ts-table tr.ts-row-friday { background: #f1f5f9; color: #64748b; }
.ts-table tr.ts-row-holiday { background: #eff6ff; color: #2563eb; }
.ts-table tr.ts-row-leave { background: #f5f3ff; color: #7c3aed; }
.ts-table tr.ts-row-woh { background: #fffbeb; color: #d97706; font-weight: 700; }
.ts-table tr.ts-row-not-joined {
    background: repeating-linear-gradient(
        135deg,
        #f8fafc,
        #f8fafc 4px,
        #e2e8f0 4px,
        #e2e8f0 8px
    );
    color: #94a3b8;
    font-style: italic;
    opacity: 0.75;
}

.ts-ot-val {
    font-weight: 800;
    color: #9333ea;
}

/* Export Bar */
.ts-export-bar {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--r-lg);
    border: 1.5px solid var(--border);
}

.ts-export-bar h3 {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.ts-export-btns {
    display: flex;
    gap: 1rem;
}

.ts-export-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 1.2rem;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: var(--r-md);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-sub);
    cursor: pointer;
    transition: var(--ease);
}

.ts-export-btn:hover {
    background: var(--bg-subtle);
    border-color: var(--text-muted);
    color: var(--text-main);
}

.ts-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6rem 2rem;
    color: var(--text-faint);
}

.ts-empty-state svg { margin-bottom: 1rem; }

/* Dark Theme overrides for TS */
body.dark-theme .ts-report-area {
    background: #fff; /* Keep report area white even in dark theme for accurate export/print */
    color: #000;
}

body.dark-theme .ts-export-btn {
    background: var(--bg-card);
    border-color: var(--border);
}

/* ===================================
   PRINT STYLES
 =================================== */
@media print {
    /* Force A4 Landscape — fixed regardless of device */
    @page {
        size: A4 landscape;
        margin: 5mm;
    }

    body {
        background: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Hide all UI chrome */
    .app-header, .main-tabs, .ts-filters-card, .ts-export-bar,
    #global-loader, #toast-container, .bulk-actions-bar, .login-view {
        display: none !important;
    }

    .app-main {
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        width: 100% !important;
    }

    .tab-section:not(.active) { display: none !important; }

    /* Time Sheet Elements */
    .ts-dual-table-wrap, .ts-table {
        margin: 0 !important;
        width: 100% !important;
    }
    
    .ts-export-bar {
        display: none !important;
    }

    /* Daily Attendance Print */
    #tab-home {
        display: block !important;
    }
    
    #da-print-header {
        display: block !important;
        text-align: center;
        margin-bottom: 20px;
        page-break-after: avoid;
    }

    #tab-home .controls-bar,
    #tab-home .table-actions-header {
        display: none !important;
    }

    #tab-home .table-container {
        max-height: none !important;
        overflow: visible !important;
        border: none !important;
        box-shadow: none !important;
    }

    #tab-home .employees-table {
        width: 100% !important;
        page-break-inside: auto;
    }

    #tab-home .employees-table tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    #tab-home .stats-cards {
        page-break-inside: avoid;
        margin-bottom: 30px;
    }

    /* Hide the select dropdown arrow and make selects look like plain text if they are disabled or read-only, 
       but for DA, the select is an element. In print we just print it as looks. */
    #tab-home select.status-select {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        border: none;
        background: transparent;
        padding-right: 0;
    }

    .row-checkbox {
        display: none !important; /* Hide checkboxes when printing */
    }
    th:first-child, td:first-child {
        display: none !important; /* Hide checkbox column */
    }

    /* Report area: full page, no decoration, flex column to fill height */
    .ts-report-area {
        box-shadow: none !important;
        border: none !important;
        padding: 15px 30px !important;
        margin: 0 !important;
        width: 100% !important;
        min-height: 100vh !important;
        background: white !important;
        color: #1a1a1a !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* Tighter header styling for landscape fit - CENTERED */
    .ts-print-header { 
        margin-bottom: 10px !important; 
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
    }
    .ts-print-logo   { 
        max-height: 55px !important; 
        margin-bottom: 5px !important;
        display: block !important;
    }
    .ts-company-name-print {
        display: block !important;
        font-size: 1.2rem !important;
        font-weight: 800 !important;
        margin-bottom: 2px !important;
    }
    .ts-print-title { 
        font-size: 1.1rem !important; 
        margin: 0 !important;
        padding-bottom: 3px !important;
        border-bottom: 1.5px solid #1a1a1a !important;
        width: 100% !important;
    }

    /* Tighter employee info for landscape */
    .ts-emp-info {
        font-size: 0.85rem !important;
        margin-bottom: 8px !important;
        gap: 3px 3rem !important;
    }

    /* Tighter summary bar for landscape */
    .ts-summary-bar {
        padding: 8px 20px !important;
        margin-bottom: 8px !important;
    }
    .ts-s-val { font-size: 1.4rem !important; }
    .ts-s-lbl { font-size: 0.75rem !important; }

    /* Dual-column table layout */
    .ts-dual-table-wrap {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 15px !important;
        flex: 1 !important;
        align-items: start !important;
    }

    /* Tighter table cells for landscape - essential to fit all rows */
    .ts-table th, .ts-table td {
        padding: 4px 8px !important;
        font-size: 0.8rem !important;
        line-height: 1.2 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .ts-table th { font-weight: 800 !important; }

    /* Compact badges */
    .badge {
        font-size: 0.7rem !important;
        padding: 1px 5px !important;
    }
}

body.dark-theme input[type="text"],
body.dark-theme input[type="password"],
body.dark-theme input[type="email"],
body.dark-theme input[type="url"],
body.dark-theme input[type="date"],
body.dark-theme input[type="number"],
body.dark-theme select {
    background: var(--bg-subtle);
    color: var(--text-main);
    border-color: var(--border);
}

body.dark-theme .td-status select.status-present {
    background-color: rgba(5, 150, 105, 0.15);
    border-color: rgba(5, 150, 105, 0.3);
}

body.dark-theme .td-status select.status-absent {
    background-color: rgba(220, 38, 38, 0.15);
    border-color: rgba(220, 38, 38, 0.3);
}

body.dark-theme input:disabled,
body.dark-theme select:disabled {
    background: var(--bg-hover);
    color: var(--text-faint);
}

body.dark-theme .employees-table th {
    background: var(--bg-subtle);
}

body.dark-theme .toast {
    background: var(--bg-card);
    border-color: var(--border);
}

body.dark-theme #global-loader {
    background: rgba(11, 17, 32, 0.85);
}

body.dark-theme .btn-glass {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
}

body.dark-theme tr.row-dirty {
    background: rgba(217, 119, 6, 0.07);
}
body.dark-theme tr.row-dirty:hover {
    background: rgba(217, 119, 6, 0.12);
}

/* ===================================
   RESPONSIVE — TABLET (≤1024px)
=================================== */
@media (max-width: 1024px) {
    .app-main { padding: 1.25rem 1.5rem; }

    /* Stats: 3 columns on tablet so all 5 cards fit cleanly (3+2) */
    .stats-cards { grid-template-columns: repeat(3, 1fr); }

    /* Header: truncate company name cleanly on iPad */
    .app-header { padding: 0 1.25rem; }
    .header-brand { max-width: 240px; }
    .header-company-name {
        font-size: 0.85rem;
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .header-app-title { font-size: 0.7rem; }

    .employees-table th, .employees-table td { padding: 0.75rem 0.85rem; }
}

/* ===================================
   RESPONSIVE — MOBILE (≤768px)
=================================== */
@media (max-width: 768px) {
    /* Login */
    .login-card { padding: 1.75rem 1.25rem; }
    .login-company-header { gap: 0.65rem; }
    .company-label { font-size: 1rem; }

    /* Header — single compact row */
    .app-header { height: auto; padding: 0.6rem 0.85rem; }
    .header-content {
        flex-wrap: nowrap;
        gap: 0.5rem;
        padding: 0;
        justify-content: space-between;
    }

    /* Hide brand text completely on small phones, keep logo */
    .header-brand-text { display: none; }
    .header-logo { width: 34px; height: 34px; }

    /* User pill — show only avatar + name, compact */
    .user-pill {
        font-size: 0.75rem;
        padding: 0.25rem 0.6rem 0.25rem 0.35rem;
        max-width: 130px;
        overflow: hidden;
    }
    #current-user-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 90px;
    }
    .header-user { gap: 0.4rem; flex-wrap: nowrap; }
    .header-app-title { display: none; }

    /* Main */
    .app-main { padding: 1rem; }
    .controls-bar { flex-direction: column; align-items: stretch; }
    .control-group input[type="date"] { width: 100%; }
    .search-group { min-width: unset; }
    .search-group input { width: 100%; }
    .action-buttons { width: 100%; }
    .action-buttons .btn { width: 100%; justify-content: center; }

    /* Stats — 2 columns, 5th card spans full width (centered) */
    .stats-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    .stats-cards .stat-card:last-child {
        grid-column: 1 / -1;
        max-width: calc(50% - 0.375rem);
        margin: 0 auto;
        justify-self: center;
        width: 100%;
    }
    .stat-card { padding: 1rem; }
    .stat-value { font-size: 1.4rem; }

    /* Table — let page scroll naturally on mobile, no fixed height container */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        max-width: 100vw;
        max-height: none; /* Remove height cap so stats cards scroll out of view naturally */
    }
    .employees-table { white-space: nowrap; min-width: 700px; }
    .table-actions-header { flex-direction: column; gap: 0.75rem; align-items: stretch; }
    .table-filters-group { flex-wrap: wrap; }
    .multi-select { min-width: 0; flex: 1; }
    .save-actions { flex-direction: row; }
    .save-actions .btn { flex: 1; justify-content: center; }

    /* Bulk bar */
    .bulk-actions-bar {
        bottom: 1rem;
        width: 94%;
        flex-direction: column;
        padding: 1rem;
        border-radius: var(--r-lg);
        gap: 0.75rem;
    }
    .bulk-divider { width: 100%; height: 1px; }
    .bulk-inputs { flex-wrap: wrap; width: 100%; }
    .bulk-inputs select, .bulk-inputs input { flex: 1; min-width: 45%; }
    .bulk-inputs .btn { width: 100%; margin-top: 0.25rem; }

    /* TIMESHEET MOBILE FIXES */
    .ts-filters-card {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    .ts-filter-group {
        min-width: 100%;
    }
    .ts-filter-actions {
        flex-direction: column;
        width: 100%;
    }
    .ts-filter-actions .btn {
        width: 100%;
        justify-content: center;
    }
    .ts-report-area {
        padding: 1.5rem 1rem;
        min-height: auto;
    }
    .ts-print-title {
        font-size: 1.25rem;
    }
    .ts-emp-info {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    .ts-summary-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        padding: 1rem;
    }
    .ts-dual-table-wrap {
        grid-template-columns: 1fr;
        gap: 2rem;
        overflow-x: auto;
    }
    .ts-table {
        min-width: 320px;
    }
    .ts-table th, .ts-table td {
        padding: 0.35rem 0.2rem;
        font-size: 0.75rem;
    }
    .ts-export-btns {
        flex-direction: column;
    }
    .ts-export-btn {
        width: 100%;
        justify-content: center;
    }
    .ts-empty-state {
        padding: 4rem 1rem;
        text-align: center;
    }
}

/* ===================================
   RESPONSIVE — SMALL (≤480px)
=================================== */
@media (max-width: 480px) {
    /* On very small screens, stack stats 1 per row */
    .stats-cards { grid-template-columns: 1fr; }
    .stats-cards .stat-card:last-child {
        grid-column: auto;
        max-width: 100%;
    }
    .login-card { padding: 1.5rem 1rem; }
}

/* ===================================
   TOAST RESPONSIVE
=================================== */
@media (max-width: 600px) {
    #toast-container {
        left: 1rem; right: 1rem;
        bottom: 1rem;
        width: auto;
    }
    .toast {
        min-width: unset;
        width: 100%;
        max-width: none;
    }
}
