/* UI kit (SPEC §4.13): sheet, toast, confirm, pickers. Colours come from the
   daisyUI tokens set in base.html, so both modes work. */

/* ---- Sheet ----------------------------------------------------------------
   One <dialog>: a bottom sheet on phones, a centred dialog from 768px.
   --vv-h / --kb-inset are set by sheet.js from window.visualViewport, because
   iOS Safari does not resize the layout viewport when the keyboard opens: the
   sheet must shrink to the *visible* area and sit above the keyboard. */
html.sheet-open, html.sheet-open body { overflow: hidden; overscroll-behavior: none; }
.sheet-box {
  padding: 0;
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
  margin-bottom: var(--kb-inset, 0px);
  max-height: calc(var(--vv-h, 100dvh) - env(safe-area-inset-top) - 0.75rem);
}
@media (max-width: 767.98px) {
  .sheet-box {
    width: 100%;
    max-width: none;
    height: calc(var(--vv-h, 100dvh) - env(safe-area-inset-top) - 0.75rem);
    border-radius: 1rem 1rem 0 0;
  }
}
@media (min-width: 768px) {
  .sheet-box { width: 36rem; max-width: calc(100vw - 2rem); max-height: min(46rem, calc(var(--vv-h, 100dvh) - 3rem)); }
}
.sheet-scroll { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-footer { padding-bottom: calc(0.75rem + env(safe-area-inset-bottom)); }
html.kb-open .sheet-footer { padding-bottom: 0.75rem; } /* keyboard covers the home-indicator inset */

/* ---- Toasts ----------------------------------------------------------------
   A manual popover, so toasts sit in the top layer and stay visible above an
   open sheet or dialog. */
#toast-region {
  position: fixed;
  inset: auto 0 calc(4rem + env(safe-area-inset-bottom) + 0.75rem) 0;
  margin: 0 auto;
  width: min(32rem, calc(100vw - 2rem));
  max-height: none;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  flex-direction: column;
  gap: 0.5rem;
  color: inherit;
}
#toast-region:popover-open { display: flex; }
@media (min-width: 768px) {
  #toast-region { inset: auto 1.5rem 1.5rem auto; margin: 0; width: min(26rem, calc(100vw - 3rem)); }
}
.toast-item { animation: toast-in 0.18s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast-item { animation: none; } }

/* ---- Pickers ---------------------------------------------------------------- */
.picker-box:focus-within { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.picker-box input { min-width: 8rem; }
.picker-list [aria-selected="true"] { background-color: color-mix(in oklab, var(--color-primary) 14%, transparent); }
:focus-visible { outline-offset: 2px; }

/* ---- Row dividers -----------------------------------------------------------
   Tailwind 4 draws `divide-y` in currentColor, and daisyUI's colour tokens are
   not registered for divide-* utilities, so `divide-base-300` generated nothing:
   every list's row dividers were text-coloured (near-black in light mode,
   near-white in dark). This gives the class its colour. */
.divide-base-300 > :not(:last-child) { border-color: var(--color-base-300); }

/* ---- Forms (P4) ------------------------------------------------------------ */
textarea[data-autogrow] { field-sizing: content; max-height: 40dvh; }

/* ---- Interactions (P5) ------------------------------------------------------
   A segmented choice (interaction type, Today / Yesterday, the type filter):
   real radio inputs laid over their labels, so it works without JS, is
   keyboard-operable, and the tap target is the whole cell. */
.choice { display: flex; gap: 0.5rem; }
.choice-option {
  position: relative;
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.125rem;
  min-height: 3rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--color-base-300);
  border-radius: var(--radius-field, 0.5rem);
  background: var(--color-base-100);
  font-size: 0.8125rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
}
.choice-option:has(:checked) {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-content);
}
.choice-option:has(:focus-visible) { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.choice-option input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }

/* ---- Reduced motion (P7) ---------------------------------------------------
   Honour the OS setting everywhere, not just on toasts: daisyUI's buttons,
   modals and cards all transition, and the sheet slides. Durations collapse to
   ~0 (not "none", so transitionend/animationend still fire for any code that
   waits on them). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Safe areas (P7) ---------------------------------------------------------
   viewport-fit=cover lets the page run under the notch / Dynamic Island and the
   home indicator. Bottom insets are handled by the dock, sheet footer and
   toasts; these are the left/right insets, which matter in landscape (a phone
   at 844px wide gets the desktop sidebar, and its edge sits under the notch). */
body { padding-right: env(safe-area-inset-right); }
@media (max-width: 767.98px) {
  body { padding-left: env(safe-area-inset-left); }
  .dock { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
}
@media (min-width: 768px) {
  #app-sidebar { width: calc(15rem + env(safe-area-inset-left)); padding-left: env(safe-area-inset-left); }
  #app-column.has-sidebar { padding-left: calc(15rem + env(safe-area-inset-left)); }
}
.fab-log { right: calc(1rem + env(safe-area-inset-right)); }
