/* The phone is the primary workspace. Wide layouts keep the existing desktop view. */
:root {
  --phone-safe-top: calc(max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --phone-safe-bottom: calc(max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px));
  --phone-safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px), var(--tg-content-safe-area-inset-left, 0px));
  --phone-safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px), var(--tg-content-safe-area-inset-right, 0px));
}
.mobile-team-list { display: none; }
.phone-preview-link { display: inline-flex; align-items: center; gap: 5px; }
@media (max-width: 760px) {
  html { scroll-padding-top: calc(68px + var(--phone-safe-top)); }
  body { font-size: 14px; padding-top: var(--phone-safe-top); }
  button, a, input, select { touch-action: manipulation; }
  button { -webkit-user-select: none; user-select: none; }
  input, select { font-size: 16px !important; min-height: 46px; }
  .btn, .btn.small, .icon-btn, .text-btn, .periods button, .issue-tab, .pagination button {
    min-height: 44px;
  }
  .icon-btn { min-width: 44px; width: 44px; height: 44px; }
  .btn, .btn.small { font-size: 13px; padding: 10px 13px; }
  .text-btn { font-size: 12px; padding: 10px 0; }
  .tiny { font-size: 12px; }
  .eyebrow { font-size: 10px; letter-spacing: 1.4px; }
  .badge { font-size: 11px; line-height: 1.4; padding: 5px 8px; }
  .demo-toolbar {
    height: 44px;
    position: sticky;
    top: var(--phone-safe-top);
    padding: 0 max(12px, var(--phone-safe-right)) 0 max(12px, var(--phone-safe-left));
    font-size: 11px;
    z-index: 110;
  }
  .demo-controls { gap: 6px; }
  .demo-role { padding: 0; background: transparent; }
  .demo-role button { min-height: 44px; padding: 7px 11px; font-size: 11px; }
  .demo-role button.active { background: #263c5c; border-radius: 0; box-shadow: inset 0 -2px #72a5ff; }
  .demo-link { min-height: 44px; font-size: 10px; padding: 7px 5px; }
  .demo-toolbar .phone-preview-link { display: none; }
  .shell { min-height: calc(var(--tg-viewport-stable-height, 100dvh) - var(--phone-safe-top)); }
  .app-header {
    position: sticky;
    top: var(--phone-safe-top);
    height: 56px;
    padding: 0 12px;
    gap: 5px;
    background: #101820f5;
    backdrop-filter: blur(16px);
    z-index: 60;
  }
  .mobile-brand { font-size: 17px; gap: 9px; }
  .mobile-brand .brand-symbol { width: 30px; height: 30px; border-radius: 9px; }
  .header-actions { gap: 2px; }
  .header-actions > .avatar { width: 44px; height: 44px; background: transparent; font-size: 12px; }
  .main-content {
    padding: 20px max(16px, var(--phone-safe-right)) calc(94px + var(--phone-safe-bottom)) max(16px, var(--phone-safe-left));
  }
  .page-heading { margin-bottom: 17px; gap: 8px; }
  .page-heading h1 { font-size: 26px; line-height: 1.23; margin: 5px 0 7px; }
  .page-heading p { font-size: 12px; line-height: 1.6; }
  .page-tools { margin: 0; }
  .page-tools .btn { min-width: 44px; min-height: 44px; padding: 10px; }
  .page-tools .btn svg { width: 18px; height: 18px; }
  .coverage { padding: 10px 12px; font-size: 11px; line-height: 1.65; margin-bottom: 15px; align-items: center; gap: 8px; }
  .coverage .text-btn { font-size: 11px; margin-top: 0; padding: 4px 0 4px 7px; }
  .filters { gap: 8px; margin-bottom: 15px; align-items: stretch; }
  .periods { flex: 1; padding: 2px; min-width: 0; }
  .periods button { flex: 1; font-size: 12px; padding: 5px 8px; min-width: 0; }
  .scope-select { flex: 0 0 132px; min-width: 0; }
  .scope-select select { width: 100%; max-width: none; font-size: 16px !important; min-height: 48px; padding-left: 28px; padding-right: 12px; }
  .scope-select > svg { left: 9px; }
  .kpi-grid { gap: 10px; margin-bottom: 16px; }
  .kpi { min-height: 124px; padding: 13px 12px 12px; border-radius: 13px; }
  .kpi-top { font-size: 12px; gap: 6px; line-height: 1.35; }
  .kpi-icon { width: 24px; height: 24px; border-radius: 7px; flex-shrink: 0; }
  .kpi-value { font-size: 29px; margin-top: 11px; letter-spacing: -.7px; }
  .kpi-bottom { font-size: 11px; margin-top: 9px; line-height: 1.45; gap: 3px 5px; flex-wrap: wrap; }
  .kpi-bottom > span:last-child { font-size: 10px; }
  .kpi-spark { display: none; }
  h2 { font-size: 16px; }
  h3 { font-size: 14px; }
  .panel-head { padding: 17px 16px 0; }
  .panel-sub { font-size: 11px; line-height: 1.6; margin-top: 4px; }
  body[data-page="overview"] .dashboard-grid { display: flex; flex-direction: column; gap: 16px; }
  body[data-page="overview"] .dashboard-grid > .panel:first-child { order: 2; }
  body[data-page="overview"] .dashboard-grid > .panel:nth-child(2) { order: 1; }
  .attention-head-counts { margin-top: 0; }
  .attention-head-counts .badge { min-width: 26px; justify-content: center; }
  .attention-row { padding: 15px 1px; gap: 10px; min-height: 90px; }
  .attention-list { padding: 4px 15px; }
  .row-title { font-size: 13px; line-height: 1.5; flex-wrap: wrap; }
  .row-detail { font-size: 12px; line-height: 1.6; margin-top: 3px; }
  .row-meta { font-size: 11px; margin-top: 6px; }
  .status-icon { width: 31px; height: 31px; }
  .row-arrow { margin-left: auto; }
  .panel-footer { padding: 4px 16px; }
  .panel-footer .text-btn { font-size: 13px; }
  .chart-legend { font-size: 11px; gap: 9px 13px; flex-wrap: wrap; padding: 15px 16px 0; }
  .legend-dot { margin-right: 4px; }
  .trend-chart { height: auto; aspect-ratio: 520 / 230; }
  .chart-label { font-size: 16px; }
  .chart-summary { font-size: 11px; line-height: 1.65; flex-wrap: wrap; padding: 11px 16px; }
  .chart-summary .dim { display: none; }
  .chart-tooltip { font-size: 12px; max-width: calc(100vw - 55px); white-space: normal; }
  .team-overview-table { display: none; }
  .mobile-team-list { display: grid; padding: 0 15px; }
  .mobile-team-row { background: none; text-align: left; padding: 15px 0; border-top: 1px solid var(--line-soft); min-width: 0; }
  .mobile-team-head { display: flex; align-items: center; justify-content: space-between; gap: 9px; }
  .mobile-team-head strong { display: block; font-size: 13px; }
  .mobile-team-head small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
  .mobile-team-head .badge { font-size: 10px; }
  .mobile-team-metrics { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 12px; }
  .mobile-team-metrics span { display: block; font-size: 11px; color: var(--muted); }
  .mobile-team-metrics strong { display: block; font-size: 18px; margin-top: 3px; font-weight: 700; }
  .table-bottom { font-size: 11px; padding: 12px 15px; line-height: 1.6; flex-wrap: wrap; gap: 12px; }
  .table-bottom > .tiny { font-size: 10px; }
  .team-grid { grid-template-columns: 1fr; gap: 12px; }
  .team-card { padding: 17px; }
  .team-card-head { flex-wrap: nowrap; gap: 10px; margin-bottom: 18px; }
  .team-card-head .team-avatar { width: 36px; height: 36px; border-radius: 10px; font-size: 12px; }
  .team-card-head .team-name { font-size: 15px; }
  .team-card-head .team-city { font-size: 12px; margin-top: 1px; }
  .team-card-head .badge { margin-left: auto; font-size: 10px; max-width: 118px; white-space: normal; text-align: left; }
  .team-card-metrics { grid-template-columns: 1fr 1fr 1.25fr; gap: 10px; }
  .team-card-metrics div:last-child { grid-column: auto; }
  .team-card-metrics span { font-size: 11px; }
  .team-card-metrics strong { font-size: 22px; margin-top: 4px; }
  .team-card-footer { margin-top: 15px; padding-top: 12px; font-size: 11px; }
  .team-city { font-size: 12px; }
  .filter-row { gap: 10px; }
  .search-input input { min-height: 48px; padding-left: 40px; }
  .search-input svg { top: 16px; left: 13px; }
  .filter-row select { font-size: 16px !important; min-height: 46px; flex: 1; max-width: calc(50% - 5px); }
  .pagination { gap: 5px; }
  .pagination button { width: 44px; min-width: 44px; height: 44px; font-size: 12px; }
  .issue-tabs { gap: 7px; }
  .issue-tab { padding: 9px 12px; font-size: 12px; flex: 1 0 calc(50% - 7px); justify-content: space-between; }
  .pill-count { font-size: 11px; padding: 2px 6px; }
  .issue-card { padding: 17px; gap: 12px; }
  .issue-title { font-size: 15px; line-height: 1.5; }
  .issue-title small { font-size: 11px; margin-left: 5px; }
  .issue-desc { font-size: 13px; line-height: 1.7; }
  .issue-footer { font-size: 11px; gap: 10px 13px; margin-top: 14px; }
  .issue-status { font-size: 11px; }
  .issue-actions { margin-top: 0; gap: 9px; }
  .issue-actions > .btn { flex: 1; }
  .section-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
  .section-tile { padding: 14px 9px; font-size: 12px; min-height: 85px; gap: 10px; line-height: 1.4; }
  .section-tile svg { width: 22px; height: 22px; }
  .back-link { min-height: 44px; font-size: 13px; padding: 8px 0; margin-bottom: 6px; }
  .settings-card { padding: 20px 17px; }
  .settings-person .badge { font-size: 10px; }
  .settings-row { flex-wrap: wrap; padding: 16px 0; font-size: 13px; }
  .settings-row > strong { font-size: 13px; }
  .settings-row p { font-size: 12px; line-height: 1.65; }
  .toggle { min-width: 48px; min-height: 44px; position: relative; padding: 0; background: transparent !important; }
  .toggle::before { content: ''; position: absolute; width: 39px; height: 23px; top: 50%; left: 50%; transform: translate(-50%, -50%); border-radius: 20px; background: #273246; }
  .toggle.active::before { background: var(--blue-main); }
  .toggle span { position: relative; margin-left: 8px; z-index: 1; }
  .security-note { font-size: 12px; line-height: 1.8; padding: 14px; }
  .form-help { font-size: 12px; line-height: 1.7; }
  .person-line { padding: 16px 0; gap: 10px; }
  .person-line .badge { font-size: 10px; }
  .person-line .tiny { font-size: 11px; }
  .person-line .avatar { width: 35px; height: 35px; font-size: 12px; }
  .rank-row { padding: 15px 0; }
  .rank-number { font-size: 13px; }
  .rank-value strong { font-size: 16px; }
  .rank-value small { font-size: 11px; }
  .ranking .tiny { font-size: 11px; }
  .bar-row { grid-template-columns: 85px 1fr 40px; gap: 10px; font-size: 12px; }
  .bar-chart { padding: 24px 17px; }
  .stat-bar-label { font-size: 13px; gap: 12px; }
  .team-stat-bars { padding: 22px 17px; }
  .team-stat-bars .stat-bar-track { height: 6px; }
  .mini-screen { min-height: 110px; }
  .screen-demo-note { font-size: 10px; white-space: normal; max-width: 95%; }
  .screen-label { font-size: 10px; gap: 5px; flex-wrap: wrap; }
  .screen-grid { grid-template-columns: 1fr 1fr; }
  .table-scroll:not(.team-overview-table) { overflow: visible; }
  .table-scroll:not(.team-overview-table) .teams-table { display: block; white-space: normal; }
  .table-scroll:not(.team-overview-table) .teams-table thead { display: none; }
  .table-scroll:not(.team-overview-table) .teams-table tbody { display: grid; gap: 12px; }
  .table-scroll:not(.team-overview-table) .teams-table tbody tr:not([data-action]) { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 10px; padding: 14px; gap: 12px; }
  .table-scroll:not(.team-overview-table) .teams-table td { display: block; padding: 0; border: 0; font-size: 14px; }
  .table-scroll:not(.team-overview-table) .teams-table td:first-child { grid-column: 1 / -1; font-weight: 700; font-size: 15px; }
  .table-scroll:not(.team-overview-table) .teams-table td:not(:first-child)::before { content: attr(data-label); display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
  .mobile-nav { height: calc(68px + var(--phone-safe-bottom)); padding: 6px max(6px, var(--phone-safe-right)) calc(8px + var(--phone-safe-bottom)) max(6px, var(--phone-safe-left)); }
  .mobile-nav button { min-height: 48px; min-width: 0; flex: 1; font-size: 11px; gap: 6px; }
  .mobile-nav button svg { width: 22px; height: 22px; }
  .mobile-nav button.active::before { top: -6px; }
  .mobile-nav .mobile-count { right: calc(50% - 23px); font-size: 9px; min-width: 16px; height: 16px; line-height: 16px; top: -1px; font-style: normal; }
  .auth-scene { padding: 20px max(16px, var(--phone-safe-right)) calc(25px + var(--phone-safe-bottom)) max(16px, var(--phone-safe-left)); min-height: calc(var(--tg-viewport-stable-height, 100dvh) - 44px - var(--phone-safe-top)); }
  .auth-layout { gap: 20px; }
  .auth-form { padding: 24px 21px; }
  .auth-form h2 { font-size: 24px; }
  .auth-form > p { font-size: 13px; line-height: 1.7; margin-bottom: 20px; }
  .auth-icon { margin-bottom: 17px; }
  .auth-identity { font-size: 12px; gap: 8px; padding: 10px; }
  .auth-identity .badge { font-size: 10px; white-space: normal; max-width: 115px; margin-left: 0; }
  .auth-identity > span:nth-child(2) { flex: 1; min-width: 110px; }
  .form-field { gap: 8px; margin-bottom: 18px; }
  .form-field label { font-size: 13px; }
  .password-wrap input { min-height: 49px; padding-right: 49px; }
  .password-wrap .icon-btn { top: 2px; right: 2px; }
  .form-error { font-size: 13px; }
  .auth-form .btn.primary { min-height: 49px; font-size: 14px; }
  .auth-footer { font-size: 12px; }
  .auth-footer .text-btn { font-size: 12px; }
  .telegram-name { font-size: 14px; }
  .telegram-status { font-size: 12px; }
  .telegram-bubble { font-size: 14px; padding: 17px; }
  .telegram-bubble p { font-size: 13px; line-height: 1.8; }
  .telegram-time { font-size: 10px; }
  .tg-button { min-height: 49px; font-size: 13px; }
  .auth-card-bottom { font-size: 12px; line-height: 1.6; }
  .modal-backdrop { padding: 14px 10px calc(14px + var(--phone-safe-bottom)); align-items: end; }
  .modal { max-height: calc(var(--phone-visible-height, 100dvh) - 32px - var(--phone-safe-top) - var(--phone-safe-bottom)); width: 100%; border-radius: 19px; }
  .modal-head { position: sticky; top: 0; background: #151e2a; z-index: 1; padding: 10px 17px; }
  .modal-head h2 { font-size: 17px; }
  .modal-body { padding: 20px 18px; }
  .modal-body p { font-size: 14px; line-height: 1.8; }
  .modal-actions { gap: 10px; flex-wrap: wrap; }
  .modal-actions .btn { flex: 1; }
  .detail-pair { font-size: 13px; gap: 14px; }
  .detail-pair strong { text-align: right; }
  .toast { bottom: calc(82px + var(--phone-safe-bottom)); font-size: 13px; width: max-content; max-width: calc(100% - 28px); }
  .keyboard-open .mobile-nav { display: none; }
  .keyboard-open .main-content { padding-bottom: 30px; }
  .keyboard-open .modal-backdrop { align-items: start; padding-top: calc(10px + var(--phone-safe-top)); }
  .keyboard-open .toast { bottom: 15px; }
  .footer-note { font-size: 10px; line-height: 1.6; gap: 15px; }
  .footer-note span:last-child { max-width: 170px; }
  .admin-banner { font-size: 12px; line-height: 1.7; }
}
@media (max-width: 359px) {
  .main-content { padding-left: 12px; padding-right: 12px; }
  .demo-toolbar { padding: 0 8px; }
  .demo-controls { gap: 1px; }
  .demo-role button { padding: 7px 9px; }
  .demo-link { font-size: 9px; }
  .coverage { padding: 9px 10px; gap: 7px; flex-wrap: wrap; }
  .coverage > span { flex: 1; }
  .coverage .text-btn { margin-left: 20px; }
  .filters { flex-wrap: wrap; }
  .periods { flex-basis: 100%; }
  .scope-select { flex: 1; }
  .kpi-top { font-size: 11px; }
  .kpi-top .kpi-icon { display: none; }
  .kpi-value { font-size: 28px; }
  .team-card { padding: 14px; }
  .team-card-head .badge { max-width: 105px; }
  .team-card-head .team-avatar { display: none; }
  .team-card-metrics { gap: 7px; }
  .team-card-metrics span { font-size: 10px; }
  .team-card-footer { font-size: 10px; }
  .mobile-nav button { font-size: 10px; }
  .auth-form { padding: 21px 17px; }
  .auth-identity .badge { max-width: none; }
  .screen-grid { grid-template-columns: 1fr; }
}

/* App buttons keep the phone's system keyboard closed. */
@media (max-width: 760px) {
  body[data-gate="password"] .auth-scene,
  body[data-gate="denied"] .auth-scene { min-height: calc(var(--tg-viewport-stable-height, 100dvh) - var(--phone-safe-top)); padding-top: 16px; }
  body[data-gate="password"] .auth-layout { gap: 14px; }
  body[data-gate="password"] .auth-intro .brand { margin-bottom: 0; }
  .auth-form.pin-auth { padding: 20px 20px 10px; }
  .pin-access { margin-bottom: 13px; font-size: 11px; }
  .pin-identity { margin-bottom: 20px; }
  .pin-identity strong { font-size: 13px; }
  .pin-identity small { font-size: 11px; }
  .pin-form .pin-heading h2 { font-size: 24px; }
  .pin-form .pin-heading p { font-size: 13px; }
  .pin-step { font-size: 11px; margin-bottom: 7px; }
  .pin-dots { margin-top: 18px; gap: 17px; }
  .pin-feedback { min-height: 47px; margin-bottom: 8px; }
  .pin-feedback .form-error,.pin-status { font-size: 12px; }
  .pin-keypad { gap: 7px; max-width: 296px; }
  .pin-key { min-height: 54px; font-size: 26px; }
  .pin-form .pin-hint { font-size: 11px; margin-top: 11px; }
  .pin-footer { margin-top: 6px; }
  .pin-footer .text-btn { font-size: 12px; }
  .pin-modal .modal-body { padding: 20px 22px; }
}
@media (max-width: 359px), (max-width: 760px) and (max-height: 700px) {
  .auth-form.pin-auth { padding: 16px 17px 8px; }
  .pin-access { display: none; }
  .pin-identity { margin-bottom: 14px; }
  .pin-form .pin-heading h2 { font-size: 21px; }
  .pin-form .pin-heading p { font-size: 12px; }
  .pin-dots { margin-top: 14px; gap: 16px; }
  .pin-key { min-height: 48px; }
  .pin-feedback { min-height: 44px; margin-bottom: 5px; }
  .pin-modal .modal-body { padding: 16px 18px; }
}

/* iPhone Pro и Pro Max (402 и 440 pt): «Все города» помещается целиком, период — рядом. */
@media (min-width: 390px) and (max-width: 760px) {
  .scope-select { flex-basis: 156px; }
}
