/* The app's own controls (see ui-kit.js). Built from the shared tokens, so the
   three interface styles, both modes and every accent restyle them. Glow comes
   from --glow-sm when the active style defines it (Neon). */

.ui-ico {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 18px;
  height: 18px;
}
.ui-ico svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentcolor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The native control stays as the source of truth, laid over its custom face
   so form validation still has somewhere to point. */
.ui-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
}
input[type="file"].ui-native {
  inset: auto;
  width: 1px;
  height: 1px;
}

/* ---------- select and date face ---------- */
.ui-select,
.ui-date {
  position: relative;
  display: block;
  min-width: 0;
}
.task-builder-add .ui-select {
  flex: 1;
}
.ui-select-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: var(--ctl, 40px);
  padding: 0 12px 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm, 11px);
  background: var(--field);
  color: var(--text);
  font: inherit;
  text-align: start;
  cursor: pointer;
  transition:
    border-color 160ms var(--ease, ease),
    box-shadow 200ms var(--ease, ease);
}
.ui-date-btn {
  justify-content: flex-start;
}
.ui-select-btn:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line-strong));
}
.ui-select-btn:focus-visible,
.ui-select-btn[aria-expanded="true"] {
  outline: none;
  border-color: var(--accent);
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent),
    var(--glow-sm, 0 0 0 0 transparent);
}
.ui-select-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.ui-select-label {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ui-select-label.is-placeholder {
  color: var(--faint);
}
.ui-select-btn > .ui-ico:last-child {
  color: var(--muted);
  transition: transform 200ms var(--spring, ease);
}
.ui-select-btn[aria-expanded="true"] > .ui-ico:last-child {
  transform: rotate(180deg);
}
.ui-date-btn > .ui-ico:first-child {
  color: var(--accent);
}

/* ---------- popovers ---------- */
.ui-pop {
  position: fixed;
  z-index: 3000;
  max-height: min(320px, 60vh);
  overflow: auto;
  margin: 0;
  padding: 6px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line-strong));
  border-radius: var(--r-md, 14px);
  background: var(--panel-strong, var(--panel));
  color: var(--text);
  box-shadow:
    0 18px 40px -16px rgb(0 0 0 / 55%),
    var(--glow-sm, 0 0 0 0 transparent);
  animation: ui-pop-in 160ms var(--spring, ease) both;
  transform-origin: top center;
}
.ui-pop[data-side="up"] {
  transform-origin: bottom center;
}
.ui-list {
  list-style: none;
  outline: none;
}
.ui-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--r-xs, 8px);
  cursor: pointer;
  transition: background-color 120ms var(--ease, ease);
}
.ui-option .ui-ico {
  opacity: 0;
  color: var(--accent);
}
.ui-option[aria-selected="true"] {
  font-weight: 620;
}
.ui-option[aria-selected="true"] .ui-ico {
  opacity: 1;
}
.ui-option.is-active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.ui-option.is-off {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- calendar ---------- */
.ui-calendar {
  width: 312px;
  padding: 14px;
}
.ui-cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.ui-cal-title {
  text-transform: capitalize;
  font-weight: 650;
}
.ui-cal-picks {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
.ui-cal-pick {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 0 8px 0 10px;
  border: 1px solid transparent;
  border-radius: var(--r-pill, 999px);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 650;
  text-transform: capitalize;
  cursor: pointer;
  transition:
    background-color 140ms var(--ease, ease),
    border-color 140ms var(--ease, ease);
}
.ui-cal-pick .ui-ico {
  width: 14px;
  height: 14px;
  color: var(--muted);
}
.ui-cal-pick:hover,
.ui-cal-pick.is-open {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.ui-cal-cells {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-block: 4px;
}
.ui-cal-cell {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm, 11px);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-transform: capitalize;
  cursor: pointer;
  transition:
    background-color 120ms var(--ease, ease),
    border-color 120ms var(--ease, ease);
}
.ui-cal-cell:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.ui-cal-cell.is-today {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
}
.ui-cal-cell.is-selected {
  border-color: transparent;
  background: linear-gradient(
    135deg,
    var(--accent),
    var(--accent-2, var(--accent))
  );
  color: var(--on-accent);
  box-shadow: var(--glow-sm, none);
}
.ui-cal-nav {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill, 999px);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.ui-cal-nav:hover {
  border-color: var(--accent);
  box-shadow: var(--glow-sm, none);
}
.ui-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.ui-cal-dow {
  padding-bottom: 4px;
  color: var(--faint);
  font-size: 11px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.ui-cal-day {
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: var(--r-pill, 999px);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition:
    background-color 120ms var(--ease, ease),
    border-color 120ms var(--ease, ease);
}
.ui-cal-day:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.ui-cal-day.is-today {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
}
.ui-cal-day.is-selected {
  background: linear-gradient(
    135deg,
    var(--accent),
    var(--accent-2, var(--accent))
  );
  color: var(--on-accent);
  box-shadow: var(--glow-sm, none);
}
.ui-cal-day:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.ui-cal-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.ui-cal-link {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- file ---------- */
.ui-file {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md, 14px);
  background: color-mix(in srgb, var(--accent) 4%, var(--field));
  cursor: pointer;
  transition:
    border-color 160ms var(--ease, ease),
    background-color 160ms var(--ease, ease),
    box-shadow 200ms var(--ease, ease);
}
.ui-file:hover,
.ui-file:focus-visible,
.ui-file.is-drop {
  outline: none;
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--field));
  box-shadow: var(--glow-sm, none);
}
.ui-file.has-file {
  border-style: solid;
}
.ui-file-thumb {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border-radius: var(--r-sm, 11px);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}
.ui-file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ui-file-copy {
  display: grid;
  min-width: 0;
  flex: 1;
}
.ui-file-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.ui-file-meta {
  color: var(--muted);
  font-size: 12px;
}
.ui-file-clear {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill, 999px);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.ui-file-clear:hover {
  border-color: var(--danger);
  color: var(--danger);
}
.ui-file-clear[hidden] {
  display: none;
}

/* ---------- audio ---------- */
.ui-audio {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  padding: 8px 12px 8px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill, 999px);
  background: var(--field);
}
.ui-audio-play {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--r-pill, 999px);
  background: linear-gradient(
    135deg,
    var(--accent),
    var(--accent-2, var(--accent))
  );
  color: var(--on-accent);
  cursor: pointer;
  transition: transform 200ms var(--spring, ease);
}
.ui-audio-play:hover {
  transform: scale(1.06);
  box-shadow: var(--glow-sm, none);
}
.ui-audio.is-playing .ui-audio-play {
  box-shadow: var(--glow-md, none);
}
.ui-audio-bar {
  position: relative;
  flex: 1;
  min-width: 60px;
  height: 6px;
  border-radius: var(--r-pill, 999px);
  background: var(--line-strong);
  cursor: pointer;
}
.ui-audio-bar::before {
  content: "";
  position: absolute;
  inset: -10px 0;
}
.ui-audio-bar:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}
.ui-audio-fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    var(--accent),
    var(--accent-2, var(--accent))
  );
  transform: scaleX(var(--ratio, 0));
  transform-origin: left center;
}
.ui-audio-time {
  flex: none;
  color: var(--muted);
  font-family: var(--mono, monospace);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ---------- tooltip ---------- */
.ui-tip {
  position: fixed;
  z-index: 3100;
  max-width: 240px;
  padding: 6px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line-strong));
  border-radius: var(--r-xs, 8px);
  background: var(--panel-strong, var(--panel));
  color: var(--text);
  font-size: 12px;
  line-height: 1.3;
  pointer-events: none;
  box-shadow: 0 10px 24px -12px rgb(0 0 0 / 55%);
  animation: ui-pop-in 140ms var(--ease, ease) both;
}

