/**
 * REC Attendance — UI components & page styles
 */

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: rgba(79, 70, 229, 0.12);
    --primary-ring: rgba(79, 70, 229, 0.22);
    --success: #059669;
    --success-soft: rgba(5, 150, 105, 0.12);
    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, 0.1);
    --warning: #d97706;
    --warning-soft: rgba(217, 119, 6, 0.14);
    --info: #0284c7;
    --info-soft: rgba(2, 132, 199, 0.12);

    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --text: #0f172a;
    --muted: #64748b;
    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.14);

    --radius-sm: 0.625rem;
    --radius-md: 0.875rem;
    --radius-lg: 1.125rem;
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: 0.14s ease;
}

* { box-sizing: border-box; }

html {
    width: 100%;
    min-height: 100%;
    scroll-behavior: smooth;
}

body.page-login {
    font-family: 'Cairo', 'Tajawal', sans-serif;
    margin: 0;
    min-height: 100%;
    width: 100%;
    line-height: 1.6;
    background:
        radial-gradient(circle at 20% 20%, rgba(79, 70, 229, 0.35), transparent 45%),
        radial-gradient(circle at 80% 80%, rgba(14, 165, 233, 0.22), transparent 40%),
        linear-gradient(160deg, #0f172a 0%, #1e3a8a 55%, #172554 100%);
    background-attachment: fixed;
}

/* ── Page header ── */

.page-header {
    margin-bottom: 1.5rem;
    animation: fadeUp 0.35s ease both;
}

.page-header h1 {
    margin: 0 0 0.35rem;
    font-size: clamp(1.4rem, 2.2vw, 1.75rem);
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1.25;
    color: var(--text);
}

.page-header__subtitle,
.rd-content > h1:first-child + .text-muted,
.rd-content > h1:first-child + p.text-muted {
    margin: 0 0 1.5rem;
    color: var(--muted);
    font-size: 0.95rem;
}

.rd-content > h1:first-child {
    margin-top: 0;
    margin-bottom: 0.35rem;
    font-size: clamp(1.4rem, 2.2vw, 1.75rem);
    font-weight: 800;
    letter-spacing: -0.025em;
    animation: fadeUp 0.35s ease both;
}

.rd-content > h1:first-child + .text-muted {
    animation: fadeUp 0.4s ease both;
}

.rd-content > h2:not(.card-title) {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 1.5rem 0 1rem;
}

/* ── Cards ── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-xs);
    overflow: hidden;
    transition: box-shadow var(--transition), border-color var(--transition-fast), transform var(--transition-fast);
    animation: fadeUp 0.45s ease both;
}

.card:hover {
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface-2) 55%, var(--surface));
}

.card-header h2,
.card-header h3,
.card > h2:first-child,
.card > h3:first-child {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.card > h2:first-child,
.card > h3:first-child {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface-2) 55%, var(--surface));
}

.card-body {
    padding: 1.25rem;
}

.card > :not(h2):not(h3):not(.card-header):not(.table-wrap) {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
}

.card > form {
    padding: 1.25rem;
}

.card > form ~ *:not(.table-wrap) {
    padding: 0 1.25rem 1.25rem;
}

.card > p:first-of-type,
.card > .text-muted:first-of-type {
    padding-top: 1.25rem;
}

.card > p,
.card > .text-muted {
    margin-top: 0;
}

.card > p strong,
.card > p {
    padding-bottom: 0;
}

.card > p + form {
    padding-top: 0.5rem;
}

/* ── Link cards (dashboard shortcuts) ── */

.link-card {
    display: block;
    text-decoration: none;
    color: inherit;
    padding: 1.25rem !important;
    position: relative;
    overflow: hidden;
}

.link-card::before {
    content: '';
    position: absolute;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, var(--primary), #6366f1);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.link-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-ring);
    color: inherit;
}

.link-card:hover::before {
    opacity: 1;
}

.link-card h3 {
    margin: 0 0 0.35rem;
    font-size: 1rem;
    font-weight: 700;
}

.link-card p {
    margin: 0;
    padding: 0 !important;
}

/* ── Stats ── */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-box,
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.15rem 1.25rem;
    box-shadow: var(--shadow-xs);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    animation: fadeUp 0.4s ease both;
}

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

.stat-box .label,
.stat-card .label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.35rem;
}

