/* Keep the form actions reachable as additional fields or shopping items appear. */
@layer errand-editor {
  dialog:has(#errand-form, #item-form[data-shop-batch]) {
    --editor-inset: clamp(16px, 3.3vw, 26px);
    --editor-limit: min(90dvh, 840px);
    width: min(490px, calc(100% - 24px));
    max-height: var(--editor-limit);
    overflow: hidden;
  }
  #dialog-inner:has(> #errand-form, > #item-form[data-shop-batch]) {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: calc(var(--editor-limit) - 2px);
    padding: 0;
  }
  #dialog-inner:has(> #errand-form, > #item-form[data-shop-batch]) > .modal-head {
    flex: none;
    margin: 0;
    padding: 12px var(--editor-inset) 8px;
    border-bottom: 1px solid var(--line);
  }
  #dialog-inner:has(> #errand-form, > #item-form[data-shop-batch]) .modal-head h2 { font-size: clamp(23px, 4.5vw, 28px); }
  #errand-form, #item-form[data-shop-batch] { display: flex; flex-direction: column; min-height: 0; }
  .errand-fields, .shop-draft-scroll {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scroll-padding-block: 12px;
    padding: 16px var(--editor-inset) 14px;
  }
  #errand-form .field, #errand-form .timing-picker { margin: 0; }
  #errand-form .editor-name input { font-size: 17px; }
  #errand-form .timing-picker { margin-top: 16px; }
  #errand-form .timing-picker > div {
    padding: 3px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--accent-light) 16%, #f4f7f6);
    gap: 4px;
  }
  #errand-form .timing-picker label {
    gap: 6px;
    min-width: 0;
    min-height: 44px;
    padding-inline: 3px;
    text-align: center;
    border: 1px solid transparent;
    border-radius: 9px;
    color: var(--muted);
    line-height: 1.22;
  }
  #errand-form .timing-picker svg, .editor-setting svg, #errand-details summary svg { width: 16px; height: 16px; }
  #errand-form .timing-picker label:has(:checked) {
    color: #fff;
    border-color: var(--accent-dark);
    background: var(--accent-dark);
    box-shadow: none;
  }
  #timing-hint { margin: 7px 0 0; }
  .editor-dates { margin-block: 13px 17px; }
  .editor-settings { border-block: 1px solid var(--line); }
  #errand-form .editor-setting {
    display: grid;
    grid-template-columns: minmax(max-content, 0.75fr) minmax(0, 1.25fr);
    align-items: center;
    gap: 12px;
    padding-block: 8px;
  }
  .editor-setting > span, #errand-details > summary { display: flex; align-items: center; gap: 9px; }
  .editor-setting > span > svg, #errand-details > summary > svg:first-child { color: var(--brand); }
  #errand-form .editor-setting select { width: 100%; min-width: 0; margin: 0; }
  .editor-setting + .editor-setting { border-top: 1px solid var(--line); }
  .editor-settings > .hint { margin-bottom: 12px; }
  #errand-form .repeat-box {
    margin: 5px 0 13px;
    padding: 8px 12px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: color-mix(in srgb, var(--accent-light) 10%, var(--surface));
  }
  #errand-form .repeat-box > legend { padding-inline: 4px; }
  #errand-form .repeat-presets { margin: 0 0 12px; }
  #errand-form .repeat-box > .field + .field, #errand-form #repeat-week { margin-top: 12px; }
  #errand-form #repeat-end { margin-top: 12px; }
  #repeat-preview:not(:empty) { margin-top: 10px; }
  #errand-details > summary {
    min-height: 48px;
    cursor: pointer;
    font-weight: 620;
    color: var(--ink);
    list-style: none;
  }
  #errand-details > summary::-webkit-details-marker { display: none; }
  #errand-details > summary > svg:last-child { margin-inline-start: auto; }
  #errand-details[open] > summary > svg:last-child { transform: rotate(90deg); }
  .editor-extra { display: grid; gap: 12px; padding: 2px 0 8px; }
  .editor-actions, .shop-draft-footer {
    flex: none;
    margin: 0;
    padding: 12px var(--editor-inset);
    border-top: 1px solid var(--line);
    background: var(--surface);
  }
  :is(.editor-actions, .shop-draft-actions) .primary { min-inline-size: 8rem; }
  @media (max-width: 650px) {
    dialog:has(#errand-form, #item-form[data-shop-batch]) {
      --editor-limit: calc(100dvh - max(8px, env(safe-area-inset-top)));
      inset: auto 0 0;
      width: 100%;
      max-width: 100%;
      margin: 0;
      border-radius: 22px 22px 0 0;
    }
    .editor-actions, .shop-draft-footer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  }
  @media (max-width: 360px) {
    #errand-form .editor-setting { grid-template-columns: minmax(0, 1fr); gap: 4px; }
    .editor-setting > span { gap: 5px; }
    :is(.editor-actions, .shop-draft-actions) .primary { min-inline-size: 0; }
  }
  @media (forced-colors: active) {
    #errand-form .timing-picker label:has(:checked) { border: 2px solid Highlight; }
  }
}

