/* Shared finishing layer. Entity colours and completion controls are owned by
   their existing styles; these rules only organise surfaces and information. */
:root {
  --ui-radius-control: 16px;
  --ui-radius-panel: 22px;
  --ui-motion-fast: 180ms;
  --ui-motion-ease: cubic-bezier(.22, 1, .36, 1);
}

/* A consistent title, close control and footer across the editor sheets. */
.sheet:not(.timer-sheet) .sheet-header {
  align-items: center;
  gap: 16px;
}
.sheet:not(.timer-sheet) .sheet-header h2 {
  line-height: 1.4;
  text-wrap: balance;
}
.sheet-content > h3 { line-height: 1.5; overflow-wrap: anywhere; }
.sheet-content > .field + .field { margin-top: 4px; }
.sheet .field input:not([type='checkbox']):not([type='color']):not([type='range']):not([data-value-source]),
.sheet .field textarea,
.sheet .field select {
  border-radius: var(--ui-radius-control);
  line-height: 1.5;
}
.sheet-footer .btn { overflow-wrap: anywhere; }
.sheet-footer .btn.primary { font-weight: 600; }
.sheet .hint,
.sheet .field-error {
  font-size: 12px;
  line-height: 1.6;
}

/* Calendar modes have descriptions; day/week/month are a compact view switch. */
.calendar-mode-menu { gap: 12px; margin-bottom: 18px; }
.calendar-mode-menu > .view-menu-option { min-height: 78px; }
.habit-view-menu.calendar-view-menu {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface-2);
}
.calendar-view-menu > .view-menu-option {
  position: relative;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 76px;
  padding: 12px 4px;
  border: 1px solid transparent;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  text-align: center;
  background: transparent;
}
.calendar-view-menu > .view-menu-option:has(> svg:nth-of-type(2)) {
  border-color: color-mix(in srgb, var(--accent) 42%, transparent);
  background: var(--accent-soft);
}
.calendar-view-menu > .view-menu-option > svg:nth-of-type(2) {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 13px;
  height: 13px;
  margin: 0;
}
.calendar-menu-actions {
  gap: 8px;
  padding-top: 20px;
  margin-top: 20px;
}
.calendar-menu-actions > .view-menu-option,
.habit-view-menu:not(.calendar-view-menu) > .view-menu-option {
  min-height: 56px;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.calendar-menu-actions > [data-action='clear-today-timeline'] {
  margin-top: 8px;
  color: var(--danger);
}
.calendar-menu-actions > [data-action='clear-today-timeline'] > svg:first-child {
  color: inherit;
}
.calendar-menu-date { gap: 12px; margin-block: 22px; }
.calendar-menu-date > .btn { min-height: 54px; }

/* Secondary action menus should read as actions, not compressed body text. */
.sheet-content > .menu-actions,
.sheet:has(.habit-detail-actions) .menu-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}
.sheet:has(.habit-detail-actions) .menu-actions { margin-top: 24px; }
.sheet .menu-actions > .btn {
  min-width: 0;
  min-height: 56px;
  padding: 14px;
  gap: 10px;
  font-size: 13px;
  line-height: 1.55;
  border: 1px solid var(--line);
  border-radius: var(--ui-radius-control);
  overflow-wrap: anywhere;
}

/* Long saved names and dates must not push the action out of the sheet. */
.sheet .template-row,
.sheet .history-row,
.sheet .session-row {
  min-width: 0;
  gap: 14px;
  padding-block: 18px;
  font-size: 13px;
  line-height: 1.65;
}
.sheet .template-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.sheet .template-row > div,
.sheet .history-row > div,
.sheet .session-row > p { min-width: 0; overflow-wrap: anywhere; }
.sheet .template-row h3 { font-size: 15px; line-height: 1.5; margin-bottom: 5px; }
.sheet .template-row > .btn,
.sheet .history-row > .btn,
.sheet .session-row > .btn { flex-shrink: 0; font-size: 13px; min-height: 44px; }
.sheet .history-row { flex-wrap: wrap; }
.sheet .history-row > div { flex: 1 1 180px; }
.sheet .history-row > .btn { margin-left: auto; }

