:root {
    --primary: #1A3C6E;
    --accent: #0D7377;
    --bg: #F5F6FA;
    --card-bg: #FFFFFF;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --text-primary: #1A1A2E;
    --text-secondary: #6B7280;
}

@import url('https://fonts.googleapis.com/css2?family=Dubai:wght@300;400;500;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Dubai', 'Segoe UI', Tahoma, sans-serif;
    background-color: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Dubai', 'Segoe UI', Tahoma, sans-serif;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

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

.btn-primary:hover {
    background-color: #153058;
}

.btn-accent {
    background-color: var(--accent);
    color: #FFFFFF;
}

.btn-accent:hover {
    background-color: #0a5c5f;
}

input, select, textarea {
    font-family: 'Dubai', 'Segoe UI', Tahoma, sans-serif;
    font-size: 14px;
    padding: 10px 14px;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s ease;
}

input[type="checkbox"], input[type="radio"] {
    padding: 0;
    border: 1px solid #9CA3AF;
    border-radius: 3px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* Hide admin-only salary fields for non-admin users */
body[data-is-admin="false"] #ext-admin-salary-fields {
    display: none !important;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
}

.grid {
    display: grid;
    gap: 16px;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
}

[dir="rtl"] body {
    text-align: right;
}

[dir="ltr"] body {
    text-align: left;
}

[dir="rtl"] input,
[dir="rtl"] select,
[dir="rtl"] textarea {
    text-align: right;
}

[dir="ltr"] input,
[dir="ltr"] select,
[dir="ltr"] textarea {
    text-align: left;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 240px;
    height: 100vh;
    background: var(--card-bg);
    box-shadow: var(--shadow);
    transition: width 0.3s ease;
    overflow: hidden;
    z-index: 100;
}

[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
}

.sidebar.collapsed {
    width: 60px;
}

.main-content {
    margin-left: 240px;
    transition: margin-left 0.3s ease;
    min-height: 100vh;
}

[dir="rtl"] .main-content {
    margin-left: 0;
    margin-right: 240px;
}

.sidebar.collapsed + .main-content,
.main-content.sidebar-collapsed {
    margin-left: 60px;
}

[dir="rtl"] .sidebar.collapsed + .main-content,
[dir="rtl"] .main-content.sidebar-collapsed {
    margin-left: 0;
    margin-right: 60px;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 300;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    max-width: 600px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #E5E7EB;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid #E5E7EB;
}

[dir="rtl"] .modal-footer {
    justify-content: flex-start;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    background: var(--bg);
    padding: 12px 16px;
    text-align: left;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid #E5E7EB;
    position: sticky;
    top: 0;
    z-index: 1;
}

[dir="rtl"] .data-table th {
    text-align: right;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #E5E7EB;
}

[dir="rtl"] .data-table td {
    text-align: right;
}

.data-table tr:hover {
    background: #F9FAFB;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.status-active {
    background: #D1FAE5;
    color: #065F46;
}

.status-inactive {
    background: #FEE2E2;
    color: #991B1B;
}

.pagination {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    padding: 16px 0;
}

.pagination button {
    padding: 6px 12px;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    background: var(--card-bg);
    cursor: pointer;
    font-family: 'Dubai', 'Segoe UI', Tahoma, sans-serif;
    font-size: 13px;
}

.pagination button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

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

.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.search-input {
    flex-grow: 1;
    min-width: 200px;
}

.filter-select {
    min-width: 140px;
}

.filter-btn {
    padding: 10px 16px;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    background: var(--card-bg);
    cursor: pointer;
    font-family: 'Dubai', 'Segoe UI', Tahoma, sans-serif;
    font-size: 13px;
}

.filter-btn:hover {
    background: var(--bg);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

[dir="rtl"] .page-header {
    flex-direction: row-reverse;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 600;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 14px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
}

.form-error {
    color: #DC2626;
    font-size: 13px;
    margin-top: 4px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.error-box {
    background: #FEE2E2;
    color: #991B1B;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    display: none;
}

.btn-danger {
    background-color: #DC2626;
    color: #FFFFFF;
}

.btn-danger:hover {
    background-color: #B91C1C;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-outline {
    background: transparent;
    border: 1px solid #D1D5DB;
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg);
}

.hidden {
    display: none !important;
}

.no-results {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.autocomplete-wrapper {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: #fff;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    margin-top: 4px;
}

[dir="rtl"] .autocomplete-dropdown {
    left: auto;
    right: 0;
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid #F3F4F6;
    transition: background 0.15s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background: #F3F4F6;
}

.autocomplete-item .worker-name {
    font-weight: 500;
    color: var(--text-primary);
}

.autocomplete-item .worker-detail {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

[dir="rtl"] .autocomplete-item {
    text-align: right;
}

.attendance-form {
    max-width: 700px;
    margin: 0 auto;
}

.attendance-form .form-group input[disabled] {
    background: #f0f0f0;
    cursor: not-allowed;
    color: var(--text-secondary);
}

.success-message {
    background: #D1FAE5;
    color: #065F46;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.success-message.fade-out {
    opacity: 0;
}

.error-message {
    background: #FEE2E2;
    color: #991B1B;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}

[dir="rtl"] .attendance-form {
    text-align: right;
}

[dir="rtl"] .attendance-form .form-row {
    direction: rtl;
}

.iqama-search-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.iqama-search-row input {
    flex: 1;
}

.iqama-search-row button {
    padding: 10px 16px;
    margin-bottom: 0;
}

.attendance-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

[dir="rtl"] .attendance-actions {
    flex-direction: row-reverse;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    flex: 1;
}

@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

.chart-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    min-height: 300px;
}

.chart-card canvas {
    max-height: 350px;
}

.chart-card h3 {
    font-weight: 500;
    margin-bottom: 12px;
    font-size: 15px;
    color: var(--text-primary);
}

.no-data-message {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
    font-size: 14px;
}

.filter-sidebar {
    width: 250px;
    min-width: 250px;
    padding: 0;
}

.filter-sidebar .form-group {
    margin-bottom: 12px;
}

.filter-sidebar .form-group label {
    font-size: 13px;
}

.filter-sidebar .form-group input,
.filter-sidebar .form-group select {
    width: 100%;
    font-size: 13px;
    padding: 8px 10px;
}

.reports-layout {
    display: flex;
    gap: 1.5rem;
}

[dir="rtl"] .reports-layout {
    direction: rtl;
}

[dir="rtl"] .filter-sidebar {
    order: -1;
}

.tabs {
    display: flex;
    border-bottom: 2px solid #E5E7EB;
    margin-bottom: 24px;
}

.tab {
    padding: 12px 24px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-weight: 400;
    color: var(--text-secondary);
    transition: all 0.2s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: 'Dubai', 'Segoe UI', Tahoma, sans-serif;
    font-size: 14px;
}

.tab.active {
    border-bottom-color: var(--primary);
    font-weight: 500;
    color: var(--primary);
}

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

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.payroll-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.payroll-table th {
    background: var(--bg);
    padding: 10px 12px;
    text-align: left;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid #E5E7EB;
    position: sticky;
    top: 0;
}

[dir="rtl"] .payroll-table th {
    text-align: right;
}

.payroll-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #E5E7EB;
}

[dir="rtl"] .payroll-table td {
    text-align: right;
}

.payroll-table .subtotal-row {
    background: #F3F4F6;
    font-weight: 500;
}

.payroll-table .subtotal-row td {
    border-bottom: 2px solid #D1D5DB;
}

.payroll-table .grand-total-row {
    background: #E8EDF5;
    font-weight: 700;
}

.payroll-table .grand-total-row td {
    border-top: 2px solid var(--primary);
    border-bottom: none;
}

.rate-not-set {
    color: #DC2626;
    font-style: italic;
    font-size: 12px;
}

[dir="rtl"] .tabs {
    direction: rtl;
}

[dir="rtl"] .tab {
    text-align: right;
}

.export-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

[dir="rtl"] .export-buttons {
    flex-direction: row-reverse;
}

.status-attend { background: #D1FAE5; color: #065F46; padding: 4px 12px; border-radius: 12px; font-weight: 500; }
.status-absent { background: #FEE2E2; color: #991B1B; padding: 4px 12px; border-radius: 12px; font-weight: 500; }
.status-dayoff { background: #DBEAFE; color: #1E40AF; padding: 4px 12px; border-radius: 12px; font-weight: 500; }
.status-holiday { background: #FDE68A; color: #92400E; padding: 4px 12px; border-radius: 12px; font-weight: 500; }

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.loading-overlay.hidden { display: none; }
.loading-popup {
    background: white;
    padding: 32px 48px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.loading-popup p {
    margin-top: 16px;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}
.loading-spinner {
    width: 48px; height: 48px;
    border: 4px solid #E5E7EB;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result popup */
.result-popup {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.result-popup.hidden { display: none; }
.result-popup-content {
    background: white;
    padding: 32px 48px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    min-width: 300px;
}
.result-popup-content p {
    margin: 16px 0;
    font-size: 16px;
    font-weight: 500;
}
.result-popup-content .result-icon-success {
    font-size: 48px;
    color: #059669;
}
.result-popup-content .result-icon-error {
    font-size: 48px;
    color: #DC2626;
}

.absence-table { width: 100%; border-collapse: collapse; }
.absence-table th { position: sticky; top: 0; background: var(--primary); color: white; padding: 10px 12px; }
.absence-table td { padding: 8px 12px; border-bottom: 1px solid #E5E7EB; }
