/* Phone breakpoints follow the short screen side. */
/* Shared mobile navigation for the clinic, technician and chief-technician cabinets. */
.mobile-bottom-nav { display: none; }
.mobile-sidebar-logout { display: none; }
.mobile-drawer-backdrop { display: none; }

@media ((max-width: 900px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 900px))) {
  html, body, #app { width: 100%; max-width: 100%; overflow-x: hidden; }
  .sidebar {
    position: fixed;
    z-index: 60;
    inset: 0 auto 0 0;
    width: min(82vw, 290px);
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .shell, .tech-shell {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    padding: 0 16px calc(94px + env(safe-area-inset-bottom));
    overflow-x: hidden;
  }
  .content, .tech-content { width: 100%; max-width: 100%; min-width: 0; }
  .dashboard-grid, .dashboard-aside, .tech-analytics-grid,
  .tech-work-grid, .tech-team-grid, .clinic-content, .form-grid,
  .patient-fields, .order-builder, .detail-grid, .tech-detail-grid,
  .teeth-layout, .confirmation, .order-files-layout {
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
  }
  .order-builder { gap: 22px; }
  .order-draft { position: static; grid-column: auto; }
  .order-draft-card { grid-template-columns: 1fr; }
  .order-draft-card dl, .order-draft-card small { grid-column: auto; }
  .clinic-form .form-grid { max-width: none; }
  .tech-pricing-list { grid-template-columns: minmax(0, 1fr) !important; }
  .tech-sidebar { width: min(82vw, 290px); }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: 60px;
    margin: 0 -16px 14px;
    padding: 0 16px;
    gap: 9px;
    border-bottom: 1px solid var(--cd-night-edge,#f0f0f0);
    background: #fbfbfbf2;
    backdrop-filter: blur(10px);
  }
  .topbar .profile { max-width: 44px; overflow: hidden; padding: 0; }
  .topbar .profile > span:nth-child(2), .topbar .profile > svg,
  .topbar-label, .clinic-select { display: none; }
  .topbar .profile .avatar { width: 36px; height: 36px; }

  .mobile-bottom-nav {
    position: fixed;
    z-index: 55;
    inset: auto 0 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    gap: 2px;
    min-height: 64px;
    padding: 5px max(8px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    border-top: 1px solid var(--cd-night-edge,#e9e9e9);
    background: var(--cd-night-paper,#fff);
  }

  .mobile-bottom-item {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 50px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 4px 2px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--cd-night-secondary,#808080);
    font-size: 10px;
    font-weight: 550;
    line-height: 1.15;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-bottom-item svg { flex: 0 0 auto; }
  .mobile-bottom-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-bottom-item.active { background: var(--cd-night-hover,#f5f5f5); color: var(--cd-night-ink,#333); font-weight: 700; }
  .mobile-bottom-item[data-page="new"] { background: #707070; color: #fff; }
  .mobile-bottom-item:focus-visible { outline: 2px solid #808080; outline-offset: -2px; }
  .mobile-nav-count {
    position: absolute;
    top: 1px;
    right: max(2px, calc((100% - 54px) / 2));
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 9px;
    background: #333;
    color: #fff;
    font-size: 9px;
    font-style: normal;
    line-height: 16px;
  }

  .shell, .tech-shell { padding-bottom: calc(94px + env(safe-area-inset-bottom)); }
  .mobile-menu { display: none !important; }
  .sidebar.open { z-index: 70; box-shadow: 10px 0 30px #33333329; }
  .role-toggle { display: none !important; }
  .mobile-sidebar-logout {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    margin-top: 12px;
    padding: 0 13px;
    border: 1px solid #ededed;
    border-radius: 10px;
    background: #fff;
    color: #707070;
    font-size: 14px;
    font-weight: 600;
    text-align: left;
  }
  .tech-sidebar .mobile-sidebar-logout { margin-top: auto; }
  .tech-icon-btn, .tech-dialog-close, .more-btn,
  .work-picker-title > button, .order-cart article button,
  .surgical-socket-quantity button { min-width: 40px; min-height: 40px; }
  .tech-pricing-row input, .tech-pricing-row select { min-height: 44px; font-size: 16px; }
  .order-cart article { grid-template-columns: minmax(0, 1fr) 40px; }
  .order-cart article button { width: 40px; height: 40px; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 56; }

  html[data-theme="dark"] .mobile-bottom-nav { border-color: #343a41; background: #17191c; }
  html[data-theme="dark"] .mobile-bottom-item { color: #9da4ad; }
  html[data-theme="dark"] .mobile-bottom-item.active { background: #252a2f; color: #f0f1f2; }
  html[data-theme="dark"] .mobile-bottom-item[data-page="new"] { background: #808890; color: #17191c; }
  html[data-theme="dark"] .mobile-nav-count { background: #e6e8eb; color: #17191c; }
  html[data-theme="dark"] .mobile-sidebar-logout { border-color: #343a41; background: #202428; color: #cbd2d9; }
  html[data-theme="dark"] .topbar { border-color: #343a41; background: #17191cf2; }
}

@media ((max-width: 900px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 900px))), (max-height: 560px) and (orientation: landscape) {
  .sidebar.open + .mobile-drawer-backdrop {
    position: fixed;
    z-index: 65;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: #22222238;
    -webkit-tap-highlight-color: transparent;
  }
}

@media ((max-width: 360px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 360px))) {
  .mobile-bottom-nav { gap: 0; padding-inline: max(4px, env(safe-area-inset-left)) max(4px, env(safe-area-inset-right)); }
  .mobile-bottom-item { font-size: 9px; }
}

/* Mobile task layouts: give each screen a clear focus instead of shrinking desktop columns. */
.mobile-tooth-picker, .mobile-jaw-choice, .mobile-order-summary { display: none; }

@media ((max-width: 900px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 900px))) {
  .page-title { align-items: flex-start; flex-direction: column; gap: 8px; margin: 10px 0 18px; }
  .page-title h1 { font-size: 23px; line-height: 1.2; }
  .page-title p { font-size: 13px; line-height: 1.45; }
  .page-title > .btn, .page-title > button { width: 100%; min-height: 46px; font-size: 14px; }
  .section-heading { align-items: flex-start; gap: 12px; }
  .section-heading h2 { font-size: 18px; line-height: 1.25; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .stat { height: auto; min-height: 76px; padding: 12px; gap: 10px; }
  .stat-icon { width: 38px; height: 38px; }
  .stat strong { font-size: 22px; }
  .stat span:not(.stat-icon) { white-space: normal; line-height: 1.25; }
  .hero { height: auto; min-height: 0; flex-direction: column; align-items: stretch; margin-bottom: 20px; }
  .hero > div { padding: 18px 18px 12px; }
  .hero h2 { margin-bottom: 7px; font-size: 20px; }
  .hero p { font-size: 13px; }
  .hero img { display: block; width: 100%; max-width: 100%; height: 132px; min-height: 112px; max-height: 160px; flex: 0 0 auto; object-fit: cover; object-position: center 48%; mask-image: linear-gradient(180deg, transparent, #000 22%); }
  .table-wrap, .tech-table-wrap, .tech-orders-table-wrap { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }
  .orders-table, .tech-orders-table, .worker-table {
    min-width: 0 !important;
    width: 100% !important;
    display: block !important;
    table-layout: auto !important;
  }
  .orders-table thead, .tech-orders-table thead, .worker-table thead { display: none !important; }
  .orders-table tbody, .tech-orders-table tbody, .worker-table tbody {
    display: grid !important;
    width: 100% !important;
    gap: 10px;
  }
  .orders-table tbody tr, .tech-orders-table tbody tr, .worker-table tbody tr {
    display: grid !important;
    width: 100% !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    gap: 0 14px;
    padding: 12px;
    border: 1px solid var(--cd-night-edge,#ededed);
    border-radius: 13px;
    background: var(--cd-night-paper,#fff);
  }
  /* Desktop column widths from styles.css also match tablet-width landscape.
     Clear those fixed widths when the tables are rendered as mobile cards. */
  .orders-table th, .orders-table td,
  .tech-orders-table th, .tech-orders-table td,
  .worker-table th, .worker-table td {
    display: grid !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    box-sizing: border-box;
    white-space: normal !important;
    overflow: visible !important;
    overflow-wrap: anywhere;
    text-overflow: clip !important;
  }
  .orders-table td, .tech-orders-table td, .worker-table td { grid-template-columns: minmax(58px, 32%) minmax(0, 1fr) !important; gap: 6px; min-width: 0; align-items: start; padding: 7px 0; border: 0; white-space: normal; overflow-wrap: anywhere; color: var(--cd-night-ink,#333); font-size: 12px; }
  .orders-table td::before, .tech-orders-table td::before, .worker-table td::before { color: var(--cd-night-secondary,#808080); font-size: 10px; font-weight: 650; line-height: 1.35; }
  .orders-table td:nth-child(1)::before { content: 'Заказ'; }
  .orders-table td:nth-child(2)::before { content: 'Пациент'; }
  .orders-table td:nth-child(3)::before { content: 'Работа'; }
  .orders-table td:nth-child(4)::before { content: 'Создан'; }
  .orders-table td:nth-child(5)::before { content: 'Срок'; }
  .orders-table td:nth-child(6)::before { content: 'Статус'; }
  .orders-table td:nth-child(7)::before { content: 'Сумма'; }
  .orders-table td:nth-child(1) { grid-column: 1 / -1; }
  .orders-table td:nth-child(2), .orders-table td:nth-child(3) { grid-column: 1 / -1; }
  .orders-table td:nth-child(6) { grid-column: 1; }
  .orders-table td:nth-child(7) { grid-column: 2; }
  .tech-orders-table td:nth-child(1)::before { content: 'Заказ'; }
  .tech-orders-table td:nth-child(2)::before { content: 'Клиника'; }
  .tech-orders-table td:nth-child(3)::before { content: 'Создан'; }
  .tech-orders-table td:nth-child(4)::before { content: 'Тип заказа'; }
  .tech-orders-table td:nth-child(5)::before { content: 'Работа'; }
  .tech-orders-table td:nth-child(6)::before { content: 'Пациент'; }
  .tech-orders-table td:nth-child(7)::before { content: 'Срок'; }
  .tech-orders-table td:nth-child(8)::before { content: 'Этап'; }
  .tech-orders-table td:nth-child(9)::before { content: 'Команда'; }
  .tech-orders-table td:nth-child(10)::before { content: 'Действия'; }
  .tech-orders-table tr { position: relative; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important; }
  .tech-orders-table td:nth-child(1) { grid-column: 1; grid-row: 1; font-size: 14px; font-weight: 700; }
  .tech-orders-table td:nth-child(10) { grid-column: 2; grid-row: 1; justify-self: end; }
  .tech-orders-table td:nth-child(2), .tech-orders-table td:nth-child(5), .tech-orders-table td:nth-child(6), .tech-orders-table td:nth-child(9) { grid-column: 1 / -1; }
  .tech-orders-table td:nth-child(3) { grid-column: 1; }
  .tech-orders-table td:nth-child(4) { grid-column: 2; }
  .tech-orders-table td:nth-child(7) { grid-column: 1; }
  .tech-orders-table td:nth-child(8) { grid-column: 2; }
  .tech-orders-table .tech-order-actions { gap: 6px; }
  .tech-orders-table .tech-order-actions .tech-icon-btn { width: 38px; height: 38px; }
  .worker-table td:nth-child(1)::before { content: 'Заказ / клиника'; }
  .worker-table td:nth-child(2)::before { content: 'Создан'; }
  .worker-table td:nth-child(3)::before { content: 'Работа / пациент'; }
  .worker-table td:nth-child(4)::before { content: 'Срок'; }
  .worker-table td:nth-child(5)::before { content: 'Этап'; }
  .worker-table td:nth-child(6)::before { content: 'Действие'; }
  .worker-table td:nth-child(1), .worker-table td:nth-child(3) { grid-column: 1 / -1; }
  .worker-table td:nth-child(2), .worker-table td:nth-child(4) { grid-column: span 1; }
  .worker-table td:nth-child(5), .worker-table td:nth-child(6) { grid-column: 1 / -1; }
  .worker-table td:nth-child(5) .tech-stage { max-width: 100%; white-space: normal; line-height: 1.35; }
  .worker-table td:nth-child(6) { align-items: center; }
  .worker-table td:nth-child(6) .tech-link { min-height: 44px; justify-self: end; }
  .tech-panel, .card, .clinic-panel { min-width: 0; }
  .clinic-tabs, .tech-segment, .tabs { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
  .wizard.order-flow { display: grid; gap: 18px; min-height: 0; padding: 0 0 158px; overflow: visible; border: 0; background: transparent; box-shadow: none; }
  .order-flow > h2 { margin: 0; font-size: 21px; line-height: 1.25; }
  .order-flow .info-note { margin-top: 0; padding: 13px 14px; font-size: 13px; line-height: 1.45; }
  .order-flow .form-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .order-type-choice { display: grid; gap: 12px; margin: 0; padding: 0; border: 0; background: transparent; }
  .order-type-choice h3 { margin: 0 0 4px; font-size: 16px; }
  .order-type-choice p { font-size: 13px; line-height: 1.4; }
  .order-type-options { display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; min-width: 0; margin: 0; }
  .order-type-options button { min-height: 62px; padding: 12px 14px; border-radius: 12px; }
  .order-type-options button strong { font-size: 15px; }
  .order-type-options button small { white-space: normal; font-size: 12px; line-height: 1.35; }
  .stepper { display: flex; align-items: center; gap: 5px; width: 100%; margin: 0 0 17px; }
  .step { display: flex; min-width: 28px; align-items: center; justify-content: center; gap: 7px; padding: 0; white-space: nowrap; }
  .step b { width: 27px; height: 27px; flex: 0 0 27px; font-size: 12px; }
  .step-label { display: none; }
  .step.active .step-label { display: inline; max-width: 145px; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
  .step-line { display: block; height: 2px; min-width: 8px; flex: 1; background: var(--cd-night-soft,#e7e7e7); font-size: 0; }
  .step.done + .step-line { background: #808080; }
  .order-builder { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .order-builder section { padding: 15px; border: 1px solid var(--cd-night-edge,#ededed); border-radius: 14px; background: var(--cd-night-paper,#fff); }
  .order-builder h2 { font-size: 17px; }
  .tooth-picker { gap: 13px; }
  .tooth-picker .desktop-tooth-chart { display: none; }
  .mobile-tooth-picker { display: grid; gap: 12px; }
  .mobile-quadrants { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .mobile-quadrants button { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 5px; padding: 7px 9px; border: 1px solid var(--cd-night-edge,#e9e9e9); border-radius: 10px; background: var(--cd-night-paper,#fbfbfb); color: var(--cd-night-secondary,#777); font-size: 11px; font-weight: 650; text-align: left; }
  .mobile-quadrants button small { color: var(--cd-night-secondary,#999); font-size: 10px; font-weight: 600; }
  .mobile-quadrants button.selected { border-color: #808080; background: var(--cd-night-hover,#f3f3f3); color: var(--cd-night-ink,#333); }
  .mobile-quadrants button.selected small { color: var(--cd-night-secondary,#666); }
  .mobile-tooth-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
  .mobile-tooth-grid button { min-height: 44px; border: 1px solid #e9e9e9; border-radius: 10px; background: #fff; color: #444; font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }
  .mobile-tooth-grid button.selected { border-color: #808080; background: #333; color: #fff; }
  .mobile-jaw-choice { display: grid; gap: 8px; }
  .mobile-jaw-choice button { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border: 1px solid #e7e7e7; border-radius: 11px; background: #fbfbfb; color: #444; font-weight: 650; text-align: left; cursor: pointer; }
  .mobile-jaw-choice button small { color: #888; font-size: 12px; font-weight: 550; }
  .mobile-jaw-choice button.selected { border-color: #808080; background: #f2f2f2; }
  .tooth-mode { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; }
  .tooth-mode button { min-height: 42px; padding-inline: 5px; font-size: 12px; }
  .tooth-picker .selected-teeth { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 10px 11px; font-size: 12px; line-height: 1.4; }
  .tooth-picker .selected-teeth .clear { min-height: 36px; padding: 4px 8px; }
  .work-picker { gap: 13px; }
  .work-picker-title { align-items: center; }
  .work-picker-title p { font-size: 12px; line-height: 1.4; }
  .order-work-grid { grid-template-columns: minmax(0, 1fr); gap: 7px; }
  .order-work-grid button { display: flex; min-height: 54px; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 10px; text-align: left; font-size: 14px; }
  .order-work-grid button::after { content: '›'; color: var(--cd-night-secondary,#888); font-size: 22px; line-height: 1; }
  .work-detail { gap: 10px; }
  .work-back { min-height: 40px; padding: 0 4px; font-size: 13px; }
  .work-current { padding: 13px 14px; }
  .work-current strong { font-size: 15px; }
  .work-option-list { gap: 7px; }
  .work-option-list button { min-height: 58px; padding: 11px 12px; border-radius: 11px; font-size: 13px; }
  .work-option-list button b { font-size: 13px; }
  .prosthetic-addons { padding: 12px; }
  .prosthetic-addon-list button { min-height: 58px; }
  .order-draft { display: grid; }
  .mobile-order-summary { display: flex; width: 100%; min-height: 58px; align-self: start; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border: 1px solid var(--cd-night-edge,#e6e6e6); border-radius: 13px; background: var(--cd-night-paper,#fff); color: var(--cd-night-ink,#333); text-align: left; }
  .mobile-order-summary > span:first-child { display: grid; gap: 2px; }
  .mobile-order-summary strong { font-size: 14px; }
  .mobile-order-summary small { color: var(--cd-night-secondary,#808080); font-size: 11px; }
  .mobile-cart-chevron { color: var(--cd-night-secondary,#808080); font-size: 20px !important; }
  .wizard-actions { position: fixed; z-index: 55; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); left: 0; display: flex; gap: 9px; padding: 10px max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); border-top: 1px solid var(--cd-night-edge,#e9e9e9); background: var(--cd-night-paper,#fff); }
  .wizard-actions:has([data-action="previous"]) { display: grid; grid-template-columns: minmax(86px, .72fr) minmax(0, 1.5fr); }
  .wizard-actions .btn { width: 100%; min-height: 48px; font-size: 14px; }
  #app:has(.order-flow) .shell { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
  #app:has(.order-builder-wizard) .shell { padding-bottom: calc(175px + env(safe-area-inset-bottom)); }
  #app:has(.order-builder-wizard) .order-draft { position: static; order: -1; z-index: auto; max-height: none; align-content: start; overflow: visible; gap: 12px; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  #app:has(.order-builder-wizard) .order-draft:not(.expanded) > :not(.mobile-order-summary) { display: none; }
  #app:has(.order-builder-wizard) .order-draft.expanded { position: fixed; z-index: 54; inset: auto 12px calc(70px + env(safe-area-inset-bottom)); max-height: min(68dvh, 560px); align-content: start; overflow-y: auto; padding: 12px; border: 1px solid var(--cd-night-edge,#e5e5e5); border-radius: 14px; background: var(--cd-night-paper,#fff); box-shadow: 0 0 0 100vmax #22222235, 0 12px 30px #22222220; }
  #app:has(.order-builder-wizard) .order-draft.expanded .order-variants { overflow: auto; }
  #app:has(.order-flow) .order-type-choice { border: 0; }
  #app:has(.order-flow) .field > span { font-size: 13px; line-height: 1.4; }
  #app:has(.order-flow) .field input, #app:has(.order-flow) .field select,
  #app:has(.order-flow) .field textarea { min-height: 48px; padding: 12px 13px; border-radius: 11px; font-size: 16px; }
  #app:has(.order-flow) .upload-zone { min-height: 112px; padding: 16px; text-align: center; }
  #app:has(.order-flow) .attachment-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .tech-heading, .clinic-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
  .tech-heading > *, .clinic-heading > * { max-width: 100%; }
  .tech-heading:has(.tech-task-count) { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
  .tech-heading:has(.tech-task-count) > div:first-child { min-width: 0; }
  .tech-heading .tech-task-count { flex: 0 0 auto; }
  .task-column:has(.task-column-empty) { min-height: 0; }
  .task-column-empty { margin: 16px 3px 8px; }
  .tech-profile-editor, .tech-profile-editor .tech-client-form { grid-template-columns: minmax(0, 1fr); }
  .tech-profile-editor > *, .tech-profile-editor .tech-client-form > * { min-width: 0; max-width: 100%; }
  .worker-rate-note { flex-direction: column; align-items: flex-start; gap: 4px; }
  .worker-rate-note span { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
  .tech-panel, .clinic-panel, .dashboard-card { padding: 15px; border-radius: 14px; }
  .tech-panel h2, .clinic-panel h2 { font-size: 18px; }
  .tech-toolbar, .tech-order-tools { grid-template-columns: minmax(0, 1fr); align-items: stretch; flex-wrap: wrap; gap: 9px; }
  .tech-toolbar > *, .tech-order-tools > * { min-width: 0; max-width: 100%; }
  .tech-order-tools > .tech-segment, .tech-order-tools > .tech-order-searchbar { width: 100%; }
  .tech-toolbar .btn, .tech-order-tools .btn { min-height: 44px; }
  .tech-dialog-backdrop, .modal-backdrop { padding: 10px; }
  .tech-dialog, .modal { width: min(100%, 520px); max-width: 100%; max-height: calc(100dvh - 20px); overflow-y: auto; padding: 18px; border-radius: 16px; }

  html[data-theme="dark"] .order-builder section,
  html[data-theme="dark"] .mobile-order-summary,
  html[data-theme="dark"] #app:has(.order-builder-wizard) .order-draft.expanded { border-color: #343a41; background: #202428; color: #e9ecef; }
  html[data-theme="dark"] .mobile-quadrants button,
  html[data-theme="dark"] .mobile-tooth-grid button,
  html[data-theme="dark"] .mobile-jaw-choice button,
  html[data-theme="dark"] .wizard-actions { border-color: #343a41; background: #17191c; color: #e9ecef; }
  html[data-theme="dark"] .mobile-tooth-grid button.selected { background: #e9ecef; color: #17191c; }
  html[data-theme="dark"] .wizard-actions { border-top-color: #343a41; }
}

@media ((max-width: 520px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 520px))) {
  .shell, .tech-shell { padding-right: 12px; padding-left: 12px; }
  .topbar { margin-right: -12px; margin-left: -12px; padding-right: 12px; padding-left: 12px; }
  .order-flow > h2 { font-size: 19px; }
  .step.active .step-label { max-width: 105px; font-size: 11px; }
  .step b { width: 25px; height: 25px; flex-basis: 25px; }
  .stepper { gap: 4px; }
  .step-line { min-width: 5px; }
  .mobile-quadrants { gap: 6px; }
  .mobile-quadrants button { font-size: 10px; }
  .order-builder section { padding: 13px; }
  .page-title > .btn, .page-title > button { white-space: normal; }
  .clinic-form .form-grid, .tech-form-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .detail-actions, .clinic-accept-actions { grid-template-columns: minmax(0, 1fr); }
  .portal-footer { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 16px 0; text-align: center; }
}

/* The phone uses the same anatomical SVG selector as desktop. Keep the
   model large enough for touch targets instead of replacing it with a grid. */
@media ((max-width: 900px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 900px))) {
  .tooth-picker .desktop-tooth-chart { display: block; }
  .tooth-picker .desktop-tooth-chart .tooth-chart { width: min(70%, 252px); max-width: 252px; padding: 0; }
  .tooth-picker .desktop-tooth-chart .tooth-chart svg { width: 100%; height: auto; max-height: none; touch-action: manipulation; }
  .tooth-picker .desktop-tooth-chart .tooth[role="button"] { -webkit-tap-highlight-color: transparent; }
  .tooth-picker .desktop-tooth-chart .tooth-hitbox { stroke-width: 14px; }
  .tooth-picker .desktop-tooth-chart .tooth.selected .tooth-image { filter: brightness(.34) contrast(1.3) saturate(0); }
  .tooth-picker .mobile-tooth-picker { display: none; }
}

/* Phone layouts: make single-purpose pages feel native to a narrow viewport. */
@media ((max-width: 760px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 760px))) {
  .content { display: flex; flex-direction: column; gap: 16px; }
  .content > * { min-width: 0; }
  .content > .page-title, .content > .tech-heading, .content > .clinic-heading { margin-bottom: 0; }

  .clinic-status-segment { display: flex; width: 100%; padding: 4px; gap: 4px; overflow-x: auto; }
  .clinic-status-segment button { flex: 0 0 auto; min-height: 40px; padding: 0 12px; white-space: nowrap; }
  .clinic-orders-panel { min-width: 0; padding: 12px; }
  .clinic-orders-panel .toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .clinic-orders-panel .search { min-width: 0; width: 100%; }
  .clinic-orders-panel .search input { min-width: 0; width: 100%; font-size: 16px; }
  .clinic-order-filter { inset-inline: 12px; width: auto; }

  .clinic-content { gap: 18px; }
  .clinic-photo { display: grid; grid-template-columns: 58px minmax(0, 1fr); align-items: center; gap: 8px 12px; padding: 12px; border: 1px solid var(--cd-night-edge,#ededed); border-radius: 14px; background: var(--cd-night-paper,#fff); }
  .clinic-photo > strong { grid-column: 1 / -1; margin: 0; font-size: 14px; }
  .clinic-photo img { grid-column: 1; grid-row: 2 / span 2; width: 58px; height: 58px; margin: 0; border-radius: 12px; object-fit: cover; }
  .clinic-photo button { grid-column: 2; grid-row: 2 / span 2; justify-self: start; min-height: 42px; }
  .clinic-form .form-grid { gap: 14px; }
  .clinic-form .save-field { position: sticky; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 20; margin: 0 -4px; padding: 8px 4px; background: linear-gradient(180deg, transparent, #fbfbfb 25%); }
  .clinic-form .save-field .btn { width: 100%; min-height: 48px; }

  .messages-layout { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; min-height: min(68dvh, 680px); gap: 0; overflow: hidden; }
  .messages-layout > .contacts { display: none; }
  .messages-layout > .conversation { min-width: 0; min-height: min(68dvh, 680px); }
  .messages-layout .conversation-head { min-height: 58px; padding: 12px; }
  .messages-layout .chat-bubbles { min-height: 260px; padding: 14px 12px; }
  .messages-layout .bubble { max-width: 88%; overflow-wrap: anywhere; }
  .messages-layout .chat-compose { display: grid; grid-template-columns: 42px minmax(0, 1fr) 42px; gap: 7px; padding: 8px; }
  .messages-layout .chat-compose input { min-width: 0; min-height: 44px; font-size: 16px; }
  .messages-layout .chat-attach-button, .messages-layout .send-btn { width: 42px; min-width: 42px; height: 42px; }

  .order-type-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .order-type-options button { min-width: 0; min-height: 88px; align-items: flex-start; justify-content: center; gap: 5px; padding: 11px; text-align: left; }
  .order-type-options button small { font-size: 11px; }

  .calendar-grid { gap: 3px; }
  .calendar-day { min-width: 0; min-height: 38px; }
  .dashboard-aside, .dashboard-main { min-width: 0; }
  .dashboard-main .tabs { max-width: calc(100vw - 24px); }

  .tech-filter-button, .clinic-filter-wrap > button { min-height: 44px; }
  .tech-toolbar input, .tech-order-tools input, .clinic-order-filter select,
  .tech-form-grid input, .tech-form-grid select, .tech-form-grid textarea,
  .clinic-form input, .clinic-form select, .clinic-form textarea,
  .modal input, .modal select, .modal textarea,
  .tech-dialog input, .tech-dialog select, .tech-dialog textarea { min-height: 44px; font-size: 16px; }
  .tech-form-grid textarea, .clinic-form textarea, .modal textarea, .tech-dialog textarea { min-height: 100px; }
  .tech-detail-grid, .tech-order-main, .tech-order-side, .detail-grid { min-width: 0; }
  .tech-order-service-body { grid-template-columns: minmax(0, 1fr); }
  .tech-order-service-chart .tooth-chart { max-width: 170px; }

  html[data-theme="dark"] .clinic-photo { border-color: #343a41; background: #202428; }
  html[data-theme="dark"] .clinic-form .save-field { background: linear-gradient(180deg, transparent, #17191c 25%); }
}

/* The chief technician has many conversations, so keep clinic switching visible on phones. */
@media ((max-width: 900px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 900px))) {
  .chief-messages { display: flex; min-height: 0; flex-direction: column; gap: 8px; overflow: visible; }
  .chief-messages > .contacts {
    display: flex;
    max-height: 78px;
    flex: 0 0 auto;
    gap: 7px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0 8px;
    border: 0;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }
  .chief-messages > .contacts .contact { display: flex; min-width: min(72vw, 250px); min-height: 58px; flex: 0 0 auto; border: 1px solid var(--cd-night-edge,#ededed); border-radius: 12px; }
  .chief-messages > .contacts .contact span:nth-child(2) { min-width: 0; }
  .chief-messages > .contacts .contact small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chief-messages > .conversation { min-height: min(54dvh, 560px); }
  .chief-messages.is-empty > .contacts { display: none; }
  .chief-messages.is-empty > .conversation { min-height: 180px; }
}

@media ((max-width: 620px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 620px))) {
  .tech-pricing-row { grid-template-columns: minmax(0, .75fr) minmax(0, 1.25fr); }
  .tech-pricing-row select { padding-right: 24px; }
}

@media ((max-width: 360px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 360px))) {
  .tech-pricing-row { grid-template-columns: minmax(0, 1fr); }
  .tech-pricing-name { grid-column: 1; }
}

@media ((max-width: 380px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 380px))) {
  .shell, .tech-shell { padding-right: 10px; padding-left: 10px; }
  .topbar { margin-right: -10px; margin-left: -10px; padding-right: 10px; padding-left: 10px; }
  .clinic-orders-panel { padding: 10px; }
  .clinic-photo { grid-template-columns: 52px minmax(0, 1fr); }
  .clinic-photo img { width: 52px; height: 52px; }
  .order-type-options button { padding: 9px; }
  .order-type-options button small { font-size: 10px; }
}

/* Order details: make the header, actions and status read as one compact mobile flow. */
@media ((max-width: 760px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 760px))) {
  .detail-heading .page-title { gap: 12px; margin: 4px 0 12px; }
  .detail-heading .page-title > div:first-child { display: grid; gap: 7px; }
  .detail-heading .page-title h1 { font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
  .detail-heading .page-title p { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 0; font-size: 12px; }
  .detail-actions { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 7px; }
  .detail-actions .btn { width: 100%; min-height: 44px; padding: 8px 7px; border-radius: 10px !important; font-size: 12px; line-height: 1.25; white-space: normal; }
  .detail-heading + .clinic-detail-tabs { margin: 0 0 14px !important; gap: 3px; padding: 4px; border: 1px solid var(--cd-night-edge,#ededed); border-radius: 13px; background: var(--cd-night-soft,#f5f5f5); }
  .clinic-detail-tabs .tab { flex: 1 0 auto; min-height: 40px; padding: 0 9px; border: 0; border-radius: 9px; }
  .clinic-detail-tabs .tab.active { background: var(--cd-night-hover,#fff); color: var(--cd-night-ink,#333); box-shadow: 0 1px 4px #00000010; }
  .detail-grid { gap: 14px; margin-top: 0; }
  .detail-main-column, .detail-side-column { gap: 14px; }
  .detail-main-column > section, .detail-side-column > section { padding: 15px; border: 1px solid var(--cd-night-edge,#e9e9e9); border-radius: 14px; background: var(--cd-night-paper,#fff); box-shadow: 0 4px 14px #22222208; }
  .detail-grid h3 { margin-bottom: 12px; font-size: 16px; line-height: 1.3; }
  .detail-main-column .facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .detail-main-column .facts > div { display: flex; min-width: 0; min-height: 62px; flex-direction: column; justify-content: center; gap: 5px; padding: 9px; border: 1px solid var(--cd-night-edge,#f0f0f0); border-radius: 10px; }
  .detail-main-column .facts span { font-size: 11px; font-weight: 600; }
  .detail-main-column .facts strong { overflow-wrap: anywhere; font-size: 13px; line-height: 1.35; }
  .clinic-stage-progress { width: 100%; max-width: none; margin: 10px 0 0; padding: 12px 13px; }
  .detail-side-column .clinic-accept-actions { grid-template-columns: 1fr !important; margin-top: 12px; }
  .detail-grid .order-service-card { padding: 12px; border-radius: 12px; }
  .detail-grid .order-service-body { grid-template-columns: 84px minmax(0, 1fr); align-items: start; gap: 10px; }
  .detail-grid .order-service-chart, .detail-grid .order-service-chart .tooth-chart { width: 84px; max-width: 84px; }
  .detail-grid .order-service-card dl div { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
  .detail-grid .order-service-card dd { text-align: right; }

  html[data-theme="dark"] .clinic-detail-tabs { border-color: #343a41; background: #202428; }
  html[data-theme="dark"] .clinic-detail-tabs .tab.active { background: #30363d; color: #f0f1f2; }
  html[data-theme="dark"] .detail-main-column > section, html[data-theme="dark"] .detail-side-column > section { border-color: #343a41; background: #202428; }
  html[data-theme="dark"] .detail-main-column .facts > div { border-color: #343a41; }
}

/* Short landscape screens need their own layout: width breakpoints alone leave
   phone interfaces too tall and make fixed navigation/actions cover content. */
@media ((max-width: 900px) and (max-height: 560px) and (orientation: landscape)) and (not ((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px))) {
  html, body, #app { width: 100%; max-width: 100%; overflow-x: hidden; }
  .sidebar { width: min(78vw, 300px); padding: 12px; transform: translateX(-105%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-nav { gap: 2px; }
  .nav-link { height: 38px; }
  .brand { height: 58px; }
  .brand .portal-logo { width: 150px; height: 58px; }
  .shell, .tech-shell { width: 100%; max-width: 100%; margin-left: 0; padding: 0 16px calc(58px + env(safe-area-inset-bottom)); overflow-x: hidden; }
  .content, .tech-content { width: 100%; max-width: 100%; min-width: 0; }
  .topbar { height: 48px; margin: 0 -16px 10px; padding: 0 16px; }
  .topbar .profile { max-width: 44px; overflow: hidden; padding: 0; }
  .topbar .profile > span:nth-child(2), .topbar .profile > svg,
  .topbar-label, .clinic-select { display: none; }
  .topbar .profile .avatar { width: 32px; height: 32px; }
  .mobile-menu { display: none !important; }

  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    position: fixed;
    z-index: 55;
    inset: auto 0 0;
    min-height: 52px;
    gap: 4px;
    padding: 3px max(8px, env(safe-area-inset-right)) calc(3px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    border-top: 1px solid var(--cd-night-edge,#e9e9e9);
    background: var(--cd-night-paper,#fff);
  }
  .mobile-bottom-item {
    position: relative;
    display: flex;
    min-height: 42px;
    min-width: 0;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 3px 5px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--cd-night-secondary,#808080);
    font-size: 10px;
    font-weight: 550;
    line-height: 1.15;
    text-align: center;
  }
  .mobile-bottom-item.active { background: var(--cd-night-hover,#f5f5f5); color: var(--cd-night-ink,#333); font-weight: 700; }
  .mobile-bottom-item[data-page="new"] { background: #707070; color: #fff; }
  .mobile-bottom-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-bottom-item svg { width: 17px; height: 17px; }
  .mobile-nav-count { top: 0; right: max(3px, calc((100% - 54px) / 2)); }
  html[data-theme="dark"] .mobile-bottom-nav { border-color: #343a41; background: #17191c; }
  html[data-theme="dark"] .mobile-bottom-item { color: #9da4ad; }
  html[data-theme="dark"] .mobile-bottom-item.active { background: #252a2f; color: #f0f1f2; }
  html[data-theme="dark"] .mobile-bottom-item[data-page="new"] { background: #808890; color: #17191c; }

  .page-title { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; margin: 5px 0 12px; }
  .page-title > .btn, .page-title > button { width: auto; min-height: 38px; }
  .section-heading { align-items: center; }
  .hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, .8fr); min-height: 170px; }
  .hero > div { padding: 16px; }
  .hero img { width: 100%; height: 170px; max-height: 170px; }

  .detail-grid, .tech-detail-grid { grid-template-columns: minmax(0, 1.45fr) minmax(240px, .85fr); gap: 12px; }
  .detail-heading .page-title { align-items: center; }
  .detail-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .clinic-detail-tabs { overflow-x: auto; }

  .messages-layout { display: grid; grid-template-columns: minmax(0, 1fr); height: calc(100dvh - 170px); min-height: 120px; gap: 0; overflow: hidden; }
  .messages-layout > .contacts { display: none; }
  .messages-layout > .conversation { display: flex; height: 100%; flex-direction: column; min-height: 0; }
  .messages-layout .conversation-head { flex: 0 0 auto; min-height: 48px; padding: 8px 12px; }
  .messages-layout .chat-bubbles { min-height: 0; height: auto; flex: 1 1 auto; padding: 10px 12px; overflow-y: auto; }
  .messages-layout .chat-compose { flex: 0 0 auto; padding: 6px 8px; }
  .messages-layout .chat-compose input { min-height: 38px; }
  .messages-layout .chat-attach-button, .messages-layout .send-btn { width: 38px; min-width: 38px; height: 38px; }
  .chief-messages { display: grid; grid-template-rows: 56px minmax(0, 1fr); height: calc(100dvh - 170px); min-height: 120px; }
  .chief-messages > .contacts { display: flex; min-height: 0; max-height: 56px; grid-row: 1; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 2px 0 6px; }
  .chief-messages > .contacts .contact { min-width: min(55vw, 210px); min-height: 44px; padding: 6px 8px; }
  .chief-messages > .contacts .contact-avatar { width: 30px; height: 30px; }
  .chief-messages > .conversation { grid-row: 2; min-height: 0; height: 100%; }

  .order-builder { grid-template-columns: minmax(0, .92fr) minmax(0, 1.08fr); align-items: start; gap: 10px; }
  .order-builder section { padding: 12px; }
  .order-builder .order-draft { grid-column: 1 / -1; }
  .order-work-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wizard-actions { bottom: calc(64px + env(safe-area-inset-bottom)); padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .wizard-actions .btn { min-height: 38px; }
  #app:has(.order-builder-wizard) .shell { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
  #app:has(.order-builder-wizard) .order-draft.expanded { bottom: calc(58px + env(safe-area-inset-bottom)); max-height: 52dvh; }

  .portal-login {
    min-height: 100vh;
    min-height: 100svh;
    justify-content: center;
    gap: 8px;
    padding: 54px 16px 8px;
  }
  .portal-login-tools { top: 8px; right: 12px; }
  .portal-login > section {
    display: grid;
    width: min(100%, 760px);
    grid-template-columns: minmax(0, .82fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    align-items: center;
    column-gap: 22px;
    row-gap: 3px;
    margin: 0;
    padding: 14px 20px;
  }
  .portal-login .portal-logo { grid-column: 1; grid-row: 1; width: 132px; height: 52px; margin: 0 0 4px; }
  .portal-login h1 { grid-column: 1; grid-row: 2; margin: 0 0 4px; font-size: 18px; }
  .portal-login > section > p { grid-column: 1; grid-row: 3; min-height: 0; margin: 0; font-size: 12px; line-height: 1.35; }
  .portal-login form { grid-column: 2; grid-row: 1 / span 3; gap: 6px; }
  .portal-login label { gap: 3px; font-size: 11px; }
  .portal-login input { height: 36px; min-height: 36px; padding-inline: 10px; font-size: 14px; }
  .portal-login form .btn { min-height: 38px; }
  .portal-login .auth-links { grid-column: 2; grid-row: 4; display: flex; justify-content: space-between; gap: 10px; margin-top: 5px; font-size: 12px; }
  .portal-login .portal-footer { display: grid; width: min(100%, 760px); grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 4px; margin: 0; font-size: 9px; line-height: 1.2; text-align: center; }
  .portal-login .portal-footer-tagline { display: block; grid-column: 1 / -1; justify-self: center; text-align: center; }
  .portal-login .portal-footer-legal { grid-column: 1 / -1; display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

  html[data-theme="dark"] .portal-login > section { border-color: #343a41; background: #202428; }
}

/* Mobile polish pass: readable labels, discoverable horizontal rails and touch targets. */
@media ((max-width: 900px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 900px))) {
  html:not([data-theme="dark"]) .shell .topbar-label,
  html:not([data-theme="dark"]) .shell .page-title p,
  html:not([data-theme="dark"]) .shell .field,
  html:not([data-theme="dark"]) .shell .hint,
  html:not([data-theme="dark"]) .shell .info-note,
  html:not([data-theme="dark"]) .tech-shell .topbar-label,
  html:not([data-theme="dark"]) .tech-shell .tech-heading p,
  html:not([data-theme="dark"]) .tech-shell .tech-demo-note,
  html:not([data-theme="dark"]) .tech-shell .tech-panel p,
  html:not([data-theme="dark"]) .tech-shell .tech-kpis article > span,
  html:not([data-theme="dark"]) .tech-shell .tech-kpis article > small:not(.positive):not(.negative),
  html:not([data-theme="dark"]) .tech-shell .tech-breakdown-name small,
  html:not([data-theme="dark"]) .tech-shell .tech-table td:not(:has(.tech-stage)),
  html:not([data-theme="dark"]) .tech-shell .tech-table td:not(:has(.tech-stage)) small,
  html:not([data-theme="dark"]) .tech-shell .tech-detail-grid span,
  html:not([data-theme="dark"]) .tech-shell .tech-timeline li:not(.current):not(.done),
  html:not([data-theme="dark"]) .tech-shell .tech-empty,
  html:not([data-theme="dark"]) .mobile-bottom-item:not([data-page="new"]),
  html:not([data-theme="dark"]) .clinic-status-segment button,
  html:not([data-theme="dark"]) .clinic-page-segment button,
  html:not([data-theme="dark"]) .tech-segment button,
  html:not([data-theme="dark"]) .tabs .tab {
    color: #6f6f6f;
  }

  html:not([data-theme="dark"]) input::placeholder,
  html:not([data-theme="dark"]) textarea::placeholder,
  html:not([data-theme="dark"]) .search input::placeholder {
    color: #707070;
    opacity: 1;
  }

  .clinic-tabs, .tech-segment, .tabs,
  .clinic-status-segment, .clinic-page-segment,
  .clinic-detail-tabs, .tech-request-filters {
    scrollbar-width: thin;
    scrollbar-color: #a0a0a0 #eeeeee;
    scroll-behavior: smooth;
  }
  .clinic-tabs::-webkit-scrollbar, .tech-segment::-webkit-scrollbar, .tabs::-webkit-scrollbar,
  .clinic-status-segment::-webkit-scrollbar, .clinic-page-segment::-webkit-scrollbar,
  .clinic-detail-tabs::-webkit-scrollbar, .tech-request-filters::-webkit-scrollbar {
    display: block;
    height: 4px;
  }
  .clinic-tabs::-webkit-scrollbar-thumb, .tech-segment::-webkit-scrollbar-thumb, .tabs::-webkit-scrollbar-thumb,
  .clinic-status-segment::-webkit-scrollbar-thumb, .clinic-page-segment::-webkit-scrollbar-thumb,
  .clinic-detail-tabs::-webkit-scrollbar-thumb, .tech-request-filters::-webkit-scrollbar-thumb {
    border-radius: 99px;
    background: #a0a0a0;
  }
  .clinic-status-segment button, .clinic-page-segment button,
  .tech-segment button, .tabs .tab { min-height: 44px; }

  .production-board {
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    scrollbar-color: #a0a0a0 #eeeeee;
    padding-bottom: 12px;
  }
  .production-column {
    flex-basis: min(84vw, 340px);
    min-height: min(62dvh, 520px);
    scroll-snap-align: start;
  }

  .tech-bars {
    grid-template-columns: repeat(12, minmax(38px, 1fr));
    gap: 4px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    scrollbar-color: #a0a0a0 #eeeeee;
  }
  .tech-bar { min-height: 44px; }

  .stepper { min-width: 0; gap: 3px; }
  .step.active .step-label { max-width: min(28vw, 105px); }
}

@media ((max-width: 340px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 340px))) {
  .step.active .step-label { max-width: 78px; }
  .stepper { gap: 2px; }
  .step b { width: 24px; height: 24px; flex-basis: 24px; }
  .step-line { min-width: 3px; }
}

@media ((min-width: 901px) and (max-height: 560px) and (orientation: landscape)) and (not ((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px))) {
  .mobile-bottom-nav { display: none !important; }
  .sidebar { transform: none !important; }
  .shell, .tech-shell { width: auto; max-width: none; margin-left: 226px; padding: 0 28px 42px; overflow: visible; }
  .topbar { height: 80px; margin: 0; padding: 0; }
  .topbar .profile { max-width: none; }
  .topbar .profile > span:nth-child(2), .topbar .profile > svg,
  .topbar-label, .clinic-select { display: initial; }
}

@media ((max-width: 900px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 900px))) {
  .clinic-production-timeline { margin: 0 0 2px; padding: 0; border-left: 0; }
  .clinic-production-timeline > div { min-height: 32px; gap: 2px; padding: 0 0 12px 28px; font-size: 12px; line-height: 1.25; }
  .clinic-production-timeline > div:not(:last-child)::before { content: ""; position: absolute; left: 6px; top: 7px; bottom: -7px; width: 2px; background: var(--cd-night-soft,#e7e7e7); }
  .clinic-production-timeline > div > i { left: 1px; top: 1px; z-index: 1; }
  .clinic-production-timeline > div.current > i { left: 0; top: 0; }
  .clinic-production-timeline > div:last-child { min-height: 18px; padding-bottom: 0; }

  /* Service charts are reduced to a small mobile column. Increase the
     selected-tooth contrast so the mark remains as clear as on desktop. */
  .order-service-chart .tooth.selected .tooth-image,
  .tech-order-service-chart .tooth.selected .tooth-image {
    filter: brightness(.32) contrast(1.45) saturate(0) !important;
    opacity: .98;
  }
  .order-service-chart .tooth-selection-overlay,
  .tech-order-service-chart .tooth-selection-overlay {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none;
  }
}

/* Keep the global mobile navigation visible during the order wizard. The
   wizard actions sit directly above it so neither control hides the other. */
@media ((max-width: 900px) and (max-height: 560px) and (orientation: landscape)) and (not ((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px))) {
  .wizard-actions { bottom: calc(52px + env(safe-area-inset-bottom)); }
  #app:has(.order-flow) .shell,
  #app:has(.order-builder-wizard) .shell { padding-bottom: calc(116px + env(safe-area-inset-bottom)); }
}

/* In the clinic chat, scroll the page itself instead of nesting two scroll areas. */
@media ((max-width: 900px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 900px))) {
  html:has(.messages-layout:not(.chief-messages)),
  body:has(.messages-layout:not(.chief-messages)) { overflow-x: clip; overflow-y: visible; }
  #app:has(.messages-layout:not(.chief-messages)),
  .shell:has(.messages-layout:not(.chief-messages)) { overflow: visible; }
  .messages-layout:not(.chief-messages) { height: auto; min-height: 0; overflow: visible; }
  .messages-layout:not(.chief-messages) > .conversation { height: auto; min-height: 0; overflow: visible; }
  .messages-layout:not(.chief-messages) .chat-bubbles { height: auto; min-height: 160px; max-height: none; overflow: visible; flex: none; }
  .messages-layout:not(.chief-messages) .conversation-head { position: sticky; top: 60px; z-index: 2; height: auto; flex: none; background: var(--cd-night-paper,#fff); }
  .messages-layout:not(.chief-messages) .chat-compose { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 3; height: auto; flex: none; margin: 0; background: var(--cd-night-paper,#fff); }
  .messages-layout:not(.chief-messages) .chat-compose-files .chat-pending-file { grid-column: 1 / -1; }
}
@media ((max-width: 900px) and (max-height: 560px) and (orientation: landscape)) and (not ((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px))) {
  .messages-layout:not(.chief-messages) .conversation-head { top: 48px; }
  .messages-layout:not(.chief-messages) .chat-compose { bottom: calc(52px + env(safe-area-inset-bottom)); }
}

/* Employee order detail: keep the work data and execution progress beside
   each other on desktop. The mobile cabinet rules above intentionally stack
   the two panels only at the mobile breakpoint. */
@media (((min-width: 901px) and (not ((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)))) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (min-height: 901px))) {
  .worker-detail-grid {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px) !important;
    gap: 24px !important;
    align-items: start;
  }

  .worker-detail-grid > .tech-order-main,
  .worker-detail-grid > .worker-detail-side {
    min-width: 0;
  }
}

@media ((max-width: 900px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 900px))) {
  .worker-detail-grid {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 16px !important;
  }
}

/* Keep labels and values close together in the clinic's mobile order cards. */
@media ((max-width: 900px) or (((pointer: coarse) and (hover: none) and (orientation: landscape) and (max-height: 560px)) and (max-height: 900px))) {
  .orders-table td {
    grid-template-columns: 58px minmax(0, 1fr) !important;
    column-gap: 6px;
  }

  /* The current clinic table also includes the doctor before the work type. */
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(3)::before { content: 'Врач'; }
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(4)::before { content: 'Работа'; }
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(5)::before { content: 'Создан'; }
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(6)::before { content: 'Срок'; }
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(7)::before { content: 'Статус'; }
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(8)::before { content: 'Сумма'; }
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(-n+4) { grid-column: 1 / -1; }
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(5),
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(7) { grid-column: 1; }
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(6),
  .orders-table tr:has(> td:nth-child(8)) > td:nth-child(8) { grid-column: 2; }
}

/* Tooth charts use the same compact footprint and graphite state on every
   cabinet. Keep the anatomical SVG inside its column on phones. */
@media (max-width: 900px) {
  .tooth-picker,
  .tooth-picker .desktop-tooth-chart,
  .order-service-body,
  .tech-order-service-body { min-width: 0; }

  .tooth-picker .desktop-tooth-chart {
    display: flex;
    width: 100%;
    max-width: 100%;
    justify-content: center;
    overflow: hidden;
    box-sizing: border-box;
  }

  .tooth-picker .desktop-tooth-chart .tooth-chart {
    flex: 0 1 252px;
    width: min(100%, 252px) !important;
    max-width: 252px !important;
    margin: 0 auto;
    padding: 0;
    overflow: visible;
  }

  .tooth-picker .desktop-tooth-chart .tooth-chart svg,
  .order-service-chart .tooth-chart svg,
  .tech-order-service-chart .tooth-chart svg {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    overflow: visible;
  }

  .detail-grid .order-service-chart,
  .detail-grid .order-service-chart .tooth-chart {
    width: 84px;
    max-width: 84px;
    overflow: visible;
  }

  .order-service-chart,
  .tech-order-service-chart {
    min-width: 0;
    max-width: 100%;
    display: flex;
    justify-content: center;
    overflow: hidden;
  }

  .order-service-chart .tooth-chart {
    flex: 0 1 105px;
    width: 105px;
    max-width: 105px;
    margin-inline: auto;
    overflow: visible;
  }

  .tech-order-service-chart .tooth-chart {
    flex: 0 1 160px;
    width: 160px;
    max-width: 160px;
    margin-inline: auto;
    overflow: visible;
  }

  /* Match desktop: selected teeth stay neutral graphite. */
  .tooth-picker .desktop-tooth-chart .tooth.selected .tooth-image,
  .order-service-chart .tooth.selected .tooth-image,
  .tech-order-service-chart .tooth.selected .tooth-image {
    filter: brightness(.65) saturate(0) !important;
    opacity: 1;
  }

  .order-service-chart .tooth-selection-overlay,
  .tech-order-service-chart .tooth-selection-overlay {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none;
  }

}

/* Native SVG fill keeps service tooth selections visible without image filters. */
.tooth-mobile-highlight{display:none;pointer-events:none}
@media (max-width:900px), ((pointer:coarse) and (hover:none) and (orientation:landscape) and (max-height:560px)){
  :is(.order-service-chart,.tech-order-service-chart) .tooth.selected .tooth-mobile-highlight{display:block;fill:#666;opacity:.88;pointer-events:none}
}
