:root {
    --primary: #0D9488;
    --primary-dark: #0F766E;
    --primary-light: #14B8A6;
    --secondary: #1E293B;
    --secondary-light: #334155;
    --accent: #F59E0B;
    --success: #10B981;
    --danger: #EF4444;
    --info: #3B82F6;
    --warning: #F59E0B;
    --surface: #F8FAFC;
    --card: #FFFFFF;
    --border: #E2E8F0;
    --text-primary: #0F172A;
    --text-muted: #64748B;
    --shadow: 0 1px 3px 0 rgba(0,0,0,.1), 0 1px 2px -1px rgba(0,0,0,.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
    --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    background: var(--surface);
    color: var(--text-primary);
    font-family: 'Inter', 'Segoe UI', sans-serif;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}
.btn-outline-primary:hover {
    background: var(--primary);
    border-color: var(--primary);
}
a { color: var(--primary); }
a:hover { color: var(--primary-dark); }

/* ---- App Layout ---- */
.app-wrapper {
    display: grid;
    grid-template-columns: 250px 1fr;
    min-height: 100vh;
}

[dir="rtl"] .app-wrapper {
    grid-template-columns: 1fr 250px;
}

.sidebar {
    background: linear-gradient(180deg, var(--secondary) 0%, var(--secondary-light) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

[dir="rtl"] .sidebar { order: 2; }

.sidebar-brand {
    padding: 1.25rem 1rem;
    font-size: 1.15rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.sidebar-brand i {
    color: var(--primary-light);
    font-size: 1.6rem;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem;
    overflow-y: auto;
}
.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.65rem 0.9rem;
    margin-bottom: 0.25rem;
    color: #cbd5e1;
    border-radius: 8px;
    font-weight: 500;
    text-decoration: none;
    transition: all .15s ease;
}
.sidebar-nav .nav-link i { width: 22px; font-size: 1.1rem; }
.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}
.sidebar-nav .nav-link.active {
    background: var(--primary);
    color: #fff;
}
.nav-section {
    color: #64748b;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    margin: 1rem 0.5rem 0.4rem;
    font-weight: 600;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.user-info {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: #fff;
}
.user-info i { font-size: 1.8rem; color: var(--primary-light); }

.main-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0.9rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-title {
    font-size: 1.15rem;
    font-weight: 600;
}
.topbar-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.page-content {
    padding: 1.5rem;
    flex: 1;
}

.page-footer {
    padding: 0.75rem 1.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-top: 1px solid var(--border);
    background: var(--card);
}

/* Cards */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
}

/* Stats cards */
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.2rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
}
.stat-card .stat-icon {
    width: 56px; height: 56px;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    display: grid; place-items: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}
.stat-card.stat-success .stat-icon { background: var(--success); }
.stat-card.stat-warning .stat-icon { background: var(--warning); }
.stat-card.stat-danger .stat-icon { background: var(--danger); }
.stat-card.stat-info .stat-icon { background: var(--info); }
.stat-card .stat-value {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1;
}
.stat-card .stat-label {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Patient card */
.patient-card {
    display: flex;
    gap: 1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    align-items: center;
}
.patient-card .photo {
    width: 96px; height: 120px;
    background: #f1f5f9;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--border);
}
.patient-card .info { flex: 1; }
.patient-card .info .name { font-size: 1.15rem; font-weight: 600; }
.patient-card .info .meta { color: var(--text-muted); font-size: 0.9rem; }
.patient-card .status-line {
    display: flex; gap: 0.5rem; flex-wrap: wrap;
    margin-top: 0.5rem;
}
.status-badge {
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.status-badge.done { background: #dcfce7; color: #15803d; }
.status-badge.pending { background: #fef3c7; color: #b45309; }
.status-badge.fit { background: #dcfce7; color: #15803d; }
.status-badge.unfit { background: #fee2e2; color: #b91c1c; }

/* Toggle buttons */
.result-toggle {
    display: inline-flex;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.result-toggle .toggle-btn {
    border: 0;
    padding: 0.35rem 0.8rem;
    background: #fff;
    cursor: pointer;
    font-weight: 500;
    transition: all .15s;
}
.result-toggle .toggle-btn.active.negative { background: var(--success); color: #fff; }
.result-toggle .toggle-btn.active.positive { background: var(--danger); color: #fff; }
.result-toggle .toggle-btn.active.notdone { background: var(--text-muted); color: #fff; }

/* Webcam */
.webcam-box {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.webcam-box video, .webcam-box img, .webcam-box canvas {
    width: 100%;
    max-width: 320px;
    border-radius: 8px;
    background: #000;
    aspect-ratio: 4/3;
    object-fit: cover;
}

/* Auth */
.auth-wrapper {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #0D9488 0%, #0F766E 100%);
    padding: 1rem;
    position: relative;
}
.auth-lang {
    position: absolute;
    top: 1rem;
    inset-inline-end: 1rem;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}
.auth-card .auth-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}
.auth-card .auth-brand i {
    font-size: 3rem;
    color: var(--primary);
}
.auth-card .auth-brand h1 {
    font-size: 1.4rem;
    margin: 0.5rem 0 0.25rem;
    font-weight: 700;
}
.auth-card .auth-brand p {
    color: var(--text-muted);
    margin: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .app-wrapper { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        inset-inline-start: -250px;
        width: 250px;
        z-index: 20;
        transition: inset-inline-start .2s;
    }
    .sidebar.open { inset-inline-start: 0; }
    [dir="rtl"] .app-wrapper { grid-template-columns: 1fr; }
}

@media print {
    .sidebar, .topbar, .page-footer, .no-print { display: none !important; }
    .main-content, .page-content { padding: 0 !important; }
    body { background: #fff; }
}

.fitness-banner {
    padding: 1.5rem;
    border-radius: var(--radius);
    text-align: center;
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: 0.05em;
}
.fitness-banner.fit { background: #d1fae5; color: #065f46; }
.fitness-banner.unfit { background: #fee2e2; color: #991b1b; }
.fitness-banner.pending { background: #f1f5f9; color: #475569; }

/* ---- Visit data table (image-style) ---- */
.data-table-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.data-table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.data-table-search {
    position: relative;
    min-width: 240px;
}
.data-table-search input {
    padding-inline-start: 2.25rem;
    border-radius: 999px;
    background: #f8fafc;
    border: 1px solid var(--border);
}
.data-table-search i {
    position: absolute;
    inset-inline-start: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.data-table thead th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 600;
    padding: 0.75rem 1rem;
    background: #fafbfc;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table tbody td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .visit-no {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}
.tests-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px; height: 28px;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: 600;
    font-size: 0.85rem;
}
.pill {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.pill-info { background: #dbeafe; color: #1d4ed8; }
.pill-warn { background: #fef3c7; color: #b45309; }
.pill-success { background: #dcfce7; color: #15803d; }
.pill-danger { background: #fee2e2; color: #b91c1c; }
.pill-muted { background: #f1f5f9; color: #475569; }

.data-table-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.per-page-select {
    display: inline-flex; align-items: center; gap: 0.5rem;
}
.per-page-select select {
    width: auto;
}
.row-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
    display: inline-flex; align-items: center; gap: 0.3rem;
}
.row-link:hover { color: var(--primary-dark); }
.row-link-muted { color: #475569; }
.row-link-muted:hover { color: #0f172a; }
.row-link-disabled {
    color: #94a3b8;
    cursor: not-allowed;
    display: inline-flex; align-items: center; gap: 0.3rem;
    font-weight: 600;
}
.row-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.85rem;
    justify-content: flex-end;
}

/* Module action chips for the Incomplete-visits page */
.module-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    border-radius: 8px;
    text-decoration: none;
    border: 1px solid transparent;
    transition: transform 80ms ease, filter 80ms ease;
}
.module-btn i.bi { font-size: 1rem; }
.module-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.module-btn-finance  { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.module-btn-doctor   { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.module-btn-lab      { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.module-btn-radiology{ background: #fff7ed; color: #c2410c; border-color: #fed7aa; }
.module-btn-done {
    background: #f1f5f9;
    color: #64748b;
    border-color: #e2e8f0;
}
.module-check {
    position: absolute;
    bottom: -3px;
    inset-inline-end: -3px;
    background: #fff;
    border-radius: 50%;
    color: #15803d;
    font-size: 0.85rem !important;
    line-height: 1;
}

