/**
 * HR Payroll – UI theme (typography, spacing, RTL/LTR)
 * English: Poppins (headings) + Inter (body)
 * Arabic: Cairo (headings) + Tajawal (body)
 */

:root {
    --hr-font-heading: 'Poppins', 'Segoe UI', system-ui, sans-serif;
    --hr-font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
    --hr-color-primary: #667eea;
    --hr-color-primary-dark: #764ba2;
    --hr-color-text: #2d3748;
    --hr-color-text-muted: #6c757d;
    --hr-color-border: #e2e8f0;
    --hr-radius: 12px;
    --hr-radius-lg: 16px;
    --hr-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --hr-shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);

    /* Typography scale */
    --hr-fs-page-title: 1.625rem;      /* 26px */
    --hr-fs-section-title: 1.125rem;   /* 18px */
    --hr-fs-card-title: 1rem;          /* 16px */
    --hr-fs-label: 0.9375rem;          /* 15px */
    --hr-fs-body: 0.9375rem;           /* 15px */
    --hr-fs-small: 0.8125rem;          /* 13px */
    --hr-fs-btn: 0.9375rem;
    --hr-lh: 1.5;
    --hr-spacing-section: 1.5rem;
    --hr-spacing-field: 1rem;
}

html[lang="ar"],
html[dir="rtl"] {
    --hr-font-heading: 'Cairo', 'Segoe UI', 'Tahoma', sans-serif;
    --hr-font-body: 'Tajawal', 'Segoe UI', 'Tahoma', sans-serif;
}

/* Base */
body {
    font-family: var(--hr-font-body);
    font-size: var(--hr-fs-body);
    line-height: var(--hr-lh);
    color: var(--hr-color-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

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

/* Headings */
h1, h2, h3, h4, h5, h6,
.page-title,
.card-header,
.offcanvas-title,
.modal-title {
    font-family: var(--hr-font-heading);
    font-weight: 600;
    color: var(--hr-color-text);
    line-height: 1.3;
}

h1, .page-title {
    font-size: var(--hr-fs-page-title);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: var(--hr-spacing-section);
}

h2 {
    font-size: var(--hr-fs-page-title);
    font-weight: 700;
}

h3, h4 {
    font-size: var(--hr-fs-section-title);
}

h5, h6 {
    font-size: var(--hr-fs-card-title);
}

.content-area > h2,
.content-area .page-header h2 {
    margin-bottom: var(--hr-spacing-section);
}

/* Forms */
.form-label {
    font-size: var(--hr-fs-label);
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.375rem;
}

.form-control,
.form-select {
    font-size: var(--hr-fs-body);
    padding: 0.5rem 0.75rem;
    min-height: 2.75rem;
    border-radius: 8px;
    border-color: var(--hr-color-border);
}

.form-control-sm,
.form-select-sm {
    font-size: 0.875rem;
    min-height: 2.25rem;
    padding: 0.375rem 0.625rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--hr-color-primary);
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.2);
}

.form-text,
small.text-muted,
.text-muted.small {
    font-size: var(--hr-fs-small);
}

.form-check-label {
    font-size: var(--hr-fs-label);
}

/* Row spacing in forms */
.row.g-3 > [class*="col-"],
.mb-3 {
    margin-bottom: var(--hr-spacing-field) !important;
}

/* Buttons */
.btn {
    font-family: var(--hr-font-body);
    font-size: var(--hr-fs-btn);
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.btn-sm {
    font-size: 0.875rem;
    min-height: 2.25rem;
    padding: 0.375rem 0.75rem;
}

.btn-lg {
    font-size: 1rem;
    min-height: 3rem;
}

.btn-group {
    gap: 0.25rem;
}

/* Tables */
.table {
    font-size: var(--hr-fs-body);
    margin-bottom: 0;
}

.table thead th {
    font-family: var(--hr-font-heading);
    font-size: var(--hr-fs-label);
    font-weight: 600;
    color: #495057;
    background-color: #f8fafc;
    border-bottom: 2px solid var(--hr-color-border);
    padding: 0.75rem 1rem;
    vertical-align: middle;
    white-space: nowrap;
}

.table tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
}

