:root {
    --top-menu-width: clamp(270px, 25vw, 480px);
    --chat-side-pad: clamp(50px, 8vw, 140px);

    --bg-main: #ffffff;
    --bg-panel: #f7fafc;
    --bg-panel-soft: #eef4fa;
    --bg-input: #dceaf5;
    --bg-button: #3d5168;
    --bg-button-hover: #24384f;
    --bg-user: #d9e8f5;

    --text-main: #111827;
    --text-muted: #4b5563;
    --text-brand: #1c357a;
    --bot-label: #1c357a;

    --border-panel: rgba(57, 90, 127, 0.18);
    --border-soft: rgba(57, 90, 127, 0.12);

    --shadow-soft: 0 6px 18px rgba(57, 90, 127, 0.16);
    --shadow-panel-left: 8px 0 24px rgba(15, 23, 42, 0.08);
    --shadow-panel-right: -8px 0 24px rgba(15, 23, 42, 0.08);
    --shadow-card: 0 3px 12px rgba(15, 23, 42, 0.05);

    --menu-button-hover: #27518f;

    --app-content-font-size: 20px;
    --app-content-line-height: 1.35;
    --app-input-line-height: 24px;
    --app-secondary-font-size: 14px;

    /* The input text line and its padding are deliberately defined once.
       This makes the textarea's total height mathematically exact. */
    --input-text-padding-y: 8px;
    --input-text-padding-x: 8px;
}

/* ---------------- Base ---------------- */

html,
body {
    margin: 0;
    min-height: 100vh;
    font-family: system-ui, Arial, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    font-family: inherit;
}

/* ---------------- Layout ---------------- */

#layout {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    box-sizing: border-box;
}

#main {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
    height: 100vh;
    overflow: hidden;
}

/* ---------------- Chat ---------------- */

#chat {
    display: flex;
    flex: 1;
    flex-direction: column;
    width: 100%;
    margin: 0;
    padding: 50px var(--chat-side-pad) 25px;
    overflow-y: auto;
    box-sizing: border-box;
}

/* ---------------- Messages ---------------- */

.msg {
    box-sizing: border-box;
    margin: 3px 0;
    padding: 12px 16px;
    border-radius: 14px;
    line-height: var(--app-content-line-height);
    white-space: normal;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.user {
    align-self: flex-end;
    border: 1px solid rgba(57, 90, 127, 0.12);
    background: var(--bg-user);
}

.bot {
    align-self: flex-start;
    max-width: calc(50% + min(410px, 43%) - var(--chat-side-pad));
    padding: 0;
}

.user,
.bot {
    font-size: var(--app-content-font-size);
}

.english-static-greeting {
    display: block;
    margin-top: 4px;
    color: rgba(0, 0, 0, 0.7);
    font-size: var(--app-secondary-font-size);
}

.english-static-greeting a {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
}

.msg.bot>.bot-label {
    margin-bottom: 4px;
    color: var(--bot-label);
    font-weight: bold;
}

.bot-content {
    line-height: var(--app-content-line-height);
    white-space: normal;
}

.bot-content> :first-child {
    margin-top: 0;
}

.bot-content> :last-child {
    margin-bottom: 0;
}

.bot-content p {
    margin: 0 0 3px;
}

.bot-content ul,
.bot-content ol {
    margin: 16px 0;
    padding-left: 18px;
}

.bot-content li {
    margin: 0 0 2px;
}

.bot-content li p {
    margin: 0;
}

.bot-content p+ul,
.bot-content p+ol {
    margin-top: 0;
}

.bot-content h1,
.bot-content h2,
.bot-content h3 {
    margin: 6px 0 3px;
    line-height: 1.2;
}

.user-message-group {
    display: flex;
    align-self: flex-end;
    flex-direction: column;
    align-items: flex-end;
    max-width: calc(50% + min(410px, 43%) - var(--chat-side-pad));
    margin: 10px 0;
}

.user-message-group .msg.user {
    max-width: 100%;
    margin: 0;
}

.user-message-text {
    white-space: pre-wrap;
}

/* ---------------- Input ---------------- */

#inputWrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

#inputRow {
    display: flex;
    align-items: center;
    width: min(820px, 86%);
    gap: 10px;
}

