/* ═══════════════════════════════════════════════════════════════════════════
   eClinic EMR — app.css  (efinance-inspired design system)
   All colours come from CSS custom properties injected by PHP themes.
═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Inter', 'Noto Sans Arabic', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; transition: opacity .15s; }
a:hover { opacity: .8; }
ul, ol { list-style: none; }
img { max-width: 100%; display: block; }
svg { flex-shrink: 0; }

/* ── CSS focus ring (accessibility) ─────────────────────────────────────── */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ── Scrollbar (Webkit) ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Form Controls ───────────────────────────────────────────────────────── */
input, select, textarea {
    font-family: inherit;
    font-size: .875rem;
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: .5rem .75rem;
    width: 100%;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb, 59,130,246), .16);
}
textarea  { resize: vertical; min-height: 80px; }
select    { cursor: pointer; }
select option { background: var(--bg2); color: var(--text); }
input[type="checkbox"], input[type="radio"] {
    width: auto;
    accent-color: var(--primary);
    cursor: pointer;
}
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: .7; }
input[disabled], select[disabled], textarea[disabled] { opacity: .5; cursor: not-allowed; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    font-family: inherit;
    font-size: .85rem;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    border: none;
    border-radius: 7px;
    padding: .52rem 1rem;
    transition: background .15s, opacity .15s, transform .1s;
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: .01em;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 15px; height: 15px; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 4px rgba(var(--primary-rgb, 59,130,246), .35);
}
.btn-primary:hover { background: var(--primary-dk); opacity: 1; }

.btn-secondary {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); opacity: 1; }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
}
.btn-ghost:hover { background: var(--bg3); color: var(--text); opacity: 1; }

.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .88; }

.btn-success { background: var(--success); color: #fff; }

.btn-sm  { padding: .32rem .7rem; font-size: .78rem; border-radius: 6px; }
.btn-xs  { padding: .2rem .5rem;  font-size: .72rem; border-radius: 5px; }
.btn-icon {
    padding: .4rem;
    border-radius: 6px;
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.btn-icon:hover { color: var(--text); background: var(--border); opacity: 1; }
.btn-icon svg  { width: 16px; height: 16px; }

/* ── App Grid Layout ─────────────────────────────────────────────────────── */
.app-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    grid-template-rows: 52px 1fr;
    min-height: 100vh;
    background: var(--bg);
}
@media (max-width: 900px) {
    .app-layout { grid-template-columns: 1fr; }
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
    grid-column: 1 / -1;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    gap: .85rem;
    position: sticky;
    top: 0;
    z-index: 100;
    height: 52px;
}
.topbar-brand {
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: .5rem;
    white-space: nowrap;
    margin-right: auto;
    letter-spacing: -.01em;
}
.topbar-brand span { color: var(--text); }
.hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: .3rem;
    border-radius: 6px;
    flex-shrink: 0;
    transition: color .15s, background .15s;
}
.hamburger:hover { color: var(--text); background: var(--bg3); }
@media (max-width: 900px) { .hamburger { display: flex; } }

.user-chip {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .8rem;
    color: var(--text-muted);
    flex-shrink: 0;
}
.user-name-label {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .82rem;
    font-weight: 500;
    color: var(--text);
}
@media (max-width: 540px) { .user-name-label { display: none; } }

.avatar {
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dk, var(--primary)));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .78rem;
    color: #fff;
    flex-shrink: 0;
    letter-spacing: 0;
}

.topbar-logout {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .35rem .75rem;
    border-radius: 6px;
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-muted);
    border: 1px solid var(--border);
    background: transparent;
    transition: all .15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.topbar-logout svg { width: 15px; height: 15px; }
.topbar-logout:hover { color: var(--danger); border-color: var(--danger); opacity: 1; background: rgba(248,81,73,.08); }
@media (max-width: 480px) { .topbar-logout span { display: none; } }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid rgba(255,255,255,.04);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    grid-row: 2;
    padding-bottom: 1.5rem;
}
@media (max-width: 900px) {
    .sidebar {
        display: none;
        position: fixed;
        top: 52px;
        left: 0;
        bottom: 0;
        width: 220px;
        z-index: 99;
        grid-row: unset;
        box-shadow: 4px 0 24px rgba(0,0,0,.4);
    }
    .sidebar.open { display: flex; }
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1rem 1.1rem .6rem;
    margin-bottom: .25rem;
    border-bottom: 1px solid rgba(255,255,255,.05);
}
.sidebar-logo-text {
    font-size: .88rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -.01em;
}
/* hide logo text when topbar is also visible */
@media (min-width: 901px) { .sidebar-logo { display: none; } }