.stat-box .value,
.stat-card .value {
    font-size: 1.85rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.03em;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat-box--success .value { color: var(--success); }
.stat-box--warning .value { color: var(--warning); }
.stat-box--muted .value { color: var(--muted); font-size: 1.1rem; font-weight: 700; }

/* ── Alerts ── */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.92rem;
    line-height: 1.5;
    animation: fadeUp 0.3s ease both;
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

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

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.58rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    color: #fff;
    background: var(--primary);
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.2);
    transition:
        background var(--transition-fast),
        transform var(--transition-fast),
        box-shadow var(--transition-fast),
        border-color var(--transition-fast);
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
    color: #fff;
}

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

.btn-sm {
    padding: 0.38rem 0.75rem;
    font-size: 0.8rem;
}

.btn-success {
    background: var(--success);
    box-shadow: 0 1px 2px rgba(5, 150, 105, 0.2);
}

.btn-success:hover {
    background: #047857;
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.25);
}

.btn-danger {
    background: var(--danger);
    box-shadow: 0 1px 2px rgba(220, 38, 38, 0.2);
}

.btn-danger:hover {
    background: #b91c1c;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.25);
}

.btn-warning {
    background: var(--warning);
    color: #fff;
    box-shadow: 0 1px 2px rgba(217, 119, 6, 0.2);
}

.btn-warning:hover {
    background: #b45309;
    color: #fff;
}

.btn-outline {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
    box-shadow: none;
}

.btn-outline:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
    color: var(--text);
    box-shadow: var(--shadow-xs);
}

.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.actions-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.actions-cell form {
    display: inline;
    margin: 0;
}

/* ── Forms ── */

.form-group {
    margin-bottom: 1.1rem;
}

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

.form-control,
select.form-control,
textarea.form-control {
    width: 100%;
    padding: 0.62rem 0.85rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:hover {
    border-color: rgba(79, 70, 229, 0.25);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}

textarea.form-control {
    resize: vertical;
    min-height: 5rem;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-xs);
    animation: fadeUp 0.35s ease both;
}

.filter-bar .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 140px;
}

.filter-bar--grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    align-items: end;
}