#inputBox {
    display: flex;
    flex: 1;
    align-items: center;
    min-width: 0;
    padding: 6px 8px;
    gap: 8px;
    border: 1px solid rgba(57, 90, 127, 0.38);
    border-radius: 12px;
    background: var(--bg-input);
    box-sizing: border-box;
    box-shadow: var(--shadow-soft);
    transition: box-shadow 0.15s ease;
}

#inputBox:focus-within {
    box-shadow: 0 0 0 3px rgba(57, 90, 127, 0.18);
}

/*
   Single-line textarea geometry:
   total height = line-height + top padding + bottom padding.
   border-box is important: the visible control is exactly this height,
   and equal vertical padding puts the placeholder/text in the middle.
*/
#msg {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    height: calc(var(--app-input-line-height) + var(--input-text-padding-y) + var(--input-text-padding-y));
    margin: 0;
    padding: var(--input-text-padding-y) var(--input-text-padding-x);

    border: 0;
    outline: 0;
    resize: none;
    appearance: none;
    box-sizing: border-box;

    background: transparent;
    color: #000;
    font-family: inherit;
    font-size: var(--app-content-font-size);
    line-height: var(--app-input-line-height);
}

#msg::placeholder {
    color: grey;
    opacity: 1;
}

/* ---------------- Main buttons ---------------- */

#sendBtn {
    flex-shrink: 0;
    padding: 8px 14px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #33465c;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.08s ease;
}

#sendBtn:hover {
    border: 1px solid var(--menu-button-hover);
    background: #27518f;
    color: #fff;
}

#sendBtn:active,
#fileBtn:active {
    transform: translateY(1px);
}

#fileBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #4a637d;
    cursor: pointer;
    opacity: 0.95;
}

#fileBtn:hover {
    border: 1px solid var(--menu-button-hover);
    background: rgba(255, 255, 255, 0.55);
    color: var(--text-brand);
    opacity: 1;
}

.selected-file-label {
    display: none;
    max-width: 220px;
    overflow: hidden;
    border: 0;
    background: transparent;
    color: #6b7280;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.selected-file-label.visible {
    display: inline-block;
}

.selected-file-label:hover {
    color: #1e3a8a;
    text-decoration: underline;
}

/* ---------------- File attachments ---------------- */

.message-attachment {
    display: inline-flex;
    align-items: center;
    max-width: 280px;
    margin-top: 5px;
    margin-right: 4px;
    padding: 6px 10px;
    gap: 7px;
    border: 1px solid rgba(70, 105, 145, 0.22);
    border-radius: 999px;
    background: #eef5ff;
    color: #365875;
    font-size: 0.84rem;
    font-weight: 500;
    line-height: 1.2;
}

.message-attachment-icon {
    flex: 0 0 auto;
    color: #5f7f99;
    font-size: 0.9rem;
}

.message-attachment-name {
    min-width: 0;
    overflow: hidden;
    color: #243b53;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------------- Floating menu buttons ---------------- */

#topMenuButton,
#medicalMenuButton {
    position: fixed;
    top: 0;
    z-index: 200;
    padding: 12px 18px;
    border: 1px solid rgba(61, 81, 104, 0.15);
    background: #fff;
    color: #4b5563;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

#topMenuButton {
    left: 0;
    border-radius: 0 0 8px;
}

#medicalMenuButton {
    right: 0;
    border-radius: 0 0 0 8px;
}

#topMenuButton:hover,
#medicalMenuButton:hover {
    border-color: var(--menu-button-hover);
    background: var(--menu-button-hover);
    color: #fff;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}

#topMenuButton.hidden,
#medicalMenuButton.hidden {
    display: none;
}

/* ---------------- Side panels ---------------- */