.nav-section {
    padding: .9rem .9rem .25rem;
    font-size: .63rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-muted);
    opacity: .55;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem 1rem;
    margin: 1px .5rem;
    color: var(--text-muted);
    font-size: .83rem;
    font-weight: 500;
    border-radius: 7px;
    border: 1px solid transparent;
    text-decoration: none;
    transition: all .14s;
    cursor: pointer;
}
.nav-item:hover {
    background: rgba(255,255,255,.05);
    color: var(--text);
    opacity: 1;
    border-color: rgba(255,255,255,.04);
}
.nav-item.active {
    background: rgba(var(--primary-rgb, 59,130,246), .14);
    color: var(--primary);
    border-color: rgba(var(--primary-rgb, 59,130,246), .2);
    font-weight: 600;
}
.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: .75;
    display: flex;
    align-items: center;
    justify-content: center;
}
.nav-icon svg { width: 20px; height: 20px; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-label { line-height: 1.2; }

/* Mobile overlay */
.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(2px);
    z-index: 98;
}
.nav-overlay.open { display: block; }

/* ── Main Content ────────────────────────────────────────────────────────── */
.main-content {
    padding: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    grid-row: 2;
    min-width: 0;
}
@media (max-width: 600px) { .main-content { padding: 1rem .75rem; } }

/* ── Page Header ─────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-title    { font-size: 1.2rem; font-weight: 700; color: var(--text); letter-spacing: -.02em; }
.page-subtitle { font-size: .78rem; color: var(--text-muted); margin-top: .12rem; }
.page-actions  { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 1rem;
    transition: border-color .15s;
}
.card:last-child { margin-bottom: 0; }
.card:hover { border-color: rgba(var(--primary-rgb, 59,130,246), .18); }
.card-header {
    padding: .85rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
}
.card-title    { font-weight: 600; font-size: .9rem; letter-spacing: -.01em; }
.card-body     { padding: 1rem; }
.card-body-sm  { padding: .65rem 1rem; }
.card-footer   { padding: .75rem 1rem; border-top: 1px solid var(--border); background: var(--bg2); }

/* ── Stat Cards ──────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
    gap: .85rem;
    margin-bottom: 1.25rem;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    position: relative;
    overflow: hidden;
    transition: border-color .15s, transform .15s;
}
.stat-card:hover { transform: translateY(-1px); border-color: rgba(var(--primary-rgb,59,130,246),.3); }
.stat-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(var(--stat-rgb,59,130,246),.06) 0%, transparent 60%);
    pointer-events: none;
}
.stat-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--stat-color, var(--primary));
    border-radius: 10px 10px 0 0;
}
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--stat-color, var(--primary)); letter-spacing: -.03em; line-height: 1; }
.stat-label { font-size: .75rem; color: var(--text-muted); margin-top: .3rem; font-weight: 500; }
.stat-icon  {
    position: absolute;
    right: .85rem; top: 50%;
    transform: translateY(-50%);
    opacity: .08;
    font-size: 2.4rem;
    pointer-events: none;
}
.stat-icon svg { width: 42px; height: 42px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th {
    text-align: left;
    padding: .6rem .85rem;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--primary); }
th.sort-asc::after  { content: ' ↑'; color: var(--primary); }
th.sort-desc::after { content: ' ↓'; color: var(--primary); }

td {
    padding: .62rem .85rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text);
}
tr:last-child td { border-bottom: none; }
tr.clickable-row  { cursor: pointer; transition: background .12s; }
tr.clickable-row:hover td { background: rgba(var(--primary-rgb,59,130,246), .05); }
.td-name    { font-weight: 600; }
.td-sub     { font-size: .76rem; color: var(--text-muted); margin-top: .1rem; }
.td-ellipsis {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .2rem;
    padding: .2rem .6rem;
    border-radius: 100px;
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .02em;
    white-space: nowrap;
}
.badge-success { background: rgba(63,185,80,.14);  color: var(--success); }
.badge-warning { background: rgba(227,179,65,.14); color: var(--warning); }
.badge-danger  { background: rgba(248,81,73,.14);  color: var(--danger);  }
.badge-info    { background: rgba(var(--primary-rgb,59,130,246),.14); color: var(--primary); }
.badge-muted   { background: var(--bg3); color: var(--text-muted); }
.badge-accent  { background: rgba(96,165,250,.14); color: var(--accent); }

/* dot indicator */
.badge::before { display: none; }
.badge-dot::before {
    content: '';
    display: inline-block;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
    padding: .7rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: .85rem;
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    border-left: 3px solid;
}
.alert-success {
    background: rgba(63,185,80,.08);
    border-color: var(--success);
    color: var(--success);
}
.alert-error {
    background: rgba(248,81,73,.08);
    border-color: var(--danger);
    color: var(--danger);
}
.alert-warning {
    background: rgba(227,179,65,.08);
    border-color: var(--warning);
    color: var(--warning);
}

