/* Custom CSS for Health Assistant Dashboard */
body {
    font-family: 'Inter', sans-serif;
}

.glass-effect {
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.9);
}

.card-shadow {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card-shadow-lg {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.gradient-bg {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.gradient-bg-2 {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.gradient-bg-3 {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.hover-lift:hover {
    transform: translateY(-2px);
    transition: all 0.2s ease;
}

.button-gradient {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.button-gradient:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

.input-focus:focus {
    transform: scale(1.02);
    transition: all 0.2s ease;
}

/* Custom Scrollbar Styling */
.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

/* Firefox scrollbar */
.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: #667eea #f1f5f9;
}

/* Pagination overflow handling */
#patient-pagination {
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

#patient-pagination::-webkit-scrollbar {
    height: 4px;
}

#patient-pagination::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

/* Chat Messages Container Scroll Fix */
#chat-messages-container {
    /* Ensure the container has proper scroll containment */
    contain: layout;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* iOS smooth scrolling */
    overscroll-behavior: contain; /* Prevent scroll chaining */
}

/* Make sure the chat container takes up the full available height */
#active-chat-view {
    height: 100%;
    max-height: 100%;
}

/* Prevent main page scrolling when hovering over chat area */
.chat-scroll-container {
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

/* Keep patient navigation and actions visible while the active section scrolls. */
.patient-sheet {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    max-height: 90dvh;
}

.patient-sheet-header,
.patient-form-navigation,
.patient-form-footer {
    flex-shrink: 0;
}

.patient-form-navigation {
    display: flex;
    justify-content: center;
    padding: 12px 24px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.patient-form-tabs {
    display: flex;
    gap: 12px;
    max-width: 100%;
    padding: 8px;
    border-radius: 16px;
    background: rgb(255 255 255 / 80%);
    box-shadow: 0 1px 2px rgb(0 0 0 / 5%);
}

.patient-form-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    border: 0;
    border-radius: 8px;
    color: #475569;
    font-size: 16px;
    font-weight: 500;
    white-space: nowrap;
    transition: background-color 0.2s, color 0.2s, box-shadow 0.2s;
}

.patient-form-tab:hover { background: rgb(255 255 255 / 50%); color: #1e293b; }
.patient-form-tab[aria-selected="true"] {
    background: #2563eb;
    color: white;
    box-shadow: 0 1px 2px rgb(0 0 0 / 5%);
}

.patient-form-content {
    min-height: 0;
    overflow-y: auto;
    padding: 24px;
    overscroll-behavior: contain;
}

.patient-form-panel[hidden],
.patient-form-footer [hidden] { display: none !important; }
.patient-step-status { margin-right: auto; }
.patient-secondary-button {
    padding: 12px 24px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: white;
    color: #334155;
    font-weight: 500;
}

.patient-secondary-button:hover { background: #f1f5f9; }
.patient-form-tab:focus-visible,
.patient-secondary-button:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.patient-form-footer button:disabled { opacity: 0.6; cursor: wait; }
.patient-gender-switch {
    display: flex;
    padding: 4px;
    gap: 4px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #f1f5f9;
}
.patient-gender-switch label { position: relative; flex: 1; cursor: pointer; }
.patient-gender-switch input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}
.patient-gender-switch span {
    display: block;
    padding: 12px 16px;
    border-radius: 8px;
    text-align: center;
    color: #64748b;
    font-weight: 500;
    transition: background-color 0.2s, color 0.2s;
}
.patient-gender-switch input:checked + span {
    background: #2563eb;
    color: white;
    box-shadow: 0 1px 3px #0f172a1a;
}
.patient-gender-switch .fa-mars { color: #0284c7; }
.patient-gender-switch input[value="female"]:checked + span { background: #db2777; }
.patient-gender-switch .fa-venus { color: #db2777; }
.patient-gender-switch input:checked + span .fa-mars { color: #bae6fd; }
.patient-gender-switch input:checked + span .fa-venus { color: #fce7f3; }
.patient-gender-switch input:focus-visible + span,
.patient-birthdate-toggle:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
.patient-birthdate-toggle {
    display: inline-block;
    margin-top: 8px;
    color: #2563eb;
    font-size: 12px;
    cursor: pointer;
}
.patient-birthdate-toggle:hover { text-decoration: underline; }
.patient-age-field [hidden] { display: none !important; }
@media (max-width: 640px) {
    .patient-form-navigation { padding: 12px; }
    .patient-form-tabs { gap: 6px; }
    .patient-form-tab { gap: 6px; padding: 12px 10px; font-size: 14px; white-space: normal; }
    .patient-form-content { padding: 20px 16px; }
    .patient-step-status { flex-basis: 100%; }
    .patient-form-footer { padding: 12px 16px; }
}

.medical-measures { display: grid; grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); gap: 12px; }
.medical-measures label, .medical-checkpoint label { display: block; color: #334155; font-weight: 500; }
.medical-measures small { font-weight: normal; }
.medical-measures input, .medical-checkpoint input, .medical-checkpoint textarea {
    display: block; width: 100%; padding: .65rem; margin-top: .25rem;
    border: 1px solid #cbd5e1; border-radius: .6rem; background: #f8fafc;
}
.medical-checkpoint { min-width: 0; padding: 1rem; border: 1px solid #cbd5e1; border-radius: .75rem; }
.medical-checkpoint > * + * { margin-top: .7rem; }
.medical-checkpoint legend { padding: 0 .3rem; font-weight: 600; }
.medical-add, .medical-checkpoint button { color: #0369a1; padding: .6rem 0; font-weight: 600; }

.medical-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-bottom: 1px solid #cbd5e1;
}
.medical-tabs button {
    padding: .75rem .5rem;
    border-bottom: 3px solid transparent;
    text-align: center;
    font-weight: 600;
    color: #475569;
}
.medical-tabs button[aria-selected="true"] { border-bottom-color: #2563eb; color: #1d4ed8; }
.medical-add { display: block; margin-inline: auto; }
.checkpoint-actions { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; }
.medical-checkpoint .checkpoint-save {
    padding: .55rem .9rem; background: #2563eb; color: white; border-radius: .5rem;
}
.medical-checkpoint:disabled { opacity: .65; }
.checkpoint-summary { padding: .75rem 1rem; border-bottom: 1px solid #e2e8f0; }
.checkpoint-summary summary { cursor: pointer; font-weight: 600; color: #334155; }
.checkpoint-summary p { margin-top: .5rem; white-space: pre-wrap; overflow-wrap: anywhere; }

#evaluation-log { height: 22rem; max-height: 34rem; min-height: 15rem; }
#evaluation-log p { width: fit-content; max-width: 88%; border-radius: .8rem; padding: .6rem .85rem; white-space: pre-wrap; overflow-wrap: anywhere; }
/* Shared interaction and layout foundations. */
:root { --mobile-nav-height: 72px; --app-height: 100dvh; }
html { scroll-padding-top: 80px; }
body { -webkit-tap-highlight-color: transparent; }
*, *::before, *::after { box-sizing: border-box; }
input, textarea, select, .flex-1, .grow { min-width: 0; }
textarea { resize: vertical; }
button, [role="button"], a, input, select, textarea { touch-action: manipulation; }
button, [role="button"] { cursor: pointer; }
button:disabled { cursor: default; }
:where(button, a, input, textarea, select, [tabindex]):focus-visible { outline: 3px solid #60a5fa; outline-offset: 3px; }
button { min-height: 44px; }
input:not([type="radio"]):not([type="checkbox"]), select { min-height: 44px; }
.input-focus:focus { transform: none; }
[hidden] { display: none !important; }
#particles-js { pointer-events: none; }
#toast { z-index: 1100; max-width: calc(100vw - 32px); overflow-wrap: anywhere; }
.patient-card h3, .patient-card span, .patient-form-panel, .diagnosis-item, #modal-managed-profiles-list { overflow-wrap: anywhere; }
.patient-basic-info > div > div:first-child { min-width: 0; }
.patient-basic-info .w-12 { flex-shrink: 0; }
.patient-sheet-header > div, .patient-sheet-header h2 { min-width: 0; overflow-wrap: anywhere; }
.patient-sheet-header button { flex-shrink: 0; min-width: 44px; }
.patient-form-content { scrollbar-gutter: stable; }
.patient-form-footer { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.chat-layout { min-height: 0; height: calc(var(--app-height) - 200px); }
.chat-sidebar, .chat-conversation { min-width: 0; min-height: 0; }
.chat-back { display: none; }
#active-chat-name, #active-chat-info { overflow-wrap: anywhere; }
#active-chat-view > div > .flex > div:last-child { min-width: 0; }
.message-row { min-width: 0; max-width: 94%; }
.message-row > .flex-col { min-width: 0; }
.message-row p { overflow-wrap: anywhere; }
#chat-messages-container { scroll-behavior: auto; }
#modal-managed-profiles-list > div { flex-wrap: wrap; }
#modal-managed-profiles-list > div > div:first-child { min-width: 0; flex: 1 1 180px; }
#modal-managed-profiles-list > div > div:last-child { flex-shrink: 0; }
body.modal-open { overflow: hidden; }

@media (max-width: 1023px) {
    .section-toolbar { flex-wrap: wrap; gap: 12px; }
    .section-toolbar h3 { flex: 1 1 100%; }
    .section-toolbar input { flex: 1 1 180px; }
    .patient-basic-info > div { align-items: flex-start; gap: 12px; }
    .patient-basic-info > div > div:first-child { flex-wrap: wrap; row-gap: 12px; }
    .patient-basic-info > div > div:first-child > .flex-wrap { flex-basis: 100%; }
}

@media (max-width: 767px), (max-width: 1023px) and (max-height: 500px) {
    html { scroll-padding-top: 76px; }
    body { background: #eef5fa !important; padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom)); }
    #particles-js { display: none; }
    .app-navigation { padding-top: env(safe-area-inset-top); background: #fff; box-shadow: 0 1px 0 #e2e8f0; }
    .app-navigation > div { padding-inline: 16px; }
    .app-navigation > div > div { height: 64px; justify-content: center; }
    .dashboard-brand { padding: 0; background: none; }
    .dashboard-brand h1 { font-size: 14px; }
    .dashboard-brand img { width: 36px; height: 36px; border-radius: 12px; }
    .primary-tabs { position: fixed; z-index: 50; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid #e2e8f0; border-radius: 0; background: #fff; box-shadow: 0 -4px 24px #0f172a08; }
    .meta-tab-button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; min-height: 55px; font-size: 11px; border-radius: 12px; }
    .meta-tab-button i { margin: 0; font-size: 18px; }
    .meta-tab-button.active-meta-tab { background: #eff6ff; color: #1d4ed8; box-shadow: none; }
    body > .relative > .min-h-screen { min-height: 0; padding-block: 16px; }
    body > .relative > .min-h-screen > .max-w-7xl { padding-inline: 12px; }
    .meta-tab-content > div { border-radius: 20px; box-shadow: 0 4px 24px #0f172a05; }
    #patients-meta-tab > div:first-child, #chats-meta-tab > div > div:first-child { padding: 16px; background: #fff; border-color: #e2e8f0; border-radius: 20px 20px 0 0; }
    .section-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 8px; }
    .section-toolbar h3 { grid-column: 1; font-size: 17px; }
    .section-toolbar h3 i { margin-right: 8px; }
    .section-toolbar input { grid-row: 2; grid-column: 1; width: 100%; }
    .section-toolbar > .rounded-full { grid-row: 3; grid-column: 1 / -1; width: fit-content; padding: 0; background: transparent; font-size: 12px; }
    .section-toolbar > button:last-child { grid-row: 1; grid-column: 2; min-width: 44px; }
    .section-toolbar > button:not(:last-child) { grid-row: 2; grid-column: 2; }
    #chat-search { grid-column: 1 / -1; }
    #patient-list { padding: 12px; min-height: 40vh; }
    .patient-basic-info { padding: 16px; }
    .patient-basic-info > div { flex-wrap: wrap; gap: 12px; }
    .patient-basic-info > div > div:first-child { flex-basis: 100%; }
    .patient-basic-info .w-12 { width: 44px; height: 44px; margin-right: 12px; }
    .patient-basic-info .mr-6 { flex: 1; min-width: 0; margin-right: 0; }
    .patient-basic-info h3 { font-size: 16px; line-height: 1.5; }
    .patient-basic-info > div > div:last-child { width: 100%; justify-content: flex-end; border-top: 1px solid #f1f5f9; padding-top: 8px; }
    .patient-basic-info button { width: 44px; background: #f8fafc; color: #475569; }
    #patient-pagination { justify-content: flex-start; padding: 12px; }
    #patient-pagination button { min-width: 44px; flex-shrink: 0; }
    .settings-navigation { justify-content: flex-start; padding: 10px; overflow-x: auto; overscroll-behavior-x: contain; }
    .settings-navigation > div { flex-wrap: nowrap; justify-content: flex-start; width: max-content; gap: 4px; }
    .settings-navigation .tab-button { white-space: nowrap; padding-inline: 14px; flex-shrink: 0; }
    #settings-meta-tab > div > .p-4 { padding: 16px; }
    #diagnosis-tab > div:first-child, #disallowed-tab > div { padding: 16px; }
    #diagnosis-tab input, #disallowed-tab input { width: 0; }
    #disallowed-tab button { padding-inline: 14px; }
    .diagnosis-item > div:first-child { gap: 8px; }
    .diagnosis-item .font-medium { overflow-wrap: anywhere; }
    #new-patient-modal, #patient-details-modal { padding: 0; align-items: stretch; }
    .patient-sheet { border-radius: 0; max-height: var(--app-height); height: var(--app-height); }
    .patient-sheet-header { padding: max(12px, env(safe-area-inset-top)) 16px 12px; gap: 8px; }
    .patient-sheet-header h2 { font-size: 18px; }
    .patient-sheet-header p { font-size: 12px; }
    .patient-sheet-header .w-8 { display: none; }
    .patient-form-navigation { padding: 8px 12px; }
    .patient-form-tabs { width: 100%; gap: 4px; padding: 4px; }
    .patient-form-tab { flex: 1; padding: 10px 6px; font-size: 12px; gap: 5px; }
    .patient-form-content { padding: 20px 16px; }
    .patient-form-content .border-l-4 { padding-left: 12px; }
    .patient-form-content h3 { font-size: 16px; }
    .patient-form-footer { gap: 8px; padding: 12px 16px max(12px, env(safe-area-inset-bottom)); }
    .patient-form-footer button { flex: 1; padding: 12px 10px; font-size: 14px; }
    .patient-step-status { font-size: 12px; }
    #new-patient-telegram-sheet { padding: 12px; }
    #new-patient-telegram-sheet > div { max-height: calc(var(--app-height) - 24px); overflow-y: auto; border-radius: 24px; }
    #new-patient-telegram-sheet h2 { font-size: 18px; }
    #new-patient-telegram-sheet .w-10 { display: none; }
    #new-patient-telegram-sheet .p-6 { padding: 20px; }
    #modal-telegram-link { width: 100%; }
    #edit-patient-panel-assistant .flex.items-center.gap-3 { flex-wrap: wrap; }
    .chat-layout { height: calc(var(--app-height) - 290px - env(safe-area-inset-bottom)); min-height: 240px; }
    .chat-sidebar { width: 100%; border: 0; }
    .chat-conversation { display: none; }
    .conversation-open .chat-sidebar { display: none; }
    .conversation-open .chat-conversation { display: flex; }
    #chats-meta-tab.conversation-open > div > div:first-child { display: none; }
    .conversation-open .chat-layout { height: calc(var(--app-height) - 170px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-height: 200px; }
    .chat-back { display: flex; align-items: center; gap: 8px; flex-shrink: 0; padding: 10px 16px; background: #fff; color: #1d4ed8; font-size: 14px; border-bottom: 1px solid #e2e8f0; }
    #active-chat-view > .px-6 { padding: 12px; }
    #active-chat-info { font-size: 11px; }
    #chat-messages-container { padding: 16px 12px; }
    .message-row { max-width: 100%; }
    .message-row .w-8 { width: 24px; height: 24px; margin-inline: 4px; }
    .message-row .px-4 { padding: 10px 12px; }
    #evaluation-log { height: 40dvh; min-height: 180px; }
    #evaluate-tab section.p-5 { padding: 16px; }
    #toast { top: calc(76px + env(safe-area-inset-top)); right: 12px; left: 12px; max-width: none; padding: 14px 16px; border-radius: 14px; }
    input:not([type="radio"]):not([type="checkbox"]), textarea, select { font-size: 16px !important; }
    input[type="radio"], input[type="checkbox"] { min-width: 20px; min-height: 20px; }
    label:has(input[type="radio"]), label:has(input[type="checkbox"]) { min-height: 44px; }
    .login-page { padding: 0; background: linear-gradient(160deg, #e0f2fe, #f8fafc 55%, #dbeafe) !important; }
    .login-page > .relative > .min-h-screen { min-height: 100svh; padding: 24px 16px; }
    .login-page .max-w-md { padding: 28px 24px; border-radius: 24px; box-shadow: 0 16px 48px #0c4a6e12; }
    .login-page [onclick="togglePassword()"] { min-width: 44px; right: 6px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
    #particles-js { display: none; }
}
@media (hover: none) { .hover-lift:hover { transform: none; } }
@media (max-width: 767px), (max-width: 1023px) and (max-height: 500px) {
    /* A backdrop filter creates a containing block and traps fixed bottom navigation. */
    .app-navigation { backdrop-filter: none; -webkit-backdrop-filter: none; }
    .diagnosis-header { padding: 12px; }
    .diagnosis-header > div { min-width: 0; gap: 8px; }
    .diagnosis-header .w-3 { display: none; }
    .diagnosis-header span { overflow-wrap: anywhere; min-width: 0; padding: 8px 10px; }
    .diagnosis-header .fa-chevron-down { margin-left: 0; flex-shrink: 0; }
    .diagnosis-header > button { min-width: 44px; flex-shrink: 0; }
    .diagnosis-content { padding-inline: 12px; }
    #disallowed-tab .inline-flex, [id$="diagnosis-tags"] > span, [id$="tone-tags"] > span { max-width: 100%; overflow-wrap: anywhere; }
    #disallowed-tab .inline-flex > i, #disallowed-tab .inline-flex > button { flex-shrink: 0; }
    [id$="diagnosis-tags"] button, [id$="tone-tags"] button { min-width: 36px; flex-shrink: 0; }
}
@media (max-width: 767px), (max-width: 1023px) and (max-height: 500px) {
    .patient-sheet-header h2, #active-chat-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    #active-chat-view .w-10 { flex-shrink: 0; }
}

/* Phone density: compact surfaces and spacing, with full-size touch targets.
   Keep every override inside this breakpoint to preserve the desktop layout. */
@media (max-width: 767px), (max-width: 1023px) and (max-height: 500px) {
    :root { --mobile-nav-height: 64px; }
    body { font-size: 14px; line-height: 1.5; }
    html { scroll-padding-top: 64px; }
    .app-navigation > div { padding-inline: 12px; }
    .app-navigation > div > div { height: 56px; justify-content: center; }
    .dashboard-brand img { width: 30px; height: 30px; border-radius: 8px; margin-right: 8px; }
    .dashboard-brand h1 { font-size: 12px; line-height: 1.4; }
    .dashboard-brand p { font-size: 11px; }
    .primary-tabs { padding: 4px 12px calc(4px + env(safe-area-inset-bottom)); }
    .meta-tab-button { min-height: 55px; gap: 3px; padding: 6px 8px; border-radius: 8px; }
    .meta-tab-button i { font-size: 17px; }
    body > .relative > .min-h-screen { padding-block: 12px; }
    body > .relative > .min-h-screen > .max-w-7xl { padding-inline: 10px; }
    .meta-tab-content > div { border-radius: 14px; }
    #patients-meta-tab > div:first-child,
    #chats-meta-tab > div > div:first-child { padding: 12px; border-radius: 14px 14px 0 0; }
    .section-toolbar { gap: 8px; }
    .section-toolbar h3 { font-size: 15px; line-height: 1.4; }
    .section-toolbar input { padding: 8px 10px; border-radius: 8px; }
    .section-toolbar > .rounded-full { font-size: 11px; }
    #patient-list { padding: 8px; }
    #patient-list > * + * { margin-top: 8px; }
    .patient-card { border-radius: 10px; box-shadow: none; }
    .patient-basic-info { padding: 12px; }
    .patient-basic-info > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; }
    .patient-basic-info > div > div:first-child { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 4px 10px; }
    .patient-basic-info .w-12 { width: 36px; height: 36px; margin: 0; border-radius: 10px; font-size: 13px; }
    .patient-basic-info .mr-6 { margin: 0; }
    .patient-basic-info h3 { font-size: 14px; line-height: 1.4; }
    .patient-basic-info p { font-size: 12px; }
    .patient-basic-info > div > div:first-child > .flex-wrap { grid-column: 1 / -1; gap: 4px; margin-top: 4px; }
    .patient-basic-info .flex-wrap > span { padding: 3px 7px; border-radius: 6px; font-size: 11px; }
    .patient-basic-info > div > div:last-child { width: auto; flex-direction: column; align-self: start; gap: 0; border: 0; padding: 0; }
    .patient-basic-info > div > div:last-child > button { margin: 0; background: transparent; }
    .patient-basic-info button { width: 44px; height: 44px; padding: 10px; font-size: 14px; }
    #patient-pagination { padding: 8px; gap: 4px; }
    #patient-pagination button { padding: 8px; font-size: 12px; border-radius: 8px; }

    .patient-sheet-header { padding: max(8px, env(safe-area-inset-top)) 12px 8px; }
    .patient-sheet-header h2 { font-size: 16px; line-height: 1.4; }
    .patient-sheet-header p { font-size: 11px; }
    .patient-form-navigation { padding: 6px 10px; }
    .patient-form-tabs { border-radius: 10px; }
    .patient-form-tab { min-height: 44px; padding: 6px 4px; font-size: 12px; }
    .patient-form-content { flex: 1; padding: 14px 12px; scrollbar-gutter: auto; }
    .patient-form-content .border-l-4 { padding-left: 10px; border-left-width: 2px; }
    .patient-form-content h3 { font-size: 14px; margin-bottom: 10px; }
    .patient-form-content h3 i { margin-right: 8px; }
    .patient-form-content .grid { gap: 14px; }
    .patient-form-content :is(.space-y-6, .space-y-5) > * + * { margin-top: 16px; }
    .patient-form-content .space-y-4 > * + * { margin-top: 12px; }
    .patient-form-content :is(label, [id$="gender-label"]) { font-size: 12px; }
    .patient-form-content :is(.mb-3, .mb-4) { margin-bottom: 6px; }
    .patient-form-content :is(input:not([type="radio"]):not([type="checkbox"]), select, textarea) {
        padding: 9px 10px; border-radius: 8px; line-height: 24px;
    }
    .patient-form-content textarea.h-36 { height: 96px; }
    .patient-form-content .flex.p-4 { padding: 10px; border-radius: 8px; }
    .patient-gender-switch { padding: 3px; border-radius: 9px; }
    .patient-gender-switch span { padding: 10px 8px; font-size: 13px; line-height: 24px; }
    .patient-birthdate-toggle { margin-top: 2px; }
    .medical-measures { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .medical-measures small { display: block; }
    .medical-tabs button { padding: 8px; font-size: 13px; }
    .medical-checkpoint { padding: 10px; font-size: 13px; }
    .patient-form-footer { padding: 8px 12px max(8px, env(safe-area-inset-bottom)); gap: 6px; }
    .patient-form-footer button { padding: 8px; font-size: 13px; border-radius: 8px; }
    .patient-step-status { font-size: 11px; line-height: 16px; }
    #new-patient-telegram-sheet .p-6 { padding: 16px; }
    #new-patient-telegram-sheet :is(input, button) { padding: 10px 12px; border-radius: 8px; }

    .settings-navigation { padding: 6px; }
    .settings-navigation > div { padding: 2px; border-radius: 10px; }
    .settings-navigation .tab-button { padding: 8px 10px; font-size: 11px; }
    #settings-meta-tab > div > .p-4 { padding: 12px; }
    #settings-meta-tab h3 { font-size: 15px; }
    #settings-meta-tab :is(.text-sm, .text-md) { font-size: 13px; }
    #settings-meta-tab :is(.p-4, .p-5, .p-6) { padding: 12px; }
    #settings-meta-tab :is(.mb-6, .mb-8) { margin-bottom: 16px; }
    #settings-meta-tab :is(.space-y-6, .space-y-4) > * + * { margin-top: 12px; }
    #settings-meta-tab :is(input, textarea) { padding: 9px 10px; border-radius: 8px; }
    #settings-meta-tab button { font-size: 12px; }
    #assistant-settings-form button { padding: 10px 14px; border-radius: 8px; }
    .diagnosis-item { border-radius: 10px; box-shadow: none; }
    .diagnosis-header { padding: 8px 10px; }
    .diagnosis-header span { padding: 4px 6px; font-size: 13px; }
    .diagnosis-content { padding: 10px; }
    #disallowed-tab .inline-flex { padding: 4px 8px; border-radius: 8px; font-size: 12px; }

    .chat-layout { height: calc(var(--app-height) - 280px - env(safe-area-inset-bottom)); }
    .conversation-open .chat-layout { height: calc(var(--app-height) - 152px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
    #chat-patient-list { padding: 8px; }
    .chat-patient-card { padding: 10px; border-radius: 9px; }
    .chat-patient-card .w-10 { width: 34px; height: 34px; margin-right: 8px; font-size: 12px; }
    .chat-patient-card .flex-wrap { gap: 3px; }
    .chat-patient-card .flex-wrap span { padding: 2px 5px; font-size: 11px; }
    .chat-back { padding: 6px 12px; font-size: 13px; }
    #active-chat-view > .px-6 { padding: 8px 10px; }
    #active-chat-name { font-size: 14px; }
    #chat-messages-container { padding: 12px 8px; }
    #chat-messages > * + * { margin-top: 12px; }
    .message-row .px-4 { padding: 8px 10px; border-radius: 12px; }
    .message-row p { font-size: 13px; line-height: 1.6; }
    #chat-send-input { padding: 9px 10px; border-radius: 8px; }
    #toast { top: calc(64px + env(safe-area-inset-top)); padding: 10px 12px; font-size: 13px; }

    .login-page > .relative > .min-h-screen { padding: 20px 16px; }
    .login-page .max-w-md { padding: 24px 20px; border-radius: 16px; }
    .login-page h1 { font-size: 22px; }
    .login-page .mb-8 { margin-bottom: 24px; }
    .login-page #loginForm > * + * { margin-top: 18px; }
    .login-page #loginForm input { padding-block: 10px; border-radius: 8px; }
    .login-page #loginForm > button { padding: 10px; border-radius: 8px; font-size: 15px; }
}

.phone-label { display: none; }

@media (max-width: 767px), (max-width: 1023px) and (max-height: 500px) {
    .phone-label { display: inline; }
    .app-navigation > div { padding-inline: 18px; }
    .app-navigation > div > div { justify-content: flex-start; }
    .dashboard-brand img { width: 36px; height: 36px; border-radius: 50%; margin-right: 10px; }
    .dashboard-brand h1 { font-size: 14px; }
    .meta-tab-button.active-meta-tab { border-radius: 14px; }
    body > .relative > .min-h-screen > .max-w-7xl { padding-inline: 14px; }
    #patients-meta-tab > div:first-child, #chats-meta-tab > div > div:first-child {
        padding: 8px 0 14px; background: transparent; border: 0; box-shadow: none;
    }
    .section-toolbar { gap: 10px 8px; }
    .section-toolbar h3 { color: #1e293b; font-size: clamp(20px, 5.7vw, 26px); letter-spacing: -.035em; }
    .section-toolbar h3 i { display: none; }
    .section-toolbar input { border-color: #dbe3ef; padding-inline: 14px; border-radius: 12px; }
    .section-toolbar > .rounded-full { color: #475569; font-size: 12px; font-weight: 600; }
    #patients-meta-tab .section-toolbar { grid-template-columns: minmax(0,1fr) auto; }
    #patients-meta-tab .section-toolbar > button:last-child {
        width: auto; padding-inline: 12px; gap: 6px; font-weight: 600; border-radius: 12px;
    }
    #patient-search { grid-column: 1 / -1; padding-right: 80px; }
    #patients-meta-tab .section-toolbar > button:not(:last-child) {
        justify-self: end; align-self: stretch; margin: 1px; padding-inline: 12px;
        background: transparent; color: #2563eb; border-radius: 12px;
    }
    #patients-meta-tab > div:last-child { background: transparent; border: 0; box-shadow: none; }
    #patient-list { padding: 0; min-height: 0; }
    .patient-card { border: 1px solid #dbe3ef; border-radius: 16px; box-shadow: 0 2px 5px #0f172a0a; }
    .patient-basic-info { padding: 14px 14px 0; }
    .patient-basic-info > div { display: block; }
    .patient-basic-info > div > div:first-child { grid-template-columns: 42px minmax(0,1fr); align-items: start; }
    .patient-basic-info .w-12 { width: 42px; height: 42px; border-radius: 50%;  }
    .patient-basic-info h3 { font-size: 16px; line-height: 1.35; }
    .patient-basic-info p { margin-top: 2px; font-size: 13px; }
    .patient-basic-info .flex-wrap > span { border-radius: 8px;  font-size: 12px; }
    .patient-basic-info > div > div:last-child {
        display: flex; flex-direction: row; border-top: 1px solid #e2e8f0; margin-top: 12px;
    }
    .patient-basic-info > div > div:last-child > button {
        display: flex; flex: 1 1 0; align-items: center; justify-content: center; gap: 6px; width: 0;
        padding-inline: 8px; font-size: 12px; font-weight: 600; color: #475569;
    }
    .patient-basic-info > div > div:last-child > button + button { position: relative; }
    .patient-basic-info > div > div:last-child > button + button::before {
        content: ''; position: absolute; left: 0; height: 22px; width: 1px; background: #dce3ec;
    }
    .patient-basic-info > div > div:last-child > button:last-child { color: #9e4343; }
    #patient-pagination { margin-top: 10px; border: 0; padding-inline: 0; }
    #chats-meta-tab > div { background: transparent; box-shadow: none; border: 0; }
    .chat-layout, #settings-meta-tab > div { border: 1px solid #dbe3ef; border-radius: 16px; overflow: hidden; }
    #active-chat-name, #settings-meta-tab h3 { color: #1e293b; }
    #settings-meta-tab h3 { font-size: 18px; }
    .message-row p { font-size: 15px; }
}

.profile-record-id { display: none; }

@media (max-width: 767px), (max-width: 1023px) and (max-height: 500px) {
    #patient-details-modal .patient-sheet-header {
        padding: max(14px, env(safe-area-inset-top)) 16px 14px;
    }
    .profile-record-id {
        display: block; margin-bottom: 2px; color: white;
        font-size: 12px; font-weight: 500;
    }
    #patient-modal-name { font-size: 20px; line-height: 1.22; }
    #patient-details-modal .patient-form-navigation {
        padding: 0 12px; background: white;
    }
    #patient-details-modal .patient-form-tabs {
        padding: 0; gap: 0; border-radius: 0; box-shadow: none;
    }
    #patient-details-modal .patient-form-tab {
        min-height: 48px; font-size: 14px; border-radius: 0;
        border-bottom: 3px solid transparent;
    }
    #patient-details-modal .patient-form-tab[aria-selected="true"] {
        color: #1d4ed8; background: white; border-color: #2563eb; box-shadow: none;
    }
    #patient-details-modal .patient-form-content { padding: 14px; background: #f1f5f9; }
    #patient-details-modal :is(.border-l-4, .medical-measures, .medical-checkpoint, .checkpoint-summary) {
        padding: 16px; background: white; border: 1px solid #dce4ef; border-radius: 14px;
    }
    #patient-details-modal .patient-form-content h3 {
        font-size: 17px; font-weight: 650; line-height: 1.35; margin-bottom: 14px;
    }
    #patient-details-modal .patient-form-content h3 i,
    #edit-patient-panel-info :is(label, #modal-patient-gender-label) > i { display: none; }
    #patient-details-modal .patient-form-content :is(label, #modal-patient-gender-label) {
        font-size: 14px; color: #334155;
    }
    #patient-details-modal .patient-form-content :is(input:not([type="radio"]), select, textarea) {
        background: #fff; border-color: #cbd5e1; border-radius: 10px;
    }
    #edit-patient-panel-info .grid { gap: 16px; }
    #patient-details-modal .patient-gender-switch input:checked + span {
        background: white; color: #1d4ed8; box-shadow: 0 1px 4px #0f172a26;
    }
    #patient-details-modal .patient-gender-switch i { color: inherit; }
    #patient-details-modal .medical-tabs { background: white; border-radius: 10px; }
    #patient-details-modal .patient-form-footer {
        display: grid; grid-template-columns: 1fr 2fr; gap: 10px;
        padding: 10px 14px max(10px, env(safe-area-inset-bottom)); background: white;
    }
    #patient-details-modal .patient-form-footer button { font-size: 14px; border-radius: 10px; }
    #patient-details-modal .patient-form-footer button:first-child {
        color: #475569; background: white; border: 1px solid #cbd5e1;
    }
    #patient-details-modal .patient-form-footer i { display: none; }
}
@media (max-width: 1023px) and (max-height: 500px) {
    #patient-details-modal .patient-sheet-header { padding-block: max(4px, env(safe-area-inset-top)) 4px; }
    #patient-details-modal .profile-record-id { display: none; }
    #patient-details-modal .patient-sheet-header h2 { font-size: 17px; }
}

.profile-row-toggle { display: none; }
.profile-row-editor { display: contents; }

@media (max-width: 767px), (max-width: 1023px) and (max-height: 500px) {
    #patient-details-modal .patient-form-content { background: white; padding: 0 18px 16px; }
    #patient-details-modal .patient-form-panel .border-l-4,
    #patient-details-modal [data-profile-field] {
        padding: 0; border: 0; border-radius: 0; background: transparent;
    }
    #patient-details-modal .patient-form-panel [data-profile-field] {
        display: block; margin: 0; border-bottom: 1px solid #e2e8f0;
    }
    #patient-details-modal #edit-patient-panel-info .grid { display: block; }
    #patient-details-modal #edit-patient-panel-info h3 { display: none; }
    #patient-details-modal #edit-examination { margin-top: 0; }
    #patient-details-modal .medical-tabs {
        margin: 16px 0 4px; padding: 3px; background: #f1f5f9; border: 0;
    }
    #patient-details-modal .medical-tabs button { border: 0; border-radius: 8px; }
    #patient-details-modal .medical-tabs [aria-selected="true"] { background: white; box-shadow: 0 1px 3px #0f172a26; }
    .profile-row-toggle {
        display: grid; grid-template-columns: 22px minmax(0,1fr) 14px; align-content: center;
        width: 100%; min-height: 70px; padding: 12px 2px; gap: 2px 12px; text-align: start;
    }
    .profile-row-toggle > i { grid-column: 1; grid-row: 1; align-self: center; text-align: center; font-size: 16px; }
    .profile-row-toggle strong { grid-column: 2; font-size: 15px; font-weight: 600; color: #1e293b; }
    .profile-row-toggle span { grid-column: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #52647b; font-size: 14px; }
    .profile-row-toggle::after {
        content: ''; grid-column: 3; grid-row: 1 / 3; align-self: center; width: 8px; height: 8px;
        border: solid #718096; border-width: 0 1.5px 1.5px 0; transform: rotate(-45deg);
    }
    .profile-row-toggle[aria-expanded="true"]::after { transform: rotate(45deg); }
    .profile-row-toggle[aria-expanded="true"] strong { color: #1d4ed8; }
    .profile-row-toggle[aria-expanded="false"] + .profile-row-editor { display: none; }
    .profile-row-toggle[aria-expanded="true"] + .profile-row-editor { display: block; padding-bottom: 16px; }
    #patient-details-modal .profile-row-editor > h3 { display: none; }
    #patient-details-modal .medical-measures .profile-row-toggle[aria-expanded="true"] + div {
        display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
    }
}

/* The mobile section picker shares the settings header's soft blue palette. */
.settings-select-wrapper { display: none; }
@media (max-width: 767px), (max-width: 1023px) and (max-height: 500px) {
    .settings-navigation { display: none; }
    .settings-select-wrapper { display: block; width: 100%; padding: 10px; }
    .settings-select-control { position: relative; }
    .settings-select-control select { appearance: none; -webkit-appearance: none; width: 100%; min-height: 48px; padding: 11px 42px 11px 43px; border: 1px solid #dbe5f2; border-radius: 12px; background: #fff; color: #1e293b; font-size: 14px; font-weight: 600; box-shadow: 0 2px 6px rgba(15, 23, 42, .05); }
    .settings-select-control select:focus-visible { outline: 3px solid rgba(37, 99, 235, .22); outline-offset: 2px; border-color: #3b82f6; }
    .settings-select-icon, .settings-select-chevron { position: absolute; top: 50%; transform: translateY(-50%); pointer-events: none; }
    .settings-select-icon { left: 15px; color: #2563eb; font-size: 15px; }
    .settings-select-chevron { right: 16px; color: #64748b; font-size: 12px; }
}