#topMenuWindow,
#medicalMenuWindow {
    position: relative;
    display: none;
    flex-direction: column;
    flex-shrink: 0;
    width: var(--top-menu-width);
    height: 100vh;
    padding: 18px 14px;
    gap: 10px;
    overflow-y: auto;
    background: var(--bg-panel);
    color: var(--text-main);
    box-sizing: border-box;
}

#topMenuWindow {
    order: -1;
    border-right: 1px solid var(--border-panel);
    box-shadow: var(--shadow-panel-left);
}

#medicalMenuWindow {
    border-left: 1px solid var(--border-panel);
    box-shadow: var(--shadow-panel-right);
    transition: width 0.25s ease;
}

#layout.top-menu-open #topMenuWindow,
#layout.medical-menu-open #medicalMenuWindow {
    display: flex;
}

/* ---------------- Side-menu buttons ---------------- */

#topMenuButtons,
#medicalMenuButtons {
    padding-top: 2px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#topMenuWindow button,
#medicalMenuWindow button {
    padding: 11px 13px;
    border: 1px solid rgba(57, 90, 127, 0.14);
    border-radius: 12px;
    background: #fff;
    color: #24384f;
    font-size: 15px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    transition:
        background 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease,
        box-shadow 0.15s ease,
        transform 0.08s ease;
}

#topMenuWindow button:hover,
#medicalMenuWindow button:hover {
    border-color: rgba(57, 90, 127, 0.28);
    background: var(--bg-panel-soft);
    color: var(--text-brand);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
}

#topMenuWindow button:active,
#medicalMenuWindow button:active {
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
    transform: translateY(0);
}

/* ---------------- Side-menu content ---------------- */

#topMenuContent,
#medicalMenuContent {
    display: none;
    color: var(--text-main);
    font-size: var(--app-content-font-size);
    line-height: var(--app-content-line-height);
}

#topMenuWindow.show-content #topMenuButtons,
#medicalMenuWindow.show-content #medicalMenuButtons {
    display: none;
}

#topMenuWindow.show-content #topMenuContent,
#medicalMenuWindow.show-content #medicalMenuContent {
    display: block;
}

#topMenuContentHeader,
#medicalMenuContentHeader {
    display: flex;
    align-items: stretch;
    margin-bottom: 18px;
    padding-bottom: 12px;
    gap: 8px;
    border-bottom: 1px solid var(--border-soft);
}

#topMenuContentHeader button,
#medicalMenuContentHeader button {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 38px;
    margin: 0;
    padding: 0 12px;
    box-sizing: border-box;
    line-height: 1;
    text-align: center;
}

#backToMenuButton,
#backToMedicalMenuButton,
#medicalMenuCaseButton {
    flex: 1;
}

#medicalMenuContentHeader #medicalMenuCaseButton {
    display: none;
}

#medicalMenuWindow.show-report #medicalMenuContentHeader #medicalMenuCaseButton {
    display: flex;
}

.menuWindowHeader {
    display: none;
    flex-shrink: 0;
    justify-content: flex-end;
}

#topMenuWindow .menuCloseButton,
#medicalMenuWindow .menuCloseButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 20px;
    line-height: 1;
    text-align: center;
}

#topMenuContentHeader .menuCloseButton,
#medicalMenuContentHeader .menuCloseButton {
    display: none;
    flex: 0 0 44px;
}

/* ---------------- Language and font-size menus ---------------- */

.language-options,
.font-size-options {
    display: flex;
    flex-direction: column;
    margin: 16px 0;
    gap: 8px;
}

.font-size-options {
    gap: 10px;
}

#topMenuWindow .language-option {
    width: 100%;
    text-align: center;
}

#topMenuWindow .font-size-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 12px;
    text-align: left;
}

#topMenuWindow .language-option.active,
#topMenuWindow .font-size-option.active {
    border-color: var(--text-brand);
    background: var(--text-brand);
    color: #fff;
}

.language-note {
    color: var(--text-muted);
    font-size: var(--app-secondary-font-size);
    line-height: 1.4;
}

.font-size-sample {
    font-weight: 800;
    line-height: 1;
}

.font-size-sample-small {
    font-size: 14px;
}