/* ── Form Layout ─────────────────────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
    gap: .9rem;
}
.form-group  { display: flex; flex-direction: column; gap: .3rem; }
.form-label  { font-size: .76rem; font-weight: 600; color: var(--text-muted); letter-spacing: .02em; text-transform: uppercase; }
.col-span-2  { grid-column: 1 / -1; }
.required    { color: var(--danger); }
.field-hint  { font-size: .72rem; color: var(--text-muted); margin-top: .12rem; }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1.1rem;
    gap: 0;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    padding: .58rem 1rem;
    font-size: .83rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color .15s, border-color .15s;
    font-family: inherit;
    flex-shrink: 0;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-pane        { display: none; }
.tab-pane.active { display: block; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 100%;
    max-width: 640px;
    max-height: 92vh;
    overflow-y: auto;
    animation: modal-in .2s cubic-bezier(.34,1.3,.7,1);
    box-shadow: 0 24px 80px rgba(0,0,0,.55);
}
.modal-lg { max-width: 820px; }
.modal-sm { max-width: 460px; }
@keyframes modal-in {
    from { transform: scale(.93) translateY(8px); opacity: 0; }
    to   { transform: scale(1)   translateY(0);   opacity: 1; }
}
.modal-header {
    padding: .9rem 1.1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 1;
}
.modal-title  { font-weight: 700; font-size: .95rem; }
.modal-body   { padding: 1.1rem; }
.modal-footer {
    padding: .85rem 1.1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: .5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
    background: var(--bg2);
}

/* ── Search Picker Modal (operations/hospitals/diagnoses) ──────────────── */
.picker-search {
    position: relative;
    margin-bottom: .75rem;
}
.picker-search input { padding-left: 2.1rem; background: var(--bg2); }
.picker-search::before {
    content: '';
    position: absolute;
    left: .7rem;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    background: var(--text-muted);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='currentColor' stroke-width='2'%3E%3Ccircle cx='8.5' cy='8.5' r='5'/%3E%3Cpath d='M15 15l-3-3'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='currentColor' stroke-width='2'%3E%3Ccircle cx='8.5' cy='8.5' r='5'/%3E%3Cpath d='M15 15l-3-3'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    pointer-events: none;
}
.picker-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg2);
}
.picker-item {
    display: flex;
    align-items: center;
    padding: .55rem .85rem;
    font-size: .85rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .12s;
    gap: .6rem;
}
.picker-item:last-child { border-bottom: none; }
.picker-item:hover { background: rgba(var(--primary-rgb,59,130,246),.08); }
.picker-item.selected { color: var(--primary); font-weight: 600; }
.picker-item-check {
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-radius: 50%;
    flex-shrink: 0;
    transition: all .15s;
}
.picker-item.selected .picker-item-check {
    background: var(--primary);
    border-color: var(--primary);
}
.picker-empty { text-align: center; padding: 2rem; color: var(--text-muted); font-size: .85rem; }
.picker-add-form {
    padding: .75rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: .5rem;
    background: var(--bg3);
}
.picker-add-form input { background: var(--bg2); }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    gap: .3rem;
    align-items: center;
    justify-content: center;
    padding: .75rem;
    flex-wrap: wrap;
}
.page-link {
    padding: .34rem .7rem;
    border-radius: 6px;
    font-size: .82rem;
    font-weight: 500;
    border: 1px solid var(--border);
    color: var(--text-muted);
    background: var(--bg2);
    text-decoration: none;
    transition: all .14s;
    min-width: 32px;
    text-align: center;
}
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-link:hover:not(.active) { background: var(--bg3); color: var(--text); opacity: 1; }