@layer phone-reminders {
  .phone-settings-row, .editor-phone > summary, .phone-row-end, .phone-status-line {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .phone-settings-row, .editor-phone > summary {
    justify-content: space-between;
    width: 100%;
    min-height: 44px;
    color: var(--ink);
    text-align: start;
    font-weight: 600;
  }
  .phone-settings-row { padding: 6px 0; }
  .setting-section > .phone-settings-row { margin: 0; }
  .phone-row-end { flex: 0 1 auto; color: var(--brand); text-align: end; }
  .phone-row-end svg { flex: none; width: 16px; height: 16px; }
  [data-phone-status] { font-size: 12px; font-weight: 600; line-height: 1.3; }
  .editor-phone { border-top: 1px solid var(--line); }
  .editor-phone summary, .phone-alternatives summary { cursor: pointer; }
  .editor-phone > summary { list-style: none; font-size: 13px; }
  .editor-phone summary::-webkit-details-marker { display: none; }
  .editor-phone[open] > summary svg { transform: rotate(90deg); }
  .phone-controls {
    border: 1px solid var(--line);
    border-radius: 15px;
    background: color-mix(in srgb, var(--accent-light) 15%, var(--surface));
    color: var(--ink);
    padding: clamp(14px, 3vw, 20px);
  }
  .editor-phone .phone-controls { margin-bottom: 10px; }
  .phone-status-line { gap: 10px; }
  .phone-indicator {
    flex: none;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--accent-dark);
    color: #fff;
  }
  .phone-indicator svg { width: 18px; height: 18px; }
  .phone-status-title { font-size: 17px; }
  .phone-description { margin: 12px 0 0; line-height: 1.5; }
  .phone-controls .hint { margin: 8px 0 0; }
  .phone-install-steps { margin: 10px 0 0; padding-inline-start: 24px; }
  .phone-install-steps li { margin-top: 6px; padding-inline-start: 2px; }
  .phone-controls-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .phone-controls-actions:not(:empty) { margin-top: 14px; }
  .phone-controls-actions button { min-height: 44px; }
  .phone-save-hint { border-inline-start: 3px solid var(--brand); padding-inline-start: 10px; margin: 8px 0; }
  .phone-test-result:not(:empty) { margin-top: 14px; font-weight: 580; color: var(--ink); }
  .phone-alternatives { border-top: 1px solid var(--line); margin-top: 18px; }
  .phone-alternatives summary { min-height: 44px; padding-block: 12px; font-weight: 600; }
  .phone-alternatives .hint, .phone-alternatives button { margin-top: 8px; }
  @media (forced-colors: active) {
    .phone-indicator { border: 1px solid ButtonText; }
  }
}

@layer shopping-entry {
  .shop-draft-row {
    min-inline-size: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }
  .shop-draft-row + .shop-draft-row {
    border-top: 1px solid var(--line);
    margin-top: 16px;
    padding-top: 16px;
  }
  .shop-row-legend {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  [data-shop-batch] .shop-row-name {
    display: flex;
    gap: 8px;
    align-items: flex-end;
  }
  [data-shop-batch] .shop-row-name .field { flex: 1; }
  [data-shop-batch] .field { min-width: 0; margin: 0; }
  [data-shop-batch] .form-grid { align-items: end; margin-top: 9px; }
  .shop-draft-row [data-shop-remove-row] { color: var(--muted); }
  .shop-draft-row [data-shop-remove-row] svg { width: 17px; height: 17px; }
  .shop-draft-footer { display: grid; gap: 8px; }
  .shop-draft-actions { margin: 0; }
  .shop-add-row {
    inline-size: 100%;
    min-height: 44px;
    color: var(--accent-dark);
    border-color: var(--accent-mid);
    background: color-mix(in srgb, var(--accent-light) 22%, var(--surface));
  }
  .shop-add-row svg { width: 18px; height: 18px; }
  @media (max-width: 650px) {
    dialog:has(#item-form[data-shop-batch]) {
      --editor-limit: calc(var(--shop-visible-height, 100dvh) - max(8px, env(safe-area-inset-top)));
      bottom: var(--shop-covered-bottom, 0px);
    }
    .shop-draft-actions .primary { flex: 1; }
  }
}
