/* ============================================================
   Clinic SaaS — Design System (per DESIGN.md)
   Premium Medical SaaS · Clean · Modern · Professional
   ============================================================ */

/* ---------- 1. Design tokens ---------- */
:root {
    --primary: #2563EB;
    --primary-dark: #1D4ED8;
    --primary-light: #EFF6FF;

    --secondary: #0F766E;
    --secondary-light: #F0FDFA;

    --success: #16A34A;
    --success-bg: #F0FDF4;
    --warning: #D97706;
    --warning-bg: #FFFBEB;
    --danger: #DC2626;
    --danger-bg: #FEF2F2;
    --info: #0284C7;
    --info-bg: #F0F9FF;
    --neutral: #64748B;
    --neutral-bg: #F8FAFC;

    --background: #F8FAFC;
    --surface: #FFFFFF;
    --surface-secondary: #F1F5F9;

    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;

    --border: #E2E8F0;
    --border-light: #F1F5F9;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.08);

    /* Map Bootstrap to the design tokens */
    --bs-primary: #2563EB;
    --bs-primary-rgb: 37, 99, 235;
    --bs-success: #16A34A;
    --bs-success-rgb: 22, 163, 74;
    --bs-warning: #D97706;
    --bs-warning-rgb: 217, 119, 6;
    --bs-danger: #DC2626;
    --bs-danger-rgb: 220, 38, 38;
    --bs-info: #0284C7;
    --bs-info-rgb: 2, 132, 199;
    --bs-body-bg: #F8FAFC;
    --bs-body-color: #0F172A;
    --bs-border-color: #E2E8F0;
    --bs-link-color: #2563EB;
    --bs-link-hover-color: #1D4ED8;
}

/* ---------- 2. Typography ---------- */
body {
    font-family: "Inter", "Noto Sans Thai", "Noto Sans Lao", sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background-color: var(--background);
}

h1, .h1 { font-size: 24px; font-weight: 600; }
h2, .h2 { font-size: 20px; font-weight: 600; }
h3, .h3, h4, .h4 { font-size: 18px; font-weight: 600; }
h5, .h5 { font-size: 16px; font-weight: 600; }
h6, .h6 { font-size: 14px; font-weight: 600; }

.small, small { font-size: 13px; }
.text-caption { font-size: 12px; color: var(--text-muted); }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted { color: var(--text-muted) !important; }

/* ---------- 3. Page header ---------- */
.clinic-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.clinic-page-header .page-title {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.clinic-page-header .page-description {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 0;
}

.breadcrumb {
    font-size: 13px;
    margin-bottom: 0.5rem;
}

.breadcrumb .breadcrumb-item a {
    color: var(--text-muted);
    text-decoration: none;
}

.breadcrumb .breadcrumb-item a:hover { color: var(--primary); }
.breadcrumb .breadcrumb-item.active { color: var(--text-secondary); }

/* ---------- 4. Sidebar (light, sectioned) ---------- */
.clinic-sidebar {
    width: 250px;
    min-height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.clinic-sidebar .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 16px;
}

.clinic-sidebar .sidebar-brand i { color: var(--primary); font-size: 1.4rem; }

.clinic-sidebar .sidebar-nav {
    padding: 0.75rem 0.75rem 1.5rem;
    overflow-y: auto;
    flex-grow: 1;
    list-style: none;
    margin: 0;
}

.clinic-sidebar .nav-section {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 1rem 0.75rem 0.35rem;
}

.clinic-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-secondary);
    font-size: 14px;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

.clinic-sidebar .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }

.clinic-sidebar .nav-link:hover {
    background: var(--surface-secondary);
    color: var(--text-primary);
}

.clinic-sidebar .nav-link.active {
    background: var(--primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 500;
}

.clinic-sidebar .nav-link.active i { color: var(--primary); }

/* Mobile offcanvas reuses the same styles */
.offcanvas .sidebar-nav { padding: 0.75rem; list-style: none; margin: 0; }

/* ---------- 5. Top navbar ---------- */
.clinic-navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    min-height: 60px;
    padding: 0.5rem 1.25rem;
}

.clinic-navbar .navbar-clinic-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.2;
}

.clinic-navbar .navbar-branch {
    font-size: 12px;
    color: var(--text-muted);
}

.clinic-navbar .global-search {
    max-width: 340px;
    width: 100%;
}

.clinic-navbar .global-search .form-control {
    background: var(--surface-secondary);
    border-color: transparent;
    min-height: 38px;
    padding-left: 2.3rem;
}

.clinic-navbar .global-search .form-control:focus {
    background: var(--surface);
    border-color: var(--primary);
}

.clinic-navbar .global-search .bi-search {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.navbar-icon-btn {
    position: relative;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    transition: all 0.2s ease;
}

.navbar-icon-btn:hover { background: var(--surface-secondary); color: var(--text-primary); }

.navbar-icon-btn .notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    font-size: 10px;
    line-height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    text-align: center;
}

.clinic-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}

.clinic-avatar.avatar-lg { width: 64px; height: 64px; font-size: 22px; }

.dropdown-menu {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
}