/* ── Tables ── */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap:not(:first-child) {
    border-top: 1px solid var(--border);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.table th,
.table td {
    padding: 0.75rem 1.25rem;
    text-align: right;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: color-mix(in srgb, var(--surface-2) 70%, var(--surface));
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    white-space: nowrap;
}

.table tbody tr {
    transition: background var(--transition-fast);
}

.table tbody tr:hover {
    background: color-mix(in srgb, var(--primary-soft) 35%, transparent);
}

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

.table td small {
    display: block;
    color: var(--muted);
    font-size: 0.8rem;
    margin-top: 0.15rem;
}

.table-empty {
    text-align: center !important;
    color: var(--muted);
    padding: 2rem 1rem !important;
}

/* legacy bare tables inside cards */
.card > .table-wrap .table,
.card > table {
    margin: 0;
}

.card > table th,
.card > table td {
    padding: 0.75rem 1.25rem;
}

.card > table th {
    background: color-mix(in srgb, var(--surface-2) 70%, var(--surface));
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.card > table tbody tr:hover {
    background: color-mix(in srgb, var(--primary-soft) 35%, transparent);
}

/* ── Badges ── */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.badge-pending { background: var(--warning-soft); color: #92400e; }
.badge-completed { background: var(--info-soft); color: #1e40af; }
.badge-evaluated { background: var(--success-soft); color: #065f46; }
.badge-active { background: var(--success-soft); color: #065f46; }
.badge-inactive { background: var(--danger-soft); color: #991b1b; }

/* ── Modal ── */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(2, 6, 23, 0.5);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease both;
}

.modal.is-open {
    display: flex;
}

.modal__dialog {
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    animation: scaleIn 0.25s ease both;
}

.modal__header {
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.modal__header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.modal__body {
    padding: 1.25rem;
}

.modal__footer {
    display: flex;
    gap: 0.5rem;
    padding: 0 1.25rem 1.25rem;
}

/* ── Signature pad ── */

.signature-pad {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    touch-action: none;
    cursor: crosshair;
    width: 100%;
    height: 160px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.signature-pad:hover,
.signature-pad:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}

.attendance-form h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0 0 0.75rem;
}

/* ── Grid ── */

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

/* ── Utilities ── */

.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }

.container {
    max-width: 1100px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

.navbar { display: none; }

/* ── Login ── */

.login-page {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-panel {
    width: 100%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    animation: fadeUp 0.5s ease both;
}

.login-panel__brand {
    text-align: center;
    color: #fff;
}

.login-logo {
    width: 72px;
    height: 72px;
    margin: 0 auto 1rem;
    border-radius: 1.25rem;
    background: linear-gradient(145deg, #6366f1, #4f46e5);
    color: #fff;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 32px rgba(79, 70, 229, 0.45);
}

.login-panel__title {
    margin: 0 0 0.35rem;
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1.4;
}

.login-panel__subtitle {
    margin: 0;
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.95rem;
}

.login-card {
    width: 100%;
    background: #fff;
    border-radius: 1.25rem;
    padding: 2rem 1.75rem;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.35);
}

.login-card__header {
    margin-bottom: 1.5rem;
    text-align: center;
}

.login-card__header h2 {
    margin: 0 0 0.35rem;
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text);
}

.login-card__header p {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.login-form .form-group:last-of-type {
    margin-bottom: 1.35rem;
}

.login-form .form-control {
    padding: 0.72rem 0.9rem;
}

.btn-login {
    width: 100%;
    padding: 0.78rem 1rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--radius-sm);
}

.login-alert {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.92rem;
}

.login-alert__icon {
    flex-shrink: 0;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
}

.login-alert--error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.login-alert--error .login-alert__icon {
    background: #fee2e2;
    color: #b91c1c;
}

.login-alert--success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.login-footer {
    margin: 0;
    text-align: center;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.82rem;
}

/* ── Animations ── */

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* stagger cards */
.rd-content > .card:nth-child(2) { animation-delay: 0.05s; }
.rd-content > .card:nth-child(3) { animation-delay: 0.1s; }
.rd-content > .stats .stat-box:nth-child(2) { animation-delay: 0.05s; }
.rd-content > .stats .stat-box:nth-child(3) { animation-delay: 0.1s; }
.rd-content > .stats .stat-box:nth-child(4) { animation-delay: 0.15s; }

@media (max-width: 768px) {
    .table th,
    .table td {
        padding: 0.65rem 0.85rem;
        font-size: 0.82rem;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Account settings */
.settings-page {
    width: 100%;
    max-width: 56rem;
    margin-inline: auto;
}

.settings-layout {
    display: grid;
    gap: 1.25rem;
    align-items: start;
}

@media (min-width: 900px) {
    .settings-layout {
        grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    }
}

.settings-card h2 {
    margin: 0 0 1rem;
    font-size: 1.05rem;
}

.settings-card__intro {
    margin: -0.35rem 0 1rem;
    font-size: 0.88rem;
}

.settings-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding: 1rem;
    border-radius: var(--rd-radius-md, 0.75rem);
    background: var(--bs-secondary-bg, rgba(0, 0, 0, 0.03));
}

.settings-profile__name {
    font-weight: 700;
    font-size: 1.05rem;
}

.settings-profile__meta {
    font-size: 0.85rem;
    margin-top: 0.15rem;
}

.settings-section + .settings-section {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--bs-border-color);
}

.settings-section__title {
    margin: 0 0 0.85rem;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text);
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.settings-form .btn {
    align-self: flex-start;
    margin-top: 0.15rem;
}

.settings-form input[type="email"] {
    text-align: start;
}

.form-hint {
    margin: 0.35rem 0 0;
    font-size: 0.8rem;
    color: var(--bs-secondary-color);
}

.breadcrumbs {
    margin-bottom: 1rem;
}

.breadcrumbs__list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.breadcrumbs__list li:not(:last-child)::after {
    content: '›';
    margin-inline-start: 0.35rem;
    opacity: 0.6;
}

.breadcrumbs__list a {
    color: var(--rd-accent);
    text-decoration: none;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.25rem 1.25rem;
    flex-wrap: wrap;
}

.pagination__info {
    font-size: 0.85rem;
    color: var(--muted);
}

.pagination__links {
    display: flex;
    gap: 0.5rem;
}

.password-field {
    position: relative;
    display: flex;
    align-items: stretch;
}

.password-field .form-control {
    padding-inline-end: 2.75rem;
}

.password-field__toggle {
    position: absolute;
    inset-inline-end: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0.25rem;
    opacity: 0.7;
}

.password-field__toggle:hover {
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

@media print {
    .no-print, .btn, .modal { display: none !important; }
    .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
    .table tbody tr:hover { background: transparent; }
}
