/* Form spacing follows the existing controls and colours. */
.sheet-header h2 { min-width: 0; overflow-wrap: anywhere; }
.sheet-header .icon-btn { flex: 0 0 44px; width: 44px; height: 44px; min-width: 44px; }
.sheet .field > span:first-child { line-height: 1.5; }
.sheet .value-trigger { min-width: 0; }
.sheet .value-trigger > [data-value-label] { min-width: 0; line-height: 1.45; overflow-wrap: anywhere; }
.sheet .date-trigger > span { min-width: 0; line-height: 1.45; }
.sheet .choice-control > summary { line-height: 1.45; }
.sheet .choice-options > button { line-height: 1.5; }
.sheet-footer .btn { white-space: normal; line-height: 1.45; }

/* Nested grids own their spacing; field margins must not double it. */
.task-editor { gap: 22px; }
.task-editor .field { gap: 8px; }
.task-editor .form-grid { gap: 18px 14px; }
.task-editor .editor-disclosure > summary { gap: 10px; line-height: 1.5; }
.task-editor .editor-disclosure > div { gap: 20px; padding: 10px 0 18px; }
.task-editor .editor-disclosure > .form-grid:has(> .field:only-child) { grid-template-columns: minmax(0, 1fr); }
.task-editor .editor-disclosure > p { font-size: 13px; line-height: 1.65; padding-bottom: 18px; }
.task-editor .disclosure-hint { flex: 0 0 auto; font-size: 12px; line-height: 1.5; }
.collection-editor { gap: 22px; }

.habit-editor-v2 { gap: 22px; }
.habit-editor-v2 .habit-form-section { margin-top: 4px; gap: 14px; }
.habit-editor-v2 .habit-form-section > h3 { margin: 0; line-height: 1.5; }
.habit-editor-v2 .habit-advanced-body { gap: 20px; padding-top: 16px; }
.habit-editor-v2 .habit-advanced-body > .field { margin: 0; }
.habit-editor-v2 .habit-advanced-body .small { font-size: 13px; line-height: 1.65; }
.habit-editor-v2 .habit-picker-panel { margin: 0; gap: 16px; }
.habit-editor-v2 .habit-summary-row { gap: 12px; }
.habit-editor-v2 .habit-summary { line-height: 1.5; }
.habit-editor-v2 .habit-change { padding-inline: 12px; }
.habit-editor-v2 .habit-weekdays { gap: 6px; }
.habit-picker-panel .icon-option > span { white-space: normal; line-height: 1.4; overflow-wrap: anywhere; }

.flexible-plan-form { gap: 22px; }
.sheet .plan-advanced-fields { gap: 20px; padding-top: 16px; }
.sheet .plan-advanced-fields > .field { margin: 0; }
.sheet .plan-repeat { display: grid; gap: 16px; }
.sheet .plan-repeat .field { margin: 0; }
.sheet [data-repeat-options] { display: grid; gap: 16px; }
.sheet [data-repeat-options][hidden] { display: none; }
.sheet .plan-repeat-note { line-height: 1.65; }
.sheet .plan-repeat .plan-repeat-note { margin: 0; }
.sheet .plan-repeat-days { gap: 5px; margin: 0; }
.sheet .plan-repeat-days label { min-width: 0; }
.sheet .plan-repeat-days input { margin: 0; }
.sheet .plan-repeat-days span { line-height: 1.4; }
.sheet .plan-advanced > summary,
.sheet .block-until > summary { min-height: 48px; line-height: 1.5; gap: 10px; }
.sheet .plan-series-actions { gap: 12px; }
.sheet .plan-series-actions > .btn { min-width: 0; white-space: normal; line-height: 1.5; }

/* One gap model for every settings page, including nested reset screens. */
.sheet:has(.settings-screen) .settings-screen { gap: 20px; }
.sheet .settings-screen > .settings-intro { margin: 0 !important; line-height: 1.65; }
.sheet .settings-screen > .settings-back,
.sheet .settings-screen > .settings-note { margin: 0; }
.sheet .settings-sections { gap: 18px; }
.sheet .settings-menu { gap: 14px; }
.sheet .settings-card { min-width: 0; padding: 18px 16px; gap: 14px; }
.sheet .settings-card strong { line-height: 1.45; overflow-wrap: anywhere; }
.sheet .settings-card small { margin-top: 5px; line-height: 1.55; overflow-wrap: anywhere; }
.sheet .settings-group { padding: 20px; }
.sheet .settings-group h3 { font-size: 17px; line-height: 1.45; margin-bottom: 8px; }
.sheet .settings-group p { line-height: 1.65; }
.sheet .settings-switch { gap: 14px; }
.sheet .settings-switch strong { font-size: 16px; line-height: 1.45; }
.sheet .settings-time-fields { grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); gap: 12px; margin-top: 18px; }
.sheet .settings-time-fields .value-trigger { gap: 8px; padding-inline: 12px; }
/* A clock value is one readable unit. Narrow cards stack the two fields. */
.sheet .settings-time-fields .value-trigger > [data-value-label] { white-space: nowrap; overflow-wrap: normal; }
.sheet .settings-note { font-size: 13px; line-height: 1.65; }
.settings-screen.reset-screen .reset-group + .reset-group { margin-top: 4px; }
.sheet .reset-group > h3 { font-size: 14px; line-height: 1.5; }
.sheet .reset-confirm { gap: 20px; }
.sheet .reset-effects { gap: 14px; padding-left: 22px; }
.sheet .reset-counts { gap: 14px 24px; }
.sheet .reset-recovery { line-height: 1.65; }
.sheet .statistics-help p { font-size: 14px; line-height: 1.75; margin-bottom: 20px; }