.table-hover tbody tr:hover {
    background-color: #f8fafc;
}

.table-responsive {
    border-radius: var(--hr-radius);
    -webkit-overflow-scrolling: touch;
}

/* Cards */
.card {
    border: none;
    border-radius: var(--hr-radius-lg);
    box-shadow: var(--hr-shadow-lg);
    margin-bottom: var(--hr-spacing-section);
    overflow: hidden;
}

.card-header:not(.bg-warning):not(.bg-primary):not(.bg-danger):not(.bg-success):not(.text-dark) {
    font-family: var(--hr-font-heading);
    font-size: var(--hr-fs-section-title);
    font-weight: 600;
    padding: 0.875rem 1.25rem;
    letter-spacing: 0.01em;
}

.card-body {
    padding: 1.25rem 1.5rem;
}

.card-footer {
    padding: 0.875rem 1.25rem;
    background: #f8fafc;
    border-top: 1px solid var(--hr-color-border);
}

/* Tabs / nav pills */
.nav-tabs .nav-link,
.nav-pills .nav-link {
    font-size: var(--hr-fs-label);
    font-weight: 600;
    padding: 0.625rem 1rem;
    border-radius: 8px;
}

/* Alerts */
.alert {
    font-size: var(--hr-fs-body);
    border-radius: var(--hr-radius);
    padding: 0.875rem 1rem;
}

/* Badges */
.badge {
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 0.35em 0.65em;
}

/* Dropdown */
.dropdown-menu {
    font-size: var(--hr-fs-body);
    border-radius: var(--hr-radius);
    box-shadow: var(--hr-shadow-lg);
    padding: 0.5rem;
}

.dropdown-item {
    padding: 0.5rem 0.875rem;
    border-radius: 6px;
    font-size: var(--hr-fs-body);
}

/* Pagination */
.pagination {
    font-size: var(--hr-fs-label);
    gap: 0.25rem;
}

.page-link {
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: var(--hr-fs-label);
}

/* Prevent oversized SVG icons if a non-Bootstrap pagination view is used */
.pagination svg,
.page-link svg {
    width: 1em !important;
    height: 1em !important;
    max-width: 1.125rem;
    max-height: 1.125rem;
    vertical-align: -0.125em;
}

/* Personal info fields (employee show) */
.personal-info-field .label {
    font-size: var(--hr-fs-small);
    font-family: var(--hr-font-heading);
}

.personal-info-field .value {
    font-size: var(--hr-fs-body);
    font-family: var(--hr-font-body);
}

/* RTL utilities */
[dir="rtl"] .ms-auto {
    margin-left: 0 !important;
    margin-right: auto !important;
}

[dir="rtl"] .me-auto {
    margin-right: 0 !important;
    margin-left: auto !important;
}

[dir="rtl"] .ms-1 { margin-left: 0 !important; margin-right: 0.25rem !important; }
[dir="rtl"] .ms-2 { margin-left: 0 !important; margin-right: 0.5rem !important; }
[dir="rtl"] .ms-3 { margin-left: 0 !important; margin-right: 1rem !important; }
[dir="rtl"] .me-1 { margin-right: 0 !important; margin-left: 0.25rem !important; }
[dir="rtl"] .me-2 { margin-right: 0 !important; margin-left: 0.5rem !important; }
[dir="rtl"] .me-3 { margin-right: 0 !important; margin-left: 1rem !important; }

[dir="rtl"] .text-start { text-align: right !important; }
[dir="rtl"] .text-end { text-align: left !important; }

[dir="rtl"] .form-check {
    padding-right: 1.5em;
    padding-left: 0;
}

[dir="rtl"] .form-check-input {
    float: right;
    margin-right: -1.5em;
    margin-left: 0;
}