.dropdown-header-user { padding: 0.6rem 1rem 0.25rem; }
.dropdown-header-user .user-name { font-weight: 600; color: var(--text-primary); }
.dropdown-header-user .user-roles { font-size: 12px; color: var(--text-muted); }

/* ---------- 6. Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    background: var(--surface) !important;
    border-bottom: 1px solid var(--border-light);
    border-radius: 12px 12px 0 0 !important;
    padding: 0.85rem 1.1rem;
    font-weight: 600;
    font-size: 15px;
}

.card-footer { background: var(--surface); border-top: 1px solid var(--border-light); }

/* Stat cards */
.clinic-stat-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease;
    height: 100%;
}

.clinic-stat-card:hover { box-shadow: var(--shadow-md); }

.clinic-stat-card .stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.clinic-stat-card .stat-title { font-size: 13px; color: var(--text-secondary); margin-bottom: 2px; }
.clinic-stat-card .stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; color: var(--text-primary); }
.clinic-stat-card .stat-meta { font-size: 12px; color: var(--text-muted); }

.icon-tint-primary { background: var(--primary-light); color: var(--primary); }
.icon-tint-secondary { background: var(--secondary-light); color: var(--secondary); }
.icon-tint-success { background: var(--success-bg); color: var(--success); }
.icon-tint-warning { background: var(--warning-bg); color: var(--warning); }
.icon-tint-danger { background: var(--danger-bg); color: var(--danger); }
.icon-tint-info { background: var(--info-bg); color: var(--info); }
.icon-tint-neutral { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- 7. Buttons ---------- */
.btn {
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn:not(.btn-sm):not(.btn-lg) { padding: 0.5rem 1rem; }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    background: var(--primary-dark) !important;
    border-color: var(--primary-dark) !important;
}

.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }

.btn-light {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-secondary);
}

.btn-light:hover { background: var(--surface-secondary); color: var(--text-primary); }

/* ---------- 8. Forms ---------- */
.form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.form-control, .form-select {
    min-height: 42px;
    border-radius: 8px;
    border-color: var(--border);
    font-size: 14px;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.form-control-sm, .form-select-sm { min-height: 34px; }

textarea.form-control { min-height: auto; }

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-control::placeholder { color: var(--text-muted); }

.required::after { content: " *"; color: var(--danger); }

.invalid-feedback { font-size: 12px; }

.form-section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border-light);
    margin: 1rem 0 0.85rem;
}

/* Select2 to match form controls */
.select2-container { width: 100% !important; }
.select2-container--bootstrap-5 .select2-selection { min-height: 42px; border-radius: 8px; border-color: var(--border); }
.select2-container--bootstrap-5.select2-container--focus .select2-selection {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ---------- 9. Tables ---------- */
.table {
    font-size: 14px;
    color: var(--text-primary);
    --bs-table-hover-bg: var(--surface-secondary);
}

.table thead th {
    background: var(--surface-secondary) !important;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 0.75rem;
}

.table tbody td {
    padding: 0.65rem 0.75rem;
    vertical-align: middle;
    border-color: var(--border-light);
}

/* DataTables chrome */
.dt-search input, .dt-length select { min-height: 36px !important; }
div.dt-container .dt-paging .dt-paging-button.current,
div.dt-container .dt-paging .dt-paging-button.current:hover {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #fff !important;
    border-radius: 8px;
}
div.dt-container .dt-paging .dt-paging-button { border-radius: 8px; }
div.dt-container.dt-empty-footer tbody > tr:last-child > * { border-bottom: none; }

/* ---------- 10. Badges (subtle medical style) ---------- */
.badge { border-radius: 999px; font-weight: 500; font-size: 12px; padding: 0.32em 0.7em; }

.clinic-status { border-radius: 999px; font-weight: 500; font-size: 12px; padding: 0.32em 0.7em; display: inline-block; text-transform: capitalize; }
.clinic-status-success { background: var(--success-bg); color: var(--success); }
.clinic-status-warning { background: var(--warning-bg); color: var(--warning); }
.clinic-status-danger  { background: var(--danger-bg); color: var(--danger); }
.clinic-status-info    { background: var(--info-bg); color: var(--info); }
.clinic-status-primary { background: var(--primary-light); color: var(--primary); }
.clinic-status-secondary { background: var(--secondary-light); color: var(--secondary); }
.clinic-status-neutral { background: var(--surface-secondary); color: var(--neutral); }

/* ---------- 11. Modals ---------- */
.modal-content { border: 0; border-radius: 14px; box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--border-light); padding: 1rem 1.25rem; }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-footer { border-top: 1px solid var(--border-light); }

/* ---------- 12. Alerts ---------- */
.alert { border-radius: var(--radius-md); border: 1px solid transparent; font-size: 14px; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #BBF7D0; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: #FECACA; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #FDE68A; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #BAE6FD; }

/* ---------- 13. Empty / loading states ---------- */
.clinic-empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-secondary);
}