/* ── Search Bar ──────────────────────────────────────────────────────────── */
.search-wrap { position: relative; }
.search-wrap input { padding-left: 2.1rem; }
.search-icon {
    position: absolute;
    left: .65rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    display: flex;
    align-items: center;
}
.search-icon svg { width: 14px; height: 14px; }

/* ── Patient Hero Header ─────────────────────────────────────────────────── */
.patient-hero {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}
.patient-avatar-lg {
    width: 54px; height: 54px;
    border-radius: 50%;
    background: linear-gradient(135deg,
        rgba(var(--primary-rgb,59,130,246),.2),
        rgba(var(--primary-rgb,59,130,246),.08));
    border: 2px solid rgba(var(--primary-rgb,59,130,246),.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
    color: var(--primary);
    font-weight: 700;
}
.patient-hero-info { flex: 1; min-width: 0; }
.patient-hero-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: .3rem;
    font-family: 'Noto Sans Arabic', 'Inter', sans-serif;
    letter-spacing: -.01em;
}
.patient-hero-meta {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    font-size: .78rem;
    color: var(--text-muted);
}
.patient-hero-meta span { display: flex; align-items: center; gap: .25rem; }

/* ── Grid helpers ────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 1rem; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ── Key-value info rows ─────────────────────────────────────────────────── */
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .5rem;
    padding: .44rem 0;
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
}
.info-row:last-child { border-bottom: none; }
.info-key   { color: var(--text-muted); flex-shrink: 0; min-width: 110px; font-size: .78rem; font-weight: 500; text-transform: uppercase; letter-spacing: .03em; }
.info-value { text-align: right; word-break: break-word; font-weight: 500; }

/* ── Diagnosis Grid ──────────────────────────────────────────────────────── */
.diag-section-header {
    padding: .5rem .75rem;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    transition: background .12s;
}
.diag-section-header:hover { background: var(--bg3); }
.diag-section-header .diag-count {
    font-size: .68rem;
    background: rgba(var(--primary-rgb,59,130,246),.15);
    color: var(--primary);
    padding: .1rem .4rem;
    border-radius: 100px;
    font-weight: 700;
}
.diag-section-body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: .4rem;
    padding: .65rem;
    background: var(--bg);
}
.diag-section-body.collapsed { display: none; }
.diag-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .38rem .65rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: .82rem;
    background: var(--card);
    transition: all .13s;
}
.diag-item:hover { border-color: var(--primary); background: rgba(var(--primary-rgb,59,130,246),.06); }
.diag-item.checked { border-color: var(--primary); background: rgba(var(--primary-rgb,59,130,246),.1); color: var(--primary); font-weight: 500; }
.diag-item input[type="checkbox"] { flex-shrink: 0; }
.diag-code { font-size: .68rem; color: var(--text-muted); background: var(--bg3); padding: .05rem .35rem; border-radius: 3px; font-family: monospace; margin-left: auto; flex-shrink: 0; }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: .65rem;
    flex-wrap: wrap;
    align-items: flex-end;
}
.filter-bar .form-group { flex: 1; min-width: 130px; }

/* ── Template Manager ────────────────────────────────────────────────────── */
.template-item {
    padding: .65rem .85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: .5rem;
    cursor: pointer;
    transition: all .13s;
    background: var(--bg2);
}
.template-item:hover { border-color: var(--primary); background: rgba(var(--primary-rgb,59,130,246),.06); }
.template-item-title { font-weight: 600; font-size: .85rem; margin-bottom: .2rem; }
.template-item-preview { font-size: .78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-vars-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: .75rem; margin-top: .75rem; }
.tpl-var-group { display: flex; flex-direction: column; gap: .3rem; }
.tpl-var-label { font-size: .75rem; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; }

