/* ===================================
   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;
}

/* Touch devices: neutralize sticky hover transforms + heavy box-shadows.
   Plain color/background hover effects remain (they flash briefly on tap, fine). */
@media (hover: none) {
    .btn-primary:hover:not(:disabled),
    .btn-secondary:hover:not(:disabled),
    .btn-outline:hover:not(:disabled),
    .btn-logout:hover:not(:disabled),
    .btn-glass:hover,
    .stat-card:hover,
    .clickable-card:hover,
    .ts-export-btn:hover {
        transform: none;
    }
    .btn-primary:hover:not(:disabled) {
        box-shadow: 0 2px 8px var(--primary-glow);
    }
    .stat-card:hover {
        box-shadow: var(--shadow-sm);
    }
    /* Tap feedback via :active instead */
    .clickable-card:active,
    .stat-card:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    .btn:active:not(:disabled) {
        transform: scale(0.97);
    }
}

/* Respect users who request reduced motion (iOS/macOS/Win accessibility) */
@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;
    }
    .view {
        transition: none;
    }
}

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;
    min-height: 100dvh;
    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;
    min-height: 100dvh;
}

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

/* ===================================
   GLOBAL LOADER
=================================== */
#global-loader {
    position: fixed;
    inset: 0;
    background: var(--bg-page, #fff);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

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

/* Logo + spinning ring wrapper */
.loader-logo-wrap {
    position: relative;
    width: 108px;
    height: 108px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-ring-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    animation: spin 1.1s linear infinite;
}

.loader-ring-track {
    fill: none;
    stroke: var(--border, #e2e8f0);
    stroke-width: 4;
}

.loader-ring-arc {
    fill: none;
    stroke: var(--primary, #2563eb);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 276;
    stroke-dashoffset: 207;
    filter: drop-shadow(0 0 4px var(--primary-glow, rgba(37,99,235,0.35)));
}

.loader-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    animation: loader-pulse 2s ease-in-out infinite;
}

.loader-text {
    color: var(--text-muted, #64748b);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    animation: loader-fade 1.5s ease-in-out infinite;
}

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

@keyframes loader-pulse {
    0%, 100% { transform: scale(1);    opacity: 1; }
    50%       { transform: scale(0.92); opacity: 0.8; }
}

@keyframes loader-fade {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

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

/* ===================================
   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"],
input[type="search"],
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;
}

/* Remove native search "x" styling inconsistencies */
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: 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%;
}

/* Prevent iOS Safari auto-zoom on input focus (requires ≥16px) */
@media (max-width: 768px) {
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="url"],
    input[type="date"],
    input[type="number"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px;
    }
}


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;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
    min-height: 100dvh;
    background-image:
        linear-gradient(rgba(15, 23, 42, 0.45), rgba(15, 23, 42, 0.45)),
        url("../../background.jpg");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    padding: 0 1rem;
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
    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 {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    z-index: 20;
    flex-shrink: 0;
    padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem 0.5rem;
}

/* 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;
    flex: 1;
    justify-content: center;
    padding-bottom: 2rem;
}

/* 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;
    padding-left: max(2rem, env(safe-area-inset-left));
    padding-right: max(2rem, env(safe-area-inset-right));
    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;
    position: relative;
}

.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;
}

/* Header overflow menu — inline on desktop, dropdown on narrow mobile */
.header-more-btn {
    display: none;
    background: var(--bg-subtle);
    border: 1.5px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text-sub);
    width: 44px;
    height: 44px;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}
.header-more-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.header-actions-pop {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ===================================
   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;
}

/* Date navigation (prev/next day arrows around date input) */
.date-nav {
    display: inline-flex;
    align-items: stretch;
    gap: 0.4rem;
}

.date-nav input[type="date"] {
    flex: 1 1 200px;
    width: auto;
    min-width: 0;
}

.date-nav-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    min-height: 38px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.date-nav-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.date-nav-btn:active {
    transform: translateY(0);
}

.date-nav-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.date-nav-btn svg {
    display: block;
}

.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);
}

/* Compact body font for the Daily Attendance table (header keeps its own size) */
.employees-table tbody td {
    font-size: 0.78rem;
    padding: 0.6rem 0.65rem;
}
.employees-table tbody .emp-name {
    font-size: 0.82rem;
}
.employees-table tbody .emp-id {
    font-size: 0.7rem;
}
.employees-table tbody .td-status select,
.employees-table tbody .td-overtime input,
.employees-table tbody .td-notes input,
.employees-table tbody .notes-input {
    font-size: 0.78rem;
    padding: 0.3rem 0.5rem;
}