.font-size-sample-medium {
    font-size: 20px;
}

.font-size-sample-large {
    font-size: 24px;
}

/* ---------------- Menu pages ---------------- */

.menuPage,
.medicalPage {
    display: none;
    font-size: var(--app-content-font-size);
    line-height: var(--app-content-line-height);
}

.menuPage.active,
.medicalPage.active {
    display: block;
}

.menuPage h1,
.medicalPage h1 {
    margin: 0 0 16px;
    color: var(--text-brand);
    font-size: calc(var(--app-content-font-size) * 1.35);
    letter-spacing: 0.1px;
}

.menuPage h2,
.medicalPage h2 {
    margin: 22px 0 10px;
    color: var(--text-brand);
    font-size: calc(var(--app-content-font-size) * 1.12);
}

.menuPage h3,
.medicalPage h3 {
    margin: 18px 0 8px;
    color: var(--text-brand);
    font-size: var(--app-content-font-size);
}

.menuPage p,
.medicalPage p {
    margin: 10px 0;
    color: var(--text-main);
}

.menuPage ul,
.menuPage ol,
.medicalPage ul,
.medicalPage ol {
    margin: 10px 0;
    padding-left: 22px;
}

.menuPage li,
.medicalPage li {
    margin: 5px 0;
}

.menuPage a,
.medicalPage a {
    color: var(--text-brand);
    font-weight: 600;
}

.menuPage blockquote,
.medicalPage blockquote {
    margin: 12px 0;
    padding: 10px 12px;
    border-left: 4px solid rgba(57, 90, 127, 0.28);
    border-radius: 0 10px 10px 0;
    background: rgba(255, 255, 255, 0.55);
}

/* ---------------- Report and diagnosis panels ---------------- */

#menuCaseContent {
    padding: 14px;
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    background: #fff;
    box-shadow: var(--shadow-card);
    font-size: var(--app-content-font-size);
    line-height: var(--app-content-line-height);
    white-space: normal;
}

#menuCaseContent h1 {
    margin: 0 0 14px;
    color: var(--text-brand);
    font-size: calc(var(--app-content-font-size) * 1.25);
    letter-spacing: 0.2px;
}

#menuCaseContent h2 {
    margin: 18px 0 8px;
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(57, 90, 127, 0.18);
    color: var(--text-brand);
    font-size: calc(var(--app-content-font-size) * 1.05);
}

#menuCaseContent ul {
    margin: 0;
    padding-left: 18px;
}

#menuCaseContent li {
    margin: 5px 0;
}

#menuCaseContent strong {
    color: var(--text-brand);
}

#diagnosisContent h2 {
    margin-top: 26px;
    margin-bottom: 4px;
}

#diagnosisContent ul {
    margin-top: 2px;
    margin-bottom: 8px;
    padding-left: 18px;
}

#diagnosisContent li {
    margin: 1px 0;
}

#diagnosisContent p {
    margin-top: 2px;
    margin-bottom: 16px;
}

/* ---------------- Modal ---------------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
}

.modalContent {
    position: relative;
    width: 800px;
    max-width: 80%;
    padding: 20px;
    border-radius: 12px;
    background: var(--bg-panel);
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
}

.modalContent h2 {
    margin-top: 0;
    color: var(--text-brand);
}

.modalContent label {
    font-weight: bold;
}

#patientName {
    width: 100%;
    margin: 12px 0 20px;
    padding: 10px 12px;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    outline: 0;
    background: #fff;
    color: #000;
    box-sizing: border-box;
    font-size: 18px;
}

#patientName:focus {
    border-color: rgba(57, 90, 127, 0.45);
    box-shadow: 0 0 0 3px rgba(57, 90, 127, 0.12);
}

#closeModal {
    position: absolute;
    top: 10px;
    right: 15px;
}

#savePatient {
    display: block;
    margin: 0 auto;
}

#savePatient,
#closeModal {
    padding: 11px 13px;
    border: 1px solid rgba(57, 90, 127, 0.14);
    border-radius: 12px;
    background: #fff;
    color: #24384f;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    transition:
        background 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease,
        box-shadow 0.15s ease,
        transform 0.08s ease;
}

#savePatient:hover,
#closeModal:hover {
    border-color: rgba(57, 90, 127, 0.28);
    background: var(--bg-panel-soft);
    color: var(--text-brand);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
}

#savePatient:active,
#closeModal:active {
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
    transform: translateY(0);
}

/* ---------------- Diagnosis loading animation ---------------- */