/* Archived names must leave a complete, reachable restore action. */
.sheet[data-screen-key="Zarchiwizowane nawyki"] .sheet-content > .row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding-block: 16px;
  border-bottom: 1px solid var(--line);
}
.sheet[data-screen-key="Zarchiwizowane nawyki"] .row > h3 { min-width: 0; overflow-wrap: anywhere; line-height: 1.5; margin: 0; }
.sheet[data-screen-key="Zarchiwizowane nawyki"] .row > .btn { white-space: nowrap; max-width: 100%; }

/* Picker text may wrap, while wheels and calendar geometry stay unchanged. */
.value-picker > header > div { min-width: 0; }
.value-picker h2,
.date-dialog h2 { line-height: 1.4; overflow-wrap: anywhere; }
.value-picker > footer { gap: 12px; }
.value-picker > footer .btn { min-width: 0; white-space: normal; line-height: 1.4; }
.value-manual summary,
.color-custom summary { min-height: 44px; line-height: 1.5; gap: 10px; }
.value-picker .field > span { font-size: 13px; line-height: 1.5; }
.color-picker-preview > span { min-width: 0; line-height: 1.5; overflow-wrap: anywhere; }
.date-dialog > footer { flex-wrap: wrap; gap: 10px; }
.date-dialog > footer .btn { flex: 1 1 auto; min-width: 0; white-space: normal; line-height: 1.4; }

@media (max-width: 560px) {
  .sheet:has(.task-editor) .sheet-content { padding-top: 20px; }
  .sheet:has(.settings-screen) .sheet-content { padding: 20px 20px calc(26px + env(safe-area-inset-bottom)); }
  .task-editor { gap: 20px; }
  .task-editor .field > span:first-child { font-size: 13px; }
  .sheet .form-grid { gap: 18px 12px; }
  .sheet .settings-card { padding: 17px 15px; }
  .sheet[data-screen-key="Zarchiwizowane nawyki"] .sheet-content > .row { grid-template-columns: minmax(0, 1fr); }
  .sheet[data-screen-key="Zarchiwizowane nawyki"] .row > .btn { justify-self: end; }
}

@media (max-width: 360px) {
  .sheet:has(.settings-screen) .sheet-header,
  .sheet:has(.settings-screen) .sheet-content { padding-inline: 16px; }
  .sheet .settings-group { padding: 16px; }
  .sheet .settings-card { padding: 16px 13px; gap: 12px; }
  .sheet .settings-card-icon { width: 40px; height: 44px; }
  .sheet .settings-time-fields { gap: 10px; }
  .sheet .settings-time-fields .value-trigger { padding-inline: 10px; }
  .task-editor .editor-disclosure > summary { flex-wrap: wrap; gap: 6px 8px; padding-block: 12px; }
  .task-editor .disclosure-hint { flex-basis: 100%; text-align: left; padding-left: 27px; }
  .habit-editor-v2 .habit-summary-row { grid-template-columns: minmax(0, 1fr) 80px; gap: 9px; }
  .habit-editor-v2 .habit-weekdays,
  .sheet .plan-repeat-days { gap: 3px; }
  .sheet .plan-repeat-days span { font-size: 11px; }
  .value-picker { padding-inline: 18px; }
}

/* Startup recovery actions keep their full labels at narrow widths. */
.import-recovery-actions{display:flex;flex-direction:column;align-items:stretch;gap:12px;width:100%;max-width:28rem;margin:18px auto 0}
.import-recovery-actions>.btn{min-width:0;max-width:100%;white-space:normal;overflow-wrap:normal}
.import-recovery-actions>[role=status]{margin:0;overflow-wrap:anywhere}

/* With a very short viewport (for example landscape + IME), keep the
   whole editor scrollable. Header/footer must not consume the field's view.
   Match editable forms rather than current focus: tapping a button must not
   switch scroll owners between pointerdown and pointerup. */
@media (max-height: 240px) {
  #modal .sheet.screen-page > form:has(.sheet-content :is(
    textarea:not([readonly]):not([disabled]),
    input:not([readonly]):not([disabled]):not([type=hidden]):not([type=checkbox]):not([type=radio]):not([type=range]):not([type=button]):not([type=submit]):not([type=reset]):not([type=file]):not([type=color]):not([type=image]):not([data-value-source])
  )) {
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    scroll-padding-block: 8px;
  }
  #modal .sheet.screen-page > form:has(.sheet-content :is(
    textarea:not([readonly]):not([disabled]),
    input:not([readonly]):not([disabled]):not([type=hidden]):not([type=checkbox]):not([type=radio]):not([type=range]):not([type=button]):not([type=submit]):not([type=reset]):not([type=file]):not([type=color]):not([type=image]):not([data-value-source])
  )) > .sheet-content {
    flex: none;
    overflow: visible;
  }
}