.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);
}

/* ─────────── Daily Attendance Pagination Footer ─────────── */
.da-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.55rem 0.85rem;
    background: var(--bg-subtle);
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-muted);
}
.da-pagination-info {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
}
.da-pagination-info strong {
    color: var(--text-main);
    font-weight: 700;
}
.da-pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
}
.da-pg-field {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.da-pg-field > span {
    white-space: nowrap;
}
.da-pg-select {
    appearance: auto;
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.2rem 1.4rem 0.2rem 0.5rem;
    font-size: 0.78rem;
    height: 28px;
    cursor: pointer;
}
html[dir="rtl"] .da-pg-select {
    padding: 0.2rem 0.5rem 0.2rem 1.4rem;
}
.da-pg-page-of {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
}
.da-pg-page-of strong {
    color: var(--text-main);
    font-weight: 700;
}
.da-pg-nav {
    display: inline-flex;
    align-items: center;
    background: #4a5462;
    border-radius: 6px;
    overflow: hidden;
}
body.dark-theme .da-pg-nav {
    background: #2c343f;
}
.da-pg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 28px;
    background: transparent;
    color: #fff;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
    padding: 0;
}
.da-pg-btn + .da-pg-btn {
    border-inline-start: 1px solid rgba(255, 255, 255, 0.18);
}
.da-pg-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
}
.da-pg-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
/* In RTL, the chevron direction is the same SVG glyph, but the visual meaning
   "first/prev/next/last" should follow reading direction. Mirror them. */
html[dir="rtl"] .da-pg-btn svg {
    transform: scaleX(-1);
}

/* 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-status select.status-half-day {
    background-color: var(--warning-light);
    color: var(--warning);
    border-color: rgba(217, 119, 6, 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;
}

.td-notes input,
.notes-input {
    padding: 0.4rem 0.6rem;
    font-size: 0.875rem;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
}

/* 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;
    bottom: max(2rem, calc(1rem + env(safe-area-inset-bottom)));
    left: 2rem;
    left: max(2rem, calc(1rem + env(safe-area-inset-left)));
    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;
    bottom: max(2rem, calc(1rem + env(safe-area-inset-bottom)));
    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-image:
        linear-gradient(rgba(2, 6, 23, 0.7), rgba(2, 6, 23, 0.7)),
        url("../../background.jpg");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

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;
}

/* Branch multi-select inside the timesheet filters card —
   override the generic .multi-select rules so it matches the sibling
   <select> inputs in size and alignment across all breakpoints. */
.ts-filter-group .ts-multi-select,
.ts-filter-group #ts-filter-branch {
    display: block;
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    align-self: stretch;
}

.ts-filter-group .ts-multi-select .multi-select-anchor {
    padding: 0.65rem 1rem;
    font-size: 1rem;
    border-width: 1.5px;
    box-sizing: border-box;
    min-height: 45px;
    width: 100%;
}

@media (max-width: 768px) {
    .ts-filter-group .ts-multi-select .multi-select-anchor {
        font-size: 16px;
    }
}

