/* ===================================================================
   eForms — MedicalVisitSurvey design system

   A token-based visual system for a clinical product. Every colour,
   surface, radius and shadow is a CSS custom property prefixed --mvs-*
   (or --status-* for state colours). The [data-theme="dark"] block at
   the end re-points every token, so all components invert for free.

   Status colours are always paired with an icon AND a text label in
   the markup (see _StatusBadge.cshtml) — state is never conveyed by
   colour alone, so the UI stays colour-blind safe.
=================================================================== */

:root {
    /* Brand — calm clinical teal/blue */
    --mvs-primary: #0e7490;          /* cyan-700 */
    --mvs-primary-dark: #155e75;     /* cyan-800 */
    --mvs-primary-soft: #e0f2fe;     /* sky-100 */
    --mvs-accent: #0d9488;           /* teal-600 */
    --mvs-accent-soft: #ccfbf1;      /* teal-100 */

    /* Neutral surfaces */
    --mvs-bg: #f3f6f8;
    --mvs-surface: #ffffff;
    --mvs-surface-2: #f7fafc;
    --mvs-text: #0f1e29;
    --mvs-text-muted: #5b6b76;
    --mvs-border: #e4eaee;
    --mvs-border-strong: #ccd6dc;

    /* Status tokens — each pairs with an icon + label, never colour alone */
    --status-success: #15803d;       --status-success-bg: #dcfce7;
    --status-neutral: #475569;       --status-neutral-bg: #eef2f5;
    --status-info: #1d4ed8;          --status-info-bg: #dbeafe;
    --status-warning: #b45309;       --status-warning-bg: #fef3c7;
    --status-danger: #b91c1c;        --status-danger-bg: #fee2e2;
    --status-accent: #0f766e;        --status-accent-bg: #ccfbf1;

    /* Shape & shadow */
    --mvs-radius-sm: 8px;
    --mvs-radius: 12px;
    --mvs-radius-lg: 20px;
    --mvs-shadow-sm: 0 1px 2px rgba(15, 30, 41, 0.04), 0 1px 3px rgba(15, 30, 41, 0.05);
    --mvs-shadow: 0 1px 2px rgba(15, 30, 41, 0.05), 0 8px 24px rgba(15, 30, 41, 0.07);
    --mvs-shadow-lg: 0 24px 48px rgba(14, 116, 144, 0.10), 0 6px 16px rgba(15, 30, 41, 0.06);

    --mvs-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* ---------- Base ---------- */

html {
    font-size: 15px;
    position: relative;
    min-height: 100%;
}

@media (min-width: 768px) {
    html { font-size: 16px; }
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--mvs-bg);
    color: var(--mvs-text);
    font-family: var(--mvs-font);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

main { flex: 1 0 auto; }

h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--mvs-text);
}

a { color: var(--mvs-primary-dark); text-decoration: none; }
a:hover { color: var(--mvs-primary); text-decoration: underline; }

.text-muted { color: var(--mvs-text-muted) !important; }

