.site-header__title-short,
.home-visit-list {
    display: none;
}

.kpi-grid--home {
    grid-template-columns: minmax(0, 1fr);
}

.kpi-card--summary {
    display: grid;
    grid-template-columns: minmax(180px, 0.7fr) minmax(0, 2.3fr);
    align-items: center;
    gap: 18px;
}

.kpi-summary__main,
.kpi-summary__breakdown {
    min-width: 0;
}

.kpi-summary__breakdown {
    padding-left: 18px;
    border-left: 1px solid var(--border);
}

.kpi-summary__breakdown-label {
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: 600;
}

.kpi-summary__items {
    display: grid;
    gap: 8px;
}

.kpi-summary__items--visits {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
}

.kpi-summary__items--doctors {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.kpi-summary__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #f8fafc;
}

.kpi-summary__item-label,
.kpi-active-doctor__name.tag-doctor {
    display: inline-block;
    min-width: 0;
    padding: 3px 7px;
    border-radius: 7px;
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.25;
}

.kpi-summary__item--planned .kpi-summary__item-label {
    color: #0f766e;
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
}

.kpi-summary__item--done .kpi-summary__item-label {
    color: #047857;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
}

.kpi-summary__item-value {
    color: var(--accent-purple);
    font-size: 22px;
    line-height: 1;
}

.kpi-summary__item--planned .kpi-summary__item-value {
    color: var(--accent);
}

.kpi-summary__item--done .kpi-summary__item-value {
    color: var(--success);
}

.kpi-active-doctors__empty {
    align-self: center;
    color: var(--text-secondary);
    font-size: var(--text-xs);
}