.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-half-day { background: #fefce8; color: #b45309; }
.ts-table tr.ts-row-half-day-woh { background: #fef3c7; color: #92400e; font-weight: 600; }
.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;
}
/* Rows whose branch does NOT match the active branch filter are visually dimmed.
   Applied via JS only when AppState.tsFilterBranch is non-empty. */
.ts-table tr.ts-row-branch-dim {
    opacity: 0.42;
}
/* First day under a newly-assigned branch gets a thicker top border so transitions
   are visible at a glance (the branch column already shows the new value). */
.ts-table tr.ts-row-branch-transition {
    border-top: 2px solid #7c3aed;
}
.ts-table td.ts-td-branch {
    font-size: 0.72rem;
    color: #334155;
    max-width: 140px;
    line-height: 1.15;
    word-break: break-word;
    white-space: normal;
}
.ts-branch-transition-mark {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    color: #7c3aed;
    background: rgba(124, 58, 237, 0.12);
    padding: 1px 5px;
    border-radius: 3px;
    margin-inline-start: 4px;
    vertical-align: middle;
}

.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,
    #tab-home .da-pagination {
        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 .td-status select.status-half-day {
    background-color: rgba(217, 119, 6, 0.15);
    border-color: rgba(217, 119, 6, 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: var(--bg-page, #0b1120);
}

body.dark-theme .loader-ring-track {
    stroke: var(--border, #1e2d4a);
}

body.dark-theme .loader-logo {
    filter: brightness(0.95);
}

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 — iPAD RANGE (769–1024) portrait & landscape
   Refinements that apply only to tablets, not mobile.
=================================== */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Tighter filters bar — 2-per-row layout */
    .table-filters-group { gap: 0.5rem; }
    .multi-select { min-width: 160px; flex: 1 1 160px; }

    /* TS filters: 2-up on iPad — use grid for predictable alignment
       (Year/Month on row 1, Branch/Employee on row 2, actions on row 3) */
    .ts-filters-card {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: end;
    }
    .ts-filter-group { min-width: 0; flex: initial; }
    .ts-filter-actions { grid-column: 1 / -1; }

    /* Cap table fixed column min-widths so horizontal scroll is minimal */
    .employees-table th:nth-child(3) { min-width: 170px; }
    .employees-table th:nth-child(4) { min-width: 110px; }
    .employees-table th:nth-child(5) { min-width: 110px; }
    .employees-table th:nth-child(6) { min-width: 105px; }
    .employees-table th:nth-child(7) { min-width: 95px; }
    .employees-table th:nth-child(8) { min-width: 120px; }

    /* Controls bar spacing */
    .controls-bar { gap: 0.85rem; }

    /* TS dual-table stays side-by-side but tighter padding */
    .ts-table th, .ts-table td {
        padding: 0.35rem 0.3rem;
        font-size: 0.78rem;
    }
}

/* iPad portrait orientation specifically — single column for TS dual tables */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    .ts-dual-table-wrap {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

/* ===================================
   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%; }
    .date-nav { display: flex; width: 100%; }
    .date-nav-btn { width: 44px; min-height: 44px; }
    .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; }

    /* ---------- TOUCH TARGETS (≥44×44) ---------- */
    .btn-icon {
        min-width: 44px;
        height: 44px;
    }
    .ctrl-btn {
        min-height: 44px;
        padding: 0.55rem 0.75rem;
    }
    .btn-toggle-password {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }
    .row-checkbox,
    #check-all {
        width: 20px;
        height: 20px;
    }
    .multi-select-anchor {
        min-height: 44px;
        padding: 0.65rem 0.9rem;
    }
    .multi-select-items label {
        min-height: 44px;
        padding: 0.35rem 0.25rem;
    }
    .multi-select-items input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }
    .btn {
        min-height: 44px;
    }
    .btn-logout {
        min-height: 40px;
        padding: 0.55rem 0.85rem;
    }
    .main-tab-btn {
        min-height: 48px;
        padding: 0.9rem 0.25rem;
    }
    /* Larger row hit area for status/overtime inputs */
    .td-status select,
    .td-overtime input,
    .td-notes input {
        min-height: 40px;
    }

    /* 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; }
}

/* ===================================
   HEADER OVERFLOW MENU (≤540px)
=================================== */
@media (max-width: 540px) {
    .header-more-btn {
        display: inline-flex;
        align-items: center;
    }

    .header-actions-pop {
        position: absolute;
        top: calc(100% + 10px);
        inset-inline-end: 0;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--r-lg);
        box-shadow: var(--shadow-lg);
        padding: 0.5rem;
        min-width: 200px;
        flex-direction: column;
        align-items: stretch;
        gap: 0.4rem;
        z-index: 60;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-6px);
        transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
    }

    .header-actions-pop.open {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    /* Stack the controls pair as full-width items inside the dropdown */
    .header-actions-pop .header-controls {
        background: transparent;
        border: none;
        padding: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
    }
    .header-actions-pop .ctrl-btn {
        justify-content: flex-start;
        padding: 0.6rem 0.75rem;
        min-height: 44px;
        border-radius: var(--r-md);
        width: 100%;
    }
    .header-actions-pop .ctrl-btn:hover {
        background: var(--bg-hover);
    }

    .header-actions-pop #btn-logout {
        width: 100%;
        justify-content: flex-start;
        margin-top: 0.25rem;
        border-top: 1px dashed var(--border);
        border-radius: 0 0 var(--r-md) var(--r-md);
        padding-top: 0.7rem;
    }
}

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