.diagnosis-loading-inline {
    padding: 4px 0;
}

.diagnosis-loading-inline h1 {
    margin: 0 0 12px;
    color: var(--text-brand);
    font-size: calc(var(--app-content-font-size) * 1.35);
}

.diagnosis-loading-inline p {
    margin: 8px 0;
    color: var(--text-main);
    line-height: 1.45;
}

.diagnosis-loading-subtext {
    color: var(--text-muted) !important;
    font-size: var(--app-secondary-font-size);
}

.diagnosis-loading-dots,
.homedoc-thinking-dots-only {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.diagnosis-loading-dots {
    margin-left: 4px;
    vertical-align: middle;
}

.diagnosis-loading-dots span,
.homedoc-thinking-dots-only span {
    display: block;
    border-radius: 999px;
    background: var(--text-brand);
    opacity: 0.35;
}

.diagnosis-loading-dots span {
    width: 5px;
    height: 5px;
    animation: diagnosisDotFade 1.2s infinite ease-in-out;
}

.diagnosis-loading-dots span:nth-child(2),
.homedoc-thinking-dots-only span:nth-child(2) {
    animation-delay: 0.18s;
}

.diagnosis-loading-dots span:nth-child(3),
.homedoc-thinking-dots-only span:nth-child(3) {
    animation-delay: 0.36s;
}

@keyframes diagnosisDotFade {

    0%,
    80%,
    100% {
        opacity: 0.25;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

/* ---------------- HomeDoc thinking dots ---------------- */

.homedoc-thinking-dots-only {
    justify-content: flex-start;
    margin: 0;
    padding: 2px;
    gap: 5px;
    line-height: 1;
    vertical-align: top;
}

.homedoc-thinking-dots-only span {
    width: 6px;
    height: 6px;
    animation: homedocThinkingDotFade 1.4s infinite ease-in-out;
}

@keyframes homedocThinkingDotFade {

    0%,
    80%,
    100% {
        opacity: 0.25;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

/* ---------------- Font-size modes ---------------- */

body.font-size-small {
    --app-content-font-size: 14px;
    --app-content-line-height: 1.45;
    --app-input-line-height: 18px;
    --app-secondary-font-size: 14px;
}

body.font-size-medium {
    --app-content-font-size: 20px;
    --app-content-line-height: 1.35;
    --app-input-line-height: 24px;
    --app-secondary-font-size: 14px;
}

body.font-size-large {
    --app-content-font-size: 24px;
    --app-content-line-height: 1.35;
    --app-input-line-height: 30px;
    --app-secondary-font-size: 17px;
}

/* ---------------- Desktop side-panel layout ---------------- */

@media (min-width: 960px) {
    #layout.medical-menu-open #medicalMenuWindow.show-content {
        width: 40%;
    }

    #layout.top-menu-open #inputWrap,
    #layout.medical-menu-open #inputWrap {
        padding: 20px var(--chat-side-pad);
    }

    #layout.top-menu-open #inputRow,
    #layout.medical-menu-open #inputRow {
        width: 100%;
    }

    #layout.top-menu-open #chat .bot,
    #layout.medical-menu-open #chat .bot,
    #layout.top-menu-open #chat .user-message-group,
    #layout.medical-menu-open #chat .user-message-group {
        max-width: 100%;
    }
}

/* ---------------- Mobile ---------------- */

@media (max-width: 959px) {
    :root {
        --chat-side-pad: 18px;
        --input-text-padding-y: 6px;
        --input-text-padding-x: 4px;
    }

    html,
    body {
        width: 100%;
        min-height: 100dvh;
        overflow: hidden;
    }

    #layout,
    #main {
        height: 100dvh;
    }

    #chat {
        padding: 54px var(--chat-side-pad) 8px;
    }

    .msg {
        margin: 1px 0;
        padding: 8px 11px;
        border-radius: 12px;
    }

    .bot,
    .user-message-group {
        max-width: 100%;
    }

    .bot-content p {
        margin: 0 0 3px;
    }

    .bot-content ul,
    .bot-content ol {
        margin: 4px 0 5px;
        padding-left: 19px;
    }

    .bot-content li {
        margin: 0 0 1px;
    }

    .bot-content h1,
    .bot-content h2,
    .bot-content h3 {
        margin: 5px 0 3px;
    }

    .user-message-group {
        margin: 2px 0;
    }

    .message-attachment {
        max-width: min(280px, calc(100vw - 60px));
        margin-top: 2px;
        font-size: 0.8rem;
    }

    #inputWrap {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    }

    #inputRow {
        width: 100%;
        max-width: none;
    }

    #inputBox {
        width: 100%;
        padding: 5px 7px;
        gap: 6px;
        border-radius: 12px;
    }

    #sendBtn {
        padding: 6px 10px;
        border-radius: 9px;
        font-size: 18px;
    }

    #fileBtn {
        width: 28px;
        height: 28px;
        font-size: 17px;
    }

    #topMenuButton,
    #medicalMenuButton {
        padding: 9px 11px;
        font-size: 14px;
    }

    #layout.top-menu-open #topMenuWindow,
    #layout.medical-menu-open #medicalMenuWindow {
        position: fixed;
        inset: 0;
        z-index: 250;
        display: flex;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        gap: 0;
        border: 0;
        overflow: hidden;
        box-shadow: none;
    }

    #topMenuWindow,
    #medicalMenuWindow {
        padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
    }

    .menuWindowHeader {
        position: sticky;
        top: 0;
        z-index: 4;
        display: flex;
        padding-bottom: 10px;
        background: var(--bg-panel);
    }

    #topMenuWindow.show-content .menuWindowHeader,
    #medicalMenuWindow.show-content .menuWindowHeader {
        display: none;
    }

    #topMenuWindow .menuCloseButton,
    #medicalMenuWindow .menuCloseButton,
    #topMenuContentHeader .menuCloseButton,
    #medicalMenuContentHeader .menuCloseButton {
        display: inline-flex;
    }

    #topMenuButtons,
    #medicalMenuButtons {
        flex: 1;
        min-height: 0;
        padding-bottom: calc(18px + env(safe-area-inset-bottom));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #topMenuWindow.show-content #topMenuContent,
    #medicalMenuWindow.show-content #medicalMenuContent {
        display: flex;
        flex: 1;
        flex-direction: column;
        min-height: 0;
        overflow: hidden;
    }

    #topMenuContentHeader,
    #medicalMenuContentHeader {
        position: sticky;
        top: 0;
        z-index: 5;
        flex-shrink: 0;
        margin-bottom: 0;
        padding-bottom: 10px;
        background: var(--bg-panel);
    }

    .menuPage.active,
    .medicalPage.active {
        flex: 1;
        min-height: 0;
        padding: 12px 2px calc(24px + env(safe-area-inset-bottom));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    body.top-menu-open,
    body.medical-menu-open {
        overflow: hidden;
    }

    #topMenuWindow button,
    #medicalMenuWindow button,
    #savePatient,
    #closeModal {
        padding: 10px 11px;
        border-radius: 11px;
        font-size: 14px;
    }

    .modalContent {
        width: calc(100vw - 32px);
        max-width: none;
        padding: 18px;
        box-sizing: border-box;
    }

    #patientName {
        font-size: 16px;
    }

    .selected-file-label {
        max-width: calc(100vw - 40px);
    }
}

@media (max-width: 420px) {
    :root {
        --chat-side-pad: 12px;
    }

    .msg {
        padding: 7px 10px;
    }

    .user-message-group {
        margin: 1px 0;
    }
}