/* Icon names are useful choices, so keep their full labels legible. */
.collection-icon-picker .icon-option > span,
.habit-picker-panel .icon-option > span,
#icon-picker .icon-option > span {
  font-size: 11px;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
  text-overflow: clip;
}
.collection-icon-picker .icon-option,
.habit-picker-panel .icon-option,
#icon-picker .icon-option {
  min-height: 76px;
  height: auto;
  justify-content: center;
  padding: 10px 5px;
  gap: 8px;
}
.collection-icon-picker .icon-grid,
.habit-picker-panel .icon-grid,
#icon-picker .icon-grid { scroll-padding-block: 8px; }
.habit-picker-panel .icon-grid,
#icon-picker .icon-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

/* Replanning used an undefined --border token, making result rows merge. */
.replan-results article {
  border-color: var(--line);
  border-radius: var(--ui-radius-panel);
  background: var(--surface-2);
  padding: 18px;
  gap: 12px;
}
.replan-results article > strong { font-size: 15px; line-height: 1.55; }
.replan-results article > div { font-variant-numeric: tabular-nums; }
.replan-pins { gap: 0; }
.replan-pins label { min-height: 72px; padding-block: 16px; }
.replan-pins label + label { border-top: 1px solid var(--line); }
.replan-pins label strong { font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.replan-pins label small { font-size: 13px; line-height: 1.5; font-variant-numeric: tabular-nums; }

/* Only paint changes animate; calendar drag geometry is left untouched. */
@media (prefers-reduced-motion: no-preference) {
  .view-menu-option,
  .sheet .menu-actions > .btn,
  .collection-member {
    transition: background-color var(--ui-motion-fast), border-color var(--ui-motion-fast), color var(--ui-motion-fast);
  }
  .habit-detail-more > summary > svg,
  .collection-icon-picker > summary > svg:last-child,
  .stats-selected-day > summary > svg {
    transition: transform 220ms var(--ui-motion-ease);
  }
  .collection-icon-picker[open] > summary > svg:last-child { transform: rotate(180deg); }
  .habit-detail-more[open] > .habit-detail-more-actions,
  .collection-icon-picker[open] > .icon-grid,
  .stats-selected-day[open] > .stats-day-entries {
    animation: ui-disclosure-in 200ms var(--ui-motion-ease);
  }
}
@keyframes ui-disclosure-in {
  from { opacity: 0; translate: 0 -4px; }
  to { opacity: 1; translate: 0 0; }
}
@media (hover: hover) and (pointer: fine) {
  .calendar-menu-actions > .view-menu-option:hover,
  .habit-view-menu > .view-menu-option:hover,
  .sheet .menu-actions > .btn:hover {
    background-color: var(--surface-3);
    border-color: color-mix(in srgb, var(--text) 20%, transparent);
  }
}

@media (max-width: 560px) {
  .collection-icon-picker .icon-grid,
  .habit-picker-panel .icon-grid,
  #icon-picker .icon-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 374px) {
  .sheet-content > .menu-actions,
  .sheet:has(.habit-detail-actions) .menu-actions { grid-template-columns: minmax(0, 1fr); }
  .sheet .menu-actions > .btn { min-height: 50px; }
  .calendar-mode-menu > .view-menu-option { padding-inline: 12px; gap: 10px; }
  .calendar-view-menu > .view-menu-option { font-size: 12px; }
  .calendar-menu-date { flex-wrap: wrap; gap: 10px; }
  .calendar-menu-date > .field { flex-basis: 100%; }
  .calendar-menu-date > .btn { min-height: 44px; margin-left: auto; }
  .sheet .template-row { column-gap: 10px; }
  .sheet .template-row > .btn { padding-inline: 13px; }
}