/* ===================================
   CARD VIEW — EMPLOYEES TABLE (≤640px)
   Converts the desktop table into stacked cards for phones.
=================================== */
@media (max-width: 640px) {
    /* Let the container flow naturally, no horizontal scroll */
    .table-container {
        background: transparent;
        border: none;
        box-shadow: none;
        overflow: visible;
        max-height: none;
    }

    /* Keep filters/actions header as a normal card */
    .table-actions-header {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--r-lg);
        margin-bottom: 0.75rem;
        padding: 0.85rem 1rem;
    }

    /* Hide the thead — labels move inline via pseudo-elements where needed */
    .employees-table thead { display: none; }

    /* Break the table structure */
    .employees-table,
    .employees-table tbody,
    .employees-table tr,
    .employees-table td {
        display: block;
        width: 100%;
        min-width: 0;
    }
    .employees-table {
        white-space: normal;
        border-collapse: separate;
        min-width: 0;
    }

    /* Each row = card */
    .employees-table tbody tr {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--r-lg);
        box-shadow: var(--shadow-xs);
        padding: 0.85rem 1rem;
        margin-bottom: 0.75rem;
        display: grid;
        grid-template-columns: auto 1fr 2fr;
        column-gap: 0.6rem;
        row-gap: 0.6rem;
        align-items: center;
    }
    .employees-table tbody tr.row-dirty {
        border-color: var(--warning);
        background: var(--bg-card);
        box-shadow: 0 0 0 1px var(--warning-light);
    }
    .employees-table tbody tr:hover { background: var(--bg-card); }

    .employees-table tbody td {
        padding: 0;
        border: none;
        min-width: 0;
    }

    /* Row 1: checkbox + name (spans remaining columns) */
    .employees-table td:nth-child(1) { grid-column: 1; grid-row: 1; }
    .employees-table td:nth-child(2) { display: none; } /* index # hidden on cards */
    .employees-table td:nth-child(3) { grid-column: 2 / -1; grid-row: 1; }
    .employees-table td:nth-child(3) .emp-name {
        font-size: 1rem;
        max-width: none;
    }

    /* Row 2: branch + designation combined on one line */
    .employees-table td:nth-child(4),
    .employees-table td:nth-child(5) {
        grid-column: 1 / -1;
        font-size: 0.82rem;
        color: var(--text-muted);
        display: flex;
        align-items: center;
        gap: 0.4rem;
    }
    .employees-table td:nth-child(4)::before,
    .employees-table td:nth-child(5)::before {
        font-size: 0.7rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-faint);
        flex-shrink: 0;
    }
    html[dir="rtl"] .employees-table td:nth-child(4)::before { content: "الفرع:"; }
    html[dir="ltr"] .employees-table td:nth-child(4)::before { content: "Branch:"; }
    html[dir="rtl"] .employees-table td:nth-child(5)::before { content: "المسمى:"; }
    html[dir="ltr"] .employees-table td:nth-child(5)::before { content: "Title:"; }

    /* Row 3: status (full width) */
    .employees-table td.td-status {
        grid-column: 1 / -1;
        margin-top: 0.25rem;
    }
    .employees-table td.td-status select {
        min-width: 0;
        width: 100%;
        min-height: 44px;
        font-size: 0.95rem;
    }

    /* Row 4: overtime (narrow) + notes (wide) side-by-side */
    .employees-table td.td-overtime {
        grid-column: 1 / 2;
    }
    .employees-table td.td-notes {
        grid-column: 2 / -1;
    }
    .employees-table td.td-overtime input {
        min-height: 44px;
        text-align: center;
        font-size: 1rem;
    }
    .employees-table td.td-notes input {
        min-height: 44px;
        width: 100%;
    }

    /* Row 5: record badge + clear button */
    .employees-table td:nth-child(9) {
        grid-column: 1 / -1;
        padding-top: 0.35rem;
        border-top: 1px dashed var(--border);
        margin-top: 0.25rem;
    }
    .employees-table td:nth-child(9) .row-actions-wrap {
        justify-content: space-between;
    }
    .employees-table td:nth-child(9) .btn-clear-row {
        min-width: 40px;
        min-height: 40px;
    }

    /* Remove column widths — they don't apply to block layout */
    .employees-table th,
    .employees-table td { min-width: 0 !important; }
}

/* Dark theme tweaks for card view */
@media (max-width: 640px) {
    body.dark-theme .employees-table tbody tr {
        background: var(--bg-card);
    }
    body.dark-theme .employees-table tbody tr.row-dirty {
        background: var(--bg-card);
    }
}