@media (max-width: 768px),
    (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
    :root {
        --space-page-x: 12px;
        --space-page-y: 14px;
        --space-grid: 10px;
    }

    .site-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 10px;
        min-height: 64px;
        padding: 9px max(12px, env(safe-area-inset-right, 0px))
            9px max(12px, env(safe-area-inset-left, 0px));
        box-shadow: none;
    }

    .site-header__brand {
        min-width: 0;
        gap: 10px;
    }

    .site-header__logo {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        font-size: 17px;
    }

    .site-header__title {
        min-width: 0;
        max-width: none;
        font-size: 14px;
        line-height: 1.2;
    }

    .site-header__title-full {
        display: none;
    }

    .site-header__title-short {
        display: block;
    }

    .site-header__user {
        display: grid;
        grid-template-columns: auto auto;
        align-items: baseline;
        gap: 1px 8px;
        line-height: 1.2;
    }

    .site-header__user-name {
        grid-column: 1 / -1;
        max-width: 126px;
        font-size: 12px;
    }

    .site-header__logout,
    .site-header__meta strong {
        font-size: 11px;
        white-space: nowrap;
    }

    .site-tabs {
        position: sticky;
        top: 0;
        z-index: 100;
        min-height: 46px;
        padding: 0 8px;
        gap: 2px;
        scroll-padding-inline: 8px;
        scroll-snap-type: x proximity;
        transition: box-shadow 0.15s ease;
    }

    .site-tabs.can-scroll-left.can-scroll-right {
        box-shadow: inset 14px 0 12px -14px rgba(255, 255, 255, 0.8),
            inset -14px 0 12px -14px rgba(255, 255, 255, 0.8);
    }

    .site-tabs.can-scroll-left:not(.can-scroll-right) {
        box-shadow: inset 14px 0 12px -14px rgba(255, 255, 255, 0.8);
    }

    .site-tabs.can-scroll-right:not(.can-scroll-left) {
        box-shadow: inset -14px 0 12px -14px rgba(255, 255, 255, 0.8);
    }

    .site-tabs__link {
        min-height: 46px;
        padding: 9px 11px;
        border-radius: 8px 8px 0 0;
        font-size: 12.5px;
        scroll-snap-align: center;
    }

    .page {
        padding: 14px 12px max(32px, env(safe-area-inset-bottom, 0px));
    }

    .page-title {
        font-size: 20px;
        line-height: 1.25;
    }

    .page-subtitle {
        margin-bottom: 14px;
        font-size: 12.5px;
        line-height: 1.4;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        margin-bottom: 14px;
    }

    .kpi-grid--home {
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
    }

    .kpi-card {
        min-width: 0;
        padding: 12px;
        border-radius: 11px;
    }

    .kpi-card__label {
        min-height: 2.4em;
        margin-bottom: 7px;
        font-size: 12px;
        line-height: 1.2;
    }

    .kpi-card__value {
        font-size: 30px;
    }

    .kpi-card__hint {
        margin-top: 6px;
        font-size: 10.5px;
        line-height: 1.3;
    }

    .kpi-card--summary {
        grid-template-columns: 88px minmax(0, 1fr);
        gap: 10px;
        min-height: 122px;
        padding: 12px;
    }

    .kpi-card--summary .kpi-card__label {
        min-height: 0;
        margin-bottom: 6px;
        font-size: 11px;
        line-height: 1.2;
    }

    .kpi-card--summary .kpi-card__value {
        font-size: 32px;
    }

    .kpi-summary__breakdown {
        padding-left: 10px;
    }

    .kpi-summary__breakdown-label {
        margin-bottom: 6px;
        font-size: 9.5px;
    }

    .kpi-summary__items {
        gap: 5px;
    }

    .kpi-summary__items--visits {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .kpi-summary__items--doctors {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .kpi-summary__item {
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        min-height: 66px;
        padding: 5px 3px;
        text-align: center;
    }

    .kpi-summary__item-label,
    .kpi-active-doctor__name.tag-doctor {
        display: block;
        width: 100%;
        padding: 3px 2px;
        font-size: 9px;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .kpi-summary__item-value {
        font-size: 19px;
    }

    .grid-2,
    .grid-2-1 {
        gap: 12px;
        margin-bottom: 12px;
    }

    .card {
        border-radius: 12px;
    }

    .card__header {
        padding: 13px 14px;
        gap: 8px 10px;
    }

    .card__title {
        font-size: 16px;
        line-height: 1.3;
    }

    .card__subtitle {
        line-height: 1.35;
    }

    .card__body {
        padding: 12px 14px 14px;
    }

    .home-charts-grid > .card > .card__header > .btn {
        width: auto;
        min-height: 36px;
        padding: 7px 11px;
        font-size: 12px;
    }

    #home-schedule-card > .card__header {
        flex-wrap: nowrap;
        align-items: center;
    }

    .home-schedule-wrap {
        display: block;
        flex: none !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        padding: 10px 12px 12px;
        overflow: visible !important;
    }

    #home-schedule-card {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
    }

    #home-schedule-card > .card__body {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    .home-schedule-wrap .day-filters {
        display: block;
        width: 100%;
        margin-bottom: 8px;
        padding: 8px 9px !important;
        border-color: #e2e8f0;
        border-radius: 10px;
        background: #f8fafc;
        box-shadow: none;
    }

    .home-schedule-wrap .day-filters__section {
        display: block;
        align-items: flex-start;
        gap: 7px;
    }

    .home-schedule-wrap .day-filters__label {
        display: block;
        margin-bottom: 6px;
        padding-top: 0;
        font-size: 11px;
    }

    .home-schedule-wrap .day-filters__chips {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
        gap: 5px;
    }

    .home-schedule-wrap .day-filter-chip--doctor {
        width: 100%;
        min-height: 32px;
        padding: 4px;
        border-radius: 8px;
        font-size: 10.5px;
    }

    .home-schedule-wrap .day-filter-meta {
        margin: 1px 2px 8px;
        font-size: 11px;
        line-height: 1.3;
    }

    #schedule-table {
        display: block !important;
        flex: none !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    #schedule-table > .schedule-table-wrap {
        display: none;
    }

    .home-visit-list {
        display: grid !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        gap: 7px;
    }

    .home-visit-card {
        position: relative;
        min-width: 0;
        padding: 8px 9px;
        border: 1px solid var(--border);
        border-left-width: 3px;
        border-radius: 10px;
        background: #ffffff;
        box-shadow: 0 1px 5px rgba(15, 45, 82, 0.04);
    }

    .home-visit-card--done {
        border-left-color: #34d399;
    }

    .home-visit-card--planned {
        border-left-color: #60a5fa;
    }

    .home-visit-card--other {
        border-left-color: #cbd5e1;
    }

    .home-visit-card__header {
        display: grid;
        grid-template-columns: 24px minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        min-height: 32px;
    }

    .home-visit-card__number {
        display: grid;
        place-items: center;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background: #eef2f7;
        color: #475569;
        font-size: 10px;
        font-weight: 700;
    }

    .home-visit-card .home-patient-cell {
        display: inline-flex;
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: flex-start;
        gap: 1px;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        background: transparent;
        color: inherit;
        font-size: 13px;
        font-family: inherit;
        font-weight: 500;
        line-height: 1.2;
        text-align: left;
    }

    .home-visit-card .home-patient-cell__name {
        white-space: normal;
        font-weight: 600;
    }

    .home-visit-card .home-patient-cell__id {
        color: var(--text-secondary);
        font-size: 10px;
        font-weight: 400;
        line-height: 1.1;
    }

    .home-visit-card__status .journal-cell-editable {
        width: auto;
    }

    .home-visit-card__status .badge {
        padding: 3px 7px;
        font-size: 10px;
        line-height: 1.2;
    }

    .home-visit-card__details {
        display: grid;
        grid-template-columns: minmax(110px, 1fr) auto;
        align-items: center;
        gap: 5px 10px;
        margin-top: 4px;
        padding-top: 5px;
        border-top: 1px solid #edf1f5;
    }

    .home-visit-card__detail {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 4px;
        min-width: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    .home-visit-card__detail-value {
        display: flex;
        align-items: center;
        min-width: 0;
        min-height: 0;
        max-width: 100%;
    }

    .home-visit-card__regimen .tag-regimen,
    .home-visit-card__doctor .tag-doctor {
        display: inline-block;
        max-width: 100%;
        padding: 2px 5px;
        font-size: 10.5px;
        line-height: 1.2;
        white-space: normal;
    }

    .home-visit-card__meta-label {
        color: var(--text-secondary);
        flex: 0 0 auto;
        font-size: 8.5px;
        font-weight: 600;
        line-height: 1;
        text-transform: uppercase;
        letter-spacing: 0.06em;
    }

    .home-visit-card__doctor .journal-cell-editable {
        width: auto;
    }

    .home-visit-card__notes {
        grid-column: 1 / -1;
        align-items: flex-start;
        padding-top: 5px;
        border-top: 1px dashed #e2e8f0;
    }

    .home-visit-card__notes .home-visit-card__detail-value {
        display: block;
        min-height: 0;
        max-width: 100%;
        padding: 0;
        background: transparent;
        color: #475569;
        font-size: 10.5px;
        line-height: 1.3;
        white-space: normal;
    }

    .workload-calendar {
        grid-auto-rows: minmax(48px, auto);
        gap: 3px;
    }

    .workload-calendar__cell {
        min-height: 48px;
        padding: 3px;
    }

    .workload-calendar__pct {
        display: none;
    }

    .workload-legend {
        gap: 6px 10px;
        font-size: 11px;
    }
}