code {
    background: var(--mvs-surface-2);
    border: 1px solid var(--mvs-border);
    border-radius: 6px;
    padding: 0.05rem 0.35rem;
    font-size: 0.85em;
    color: var(--mvs-primary-dark);
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus,
.form-control:focus, .form-check-input:focus, .form-select:focus {
    box-shadow: 0 0 0 0.2rem rgba(14, 116, 144, 0.20);
}

/* ---------- Buttons ---------- */

.btn {
    border-radius: 999px;
    font-weight: 600;
    padding: 0.45rem 1.05rem;
    transition: transform 0.06s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 0.3rem 0.8rem; font-size: 0.82rem; }

.btn-primary {
    background: linear-gradient(180deg, var(--mvs-primary) 0%, var(--mvs-primary-dark) 100%);
    border: 0;
    color: #fff;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 6px 16px rgba(14, 116, 144, 0.22);
}
.btn-primary:hover { background: var(--mvs-primary-dark); color: #fff; }

.btn-outline-primary { border-color: var(--mvs-primary); color: var(--mvs-primary-dark); }
.btn-outline-primary:hover { background: var(--mvs-primary); border-color: var(--mvs-primary); color: #fff; }

.btn-outline-secondary { border-color: var(--mvs-border-strong); color: var(--mvs-text); }
.btn-outline-secondary:hover { background: var(--mvs-surface-2); border-color: var(--mvs-primary); color: var(--mvs-primary-dark); }

.btn-success { background: var(--status-success); border-color: var(--status-success); }
.btn-success:hover { background: #166534; border-color: #166534; }
.btn-outline-success { border-color: var(--status-success); color: var(--status-success); }
.btn-outline-success:hover { background: var(--status-success); color: #fff; }

.btn-warning { background: var(--status-warning); border-color: var(--status-warning); color: #fff; }
.btn-warning:hover { background: #92400e; border-color: #92400e; color: #fff; }
.btn-outline-warning { border-color: var(--status-warning); color: var(--status-warning); }
.btn-outline-warning:hover { background: var(--status-warning); color: #fff; }

.btn-danger { background: var(--status-danger); border-color: var(--status-danger); }
.btn-danger:hover { background: #991b1b; border-color: #991b1b; }
.btn-outline-danger { border-color: var(--status-danger); color: var(--status-danger); }
.btn-outline-danger:hover { background: var(--status-danger); color: #fff; }

.btn-link { color: var(--mvs-primary-dark); }

/* ---------- Forms ---------- */

.form-control, .form-select {
    border-radius: var(--mvs-radius-sm);
    border: 1px solid var(--mvs-border-strong);
    background: var(--mvs-surface);
    color: var(--mvs-text);
    padding: 0.5rem 0.8rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--mvs-primary);
    background: var(--mvs-surface);
    color: var(--mvs-text);
}
.form-control::placeholder { color: var(--mvs-text-muted); opacity: 0.8; }
.form-control-sm, .form-select-sm { font-size: 0.85rem; }
.form-label { font-weight: 600; font-size: 0.88rem; color: var(--mvs-text); margin-bottom: 0.3rem; }
.form-text { color: var(--mvs-text-muted); }
.form-check-input:checked { background-color: var(--mvs-primary); border-color: var(--mvs-primary); }

/* ---------- Cards ---------- */

.card {
    border: 1px solid var(--mvs-border);
    border-radius: var(--mvs-radius);
    background: var(--mvs-surface);
    box-shadow: var(--mvs-shadow-sm);
}
.card-header {
    background: var(--mvs-surface);
    border-bottom: 1px solid var(--mvs-border);
    border-radius: var(--mvs-radius) var(--mvs-radius) 0 0 !important;
    font-weight: 600;
}
.card-header.bg-transparent { background: transparent !important; }

/* ---------- Navbar ---------- */

.navbar.bg-mvs {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.88) 100%);
    backdrop-filter: saturate(140%) blur(8px);
    border-bottom: 1px solid var(--mvs-border);
    box-shadow: 0 1px 0 rgba(15, 30, 41, 0.02);
    padding: 0.55rem 0;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.navbar.bg-mvs .navbar-brand,
.navbar.bg-mvs .nav-link {
    color: var(--mvs-text) !important;
    font-weight: 600;
}
.navbar.bg-mvs .navbar-brand { font-weight: 800; letter-spacing: -0.02em; }
.navbar.bg-mvs .nav-link {
    border-radius: 999px;
    padding: 0.4rem 0.8rem;
    margin: 0 0.1rem;
    font-size: 0.92rem;
}
.navbar.bg-mvs .nav-link:hover,
.navbar.bg-mvs .nav-link:focus {
    color: var(--mvs-primary-dark) !important;
    background: var(--mvs-primary-soft);
}
.navbar.bg-mvs .navbar-toggler { border: 0; }
.navbar.bg-mvs .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%230f1e29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
.navbar-brand .brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--mvs-primary) 0%, var(--mvs-accent) 100%);
    color: #fff;
}
.theme-toggle {
    border: 1px solid var(--mvs-border-strong);
    background: var(--mvs-surface);
    color: var(--mvs-text);
    border-radius: 999px;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.theme-toggle:hover { background: var(--mvs-primary-soft); color: var(--mvs-primary-dark); }

/* ---------- Status badges (icon + label + colour) ---------- */

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    padding: 0.2em 0.7em;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 600;
    line-height: 1.4;
    border: 1px solid currentColor;
    white-space: nowrap;
}
.status-badge .status-icon { display: inline-flex; line-height: 1; }
.status-badge .status-label { white-space: nowrap; }

.status-success,
.status-active,
.status-yes      { color: var(--status-success); background: var(--status-success-bg); border-color: rgba(21, 128, 61, 0.30); }
.status-neutral,
.status-inactive,
.status-rep,
.status-no       { color: var(--status-neutral); background: var(--status-neutral-bg); border-color: rgba(71, 85, 105, 0.30); }
.status-info,
.status-create   { color: var(--status-info);    background: var(--status-info-bg);    border-color: rgba(29, 78, 216, 0.30); }
.status-warning,
.status-update   { color: var(--status-warning); background: var(--status-warning-bg); border-color: rgba(180, 83, 9, 0.30); }
.status-danger,
.status-admin    { color: var(--status-danger);  background: var(--status-danger-bg);  border-color: rgba(185, 28, 28, 0.30); }
.status-accent   { color: var(--status-accent);  background: var(--status-accent-bg);  border-color: rgba(15, 118, 110, 0.30); }

/* ---------- Stat cards (dashboard) ---------- */

.mvs-stat-card {
    background: var(--mvs-surface);
    border: 1px solid var(--mvs-border);
    border-radius: var(--mvs-radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--mvs-shadow-sm);
    height: 100%;
    position: relative;
    overflow: hidden;
}
.mvs-stat-card::after {
    content: "";
    position: absolute;
    top: -40px; right: -40px;
    width: 120px; height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(14, 116, 144, 0.10) 0%, transparent 70%);
    pointer-events: none;
}
.mvs-stat-card .icon {
    width: 40px; height: 40px;
    border-radius: 11px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--mvs-primary-soft);
    color: var(--mvs-primary-dark);
    font-size: 1.15rem;
    margin-bottom: 0.6rem;
}
.mvs-stat-card .stat-number {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1;
}
.mvs-stat-card .stat-label {
    font-size: 0.76rem;
    color: var(--mvs-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 0.35rem;
    font-weight: 600;
}
.mvs-stat-card .stat-link {
    margin-top: 0.55rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    font-weight: 600;
}
.mvs-stat-card.tone-green  .icon { background: var(--status-success-bg); color: var(--status-success); }
.mvs-stat-card.tone-blue   .icon { background: var(--status-info-bg);    color: var(--status-info); }
.mvs-stat-card.tone-amber  .icon { background: var(--status-warning-bg); color: var(--status-warning); }
.mvs-stat-card.tone-teal   .icon { background: var(--status-accent-bg);  color: var(--status-accent); }
.mvs-stat-card.tone-rose   .icon { background: var(--status-danger-bg);  color: var(--status-danger); }

/* ---------- Empty states ---------- */

.mvs-empty {
    border: 1px dashed var(--mvs-border-strong);
    border-radius: var(--mvs-radius);
    background: var(--mvs-surface-2);
    padding: 2rem 1.2rem;
    text-align: center;
    color: var(--mvs-text-muted);
}
.mvs-empty .icon {
    width: 56px; height: 56px;
    margin: 0 auto 0.7rem;
    border-radius: 16px;
    background: var(--mvs-primary-soft);
    color: var(--mvs-primary-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}
.mvs-empty h3 { color: var(--mvs-text); font-size: 1.05rem; font-weight: 700; margin: 0 0 0.25rem; }
.mvs-empty p  { margin: 0; font-size: 0.92rem; }

/* ---------- Survey form cards ---------- */

.survey-card {
    border: 1px solid var(--mvs-border);
    border-radius: var(--mvs-radius);
    background: var(--mvs-surface);
    box-shadow: var(--mvs-shadow-sm);
    margin-bottom: 1.25rem;
}
.survey-card > .card-header,
.survey-card-header {
    background: var(--mvs-surface-2);
    border-bottom: 1px solid var(--mvs-border);
    border-radius: var(--mvs-radius) var(--mvs-radius) 0 0;
    padding: 0.75rem 1.15rem;
    font-weight: 700;
    color: var(--mvs-primary-dark);
}

/* ---------- Audit timeline ---------- */

.audit-timeline { display: flex; flex-direction: column; gap: 0.6rem; }
.audit-entry {
    border: 1px solid var(--mvs-border);
    border-left: 4px solid var(--mvs-border-strong);
    border-radius: var(--mvs-radius-sm);
    background: var(--mvs-surface);
    padding: 0.7rem 0.95rem;
}
.audit-entry.action-create { border-left-color: var(--status-info); }
.audit-entry.action-update { border-left-color: var(--status-warning); }
.audit-entry .audit-meta {
    font-size: 0.8rem;
    color: var(--mvs-text-muted);
    font-variant-numeric: tabular-nums;
}

/* ---------- Tables ---------- */

.table {
    --bs-table-bg: var(--mvs-surface);
    --bs-table-color: var(--mvs-text);
    color: var(--mvs-text);
    margin-bottom: 0;
}
.table > :not(caption) > * > * {
    padding: 0.8rem 0.85rem;
    border-bottom-color: var(--mvs-border);
    background: var(--mvs-surface);
    color: var(--mvs-text);
}
.table thead th,
.table thead.table-dark th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    color: var(--mvs-text-muted) !important;
    background: var(--mvs-surface-2) !important;
    border-bottom: 1px solid var(--mvs-border);
}
.table-hover > tbody > tr:hover > * {
    background: var(--mvs-primary-soft);
}

/* ---------- Alerts ---------- */

.alert { border-radius: var(--mvs-radius); border: 1px solid transparent; }
.alert-success { background: var(--status-success-bg); color: #14532d; border-color: rgba(21, 128, 61, 0.20); }
.alert-danger  { background: var(--status-danger-bg);  color: #7f1d1d; border-color: rgba(185, 28, 28, 0.20); }
.alert-info    { background: var(--mvs-primary-soft);  color: var(--mvs-primary-dark); border-color: rgba(14, 116, 144, 0.20); }
.alert-warning { background: var(--status-warning-bg); color: #78350f; border-color: rgba(180, 83, 9, 0.20); }

/* ---------- Badges (Bootstrap fallback) ---------- */

.badge.bg-success   { background: var(--status-success) !important; }
.badge.bg-secondary { background: var(--status-neutral) !important; }
.badge.bg-danger    { background: var(--status-danger) !important; }
.badge.bg-info      { background: var(--status-info) !important; color: #fff !important; }

/* ---------- Pagination ---------- */

.page-link { color: var(--mvs-primary-dark); border-color: var(--mvs-border); background: var(--mvs-surface); }
.page-link:hover { background: var(--mvs-primary-soft); color: var(--mvs-primary-dark); }
.page-item.active .page-link { background: var(--mvs-primary); border-color: var(--mvs-primary); }
.page-item.disabled .page-link { background: var(--mvs-surface-2); color: var(--mvs-text-muted); }

/* ---------- Hero (home page) ---------- */

.mvs-hero {
    text-align: center;
    padding: 3rem 1.25rem 2.5rem;
    border-radius: var(--mvs-radius-lg);
    background: linear-gradient(135deg, var(--mvs-surface) 0%, var(--mvs-primary-soft) 65%, var(--mvs-accent-soft) 100%);
    box-shadow: var(--mvs-shadow-lg);
    border: 1px solid var(--mvs-border);
}
.mvs-hero h1 {
    font-size: clamp(1.8rem, 3vw + 1rem, 3rem);
    font-weight: 800;
}
.mvs-hero .lead { color: var(--mvs-text-muted); max-width: 540px; margin: 0 auto 1.25rem; }

/* ---------- Footer ---------- */

footer.mvs-footer {
    flex-shrink: 0;
    margin-top: 3rem;
    padding: 1.5rem 0;
    border-top: 1px solid var(--mvs-border);
    background: var(--mvs-surface);
    color: var(--mvs-text-muted);
    font-size: 0.86rem;
}
footer.mvs-footer a { color: var(--mvs-text-muted); }
footer.mvs-footer a:hover { color: var(--mvs-primary); }

/* ---------- Autocomplete (legacy site.js widget) ---------- */

.autocomplete-wrapper { position: relative; }
.autocomplete-list {
    position: absolute;
    z-index: 1050;
    width: 100%;
    max-height: 240px;
    overflow-y: auto;
    display: none;
    background: var(--mvs-surface);
    border: 1px solid var(--mvs-border-strong);
    border-radius: var(--mvs-radius-sm);
    box-shadow: var(--mvs-shadow);
}
.autocomplete-list .list-group-item {
    cursor: pointer;
    background: var(--mvs-surface);
    color: var(--mvs-text);
    border-color: var(--mvs-border);
}
.autocomplete-list .list-group-item:hover,
.autocomplete-list .list-group-item.active {
    background: var(--mvs-primary-soft);
    color: var(--mvs-primary-dark);
}

/* ---------- Rich text (Quill output on Details views) ---------- */

.rich-text { margin-bottom: 1rem; }
.rich-text > :last-child { margin-bottom: 0; }
.quill-host { background: var(--mvs-surface); border-radius: 0 0 var(--mvs-radius-sm) var(--mvs-radius-sm); }

.sticky-bottom { position: sticky; bottom: 0; z-index: 100; }

/* ---------- Confirmation toast host ---------- */

#mvsToastHost { z-index: 1090; }

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
    .mvs-stat-card { padding: 0.85rem 0.95rem; }
    .mvs-stat-card .stat-number { font-size: 1.65rem; }
    .mvs-hero { padding: 2.25rem 1rem 2rem; }
}

/* ===================================================================
   Dark theme — same palette, sensibly inverted. Driven by
   [data-theme="dark"] on <html>. Re-pointing the --mvs-* / --status-*
   tokens cascades to every component above; the rules after it patch
   the few third-party / hard-coded-tint surfaces.
=================================================================== */

[data-theme="dark"] {
    color-scheme: dark;

    --mvs-primary: #22b8cf;
    --mvs-primary-dark: #67d3e3;
    --mvs-primary-soft: #133038;
    --mvs-accent: #2dd4bf;
    --mvs-accent-soft: #0f3b36;

    --mvs-bg: #10171c;
    --mvs-surface: #1a242b;
    --mvs-surface-2: #212e36;
    --mvs-text: #e7eef2;
    --mvs-text-muted: #9aaab4;
    --mvs-border: #2c3a43;
    --mvs-border-strong: #3d4d57;

    --status-success: #4ade80;  --status-success-bg: #14321f;
    --status-neutral: #b6c0c9;  --status-neutral-bg: #29343c;
    --status-info: #7cb1fb;     --status-info-bg: #16294a;
    --status-warning: #fbbf24;  --status-warning-bg: #3a2c0f;
    --status-danger: #f87171;   --status-danger-bg: #3a1c1c;
    --status-accent: #2dd4bf;   --status-accent-bg: #0f3b36;

    --mvs-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.40);
    --mvs-shadow: 0 1px 2px rgba(0, 0, 0, 0.40), 0 8px 24px rgba(0, 0, 0, 0.50);
    --mvs-shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.60), 0 6px 16px rgba(0, 0, 0, 0.40);

    /* feed Bootstrap's own components (modal, dropdown, offcanvas) */
    --bs-body-bg: #10171c;
    --bs-body-color: #e7eef2;
}

[data-theme="dark"] .navbar.bg-mvs {
    background: linear-gradient(180deg, rgba(26, 36, 43, 0.96) 0%, rgba(26, 36, 43, 0.90) 100%);
    border-bottom-color: var(--mvs-border);
}
[data-theme="dark"] .navbar.bg-mvs .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%23e7eef2' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
[data-theme="dark"] .dropdown-menu {
    background: var(--mvs-surface);
    border-color: var(--mvs-border);
}
[data-theme="dark"] .dropdown-item { color: var(--mvs-text); }
[data-theme="dark"] .dropdown-item:hover,
[data-theme="dark"] .dropdown-item:focus {
    background: var(--mvs-primary-soft);
    color: var(--mvs-primary-dark);
}
[data-theme="dark"] .dropdown-divider { border-top-color: var(--mvs-border); }
[data-theme="dark"] .modal-content,
[data-theme="dark"] .toast {
    background: var(--mvs-surface);
    color: var(--mvs-text);
}
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(180%); }
[data-theme="dark"] .alert-success { color: #bbf7d0; }
[data-theme="dark"] .alert-danger  { color: #fecaca; }
[data-theme="dark"] .alert-warning { color: #fde68a; }

/* Tom Select — Bootstrap 5 theme hard-codes light surfaces */
[data-theme="dark"] .ts-control,
[data-theme="dark"] .ts-dropdown {
    background: var(--mvs-surface);
    color: var(--mvs-text);
    border-color: var(--mvs-border-strong);
}
[data-theme="dark"] .ts-dropdown .active { background: var(--mvs-primary-soft); color: var(--mvs-primary-dark); }
[data-theme="dark"] .ts-control .item {
    background: var(--mvs-primary-soft);
    color: var(--mvs-primary-dark);
}

/* Quill — snow theme is light-only; soften it for dark mode */
[data-theme="dark"] .ql-toolbar,
[data-theme="dark"] .ql-container {
    border-color: var(--mvs-border-strong) !important;
}
[data-theme="dark"] .ql-editor { color: var(--mvs-text); }
[data-theme="dark"] .ql-snow .ql-stroke { stroke: var(--mvs-text-muted); }
[data-theme="dark"] .ql-snow .ql-fill { fill: var(--mvs-text-muted); }
[data-theme="dark"] .ql-snow .ql-picker { color: var(--mvs-text-muted); }