[dir="rtl"] .input-group > :not(:first-child) {
    border-radius: 0.375rem 0 0 0.375rem;
}

[dir="rtl"] .btn-close {
    margin: 0;
}

/* Icon spacing in nav */
[dir="rtl"] .nav-link i.bi,
[dir="rtl"] .sidebar .nav-link i {
    margin-left: 0.5rem;
    margin-right: 0;
}

[dir="ltr"] .nav-link i.bi,
[dir="ltr"] .sidebar .nav-link i {
    margin-right: 0.5rem;
}

/* Auth pages */
.auth-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    padding: 2rem 1.5rem;
    max-width: 450px;
    width: 100%;
}

.auth-card .auth-title {
    font-family: var(--hr-font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--hr-color-primary);
    text-align: center;
    margin-bottom: 0.5rem;
}

.auth-card .auth-subtitle {
    text-align: center;
    color: var(--hr-color-text-muted);
    font-size: var(--hr-fs-label);
    margin-bottom: 1.5rem;
}

/* Responsive */
@media (max-width: 991.98px) {
    :root {
        --hr-fs-page-title: 1.375rem;
    }

    .content-area {
        padding: 1rem !important;
    }
}

@media (max-width: 576px) {
    :root {
        --hr-fs-page-title: 1.25rem;
        --hr-fs-section-title: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .table thead th,
    .table tbody td {
        padding: 0.5rem 0.625rem;
        font-size: 0.875rem;
    }
}

/* Employee list: passport / iqama / health card expiring within 30 days */
.table tbody tr.employee-row-expiry-warning {
    background-color: #fff8e6 !important;
    border-inline-start: 3px solid #f59e0b;
}

.table tbody tr.employee-row-expiry-warning:hover {
    background-color: #ffefcc !important;
}

.table tbody tr.employee-row-expiry-warning > td {
    background-color: transparent !important;
}

.employee-name-expiry-warning {
    color: #b45309;
    font-weight: 600;
    cursor: help;
    border-bottom: 1px dotted #d97706;
}

.employee-expiry-badge {
    cursor: help;
    vertical-align: middle;
}

/* Branch document details — dates stay LTR in RTL layout */
.branch-doc-details div {
    margin-bottom: 0.25rem;
}

.branch-doc-date {
    display: inline-block;
    unicode-bidi: isolate;
}

html[dir="rtl"] .branch-doc-details strong {
    margin-inline-end: 0.25rem;
}

/* Mobile-first helpers */
.hr-page-wrap {
    max-width: 100%;
}

.hr-filter-form .form-label {
    margin-bottom: 0.25rem;
}

@media (max-width: 576px) {
    .auth-card {
        padding: 1.25rem 1rem;
        border-radius: 16px;
    }

    .auth-card .auth-title {
        font-size: 1.25rem;
    }

    .btn-login,
    .btn-register,
    .btn-submit {
        min-height: 48px;
        font-size: 1rem;
    }

    .hr-page-wrap h2 {
        font-size: var(--hr-fs-page-title);
    }

    .hr-page-wrap .btn-group {
        display: flex;
        width: 100%;
    }

    .hr-page-wrap .btn-group .btn {
        flex: 1 1 50%;
    }

    [dir="rtl"] .hr-report-card .hr-report-actions .btn i {
        margin: 0;
    }

    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    .offcanvas.offcanvas-start[dir="rtl"],
    html[dir="rtl"] .offcanvas.offcanvas-start {
        right: 0;
        left: auto;
    }
}

[dir="rtl"] .auth-card code,
[dir="rtl"] .hr-report-card code {
    direction: ltr;
    unicode-bidi: embed;
    display: inline-block;
}

/* —— HR / Admin dashboard (corporate · brand-aligned · RTL) —— */
.dash-hr {
    --dash-radius: var(--hr-radius-lg, 14px);
    --dash-shadow: var(--hr-shadow);
    --dash-accent: var(--hr-color-primary);
    --dash-accent-soft: #eef1fc;
    padding-bottom: 1.5rem;
}

.dash-welcome {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    padding: 1.125rem 1.25rem;
    background: #fff;
    border: 1px solid var(--hr-color-border);
    border-inline-start: 4px solid var(--hr-color-primary);
    border-radius: var(--dash-radius);
    box-shadow: var(--dash-shadow);
}

.dash-welcome__title {
    font-family: var(--hr-font-heading, inherit);
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--hr-color-text);
}