@media (max-width: 360px) {
    .site-header__user-name {
        max-width: 104px;
    }

    .site-header__title {
        font-size: 13px;
    }

    .site-tabs__link {
        padding-inline: 9px;
        font-size: 12px;
    }

    .kpi-card {
        padding: 10px;
    }

    .kpi-card__value {
        font-size: 28px;
    }

    .kpi-card--summary {
        grid-template-columns: 82px minmax(0, 1fr);
        gap: 8px;
        padding: 10px;
    }

    .kpi-summary__breakdown {
        padding-left: 8px;
    }

    .kpi-summary__item-label,
    .kpi-active-doctor__name.tag-doctor {
        font-size: 11px;
    }

    .kpi-summary__item-value {
        font-size: 18px;
    }

    .home-visit-card__header {
        grid-template-columns: 23px minmax(0, 1fr) auto;
        gap: 7px;
    }

    .home-visit-card__number {
        width: 23px;
        height: 23px;
        font-size: 9.5px;
    }

    .home-visit-card__details {
        grid-template-columns: minmax(100px, 1fr) auto;
        gap: 5px 8px;
    }

    .home-visit-card__regimen .tag-regimen,
    .home-visit-card__doctor .tag-doctor {
        padding-inline: 4px;
        font-size: 10px;
    }

    #home-schedule-card .card__title {
        font-size: 15px;
    }

    #home-schedule-card > .card__header > .btn {
        min-height: 32px;
        padding: 6px 8px;
        font-size: 10.5px;
    }
}

/* ── Mobile application layer ──────────────────────────────────────────────
   Everything below is deliberately scoped to phone/tablet viewports so that
   the desktop presentation remains unchanged. */
