body.theme-light {
    --bg-main: #eaf0fb;
    --surface: #ffffff;
    --surface-muted: #f8faff;
    --text-strong: #0f172a;
    --text-body: #1e293b;
    --text-muted: #64748b;
    --border: #cbd5e1;
    --border-strong: #94a3b8;
    --brand: #2563eb;
    --brand-strong: #1d4ed8;
    --brand-soft: #e7efff;
    --shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.05);
}

body.theme-dark {
    --bg-main: #1c212b;
    --surface: #2a313d;
    --surface-muted: #323a48;
    --text-strong: #f8fafc;
    --text-body: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #3f4a5d;
    --border-strong: #5b6b84;
    --brand: #14b8a6;
    --brand-strong: #0f9a8c;
    --brand-soft: #163f3a;
    --shadow-soft: 0 8px 24px rgba(2, 8, 20, 0.34);
}

/* ── Page Background ── */
body.clinic-detail {
    background: radial-gradient(1200px 700px at 10% -10%, #dbe7ff 0%, var(--bg-main) 50%, #e6edf8 100%);
    color: var(--text-body);
}
body.theme-dark.clinic-detail {
    background: radial-gradient(1200px 700px at 10% -10%, #2d3644 0%, var(--bg-main) 50%, #181d26 100%);
}

/* ── Status Badges ── */
.status-badge { font-size: 0.65rem; font-weight: 700; padding: 3px 10px; border-radius: 9999px; text-transform: uppercase; letter-spacing: 0.05em; cursor: pointer; }
body.theme-light .status-pending { background: #fef3c7; color: #92400e; }
body.theme-light .status-in_progress { background: #dbeafe; color: #1e40af; }
body.theme-light .status-active { background: #d1fae5; color: #065f46; }
body.theme-light .status-paused { background: #f3f4f6; color: #6b7280; }
body.theme-dark .status-pending { background: #5b3d1a; color: #fcd34d; }
body.theme-dark .status-in_progress { background: #1e3a5f; color: #93c5fd; }
body.theme-dark .status-active { background: #10443c; color: #6ee7b7; }
body.theme-dark .status-paused { background: #374151; color: #d1d5db; }

/* ── Tabs (panel visibility) ── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Section Container ── */
.section-container { background: var(--surface); border-radius: 0.8rem; border: 1px solid var(--border); padding: 1.5rem; box-shadow: var(--shadow-soft); }

/* ── Field Display ── */
.field-card { background: var(--surface-muted); border-radius: 0.6rem; padding: 0.85rem 1rem; border: 1px solid var(--border); position: relative; transition: all 0.15s; }
.field-card:hover { border-color: var(--border-strong); box-shadow: 0 2px 8px rgba(15,23,42,0.05); }
.field-card .field-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 0.3rem; }
.field-card .field-value { font-size: 0.875rem; color: var(--text-body); font-weight: 500; word-break: break-word; line-height: 1.45; }
.field-card .field-value.empty { color: #97a4b8; font-style: italic; font-weight: 400; }

/* ── Editable fields ── */
.field-card .edit-btn { position: absolute; top: 0.5rem; right: 0.5rem; opacity: 0; transition: opacity 0.15s; cursor: pointer; color: var(--text-muted); font-size: 0.85rem; }
.field-card:hover .edit-btn { opacity: 1; }
.field-card .edit-btn:hover { color: var(--brand); }
.field-card.editing { background: var(--surface); border-color: #2dd4bf; box-shadow: 0 0 0 3px rgba(20,184,166,0.16); }
body.theme-light .field-card.editing { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.field-card.editing .edit-input { width: 100%; padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 0.375rem; font-size: 0.85rem; outline: none; margin-top: 0.25rem; background: var(--surface-muted); color: var(--text-body); }
.field-card.editing .edit-input:focus { border-color: var(--brand); background: var(--surface); }
.edit-actions { display: flex; gap: 0.375rem; margin-top: 0.375rem; }
.edit-actions button { font-size: 0.7rem; font-weight: 600; padding: 0.25rem 0.625rem; border-radius: 0.375rem; cursor: pointer; transition: all 0.15s; }
.btn-save { background: var(--brand); color: white; border: none; }
.btn-save:hover { background: var(--brand-strong); }
.btn-cancel { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); }
.btn-cancel:hover { background: var(--surface-muted); }

/* ── Section Header ── */
.section-edit-all { font-size: 0.7rem; font-weight: 600; color: var(--brand); cursor: pointer; padding: 0.25rem 0.75rem; border: 1px solid var(--border); background: var(--surface-muted); border-radius: 0.375rem; transition: all 0.15s; }
.section-edit-all:hover { background: #eaf2ff; }
body.theme-dark .section-edit-all { color: #5eead4; border-color: #2f766d; background: #1d3b38; }
body.theme-dark .section-edit-all:hover { background: #234744; }

/* ── Internal Badge ── */
.internal-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.65rem; font-weight: 700; padding: 2px 8px; border-radius: 9999px; text-transform: uppercase; letter-spacing: 0.05em; }
body.theme-light .internal-badge { background: #fef3c7; color: #92400e; }
body.theme-dark .internal-badge { background: #3f2d18; color: #fbbf24; }

/* ── Upload Preview ── */
.file-link { color: var(--brand); font-size: 0.8rem; text-decoration: underline; display: inline-flex; align-items: center; gap: 4px; }
.file-link:hover { color: var(--brand-strong); }
.copy-link-btn { margin-left: 0.5rem; border: 1px solid var(--border); background: var(--surface-muted); color: var(--brand-strong); font-size: 0.7rem; font-weight: 600; padding: 0.2rem 0.5rem; border-radius: 0.35rem; cursor: pointer; }
.copy-link-btn:hover { background: #e1ecff; }
body.theme-dark .copy-link-btn { border-color: #2f766d; background: #1a4f49; color: #99f6e4; }
body.theme-dark .copy-link-btn:hover { background: #23615b; }

/* ── Loading skeleton ── */
.skeleton { background: linear-gradient(90deg, #dde6f4 25%, #cad5e8 50%, #dde6f4 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 0.5rem; }
body.theme-dark .skeleton { background: linear-gradient(90deg, #303a49 25%, #3a4558 50%, #303a49 75%); background-size: 200% 100%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Overview Cards ── */
.overview-card { background: var(--surface); border-radius: 0.8rem; border: 1px solid var(--border); padding: 1rem 1.1rem; overflow: hidden; min-width: 0; box-shadow: var(--shadow-soft); }
.overview-card .oc-icon { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.overview-card .oc-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.overview-card .oc-value { font-size: 1rem; font-weight: 700; color: var(--text-strong); margin-top: 0.25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.overview-card .oc-value.wrap { white-space: normal; font-size: 0.9rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.overview-card .oc-sub { font-size: 0.68rem; color: var(--text-muted); margin-top: 0.2rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Tab Pills (wrap layout) ── */
.tab-pills { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.5rem; }
.tab-pill { display: inline-flex; align-items: center; gap: 5px; padding: 0.45rem 0.9rem; font-size: 0.78rem; font-weight: 600; color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: 9999px; cursor: pointer; transition: all 0.15s; white-space: nowrap; box-shadow: 0 1px 2px rgba(15,23,42,0.03); }
.tab-pill:hover { color: var(--text-body); border-color: var(--border-strong); transform: translateY(-1px); }
body.theme-light .tab-pill:hover { background: #f8fbff; }
body.theme-dark .tab-pill:hover { background: #364152; }
.tab-pill.active { color: var(--brand-strong); background: var(--brand-soft); border-color: #2f766d; box-shadow: 0 0 0 1px rgba(20,184,166,0.16); }
body.theme-light .tab-pill.active { color: #1d4ed8; border-color: #9db9ff; box-shadow: 0 0 0 1px rgba(37,99,235,0.12); }
.tab-progress { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; padding: 2px 6px; border-radius: 9999px; font-size: 0.62rem; font-weight: 700; background: #213f3c; color: #7df3e6; }
body.theme-light .tab-progress { background: #e8edff; color: #374fc7; }

/* ── Tab Divider ── */
.tab-divider {
    display: inline-flex;
    width: 1px;
    height: 24px;
    background: var(--border-strong);
    margin: 0 0.25rem;
    align-self: center;
    opacity: 0.6;
}

/* ── Action Center ── */
.action-center { position: sticky; top: 76px; z-index: 20; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid #94a3b8; border-radius: 0.8rem; padding: 0.9rem 1rem; margin-bottom: 1rem; box-shadow: var(--shadow-soft); }
.action-center.ac-state-good { border-left-color: #16a34a; }
.action-center.ac-state-warn { border-left-color: #f59e0b; }
.action-center.ac-state-risk { border-left-color: #ef4444; }
.ac-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.ac-title { font-size: 0.8rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-body); }
.ac-pill { font-size: 0.68rem; font-weight: 700; border-radius: 9999px; padding: 0.2rem 0.55rem; }
body.theme-light .ac-pill.good { background: #dcfce7; color: #166534; }
body.theme-light .ac-pill.warn { background: #fef3c7; color: #92400e; }
body.theme-dark .ac-pill.good { background: #10443c; color: #6ee7b7; }
body.theme-dark .ac-pill.warn { background: #4a3b1b; color: #fcd34d; }
.ac-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text-body); font-size: 0.72rem; font-weight: 700; border-radius: 0.42rem; padding: 0.35rem 0.62rem; cursor: pointer; }
body.theme-light .ac-btn:hover { background: #f8fbff; border-color: var(--border-strong); }
body.theme-dark .ac-btn:hover { background: #364152; border-color: var(--border-strong); }
/* ── Action Center Collapse ── */
.ac-details { overflow: hidden; max-height: 0; opacity: 0; transition: max-height 0.3s ease, opacity 0.2s ease; }
.action-center.ac-expanded .ac-details { max-height: 500px; opacity: 1; }
.ac-expand-btn { border: none; background: transparent; color: var(--text-muted); font-size: 0.8rem; cursor: pointer; padding: 0.15rem 0.35rem; border-radius: 0.25rem; transition: all 0.15s; display: inline-flex; align-items: center; }
.ac-expand-btn:hover { color: var(--brand); }
.ac-expand-btn i { transition: transform 0.2s; }
.action-center.ac-expanded .ac-expand-btn i { transform: rotate(180deg); }

.ac-tags { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.55rem; }
body.theme-light .ac-tag { font-size: 0.68rem; border-radius: 9999px; padding: 0.2rem 0.6rem; background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
body.theme-dark .ac-tag { font-size: 0.68rem; border-radius: 9999px; padding: 0.2rem 0.6rem; background: #4a3b1b; color: #fcd34d; border: 1px solid #7a5a22; }
.ac-warn-list { margin-top: 0.5rem; display: grid; gap: 0.2rem; }
body.theme-light .ac-warn-item { font-size: 0.72rem; color: #9a3412; display: flex; gap: 0.35rem; align-items: flex-start; }
body.theme-dark .ac-warn-item { font-size: 0.72rem; color: #fdba74; display: flex; gap: 0.35rem; align-items: flex-start; }
.ac-timeline { margin-top: 0.55rem; display: grid; gap: 0.25rem; }
.ac-event { font-size: 0.72rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.38rem; }
.ac-event b { color: var(--text-body); }

/* ── Long Text ── */
.longtext-wrap { display: block; }
.longtext-content { white-space: pre-wrap; }
.longtext-wrap.collapsed .longtext-content { display: -webkit-box; -webkit-line-clamp: 4; line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.longtext-toggle { margin-top: 0.35rem; border: none; background: transparent; color: var(--brand); font-size: 0.72rem; font-weight: 700; cursor: pointer; padding: 0; }

/* ── Density Modes ── */
body.compact-density .section-container { padding: 1rem; }
body.compact-density .field-card { padding: 0.65rem 0.75rem; }
body.compact-density .field-card .field-label { margin-bottom: 0.2rem; }
body.compact-density .field-card .field-value { font-size: 0.81rem; line-height: 1.35; }
body.compact-density .overview-card { padding: 0.8rem 0.9rem; }
body.compact-density .tab-pill { padding: 0.35rem 0.72rem; font-size: 0.72rem; }

/* ── Top Bar polish ── */
header.sticky { backdrop-filter: blur(8px); }
body.theme-light header.sticky {
    background: rgba(255, 255, 255, 0.85) !important;
    border-bottom-color: #c9d5ea !important;
}
body.theme-dark header.sticky {
    background: rgba(28, 33, 43, 0.82) !important;
    border-bottom-color: #3f4a5d !important;
}
#status-select {
    border-color: var(--border);
    color: var(--text-body);
    background: var(--surface);
}
#status-select:focus {
    border-color: #2dd4bf;
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.18);
}
body.theme-light #status-select:focus {
    border-color: #9db9ff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
#density-toggle,
#theme-toggle {
    border-color: var(--border) !important;
    color: var(--text-body);
    background: var(--surface);
}
body.theme-light #density-toggle:hover,
body.theme-light #theme-toggle:hover { border-color: var(--border-strong) !important; background: #f8fbff; }
body.theme-dark #density-toggle:hover,
body.theme-dark #theme-toggle:hover { border-color: var(--border-strong) !important; background: #364152; }

/* ── Login Page ── */
body.login-page {
    background: radial-gradient(ellipse at 30% 0%, #dbe7ff 0%, var(--bg-main) 55%);
    color: var(--text-body);
}
body.theme-dark.login-page {
    background: radial-gradient(ellipse at 30% 0%, #2d3644 0%, var(--bg-main) 55%);
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft), 0 20px 60px rgba(15, 23, 42, 0.08);
}
.login-card input {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    color: var(--text-body);
}
.login-card input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
    background: var(--surface);
}
body.theme-dark .login-card input:focus {
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.16);
}
.login-card label { color: var(--text-muted); }

/* ── Clinics List Page ── */
body.clinics-page {
    background: radial-gradient(1200px 700px at 10% -10%, #dbe7ff 0%, var(--bg-main) 50%, #e6edf8 100%);
    color: var(--text-body);
}
body.theme-dark.clinics-page {
    background: radial-gradient(1200px 700px at 10% -10%, #2d3644 0%, var(--bg-main) 50%, #181d26 100%);
}

/* ── Summary Stat Cards ── */
.summary-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-soft);
}
.summary-card .sc-icon {
    width: 36px; height: 36px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; flex-shrink: 0;
}
.summary-card .sc-label {
    font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--text-muted);
}
.summary-card .sc-value {
    font-size: 1.75rem; font-weight: 800; color: var(--text-strong); margin-top: 0.15rem;
}

/* ── Clinic Cards (list page) ── */
.clinic-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    padding: 1.25rem;
    transition: all 0.2s;
    box-shadow: var(--shadow-soft);
}
.clinic-card:hover {
    border-color: var(--brand);
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.1);
    transform: translateY(-2px);
}
body.theme-dark .clinic-card:hover {
    box-shadow: 0 8px 24px rgba(20, 184, 166, 0.12);
}
.clinic-card .stat-mini { font-size: 0.7rem; color: var(--text-muted); }
.clinic-card .stat-mini strong { color: var(--text-body); font-weight: 600; }
.clinic-card .card-footer {
    border-top: 1px solid var(--border);
}

/* ── Completion Ring (mini) ── */
.completion-ring {
    width: 32px; height: 32px; border-radius: 50%; position: relative;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.55rem; font-weight: 800; flex-shrink: 0;
}
.completion-ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.completion-ring circle { fill: none; stroke-width: 3; }
.completion-ring .ring-bg { stroke: var(--border); }
body.theme-light .completion-ring .ring-fill { stroke: #2563eb; }
body.theme-dark .completion-ring .ring-fill { stroke: #14b8a6; }

/* ── Search & Filter (themed) ── */
.search-box {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-body);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
body.theme-dark .search-box:focus {
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.16);
}
.filter-select {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-body);
}

/* ── Shared Header Brand Logo ── */
.logo-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 9999px;
    padding: 4px 14px;
}
body.theme-dark .logo-pill {
    background: #ffffff;
}
.logo-pill img { height: 20px; width: auto; display: block; }
.header-logo { height: 28px; width: auto; }

/* ── Utility class adaptation for dark mode ── */
body.theme-dark .text-gray-900 { color: var(--text-strong) !important; }
body.theme-dark .text-gray-800 { color: var(--text-body) !important; }
body.theme-dark .text-gray-700 { color: #cbd5e1 !important; }
body.theme-dark .text-gray-600 { color: #b6c2d3 !important; }
body.theme-dark .text-gray-500 { color: var(--text-muted) !important; }
body.theme-dark .text-gray-400 { color: #8ea0b8 !important; }
body.theme-dark .text-gray-300 { color: #64748b !important; }
body.theme-dark .border-gray-200 { border-color: var(--border) !important; }
body.theme-dark .border-gray-100 { border-color: var(--border) !important; }
body.theme-dark .bg-white { background-color: var(--surface) !important; }
body.theme-dark .bg-gray-50 { background-color: var(--bg-main) !important; }
body.theme-dark .bg-gray-100 { background-color: var(--surface-muted) !important; }
