/* Телефонная версия. Ориентиры:
   - зона нажатия не меньше 44–48 px, между соседними элементами от 8 px (Apple HIG, Material Design);
   - основной текст 16–17 px, второстепенный не мельче 13–14 px;
   - поля ввода 16 px — иначе iPhone приближает страницу при фокусе;
   - окна выезжают снизу листом, главное — в зоне большого пальца. */

@media (max-width: 899px) {
  :root {
    --radius: 14px;
    --radius-sm: 10px;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --faint: #7d8597; --muted: #a0a7b6; }
  }

  body { font-size: 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
  button, a, input, select, label, summary { touch-action: manipulation; }
  .small { font-size: 14px; }
  .hide-sm { display: none !important; }
  .sub, .rows .sub { font-size: 14px; }
  h2 { font-size: 17px; }

  #app { padding: 0 16px calc(150px + env(safe-area-inset-bottom)); }

  /* Закреплённый заголовок экрана с крупным названием */
  .page-head {
    position: sticky; top: 0; z-index: 20;
    margin: 0 -16px 12px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid transparent;
  }
  .page-head h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
  .page-head .sub { font-size: 15px; }

  /* Кнопки и поля */
  .btn { height: 44px; padding: 0 16px; font-size: 15px; border-radius: 12px; }
  .btn.sm { height: 40px; padding: 0 14px; font-size: 15px; }
  .btn.xs { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
  .btn svg { width: 18px; height: 18px; }
  .btn:active, .stepper button:active, .tabs button:active, .seg button:active { transform: scale(.97); }
  .icon-btn { width: 44px; height: 44px; border-radius: 12px; }
  .icon-btn svg { width: 20px; height: 20px; }

  input, select, textarea { font-size: 16px; min-height: 48px; padding: 10px 12px; border-radius: 12px; }
  textarea { min-height: 110px; }
  label.field > span { font-size: 14px; margin-bottom: 6px; }

  .check { width: 26px; height: 26px; border-radius: 8px; border-width: 2px; }
  .check:checked::after { left: 7px; top: 2px; width: 6px; height: 12px; border-width: 0 2.5px 2.5px 0; }

  .pill { height: 26px; padding: 0 10px; font-size: 13px; }

  /* Карточки и списки */
  .card-head { padding: 14px 16px; }
  .card-head h2 { font-size: 17px; }
  .empty-row { font-size: 15px; padding: 22px 16px; }

  .rows > li { min-height: 56px; padding: 12px 16px; gap: 14px; }
  .rows .txt { font-size: 16px; }
  .rows .due { font-size: 14px; }
  .rows li:active:not(.editing) { background: var(--surface-2); }
  .rows .tools { opacity: 1; }
  .rows .task-tools { display: none; }
  .qty { font-size: 14px; }

  .feed li { padding: 12px 16px; font-size: 15px; }
  .feed .when { font-size: 13px; }

  /* Обзор */
  .quick { min-height: 52px; border-radius: 14px; padding: 0 14px; }
  .quick input { font-size: 16px; min-height: 52px; }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .label { font-size: 14px; }
  .kpi .value { font-size: 28px; }
  .kpi .delta { font-size: 13px; }
  .dash { gap: 12px; margin-top: 12px; }
  .stack { gap: 12px; }

  /* Проекты: поиск, чипы направлений, вкладки статусов */
  .toolbar { gap: 10px; margin-bottom: 12px; }
  .toolbar input[type="search"] { max-width: none; flex: 1 1 100%; }
  .chips {
    display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
    margin: 0 -16px 12px; padding: 2px 16px;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip {
    flex: 0 0 auto; height: 36px; padding: 0 14px;
    display: inline-flex; align-items: center; gap: 6px;
    font: inherit; font-size: 14px; font-weight: 500;
    border: 1px solid var(--border-strong); border-radius: 999px;
    background: var(--surface); color: var(--text); cursor: pointer;
  }
  .chip .dot { width: 8px; height: 8px; border-radius: 50%; }
  .chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

  .tabs { padding: 4px; border-radius: 14px; }
  .tabs button { height: 44px; font-size: 15px; border-radius: 10px; flex-direction: column; gap: 0; line-height: 1.1; }
  .tabs button span { font-size: 12px; }
  .tabs button.on { background: var(--surface); box-shadow: 0 0 0 1px var(--border-strong), var(--shadow); }
  .seg button { height: 40px; font-size: 15px; padding: 0 14px; }

  .col-list { gap: 10px; }
  .pcard { padding: 16px; }
  .pcard .t { font-size: 17px; }
  .pcard .meta { margin-top: 10px; }
  .pcard .next-task { font-size: 15px; margin-top: 10px; }
  .pcard .progress { margin-top: 12px; height: 6px; }
  .pcard .row { font-size: 14px; margin-top: 10px; }
  .pcard:active { transform: scale(.985); }

  /* Карточка проекта */
  .narrow { gap: 14px; }
  .narrow > .crumbs {
    position: sticky; top: 0; z-index: 20;
    margin: 0 -16px -6px; padding: env(safe-area-inset-top) 8px 0;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  }
  .narrow > .crumbs .back-btn { height: 48px; padding: 0 12px 0 0; margin-left: 0; font-size: 17px; font-weight: 400; }
  .narrow > .crumbs .back-btn svg { width: 26px; height: 26px; }
  .narrow > .crumbs .back-btn:active { opacity: .5; }

  /* Выбор вариантов в листах */
  .chip-pick { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
  .chip-pick::-webkit-scrollbar { display: none; }
  .field-label { font-size: 14px; }
  .seg-pick label { height: 40px; font-size: 15px; }
  .cat-color { width: 30px; height: 30px; }
  .cat-name { min-height: 44px; }
  .project-title { font-size: 26px; font-weight: 700; line-height: 1.2; }

  .stepper { gap: 6px; }
  .stepper button { height: 44px; font-size: 14px; border-radius: 12px; }

  /* Свойства проекта — строками, как в настройках телефона */
  .meta-row {
    flex-direction: column; gap: 0;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden;
  }
  .meta-row label {
    flex: none; min-height: 52px; padding: 4px 8px 4px 16px;
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    font-size: 16px; color: var(--text);
    border-bottom: 1px solid var(--border);
  }
  .meta-row label:last-child { border-bottom: 0; }
  .meta-row select, .meta-row input {
    flex: 0 1 auto; width: auto; max-width: 60%;
    min-height: 44px; border: 0; background: transparent; color: var(--muted);
    text-align: right; text-align-last: right; padding: 0 8px; font-size: 16px;
  }

  .add-row { padding: 12px 16px; }
  .add-row form { flex-wrap: nowrap; gap: 8px; }
  .add-row input { flex: 1 1 auto; min-width: 0; }
  .add-row .date-opt { display: none; }
  .add-row .qty-in { flex: 0 0 96px; }
  .add-row .btn, .add-card .btn { width: 48px; height: 48px; padding: 0; flex: 0 0 auto; }
  .add-row .btn svg, .add-card .btn svg { width: 22px; height: 22px; }

  .inline-edit { gap: 8px; }
  .inline-edit input[name=title] { flex: 1 1 100%; }
  .inline-edit input[type=date] { flex: 1 1 100%; }
  .inline-edit .btn { flex: 1 1 auto; }

  .photos { gap: 12px; padding: 12px 16px 16px; }
  .photo { font-size: 14px; border-radius: 12px; }

  details.more > summary { min-height: 52px; }

  /* Покупки */
  .add-card { padding: 12px; gap: 8px; }
  .add-card input[name=name] { flex: 1 1 100%; }
  .add-card .qty-in { flex: 0 0 96px; }
  .add-card select { flex: 1 1 0; min-width: 0; }

  /* Нижнее меню: крупные иконки и «таблетка» у активного раздела */
  .tabbar { padding-top: 6px; }
  .tabbar a { gap: 4px; padding: 4px 2px 10px; font-size: 12px; min-height: 60px; }
  .tabbar svg { width: 24px; height: 24px; box-sizing: content-box; padding: 4px 18px; border-radius: 16px; transition: background .15s; }
  .tabbar a.active svg { background: var(--accent-weak); }
  .tabbar a.active { color: var(--text); font-weight: 600; }
  .tabbar a.active svg { color: var(--accent); }

  .fab { width: 56px; height: 56px; border-radius: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); }
  #pet-roam { bottom: calc(74px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(150px + env(safe-area-inset-bottom)); }
  .toast { font-size: 15px; padding: 12px 16px; border-radius: 14px; }
  .roam-bubble { font-size: 14px; max-width: 240px; }

  /* Окна выезжают снизу листом */
  /* Лист занимает только видимую область: когда открыта клавиатура, он поднимается над ней */
  .modal-back { align-items: flex-end; padding: 0; top: var(--vvt, 0px); bottom: auto; height: var(--vvh, 100%); }
  .modal {
    max-width: none; max-height: calc(var(--vvh, 100vh) - 16px);
    border-radius: 20px 20px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheet-up .22s cubic-bezier(.2, .8, .2, 1);
  }
  .modal::before {
    content: ""; display: block; width: 40px; height: 5px; border-radius: 3px;
    background: var(--border-strong); margin: 8px auto 0;
  }
  .modal .card-body { padding: 12px 16px 16px; }
  .modal-title { font-size: 20px; font-weight: 700; }
  .modal .actions { gap: 10px; }
  .modal .actions .btn { flex: 1; height: 50px; font-size: 16px; }
  @keyframes sheet-up { from { transform: translateY(100%); } }

  .species label { padding: 14px 6px; font-size: 15px; }
  .evo { gap: 4px; padding: 12px 6px; }
  .evo-step { padding: 8px 2px; min-width: 0; }
  .evo-step .nm { font-size: 11.5px; overflow-wrap: anywhere; line-height: 1.2; }

  /* Питомец и настройки */
  .stats-line .v { font-size: 22px; }
  .stats-line .l { font-size: 13px; }
  .rules li { font-size: 15px; }
  .switch { min-height: 44px; font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .modal { animation: none; }
}