/* ---------- voice input ---------- */
.voice-host {
  position: relative;
}
.has-voice {
  padding-inline-end: 46px;
}
.voice-btn {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill, 999px);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  transition:
    transform 200ms var(--spring, ease),
    border-color 160ms var(--ease, ease),
    color 160ms var(--ease, ease);
}
.voice-btn:hover,
.voice-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow-sm, none);
}
.voice-btn.is-rec {
  border-color: var(--danger, #ff5c8a);
  background: color-mix(in srgb, var(--danger, #ff5c8a) 16%, var(--panel));
  color: var(--danger, #ff5c8a);
  box-shadow: 0 0 calc(8px + 22px * var(--lvl, 0))
    color-mix(in srgb, var(--danger, #ff5c8a) 55%, transparent);
}
.voice-btn.is-busy {
  animation: ui-pulse 1s ease-in-out infinite;
}
.voice-bar {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 5px 12px 5px 6px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line-strong));
  border-radius: var(--r-pill, 999px);
  background: var(--panel-strong, var(--panel));
  box-shadow: var(--glow-sm, none);
  font-size: 12px;
  animation: ui-pop-in 160ms var(--spring, ease) both;
}
.voice-lang {
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: var(--r-pill, 999px);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.voice-meter {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 18px;
}
.voice-meter i {
  width: 3px;
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  opacity: var(--on, 0.18);
  transform: scaleY(calc(0.35 + 0.65 * var(--on, 0.18)));
  transition:
    opacity 80ms linear,
    transform 80ms linear;
}
.voice-status {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

/* ---------- checkbox, radio, range, number ---------- */
input[type="checkbox"],
input[type="radio"] {
  appearance: none;
  display: inline-grid;
  place-content: center;
  flex: none;
  width: 20px;
  height: 20px;
  margin: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: 6px;
  background: var(--field);
  cursor: pointer;
  transition:
    border-color 140ms var(--ease, ease),
    background-color 140ms var(--ease, ease),
    box-shadow 180ms var(--ease, ease);
}
input[type="radio"] {
  border-radius: 50%;
}
input[type="checkbox"]::after {
  content: "";
  width: 10px;
  height: 6px;
  border-inline-start: 2px solid var(--on-accent);
  border-block-end: 2px solid var(--on-accent);
  transform: translateY(-1px) rotate(-45deg) scale(0);
  transition: transform 180ms var(--spring, ease);
}
input[type="radio"]::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--on-accent);
  transform: scale(0);
  transition: transform 180ms var(--spring, ease);
}
input[type="checkbox"]:checked,
input[type="radio"]:checked {
  border-color: var(--accent);
  background: linear-gradient(
    135deg,
    var(--accent),
    var(--accent-2, var(--accent))
  );
  box-shadow: var(--glow-sm, none);
}
input[type="checkbox"]:checked::after {
  transform: translateY(-1px) rotate(-45deg) scale(1);
}
input[type="radio"]:checked::after {
  transform: scale(1);
}
input[type="checkbox"]:hover,
input[type="radio"]:hover {
  border-color: var(--accent);
}
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input[type="checkbox"]:disabled,
input[type="radio"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Slider: a thin track filled up to the value (--fill, set by paintRange in
   app.js) and a round thumb. The input itself is transparent, so the field
   look of the styles never turns it into a box; its height is the touch area. */
:root[data-style] input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill, 999px);
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  --fill: 50%;
}
:root[data-style] input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: var(--r-pill, 999px);
  background: linear-gradient(
    90deg,
    var(--accent) var(--fill),
    var(--line-strong) var(--fill)
  );
}
:root[data-style] input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: var(--r-pill, 999px);
  background: var(--line-strong);
}
:root[data-style] input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: var(--r-pill, 999px);
  background: var(--accent);
}
:root[data-style] input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    var(--accent),
    var(--accent-2, var(--accent))
  );
  box-shadow: var(--glow-sm, none);
  transition: transform 160ms var(--spring, ease);
}
:root[data-style] input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
:root[data-style] input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
}
:root[data-style] input[type="range"]:focus-visible {
  outline: none;
  box-shadow: none;
}
:root[data-style] input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}
input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}
input[type="search"]::-webkit-search-cancel-button {
  appearance: none;
}
input,
textarea {
  caret-color: var(--accent);
}
::selection {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}

@keyframes ui-pop-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes ui-pulse {
  50% {
    opacity: 0.55;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ui-pop,
  .ui-tip,
  .voice-bar,
  .voice-btn,
  .ui-audio-play,
  .ui-select-btn > .ui-ico:last-child {
    animation: none;
    transition: none;
  }
}
:root[data-anim="off"] .ui-pop,
:root[data-anim="off"] .ui-tip,
:root[data-anim="off"] .voice-bar,
:root[data-anim="off"] .voice-btn,
:root[data-anim="off"] .ui-audio-play {
  animation: none;
  transition: none;
}

@media (max-width: 767px) {
  .ui-calendar {
    width: min(320px, calc(100vw - 24px));
  }
  .ui-pop {
    max-height: 50vh;
  }
  .ui-option {
    padding: 12px;
  }
}
