/* Mobile is the primary working surface. Keep content readable at 320px. */
.nav-label-short { display: none; }
.owner-tag { width: auto; padding: 0 5px; white-space: nowrap; }
/* Scrolling stays available; only the visual gutter is removed. */
* { scrollbar-width: none; }
*::-webkit-scrollbar { display: none; width: 0; height: 0; }
html { touch-action: pan-y pinch-zoom; }
:root {
  --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));
  --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));
  --safe-left: calc(max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px)) + var(--tg-content-safe-area-inset-left, 0px));
  --safe-right: calc(max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px)) + var(--tg-content-safe-area-inset-right, 0px));
}
.workspace { padding-top: var(--safe-top); }
.telegram-native-back dialog [data-action="close"] { display: none; }
.telegram-native-back .dialog-actions { grid-template-columns: minmax(0, 1fr); }
.telegram-native-back .dialog-actions > [type="submit"] { width: 100%; }
#dialog-title:focus { outline: none; }
@media (min-width: 641px) {
  .workspace { padding-left: max(44px, var(--safe-left)); padding-right: max(44px, var(--safe-right)); }
  .telegram-fullscreen dialog { top: var(--safe-top); bottom: var(--safe-bottom); max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 24px); }
}
.task-category, .category-choice { --category-fg: #52606e; --category-bg: #eef1f4; }
.category-health { --category-fg: #a52d42; --category-bg: #fff0f2; }
.category-housing { --category-fg: #246140; --category-bg: #eaf6ed; }
.category-work { --category-fg: #7139a5; --category-bg: #f3edff; }
.category-transport { --category-fg: #245fa5; --category-bg: #ebf3ff; }
.task-category { display: inline-flex; align-items: center; color: var(--category-fg); background: var(--category-bg); border-radius: 7px; padding: 4px 7px; font-size: 12px; line-height: 1.4; }
.category-picker, .payment-picker { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
.category-picker legend, .payment-picker legend { font-size: 14px; color: #58684f; margin-bottom: 9px; }
.category-picker > div { display: flex; flex-wrap: wrap; gap: 8px; }
.category-choice, .payment-picker label { position: relative; cursor: pointer; }
.category-choice input, .payment-picker input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.category-choice span { display: flex; align-items: center; min-height: 42px; padding: 8px 11px; border: 1px solid transparent; border-radius: 12px; color: var(--category-fg); background: var(--category-bg); font-size: 13px; }
.category-choice input:checked + span { border-color: currentColor; box-shadow: inset 0 0 0 1px currentColor; font-weight: 700; }
.category-choice input:focus-visible + span, .payment-picker input:focus-visible + span { outline: 3px solid #193748; outline-offset: 3px; }
.payment-picker { display: flex; gap: 8px; }
.payment-picker label { flex: 1; }
.payment-picker span { display: flex; justify-content: center; align-items: center; min-height: 44px; border: 1px solid #dde4d7; border-radius: 12px; background: #f6f8f3; font-size: 14px; }
.payment-picker input:checked + span { background: #e7f2dd; border-color: #647d43; font-weight: 700; }
.form-section { border-top: 1px solid #e5e9e1; margin: 0; padding: 0; }
.form-section summary { display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; min-height: 54px; padding: 12px 0; font-size: 14px; font-weight: 600; }
.form-section summary::-webkit-details-marker { display: none; }
.form-section summary::after { content: '+'; margin-left: auto; font-size: 19px; color: #6a795f; }
.form-section[open] summary::after { content: '−'; }
.form-section summary small { font-weight: 400; font-size: 12px; color: #6a795f; overflow-wrap: anywhere; min-width: 0; }
.form-section > .field:last-child { margin-bottom: 16px; }
.form-error:empty { display: none; }

@media (max-width: 640px) {
  :root {
    --radius: 20px;
  }
  html { scroll-padding-bottom: calc(90px + var(--safe-bottom)); }
  .workspace { padding: var(--safe-top) max(16px, var(--safe-right)) 0 max(16px, var(--safe-left)); }
  .topbar { height: 76px; gap: 12px; }
  .brand { gap: 9px; font-size: 20px; }
  .brand-mark { width: 40px; height: 40px; border-radius: 13px; font-size: 30px; }
  .brand-sub { font-size: 9px; letter-spacing: .65px; }
  .top-right { gap: 0; }
  .top-right .avatar { width: 36px; height: 36px; margin-left: 0; }
  .top-right .live-dot, .desktop-only { display: none; }

  .navigation {
    position: fixed;
    inset: auto 0 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    margin: 0;
    padding: 8px max(8px, var(--safe-right)) calc(8px + var(--safe-bottom)) max(8px, var(--safe-left));
    border: 0;
    border-top: 1px solid #e2e8dc;
    background: #fffffff2;
    backdrop-filter: blur(18px);
  }
  .nav-item { min-width: 0; min-height: 56px; padding: 7px 0; gap: 5px; flex-direction: column; border-radius: 12px; }
  .nav-item .icon { width: 21px; height: 21px; }
  .nav-label-full { display: none; }
  .nav-label-short { display: block; font-size: 11px; line-height: 1.2; white-space: nowrap; }

  .page-heading { display: flex; flex-direction: column; align-items: stretch; gap: 16px; margin: 12px 0 20px; }
  .page-heading > div { min-width: 0; }
  .page-heading h1 { font-size: clamp(26px, 7.2vw, 32px); line-height: 1.18; letter-spacing: -.8px; overflow-wrap: anywhere; text-wrap: balance; }
  .page-heading h1 > span { display: inline; font-size: .85em; margin-left: 3px; white-space: nowrap; }
  .page-heading .eyebrow { font-size: 10px; letter-spacing: .9px; line-height: 1.5; margin-bottom: 9px; color: #647263; }
  .page-heading p { max-width: none; font-size: 14px; line-height: 1.55; margin-top: 9px; color: #627066; }
  .page-heading > .secondary { align-self: flex-start; font-size: 14px; min-height: 44px; padding: 10px 14px; }
  .page-heading > .primary { width: 100%; font-size: 15px; min-height: 48px; }
  .primary, .secondary, .text-button, .danger-button { min-height: 44px; font-size: 14px; white-space: normal; line-height: 1.4; }
  .icon-button { width: 44px; height: 44px; }
  .demo-banner { font-size: 12px; padding: 8px 12px; line-height: 1.5; margin-bottom: 16px; }

  .overview-grid, .lower-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .journey-card { padding: 20px 20px 0; }
  .journey-top { gap: 10px; flex-wrap: wrap; }
  .pill-light { font-size: 10px; letter-spacing: .65px; }
  .journey-days { font-size: 11px; }
  .journey-core { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 18px 16px; align-items: center; padding: 24px 0 20px; }
  .journey-core > div:first-child { display: contents; }
  .journey-core h2 { grid-column: 1; grid-row: 1; font-size: 26px; line-height: 1.2; letter-spacing: -.7px; }
  .journey-core p { grid-column: 1 / -1; grid-row: 2; margin: 0; font-size: 14px; line-height: 1.5; white-space: normal; color: #bdc9cb; }
  .progress-ring { grid-column: 2; grid-row: 1; width: 120px; height: 120px; margin: 0; padding: 8px; }
  .progress-ring::after { inset: -6px; }
  .progress-ring strong { font-size: 42px; }
  .progress-ring small { font-size: 21px; }
  .progress-ring > div > span { font-size: 12px; }
  .travel-route { grid-column: 1 / -1; grid-row: 3; gap: 12px; font-size: 12px; margin: 0; }
  .travel-route > span:first-child, .travel-route > strong { white-space: nowrap; }
  .route-line { min-width: 30px; max-width: none; }
  .route-line .icon { width: 17px; height: 17px; }
  .journey-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px 0; font-size: 12px; line-height: 1.45; }
  .journey-bottom span:last-child { max-width: none; text-align: right; }
  .journey-bottom .icon { display: none; }

  .finance-card { padding: 18px; min-width: 0; }
  .finance-card h2 { font-size: 19px; }
  .finance-card .section-title { margin-bottom: 18px; }
  .money-top { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .money-top > div { min-width: 0; }
  .money-top > div + div { padding-left: 12px; }
  .money-label { font-size: 13px; color: #65715f; }
  .money-top strong { font-size: clamp(21px, 6vw, 28px); line-height: 1.25; letter-spacing: -.7px; overflow-wrap: anywhere; }
  .money-top.wide-money, .finance-summary.wide-money { grid-template-columns: minmax(0, 1fr); }
  .money-top.wide-money > div + div { border-left: 0; border-top: 1px solid var(--line); padding: 12px 0 0; }
  .budget-bar { margin-top: 18px; }
  .remaining { font-size: 13px; color: #65755c; line-height: 1.5; }
  .budget-total { padding: 14px; margin-top: 18px; min-width: 0; }
  .budget-total > div { min-width: 0; }
  .budget-total span { font-size: 13px; }
  .budget-total strong { font-size: 26px; overflow-wrap: anywhere; }
  .finance-card > .text-button { font-size: 14px; margin-top: 10px; }

  .team-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 16px 0 24px; }
  .team-card { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px 8px; padding: 14px; }
  .team-avatar { width: 34px; height: 38px; border-radius: 11px; font-size: 24px; }
  .team-card > .team-avatar { grid-column: 1; grid-row: 1; }
  .team-body { display: contents; }
  .team-body > b { grid-column: 2; grid-row: 1; font-size: 13px; line-height: 1.35; white-space: normal; }
  .team-body > span:not(.mini-bar) { display: none; }
  .team-card > strong { grid-column: 1 / -1; grid-row: 2; width: auto; font-size: 27px; margin: 0; }
  .team-card > strong > small { font-size: 14px; }
  .mini-bar { position: static; grid-column: 1 / -1; grid-row: 3; margin: 0; height: 5px; width: 100%; }

  .panel { padding: 18px; min-width: 0; }
  .section-title { gap: 10px; align-items: center; }
  .section-title > div { min-width: 0; }
  .section-title h2 { font-size: 21px; overflow-wrap: anywhere; }
  .section-title .eyebrow { font-size: 10px; letter-spacing: .6px; line-height: 1.5; }
  .section-title > .secondary { min-height: 44px; padding: 8px 12px; font-size: 13px; }
  .task-row { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 6px 8px; align-items: start; padding: 16px 0; }
  .task-check { grid-column: 1; grid-row: 1; width: 28px; height: 28px; min-width: 28px; margin-top: 2px; border-radius: 8px; }
  .task-check::before { inset: -8px; }
  .task-detail { grid-column: 2; grid-row: 1; padding: 2px 0; }
  .task-detail > strong { font-size: 16px; line-height: 1.4; }
  .task-meta { font-size: 12px; gap: 7px 9px; margin-top: 9px; color: #65725c; }
  .task-meta .priority { font-size: 12px; }
  .task-meta .icon { width: 14px; height: 14px; }
  .owner-tag { font-size: 12px; min-height: 23px; padding: 2px 6px; width: auto; }
  .task-side { grid-column: 2; grid-row: 2; max-width: none; flex-direction: row; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 5px 12px; }
  .task-side > b { font-size: 14px; white-space: normal; overflow-wrap: anywhere; }
  .task-side > span { max-width: none; font-size: 12px; line-height: 1.5; text-align: left; color: #6c805b; }
  .event p { font-size: 14px; }
  .event time { font-size: 12px; }
  .event-avatar { min-width: 28px; height: 28px; font-size: 12px; }
  .empty { padding: 30px 4px; }
  .empty h3 { line-height: 1.35; font-size: 18px; }
  .empty p { font-size: 14px; color: #65765c; }
  .footer { flex-direction: column; text-align: center; gap: 10px; padding: 26px 0 calc(98px + var(--safe-bottom)); font-size: 12px; line-height: 1.5; color: #67775e; }

  .section-progress { padding: 18px; gap: 12px; flex-wrap: wrap; }
  .section-progress > div:not(.wide-progress) { min-width: 0; flex: 1; }
  .section-progress .team-avatar { font-size: 25px; }
  .section-progress strong { font-size: 16px; }
  .section-progress span { font-size: 13px; }
  .section-progress > b { font-size: 28px; }
  .wide-progress { flex-basis: 100%; order: 5; margin: 4px 0 0; height: 7px; }
  .pet-switch { width: 100%; gap: 5px; padding: 5px; }
  .pet-switch button { padding: 9px 8px; flex: 1; gap: 6px; min-width: 0; min-height: 48px; justify-content: center; font-size: 16px; }
  .pet-switch button > span { font-size: 24px; }
  .pet-switch small { font-size: 12px; margin-left: 0; }
  .task-panel { padding: 16px 16px 4px; }
  .task-toolbar { gap: 12px; flex-wrap: wrap; }
  .segmented { padding: 3px; gap: 0; flex: 1; }
  .segmented > button { min-height: 42px; padding: 9px 10px; font-size: 13px; white-space: nowrap; }
  .view-toggle { padding: 3px; margin-left: auto; }
  .view-toggle .icon-button { width: 42px; height: 42px; }
  .view-toggle .icon { width: 19px; height: 19px; }
  .calendar-grid { gap: 2px; grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .calendar-heading strong { font-size: 16px; text-align: center; }
  .weekday { padding: 9px 0; font-size: 11px; }
  .day { min-height: 46px; padding: 6px 0; font-size: 15px; }
  .selected-date { font-size: 14px; gap: 8px; flex-wrap: wrap; }
  .weight-note { font-size: 13px; line-height: 1.65; color: #687960; }

  .board-toolbar { flex-wrap: wrap; gap: 12px; font-size: 14px; }
  .board-toolbar label { width: 100%; font-size: 14px; justify-content: space-between; }
  .board-toolbar select { max-width: 210px; padding: 10px; font-size: 14px; border: 1px solid #dce3d4; background: white; border-radius: 10px; min-height: 44px; }
  .apartment-grid { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .apartment-cover { height: 120px; }
  .apartment-body { padding: 18px; }
  .apartment-body .section-title { align-items: flex-start; }
  .apartment-body h2 { font-size: 21px; line-height: 1.3; }
  .apartment-body .area { font-size: 14px; color: #6c7a60; }
  .rent { display: flex; flex-wrap: wrap; align-items: baseline; gap: 3px 5px; }
  .rent strong { font-size: 27px; line-height: 1.3; min-width: 0; overflow-wrap: anywhere; }
  .rent > span, .converted { font-size: 13px; }
  .apartment-notes { font-size: 14px; color: #68765c; }
  .rating-row { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 6px 9px; margin: 12px 0; }
  .avatar.small { width: 30px; height: 30px; font-size: 13px; }
  .rating-label { font-size: 14px; color: #65765a; white-space: normal; }
  .stars { grid-column: 1 / -1; justify-content: space-between; gap: 2px; }
  .star { width: 44px; min-width: 0; min-height: 44px; padding: 8px; }
  .star .icon { width: 26px; height: 26px; }
  .listing-link { font-size: 14px; min-height: 48px; gap: 12px; }
  .board-empty .empty { padding: 36px 4px; }
  .board-empty h3 { font-size: 22px; }
  .board-empty .empty p { font-size: 14px; }

  body:has(dialog[open]) { overflow: hidden; }
  dialog {
    width: calc(100% - 20px - var(--safe-left) - var(--safe-right));
    max-width: 540px;
    max-height: calc(var(--app-visible-height, 100dvh) - 24px - var(--safe-top) - var(--safe-bottom));
    top: calc(var(--app-visible-top, 0px) + var(--safe-top));
    bottom: auto;
    left: var(--safe-left);
    right: var(--safe-right);
    margin: 12px auto;
    padding: 20px 16px;
    border-radius: 20px;
    overscroll-behavior: contain;
    scroll-padding: 16px;
  }
  .dialog-head { margin-bottom: 20px; gap: 8px; align-items: flex-start; }
  .dialog-head > div { min-width: 0; }
  .dialog-head h2 { font-size: 23px; line-height: 1.25; overflow-wrap: anywhere; text-wrap: balance; }
  .dialog-head .eyebrow { font-size: 10px; line-height: 1.5; }
  .dialog-head .eyebrow { display: none; }
  .dialog-head { margin-bottom: 16px; align-items: center; }
  .dialog-head h2 { font-size: 22px; }
  .category-choice span { min-height: 44px; }
  .field { font-size: 14px; margin-bottom: 17px; color: #58684f; }
  .field input, .field select, .field textarea { min-width: 0; width: 100%; min-height: 48px; padding: 11px 12px; font-size: 16px; }
  .form-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .form-row.currency-row { grid-template-columns: minmax(0, 1fr) 100px; gap: 12px; }
  .form-row:has(> .field:only-child) { grid-template-columns: minmax(0, 1fr); }
  .form-hint, .form-divider span { font-size: 13px; line-height: 1.6; color: #69795e; }
  .dialog-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
  .dialog-actions button { width: 100%; min-width: 0; min-height: 48px; padding: 11px 10px; font-size: 14px; }
  .dialog-actions .danger-button { order: 3; grid-column: 1 / -1; margin: 0; min-width: 0; font-size: 14px; }
  .finance-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 15px; gap: 12px; }
  .finance-summary span { min-width: 0; font-size: 13px; }
  .finance-summary b { font-size: 23px; overflow-wrap: anywhere; }
  .category-totals > div { flex-wrap: wrap; gap: 7px 12px; }
  .category-totals b { font-size: 14px; overflow-wrap: anywhere; }
  .tag { font-size: 12px; }
  .expense-row { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 7px 9px; }
  .expense-row b { font-size: 15px; }
  .expense-row small { font-size: 12px; line-height: 1.5; }
  .expense-row > strong { grid-column: 2; font-size: 15px; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  .expense-row > .icon { display: none; }
  #toast { bottom: calc(90px + var(--safe-bottom)); width: max-content; max-width: calc(100vw - 28px); font-size: 14px; }
  .locked { padding: 24px; }
  .locked h1 { font-size: 28px; }
  .locked p { font-size: 15px; }
}

@media (max-width: 360px) {
  .workspace { padding-left: max(12px, var(--safe-left)); padding-right: max(12px, var(--safe-right)); }
  .brand { font-size: 18px; }
  .brand-sub { font-size: 8px; }
  .journey-card { padding-inline: 16px; }
  .journey-core { grid-template-columns: minmax(0, 1fr) 108px; column-gap: 14px; }
  .journey-core h2 { font-size: 24px; }
  .progress-ring { width: 108px; height: 108px; padding: 7px; }
  .progress-ring strong { font-size: 37px; }
  .money-top, .finance-summary { grid-template-columns: minmax(0, 1fr); }
  .money-top > div + div { border-left: 0; border-top: 1px solid var(--line); padding: 12px 0 0; }
  .team-grid { gap: 10px; }
  .team-card { padding: 12px; gap: 9px 6px; }
  .team-body > b { font-size: 12px; }
  .section-title { flex-wrap: wrap; }
  .finance-card .section-title, .apartment-body .section-title { flex-wrap: nowrap; }
  .segmented { flex: 1 0 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .segmented > button { padding-inline: 7px; }
}
