/* Phone shell (≤760px): bottom tab bar, safe areas, 44px touch targets, 16px inputs.
   Driven by width, so a narrow desktop window gets the same layout. */
@media (max-width: 760px) {
  :root { --tabbar-h: 60px; --safe-b: env(safe-area-inset-bottom, 0px); }
  html, body { background: var(--bg-primary); }
  body { display: block; padding-top: env(safe-area-inset-top, 0px); }

  .sidebar {
    position: fixed; inset: auto 0 0 0; z-index: 50; width: 100%; height: auto;
    padding: 0 max(6px, env(safe-area-inset-left, 0px)) var(--safe-b) max(6px, env(safe-area-inset-right, 0px));
    border: 0; border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.92);
    transition: transform 0.18s ease;
  }
  @supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .sidebar { background: rgba(255, 255, 255, 0.78); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
  }
  .sidebar .brand, .sidebar .sidebar-bottom { display: none; }
  .sidebar nav { display: flex; flex-wrap: nowrap; gap: 0; padding: 0; margin: 0; height: var(--tabbar-h); }
  .sidebar nav button {
    flex: 1 1 0; width: auto; min-width: 0; min-height: 44px; margin: 0; padding: 6px 2px 4px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 11px; line-height: 1.1; border: 0; border-radius: 0; background: transparent; box-shadow: none;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .sidebar nav button::before, .sidebar nav button::after { display: none; }
  .sidebar nav button svg { width: 22px; height: 22px; margin: 0; }
  .sidebar nav button.active { color: var(--accent-action); background: transparent; box-shadow: none !important; }
  body.keyboard-open .sidebar { transform: translateY(110%); }

  .main { height: auto; min-height: 100vh; overflow: visible; padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); }
  .topbar {
    position: sticky; top: 0; z-index: 40; flex-wrap: nowrap; align-items: center; gap: 10px;
    padding: 10px 14px; background: rgba(248, 250, 252, 0.94); border-bottom: 1px solid var(--border);
  }
  .topbar .eyebrow, #page-description, .top-actions .avatar { display: none; }
  .topbar h1 { font-size: 19px; line-height: 1.2; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar > div:first-child { min-width: 0; flex: 1 1 auto; }
  .top-actions { width: auto; flex: 0 0 auto; gap: 6px; }
  #refresh { font-size: 0; padding: 0; width: 44px; }
  #refresh svg { width: 20px; height: 20px; margin: 0; }
  html[data-shell="telegram"] #app-back { display: none; }

  .content { padding: 12px 12px 8px; }
  .panel { padding: 14px; border-radius: 14px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric { padding: 12px; }
  .metric strong { font-size: 24px; }

  button, .btn, .ghost, .danger, .tab, select, input:not([type="checkbox"]):not([type="radio"]) { min-height: 44px; }
  input, select, textarea { font-size: 16px; }
  .toolbar { flex-wrap: wrap; gap: 8px; }
  .toolbar > input { flex: 1 1 100%; }
  .row-actions .btn, .row-actions .ghost { flex: 1 1 auto; }
  .checkboxes label { min-height: 44px; display: inline-flex; align-items: center; gap: 8px; }

  #toast { bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); left: 12px; right: 12px; max-width: none; }
  body.auth-blocked .sidebar { display: none; }
}

/* Glass folders become plain vertical cards on phones: name, counts, «Открыть». */
@media (max-width: 760px) {
  .glass-folder-grid { display: grid !important; grid-template-columns: minmax(0, 1fr) !important; gap: 10px !important; padding: 12px 0 0 !important; margin: 0 !important; }
  .glass-folder-card { width: auto !important; max-width: none !important; justify-self: stretch !important; height: auto !important; min-height: 0 !important; padding: 0 !important; aspect-ratio: auto !important; margin: 0 !important; transform: none !important;
    border: 1px solid var(--border); border-radius: 14px; background: var(--bg-secondary); }
  .glass-folder-scene { display: none !important; }
  .glass-folder-footer { position: static !important; display: flex !important; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 14px !important; margin: 0 !important; opacity: 1 !important; transform: none !important; }
  .glass-folder-footer > div { display: block !important; min-width: 0; }
  .glass-folder-footer h3 { position: static !important; clip: auto !important; width: auto !important; height: auto !important;
    margin: 0 0 2px; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .glass-folder-footer p { position: static !important; clip: auto !important; width: auto !important; height: auto !important; margin: 0; font-size: 13px; color: var(--text-secondary); }
  .glass-folder-open { flex: 0 0 auto; }
}

/* One scroll container on phones: lists grow instead of scrolling inside the page. */
@media (max-width: 760px) {
  .script-list, .proposal-panel, .scripts-layout > * { max-height: none !important; overflow: visible !important; position: static !important; }
  .scripts-layout { grid-template-columns: minmax(0, 1fr) !important; }
}

@media (max-width: 760px) {
  .sidebar nav button { padding-left: 1px; padding-right: 1px; }
  .sidebar nav .tab-label { display: block; max-width: 100%; font-size: 10px; letter-spacing: -0.1px; overflow: hidden; text-overflow: ellipsis; }
}

/* Phones: «Сегодня» replaces «Панель» in the tab bar; the overview lives in Настройки. */
@media (max-width: 760px) { .sidebar nav button[data-view="dashboard"] { display: none; } }