.dash-welcome__title i {
    color: var(--hr-color-primary);
    margin-inline-end: 0.35rem;
}

.dash-welcome__sub {
    color: var(--hr-color-text-muted);
    font-size: var(--hr-fs-label);
}

.dash-welcome__date {
    font-size: var(--hr-fs-small);
    color: #475569;
    background: #f8fafc;
    padding: 0.4rem 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--hr-color-border);
    white-space: nowrap;
}

.dash-section {
    margin-bottom: 1.25rem;
}

.dash-section__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--hr-font-heading);
    font-size: var(--hr-fs-section-title);
    font-weight: 600;
    color: var(--hr-color-text);
    margin: 0 0 0.75rem;
    letter-spacing: -0.01em;
}

.dash-section__bar {
    width: 3px;
    height: 1.125rem;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--hr-color-primary) 0%, var(--hr-color-primary-dark) 100%);
    flex-shrink: 0;
}

.dash-kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.625rem;
}

.dash-kpi-grid--actions,
.dash-kpi-grid--payroll,
.dash-kpi-grid--3 {
    grid-template-columns: 1fr;
}

@media (min-width: 576px) {
    .dash-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }
    .dash-kpi-grid--3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 992px) {
    .dash-kpi-grid--actions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .dash-kpi-grid--payroll {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.dash-kpi {
    --dash-accent: var(--hr-color-primary);
    --dash-card-bg: #eef1fc;
    --dash-card-border: #dce3f7;
    --dash-icon-bg: #fff;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    background: var(--dash-card-bg);
    border: 1px solid var(--dash-card-border);
    border-inline-start: 3px solid var(--dash-accent);
    border-radius: var(--dash-radius);
    box-shadow: var(--dash-shadow);
    text-decoration: none;
    color: var(--hr-color-text);
    min-height: 4.5rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.dash-kpi:hover,
.dash-kpi:focus-visible {
    color: var(--hr-color-text);
    text-decoration: none;
    transform: translateY(-1px);
    filter: brightness(0.98);
    box-shadow: var(--hr-shadow-lg);
}

.dash-kpi__icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    background: var(--dash-icon-bg);
    color: var(--dash-accent);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.dash-kpi__body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.dash-kpi__label {
    font-size: var(--hr-fs-small);
    font-weight: 600;
    color: var(--hr-color-text-muted);
    line-height: 1.35;
}

.dash-kpi__value {
    font-family: var(--hr-font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--hr-color-text);
    line-height: 1.2;
    word-break: break-word;
}

.dash-kpi__sub {
    font-size: 0.6875rem;
    color: #94a3b8;
    line-height: 1.3;
}

.dash-kpi__arrow {
    color: #cbd5e1;
    font-size: 0.8rem;
    flex-shrink: 0;
    transition: color 0.2s ease, transform 0.2s ease;
}

.dash-kpi:hover .dash-kpi__arrow {
    color: var(--dash-accent);
}

[dir="rtl"] .dash-kpi__arrow {
    transform: scaleX(-1);
}

[dir="rtl"] .dash-kpi:hover .dash-kpi__arrow {
    transform: scaleX(-1) translateX(-2px);
}

[dir="ltr"] .dash-kpi:hover .dash-kpi__arrow {
    transform: translateX(2px);
}

/* Card bg = light tint of icon color (brand + semantic) */
.dash-kpi--primary,
.dash-kpi--indigo {
    --dash-accent: #667eea;
    --dash-card-bg: #eef1fc;
    --dash-card-border: #dce3f9;
}

.dash-kpi--pink,
.dash-kpi--violet {
    --dash-accent: #764ba2;
    --dash-card-bg: #f5f0fa;
    --dash-card-border: #e8ddf2;
}

.dash-kpi--cyan,
.dash-kpi--teal {
    --dash-accent: #0e7490;
    --dash-card-bg: #ecfafd;
    --dash-card-border: #cce8ef;
}

.dash-kpi--green {
    --dash-accent: #2f855a;
    --dash-card-bg: #edf7f1;
    --dash-card-border: #d1ebe0;
}

.dash-kpi--amber {
    --dash-accent: #b7791f;
    --dash-card-bg: #fdf8ef;
    --dash-card-border: #f0e4c8;
}

.dash-kpi--orange {
    --dash-accent: #c05621;
    --dash-card-bg: #fef5f0;
    --dash-card-border: #f5ddd0;
}

.dash-kpi--red {
    --dash-accent: #c53030;
    --dash-card-bg: #fef2f2;
    --dash-card-border: #f5d5d5;
}

.dash-kpi--slate {
    --dash-accent: #64748b;
    --dash-card-bg: #f1f5f9;
    --dash-card-border: #e2e8f0;
}

.dash-kpi--pulse {
    animation: dash-kpi-pulse 2.5s ease-in-out infinite;
}

@keyframes dash-kpi-pulse {
    0%, 100% {
        box-shadow: var(--dash-shadow);
    }
    50% {
        box-shadow: 0 0 0 2px rgba(183, 121, 31, 0.2);
    }
}

.dash-panel {
    background: #fff;
    border: 1px solid var(--hr-color-border);
    border-radius: var(--dash-radius);
    box-shadow: var(--dash-shadow);
    overflow: hidden;
}

.dash-panel .card-header {
    font-family: var(--hr-font-heading);
    font-size: var(--hr-fs-card-title);
    font-weight: 600;
    color: var(--hr-color-text);
    background: #fff;
    border-bottom: 1px solid var(--hr-color-border);
}

.dash-panel .card-header i {
    color: var(--hr-color-primary);
    margin-inline-end: 0.35rem;
}

.dash-panel .card-footer {
    background: #fafbfc;
    border-top: 1px solid var(--hr-color-border);
}

.dash-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    text-decoration: none;
    color: inherit;
    min-height: 3.25rem;
}

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

.dash-list-item:active {
    background: #f8fafc;
}

.dash-row-link {
    cursor: pointer;
}

.dash-chip-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}

@media (min-width: 768px) {
    .dash-chip-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.dash-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border: 1px solid var(--hr-color-border);
    border-radius: 10px;
    text-decoration: none;
    color: var(--hr-color-text);
    font-size: 0.875rem;
    box-shadow: var(--dash-shadow);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.dash-chip:hover {
    border-color: #c5ccec;
    color: var(--hr-color-text);
    box-shadow: var(--hr-shadow-lg);
}

.dash-chip--warn {
    border-color: #f0e4c8;
    background: #fffdf8;
}

.dash-chip__label {
    font-weight: 600;
    line-height: 1.35;
    flex: 1;
    min-width: 0;
}

.dash-chip__count {
    font-weight: 700;
    font-size: 0.9375rem;
    color: #fff;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--hr-color-primary) 0%, var(--hr-color-primary-dark) 100%);
    padding: 0.25rem 0.6rem;
    border-radius: 8px;
    min-width: 2rem;
    text-align: center;
}

.dash-chip--warn .dash-chip__count {
    background: #b7791f;
}

.dash-mini-alert {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-size: 0.875rem;
    text-decoration: none;
    font-weight: 500;
}

.dash-mini-alert--danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.dash-kpi-grid--2 {
    grid-template-columns: 1fr;
}

@media (min-width: 576px) {
    .dash-kpi-grid--2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