/* ── Data pill (weight etc) ──────────────────────────────────────────────── */
.data-pill {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: var(--bg3);
    border-radius: 100px;
    padding: .14rem .55rem;
    font-size: .76rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Selected display (operation/hospital picker) ─────────────────────────  */
.selected-display {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    background: rgba(var(--primary-rgb,59,130,246),.08);
    border: 1px solid rgba(var(--primary-rgb,59,130,246),.25);
    border-radius: 7px;
    font-size: .85rem;
    font-weight: 500;
    color: var(--primary);
    cursor: pointer;
    transition: all .15s;
    min-height: 38px;
}
.selected-display:hover { border-color: var(--primary); background: rgba(var(--primary-rgb,59,130,246),.14); }
.selected-display .placeholder { color: var(--text-muted); font-weight: 400; }
.selected-display .change-btn  { margin-left: auto; font-size: .72rem; color: var(--text-muted); flex-shrink: 0; }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-sm      { font-size: .8rem; }
.text-xs      { font-size: .72rem; }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.font-bold    { font-weight: 700; }
.font-medium  { font-weight: 500; }
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.flex-wrap    { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1  { gap: .35rem; }
.gap-2  { gap: .75rem; }
.gap-3  { gap: 1rem; }
.mb-0   { margin-bottom: 0 !important; }
.mb-1   { margin-bottom: .5rem; }
.mb-2   { margin-bottom: 1rem; }
.mt-1   { margin-top: .5rem; }
.mt-2   { margin-top: 1rem; }
.w-full { width: 100%; }
.arabic {
    font-family: 'Noto Sans Arabic', 'Inter', sans-serif;
    direction: rtl;
    text-align: right;
}
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--text-muted); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: .75rem; display: block; opacity: .5; }
.empty-state p { font-size: .875rem; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Calendar filter buttons ─────────────────────────────────────────────── */
.cal-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .28rem .65rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .78rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-muted);
    background: var(--bg2);
    transition: all .14s;
    user-select: none;
}
.cal-filter-btn input[type="checkbox"] { width: 13px; height: 13px; margin: 0; }
.cal-filter-btn:hover { border-color: var(--primary); color: var(--text); }

/* ── Diagnosis check icon (category mirror view) ─────────────────────────── */
.diag-check-icon {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border);
    border-radius: 3px;
    font-size: .7rem;
    flex-shrink: 0;
    transition: all .13s;
    background: var(--bg3);
    color: var(--primary);
}
.diag-item.checked .diag-check-icon {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ── Attachment card hover ────────────────────────────────────────────────── */
.att-card { transition: border-color .15s, transform .15s; }
.att-card:hover { border-color: rgba(var(--primary-rgb,59,130,246),.3); transform: translateY(-1px); }

/* ── Lab results table — fixed widths, hover, click ───────────────────────── */
.lab-results-table {
    width: 100%;
    font-size: .82rem;
    border-collapse: collapse;
    table-layout: fixed;
}
.lab-th {
    padding: .4rem .6rem;
    text-align: center;
    color: var(--text-muted);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--border);
    background: var(--bg2);
}
.lab-th-left { text-align: left; }
.lab-td {
    padding: .35rem .6rem;
    border-top: 1px solid var(--border);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.lab-td-name    { text-align: left; font-weight: 500; }
.lab-td-center  { text-align: center; }
.lab-td-comment { text-align: left; color: var(--text-muted); font-size: .76rem; cursor: pointer; }
.lab-td-comment:hover::after { content: ' ✎'; opacity: .45; font-size: .7rem; }
.lab-muted      { color: var(--text-muted); }

.lab-row {
    cursor: pointer;
    transition: background .12s;
}
.lab-row:hover { background: rgba(var(--primary-rgb,59,130,246),.06); }
.lab-row:hover .lab-td { border-top-color: transparent; }

/* ── Medication cards ──────────────────────────────────────────────────────── */
.med-card { transition: border-color .15s, box-shadow .15s; }
.med-card:hover {
    border-color: rgba(var(--primary-rgb,59,130,246),.4);
    box-shadow: 0 2px 12px rgba(var(--primary-rgb,59,130,246),.1);
}

/* ── Diagnosis tick indicator ─────────────────────────────────────────────── */
.diag-tick {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1.5px solid var(--border);
    background: var(--bg3);
    font-size: .72rem;
    color: transparent;
    flex-shrink: 0;
    transition: all .13s;
}
.diag-item.checked .diag-tick {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ── Sub nav items (admin lookup table links) ─────────────────────────── */
.nav-sub {
    padding-left: 1.75rem;
    font-size: .78rem;
}
.nav-sub .nav-icon { opacity: .55; transform: scale(.85); }