.clinic-empty-state .empty-icon { font-size: 2.6rem; color: var(--text-muted); }
.clinic-empty-state .empty-title { font-weight: 600; font-size: 16px; margin-top: 0.75rem; color: var(--text-primary); }
.clinic-empty-state .empty-text { font-size: 13px; max-width: 320px; margin: 0.25rem auto 1rem; }

.skeleton {
    background: linear-gradient(90deg, var(--surface-secondary) 25%, var(--border-light) 50%, var(--surface-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-wave 1.4s ease infinite;
    border-radius: var(--radius-sm);
    display: inline-block;
    min-height: 1em;
}

@keyframes skeleton-wave {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ---------- 14. Queue ---------- */
.queue-number { font-size: 2rem; font-weight: 700; letter-spacing: 1px; color: var(--primary); }

.queue-column-header {
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.6rem 1rem;
    border-radius: 12px 12px 0 0;
}

.queue-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.6rem;
}

/* TV display mode */
.queue-display {
    min-height: 100vh;
    background: var(--background);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.queue-display .now-serving-label {
    font-size: 1.5rem;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.queue-display .now-serving-number {
    font-size: clamp(6rem, 22vw, 14rem);
    font-weight: 700;
    color: var(--primary);
    line-height: 1.1;
}

.queue-display .waiting-list .queue-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.5rem 1.4rem;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* ---------- 15. Vital sign cards ---------- */
.vital-card {
    background: var(--secondary-light);
    border: 1px solid #CCFBF1;
    border-radius: var(--radius-md);
    padding: 0.65rem 0.75rem;
    text-align: center;
    height: 100%;
}

.vital-card .vital-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--secondary); }
.vital-card .vital-value { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.vital-card .vital-unit { font-size: 11px; color: var(--text-muted); }

/* Medical alert (allergies etc.) */
.medical-alert {
    background: var(--danger-bg);
    border: 1px solid #FECACA;
    border-radius: var(--radius-md);
    color: var(--danger);
    padding: 0.5rem 0.85rem;
    font-size: 13px;
    font-weight: 500;
}

/* ---------- 16. Workflow stepper ---------- */
.clinic-stepper { display: flex; align-items: center; gap: 0; flex-wrap: wrap; }

.clinic-stepper .step {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 12px;
    color: var(--text-muted);
}

.clinic-stepper .step .step-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}

.clinic-stepper .step.done { color: var(--success); }
.clinic-stepper .step.done .step-dot { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.clinic-stepper .step.current { color: var(--primary); font-weight: 600; }
.clinic-stepper .step.current .step-dot { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

.clinic-stepper .step-line { flex: 1 1 14px; min-width: 14px; height: 1px; background: var(--border); margin: 0 0.4rem; }

/* ---------- 17. Tabs ---------- */
.nav-tabs { border-bottom: 1px solid var(--border); }

.nav-tabs .nav-link {
    color: var(--text-secondary);
    font-size: 14px;
    border: 0;
    border-bottom: 2px solid transparent;
    padding: 0.6rem 0.9rem;
}

.nav-tabs .nav-link:hover { color: var(--text-primary); border-color: transparent; }

.nav-tabs .nav-link.active {
    color: var(--primary);
    font-weight: 500;
    background: transparent;
    border-bottom: 2px solid var(--primary);
}

/* ---------- 18. Auth pages ---------- */
.auth-page {
    min-height: 100vh;
    background: var(--background);
}

.auth-brand-panel {
    background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3rem;
}

.auth-brand-panel .brand-icon { font-size: 2.6rem; }

.auth-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    background: var(--surface);
}

/* ---------- 19. Error pages ---------- */
.error-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: var(--background);
    padding: 2rem;
}

.error-page .error-code { font-size: 5rem; font-weight: 700; color: var(--primary); line-height: 1; }
.error-page .error-title { font-size: 20px; font-weight: 600; margin-top: 0.5rem; }
.error-page .error-text { color: var(--text-secondary); max-width: 380px; margin: 0.5rem auto 1.25rem; }

/* ---------- 20. Utility ---------- */
.transition-base { transition: all 0.2s ease; }
.swal2-container { z-index: 20000 !important; }
.swal2-popup { border-radius: var(--radius-lg) !important; font-size: 14px !important; }

footer.clinic-footer { font-size: 12px; color: var(--text-muted); }

/* ---------- 21. Responsive ---------- */
@media (max-width: 991.98px) {
    .clinic-sidebar { display: none !important; }
    .clinic-navbar .global-search { display: none; }
}

@media (max-width: 575.98px) {
    .clinic-page-header .page-title { font-size: 20px; }
    main.clinic-main { padding: 1rem !important; }
}

/* ---------- 22. Print (invoices, prescriptions, results) ---------- */
@media print {
    body { background: #fff !important; font-size: 12pt; }
    .clinic-sidebar, .clinic-navbar, .breadcrumb, .btn, .no-print,
    footer.clinic-footer, .offcanvas, .dt-search, .dt-length, .dt-paging, .dt-info { display: none !important; }
    main.clinic-main { padding: 0 !important; }
    .card { border: 0 !important; box-shadow: none !important; }
    .print-header { display: block !important; }
    a { text-decoration: none !important; color: inherit !important; }
}

.print-header { display: none; }