@media (max-width: 768px),
    (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
    :root {
        --mobile-control-height: 44px;
        --mobile-readable-xs: 11px;
        --mobile-readable-sm: 12px;
        --mobile-card-gap: 9px;
    }

    body {
        font-size: 14px;
        line-height: 1.45;
        overflow-wrap: anywhere;
    }

    .site-header {
        padding-top: max(9px, env(safe-area-inset-top, 0px));
    }

    .site-header__logout {
        display: inline-flex;
        align-items: center;
        justify-content: flex-end;
        min-width: 44px;
        min-height: 40px;
        padding: 6px 0 6px 8px;
    }

    /* All primary destinations stay visible; no hidden horizontal menu. */
    .site-tabs {
        display: grid;
        grid-template-columns: repeat(var(--mobile-nav-columns, 5), minmax(0, 1fr));
        grid-auto-flow: row;
        width: 100%;
        min-height: 50px;
        padding: 0 4px;
        gap: 0;
        overflow: visible;
        scroll-snap-type: none;
        box-shadow: none !important;
    }

    .site-tabs__link {
        justify-content: center;
        min-width: 0;
        min-height: 50px;
        padding: 8px 2px;
        border-radius: 0;
        font-size: clamp(11px, 3vw, 12px);
        line-height: 1.15;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .site-tabs__link.is-active {
        box-shadow: inset 0 -3px 0 var(--accent);
    }

    .page {
        width: 100%;
        max-width: none;
    }

    .page-title {
        margin-bottom: 3px;
        font-size: 21px;
        line-height: 1.2;
    }

    .page-subtitle {
        font-size: 13px;
        line-height: 1.4;
    }

    .card__subtitle,
    .meta,
    .day-filter-meta {
        font-size: var(--mobile-readable-sm);
        line-height: 1.4;
    }

    .btn,
    button,
    select,
    input:not([type="hidden"]),
    textarea {
        touch-action: manipulation;
    }

    .form-field input,
    .form-field select,
    .form-field textarea,
    .auth-form input,
    .auth-form select,
    .auth-form textarea {
        min-height: var(--mobile-control-height);
        font-size: 16px;
    }

    .auth-page {
        padding: 16px;
    }

    .auth-card {
        padding: 20px;
    }

    .btn,
    .day-filter-chip,
    .journal-view-tab,
    .journal-period-nav__btn,
    .side-cal__nav button,
    .side-cal__today-btn,
    .modal__close,
    .admin-matrix__toggle {
        min-height: var(--mobile-control-height);
    }

    .modal__close,
    .side-cal__nav button,
    .journal-period-nav__btn {
        min-width: var(--mobile-control-height);
        width: var(--mobile-control-height);
        height: var(--mobile-control-height);
    }

    /* Home: readable KPI labels without clipped doctor names. */
    .kpi-card--summary .kpi-card__label {
        font-size: 12px;
    }

    .kpi-summary__breakdown-label {
        font-size: 11px;
        line-height: 1.25;
    }

    .kpi-summary__item-label,
    .kpi-active-doctor__name.tag-doctor {
        font-size: 11px;
        line-height: 1.2;
    }

    .kpi-active-doctor__name.tag-doctor {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        overflow-wrap: anywhere;
    }

    .kpi-summary__item-value {
        font-size: 21px;
    }

    .home-schedule-wrap .day-filter-chip--doctor {
        min-height: var(--mobile-control-height);
        padding: 7px 10px;
        font-size: 12px;
    }

    .home-visit-card .home-patient-cell {
        font-size: 13.5px;
    }

    .home-visit-card .home-patient-cell__id {
        font-size: 11px;
    }

    .home-visit-card__status .badge,
    .home-visit-card__regimen .tag-regimen,
    .home-visit-card__doctor .tag-doctor,
    .home-visit-card__notes .home-visit-card__detail-value {
        font-size: 11.5px;
    }

    .home-visit-card__meta-label {
        font-size: 10px;
        letter-spacing: 0.04em;
    }

    .home-visit-card .patient-name-link {
        min-height: 36px;
        padding-block: 2px;
    }

    #home-schedule-card > .card__header > .btn {
        flex: 0 0 auto;
        min-width: 104px;
        min-height: 40px;
        padding: 8px 10px;
        font-size: 11.5px;
        line-height: 1.2;
        white-space: nowrap;
    }

    /* Patients: turn the wide desktop registry into readable mobile cards. */
    .patients-toolbar {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 12px;
    }

    .patients-toolbar__search {
        width: 100%;
        max-width: none;
    }

    .patients-search-input {
        min-height: var(--mobile-control-height);
        font-size: 16px;
    }

    .patients-toolbar__right {
        justify-content: space-between;
        gap: 10px;
        width: 100%;
        margin-top: 0;
    }

    .patients-first-visit-filter,
    .patients-first-visit-filter__controls {
        width: 100%;
    }

    .patients-first-visit-filter {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
    }

    .patients-first-visit-filter__title {
        line-height: 20px;
    }

    .patients-first-visit-filter__controls input {
        width: 100%;
    }

    .patients-first-visit-filter__controls label {
        flex: 1;
    }

    .patients-toolbar__right .btn {
        flex: 0 1 auto;
    }

    .page--patients #patients-filters .day-filters {
        padding: 9px 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .page--patients #patients-table {
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    .page--patients #patients-table .schedule-table-wrap {
        padding: 0;
        overflow: visible;
    }

    .page--patients .schedule-table--layout-patients,
    .page--patients .schedule-table--layout-patients tbody,
    .page--patients .schedule-table--layout-patients tr,
    .page--patients .schedule-table--layout-patients td {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .page--patients .schedule-table--layout-patients {
        min-width: 0;
        border: 0;
        background: transparent;
    }

    .page--patients .schedule-table--layout-patients colgroup,
    .page--patients .schedule-table--layout-patients thead {
        display: none;
    }

    .page--patients .schedule-table--layout-patients tbody {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: var(--mobile-card-gap);
    }

    .page--patients .schedule-table--layout-patients .patients-row {
        position: relative;
        display: grid;
        width: 100% !important;
        inline-size: 100%;
        grid-template-columns: 28px minmax(0, 1fr) auto;
        gap: 2px 8px;
        padding: 11px 12px;
        border: 1px solid var(--border);
        border-left: 3px solid #93c5fd;
        border-radius: 11px;
        background: #fff;
        box-shadow: 0 1px 4px rgba(15, 45, 82, 0.05);
    }

    .page--patients .patients-row td {
        padding: 0;
        border: 0;
        overflow: visible;
        text-overflow: clip;
        white-space: normal;
    }

    .page--patients .patients-row .tag-name,
    .page--patients .patients-row .tag-regimen,
    .page--patients .patients-row .tag-doctor,
    .page--patients .patients-row .tag-id,
    .page--patients .patients-row .flow-status,
    .page--journal #journal-content .tag-name,
    .page--journal #journal-content .tag-regimen,
    .page--journal #journal-content .tag-doctor,
    .page--journal #journal-content .tag-id,
    .page--journal #journal-content .tag-notes,
    .page--journal #journal-content .badge {
        display: inline-block;
        max-width: 100%;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        overflow-wrap: anywhere;
    }

    .page--journal #journal-content .patient-name-link {
        width: 100%;
        height: auto;
        line-height: 1.3;
        white-space: normal;
    }

    .page--patients .patients-row .col-num {
        grid-column: 1;
        grid-row: 1 / span 2;
        display: grid;
        place-items: center;
        width: 26px;
        height: 26px;
        border-radius: 50%;
        background: #eef2f7;
        color: #475569;
        font-size: 11px;
        font-weight: 700;
    }

    .page--patients .patients-row .col-name {
        grid-column: 2;
        grid-row: 1;
        font-size: 14px;
        font-weight: 600;
    }

    .page--patients .patients-row .col-id {
        grid-column: 2;
        grid-row: 2;
        font-size: 11px;
    }

    .page--patients .patients-row .col-status {
        grid-column: 3;
        grid-row: 1 / span 2;
        align-self: center;
    }

    .page--patients .patients-row .col-doctor,
    .page--patients .patients-row .col-regimen,
    .page--patients .patients-row .col-date,
    .page--patients .patients-row .col-visits {
        display: grid;
        grid-template-columns: 1fr;
        align-items: baseline;
        gap: 3px;
        padding-top: 7px;
        border-top: 1px solid #edf1f5;
        font-size: 12px;
    }

    .page--patients .patients-row .col-regimen {
        grid-column: 2 / 3;
        grid-row: 3;
    }

    .page--patients .patients-row .col-doctor {
        grid-column: 3;
        grid-row: 3;
    }

    .page--patients .patients-row .col-date {
        grid-column: 2 / 3;
        grid-row: 4;
    }

    .page--patients .patients-row .col-visits {
        grid-column: 3;
        grid-row: 4;
    }

    .page--patients .patients-row .col-doctor::before { content: "Врач"; }
    .page--patients .patients-row .col-regimen::before { content: "Режим"; }
    .page--patients .patients-row .col-date::before { content: "Визит"; }
    .page--patients .patients-row .col-visits::before { content: "Визитов"; }

    .page--patients .patients-row .col-doctor::before,
    .page--patients .patients-row .col-regimen::before,
    .page--patients .patients-row .col-date::before,
    .page--patients .patients-row .col-visits::before {
        color: var(--text-secondary);
        font-size: 10px;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    /* Journal: schedule first, calendar second, records as cards. */
    .page--journal .journal-layout {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .page--journal .journal-main {
        order: 1;
        min-height: 0;
    }

    .page--journal .journal-sidebar {
        order: 2;
    }

    .page--journal .journal-sidebar .card {
        position: static;
    }

    .journal-toolbar {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
        margin-bottom: 10px;
    }

    .journal-view-tabs {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        width: 100%;
    }

    .journal-view-tab {
        min-width: 0;
        padding: 8px 4px;
        font-size: 12px;
    }

    .journal-week-layout {
        justify-content: space-between;
    }

    .journal-week-layout .journal-view-tabs {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: min(220px, 70%);
    }

    .journal-total-badge {
        justify-self: start;
        margin-left: 0;
        padding: 6px 10px;
        font-size: 12px;
    }

    .journal-day-header,
    .journal-period-header {
        padding: 12px;
    }

    .journal-day-header h2,
    .journal-period-header h2 {
        font-size: 17px;
    }

    .page--journal #journal-content .schedule-table-wrap {
        padding: 10px;
        overflow: visible;
    }

    .page--journal #journal-content .schedule-table,
    .page--journal #journal-content .schedule-table tbody,
    .page--journal #journal-content .schedule-table tr,
    .page--journal #journal-content .schedule-table td {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .page--journal #journal-content .schedule-table {
        min-width: 0;
        border: 0;
        background: transparent;
    }

    .page--journal #journal-content .schedule-table colgroup,
    .page--journal #journal-content .schedule-table thead {
        display: none;
    }

    .page--journal #journal-content .schedule-table tbody {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: var(--mobile-card-gap);
    }

    .page--journal #journal-content .schedule-table tr {
        position: relative;
        display: grid;
        width: 100% !important;
        inline-size: 100%;
        grid-template-columns: 28px minmax(0, 1fr) auto;
        gap: 2px 8px;
        padding: 11px 12px;
        border: 1px solid var(--border);
        border-left: 3px solid #60a5fa;
        border-radius: 11px;
        background: #fff;
        box-shadow: 0 1px 4px rgba(15, 45, 82, 0.05);
    }

    .page--journal #journal-content .schedule-table td {
        padding: 0;
        border: 0;
        overflow: visible;
        text-overflow: clip;
        white-space: normal;
    }

    .page--journal #journal-content .schedule-table .col-num {
        grid-column: 1;
        grid-row: 1 / span 2;
        display: grid;
        place-items: center;
        width: 26px;
        height: 26px;
        border-radius: 50%;
        background: #eef2f7;
        color: #475569;
        font-size: 11px;
        font-weight: 700;
    }

    .page--journal #journal-content .schedule-table .col-name {
        grid-column: 2;
        grid-row: 1;
        font-size: 14px;
        font-weight: 600;
    }

    .page--journal #journal-content .schedule-table .col-id {
        grid-column: 2;
        grid-row: 2;
        font-size: 11px;
    }

    .page--journal #journal-content .schedule-table .col-status {
        grid-column: 3;
        grid-row: 1 / span 2;
        align-self: center;
    }

    .page--journal #journal-content .schedule-table .col-date,
    .page--journal #journal-content .schedule-table .col-regimen,
    .page--journal #journal-content .schedule-table .col-doctor,
    .page--journal #journal-content .schedule-table .col-notes,
    .page--journal #journal-content .schedule-table .col-visit-action {
        display: grid;
        grid-template-columns: 1fr;
        align-items: baseline;
        gap: 3px;
        padding-top: 7px;
        border-top: 1px solid #edf1f5;
        font-size: 12px;
    }

    .page--journal #journal-content .schedule-table .col-date {
        display: none;
    }

    .page--journal #journal-content .schedule-table .col-regimen {
        grid-column: 1 / 3;
        grid-row: 3;
    }

    .page--journal #journal-content .schedule-table .col-doctor {
        grid-column: 3;
        grid-row: 3;
    }

    .page--journal #journal-content .schedule-table .col-notes {
        grid-column: 1 / -1;
        grid-row: 4;
    }

    .page--journal #journal-content .schedule-table .col-visit-action {
        grid-column: 1 / -1;
        grid-row: 5;
    }

    .page--journal #journal-content .schedule-table .col-date::before { content: "Дата"; }
    .page--journal #journal-content .schedule-table .col-regimen::before { content: "Режим"; }
    .page--journal #journal-content .schedule-table .col-doctor::before { content: "Врач"; }
    .page--journal #journal-content .schedule-table .col-notes::before { content: "Примечание"; }
    .page--journal #journal-content .schedule-table .col-visit-action::before { content: "Следующий"; }

    .page--journal #journal-content .schedule-table td::before {
        color: var(--text-secondary);
        font-size: 10px;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    /* Journal day cards use the same compact visual language as Home. */
    .page--journal #journal-content .schedule-table-wrap {
        display: none;
    }

    .page--journal #journal-content .journal-visit-list {
        display: grid !important;
        gap: 7px;
        padding: 10px;
    }

    .page--journal #journal-content .journal-week-row-body .journal-visit-list {
        padding: 0;
    }

    .page--journal #journal-content .journal-visit-card .journal-cell-editable {
        width: auto;
        max-width: 100%;
    }

    .page--journal #journal-content .journal-visit-card .home-visit-card__regimen,
    .page--journal #journal-content .journal-visit-card .home-visit-card__doctor,
    .page--journal #journal-content .journal-visit-card .home-visit-card__resident,
    .page--journal #journal-content .journal-visit-card .home-visit-card__extimia {
        min-width: 0;
    }

    .page--journal #journal-content .journal-visit-card .home-visit-card__details {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: start;
    }

    .page--journal #journal-content .journal-visit-card .home-visit-card__regimen .journal-cell-editable,
    .page--journal #journal-content .journal-visit-card .home-visit-card__doctor .journal-cell-editable,
    .page--journal #journal-content .journal-visit-card .resident-trigger {
        display: inline-flex;
        min-height: 32px;
        align-items: center;
    }

    .page--journal #journal-content .journal-visit-card .home-visit-card__resident,
    .page--journal #journal-content .journal-visit-card .home-visit-card__extimia {
        padding-top: 5px;
        border-top: 1px dashed #e2e8f0;
    }

    .page--journal #journal-content .journal-visit-card .resident-field,
    .page--journal #journal-content .journal-visit-card .extimia-field {
        max-width: 100%;
        font-size: 13px;
        line-height: 1.35;
    }

    .page--journal #journal-content .journal-visit-card .resident-trigger {
        max-width: 100%;
        padding: 0;
    }

    .page--journal #journal-content .journal-visit-card .resident-tag {
        max-width: 100%;
        padding: 4px 7px;
        font-size: 12px;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .page--journal #journal-content .journal-visit-card .extimia-field {
        min-height: 32px;
        flex-wrap: nowrap;
    }

    .page--journal #journal-content .journal-visit-card .extimia-field > span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }

    .page--journal #journal-content .journal-visit-card .extimia-field input {
        flex: 0 0 20px;
        width: 20px;
        height: 20px;
        margin: 0;
    }

    .page--journal #journal-content .patient-name-link,
    .page--patients .patients-row {
        min-height: 44px;
    }

    .journal-week-grid.is-columns,
    .journal-week-grid.is-rows {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 10px;
    }

    .journal-week-col,
    .journal-week-row {
        min-width: 0;
    }

    .journal-month-grid,
    .journal-month-weekdays {
        gap: 2px;
        padding-inline: 8px;
    }

    .journal-month-cell {
        min-height: 48px;
        padding: 3px 2px;
    }

    .journal-month-count {
        font-size: 11px;
    }

    .journal-month-count-label {
        font-size: 9px;
    }

    .journal-year-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding: 10px;
    }

    /* Modals become full-height mobile sheets and remain usable with keyboard. */
    .modal {
        align-items: stretch;
        padding: 0;
    }

    .modal__dialog,
    .modal__dialog--schedule,
    .modal__dialog--wide {
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: 100dvh;
        border-radius: 0;
    }

    .modal__header {
        flex: 0 0 auto;
        padding: max(10px, env(safe-area-inset-top, 0px)) 14px 10px;
    }

    .modal__body,
    .modal__dialog--wide .modal__body {
        flex: 1 1 auto;
        min-height: 0;
        padding: 14px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal__footer {
        position: sticky;
        bottom: 0;
        flex: 0 0 auto;
        padding: 10px 14px max(10px, env(safe-area-inset-bottom, 0px));
        background: #fff;
    }

    .modal__footer .btn {
        flex: 1;
    }

    .patient-card-visits__header {
        flex-direction: column;
        align-items: stretch;
    }

    .patient-card-visits__actions {
        justify-content: stretch;
    }

    .patient-card-visits__actions .btn {
        flex: 1 1 140px;
    }

    /* Analytics and operational dashboards: compact controls, readable charts. */
    .analytics-hub-grid,
    .grid-2.analytics-hub-grid,
    .workload-charts-grid,
    .pharmacy-chart-grid {
        grid-template-columns: 1fr;
    }

    .analytics-hub-card .card__header {
        flex-direction: row;
        align-items: flex-start;
    }

    .analytics-card-preview {
        min-height: 170px;
        max-height: 190px;
    }

    .controls,
    .forecast-fields,
    .forecast-chart-actions,
    .pharmacy-toolbar,
    .pharmacy-chart-controls,
    .pharmacy-table-tools,
    .workload-chart-controls {
        width: 100%;
        align-items: stretch;
    }

    .controls .controls-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
        gap: 8px;
        flex: 0 0 100%;
    }

    .controls .controls-actions #period-picker-mount,
    .controls .controls-actions .period-pickers {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-column: 1 / -1;
        grid-row: 1;
        width: 100%;
        gap: 6px;
        flex: none;
    }

    .controls .controls-actions .period-picker,
    .controls .controls-actions .period-picker__trigger,
    .controls .controls-actions > .controls-action-btn {
        width: 100%;
        min-width: 0;
    }

    .controls .controls-actions .period-picker__trigger,
    .controls .controls-actions > .controls-action-btn {
        min-height: var(--mobile-control-height);
        padding-inline: 8px;
    }

    .controls > .controls-action-btn {
        width: auto !important;
        min-width: 0;
        min-height: var(--mobile-control-height);
        flex: 1 1 calc(50% - 4px);
    }

    .controls > a.btn {
        width: 100%;
        min-height: var(--mobile-control-height);
        margin-left: 0 !important;
    }

    .controls label,
    .forecast-fields label,
    .forecast-chart-view,
    .pharmacy-toolbar label,
    .pharmacy-chart-controls label,
    .workload-chart-controls label {
        width: 100%;
        align-items: stretch;
        white-space: normal;
    }

    .controls select,
    .controls input,
    .forecast-fields input,
    .forecast-fields select,
    .forecast-chart-view select,
    .pharmacy-toolbar select,
    .pharmacy-toolbar input,
    .pharmacy-chart-controls select,
    .pharmacy-search input,
    .workload-chart-controls select {
        width: 100%;
        min-height: var(--mobile-control-height);
        font-size: 16px;
    }

    .forecast-range-label {
        width: 100%;
        min-width: 0;
        white-space: normal;
    }

    .forecast-range-label strong {
        flex: 0 0 auto;
    }

    .therapy-progress-row__link.patient-name-link,
    .active-cycles-row--clickable .patient-name-link {
        display: inline-flex;
        align-items: center;
        min-height: 36px;
        padding: 4px 6px;
    }

    .forecast-kpis,
    .pharmacy-kpis,
    .workload-kpi-grid,
    .dynamics-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .workload-kpi-grid .workload-kpi {
        padding: 10px;
        border-right: 1px solid var(--border, #e2e8f0);
    }

    .workload-kpi__label,
    .workload-kpi__hint {
        font-size: 11px;
    }

    .workload-kpi__value {
        font-size: 20px;
    }

    .chart-box,
    .chart-box--tall,
    .active-cycles-chart,
    .forecast-chart,
    .forecast-chart--drugs,
    .pharmacy-chart,
    .pharmacy-chart--main,
    #chart1,
    #chart2,
    #chart-daily,
    #chart-weekday,
    .workload-chart-panel {
        min-height: 300px !important;
        height: 300px !important;
    }

    .plotly .modebar-container {
        opacity: 0.72;
        transform: scale(0.88);
        transform-origin: top right;
    }

    .forecast-table,
    .admin-matrix {
        font-size: 12px;
    }

    .schedule-table-wrap,
    .admin-matrix-wrap {
        position: relative;
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .mobile-table-scroll-hint {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 30px;
        margin: 0 0 6px;
        padding: 5px 9px;
        border: 1px solid #dbe6f2;
        border-radius: 8px;
        background: #f8fafc;
        color: #64748b;
        font-size: 10.5px;
        font-weight: 500;
        line-height: 1.25;
        text-align: center;
    }

    .card__body--flush:has(> .data-table > tbody > tr:only-child > td[colspan]) {
        overflow-x: hidden;
    }

    .data-table:has(> tbody > tr:only-child > td[colspan]) {
        width: 100% !important;
        min-width: 0 !important;
    }

    .data-table:has(> tbody > tr:only-child > td[colspan]) thead {
        display: none;
    }

    .data-table:has(> tbody > tr:only-child > td[colspan]) tbody,
    .data-table:has(> tbody > tr:only-child > td[colspan]) tr,
    .data-table:has(> tbody > tr:only-child > td[colspan]) td {
        display: block;
        width: 100%;
    }

    .data-table:has(> tbody > tr:only-child > td[colspan]) td {
        padding: 24px 14px;
        border: 0;
        color: var(--text-secondary);
        text-align: center;
    }

    .forecast-table th:first-child,
    .forecast-table td:first-child,
    .admin-matrix th:first-child,
    .admin-matrix td:first-child {
        position: sticky;
        left: 0;
        z-index: 2;
        background: #fff;
        box-shadow: 1px 0 0 var(--border);
    }

    .pharmacy-kpis .kpi-card,
    .forecast-kpis .kpi-card {
        min-height: 112px;
        padding: 11px;
    }

    .pharmacy-kpis .kpi-card__value,
    .forecast-kpis .kpi-card__value {
        font-size: 25px;
    }

    .pharmacy-inventory-table input {
        width: 86px;
        min-height: var(--mobile-control-height);
        font-size: 16px;
    }

    .pharmacy-notice {
        flex-direction: column;
        align-items: stretch;
    }

    .admin-tabs {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }

    .admin-tabs__link {
        display: grid;
        place-items: center;
        min-height: var(--mobile-control-height);
        padding: 6px;
        font-size: 11px;
        line-height: 1.2;
        text-align: center;
    }

    .admin-approve-form {
        min-width: 150px;
    }

    .admin-matrix__toggle {
        min-width: var(--mobile-control-height);
        height: var(--mobile-control-height);
    }

    .pwa-install {
        max-width: calc(100vw - 24px);
    }
}

@media (max-width: 430px) {
    .kpi-summary__items--doctors {
        gap: 4px;
    }

    .kpi-summary__items--doctors .kpi-summary__item {
        padding-inline: 2px;
    }

    .kpi-summary__items--doctors .kpi-active-doctor__name.tag-doctor {
        padding-inline: 2px;
        font-size: clamp(9px, 2.55vw, 10.5px);
        white-space: nowrap;
        overflow-wrap: normal;
        word-break: normal;
    }
}

@media (max-width: 340px) {
    .kpi-summary__items--visits {
        grid-template-columns: 1fr;
    }

    .kpi-summary__items--visits .kpi-summary__item {
        flex-direction: row;
        justify-content: space-between;
        min-height: 32px;
        padding: 4px 6px;
        text-align: left;
    }

    .kpi-summary__items--visits .kpi-summary__item-label {
        width: auto;
        padding-inline: 5px;
        white-space: nowrap;
        overflow: visible;
        text-overflow: clip;
    }
}

@media (max-width: 360px) {
    .home-schedule-wrap .day-filters__chips {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .home-schedule-wrap .day-filter-chip--doctor:nth-child(odd):last-child {
        grid-column: 1 / -1;
    }

    .kpi-summary__items--doctors {
        grid-template-columns: 1fr;
    }

    .kpi-summary__items--doctors .kpi-summary__item {
        flex-direction: row;
        min-height: 31px;
        padding: 4px 6px;
        text-align: left;
    }

    .kpi-summary__items--doctors .kpi-active-doctor__name.tag-doctor {
        width: auto;
        padding: 2px 5px;
        overflow: visible;
        text-overflow: clip;
    }

    .home-visit-card__details {
        grid-template-columns: 1fr;
    }

    .home-visit-card__doctor,
    .home-visit-card__regimen {
        grid-column: 1;
    }

    .page--patients .patients-row .col-status,
    .page--journal #journal-content .schedule-table .col-status {
        grid-column: 2 / -1;
        grid-row: 3;
        justify-self: start;
        margin-top: 4px;
    }

    .page--patients .patients-row .col-regimen,
    .page--journal #journal-content .schedule-table .col-regimen {
        grid-row: 4;
    }

    .page--patients .patients-row .col-doctor,
    .page--journal #journal-content .schedule-table .col-doctor {
        grid-row: 4;
    }

    .page--patients .patients-row .col-date {
        grid-row: 5;
    }

    .page--patients .patients-row .col-visits {
        grid-row: 5;
    }

    .page--journal #journal-content .schedule-table .col-notes {
        grid-row: 5;
    }

    .page--journal #journal-content .schedule-table .col-visit-action {
        grid-row: 6;
    }

    .forecast-kpis,
    .pharmacy-kpis,
    .workload-kpi-grid,
    .dynamics-kpi-grid {
        gap: 8px !important;
    }
}
