/* PomoMed — CORE styles: settings dialog internals, preset chips, toasts, ECG head.
   Relies on shared tokens from app.css (--mode-bg, --surface, --surface-text,
   --radius, --shadow) and provides fallbacks so it renders sensibly alone. */

/* ---------- Settings dialog: local tokens ---------- */
#settings-modal {
  --set-accent: var(--mode-solid, var(--mode-bg, #0f766e));
  --set-on-accent: #ffffff;
  --set-text: var(--surface-text, #16202c);
  --set-bg: var(--surface, #ffffff);
  --set-muted: var(--surface-muted, #4b5866);
  --set-line: var(--surface-border, #dde3e8);
  --set-soft: var(--surface-2, #f3f5f7);
  --set-field: var(--surface-field, #ffffff);
  --set-track: #8a96a3;
  --set-focus: var(--mode-solid, #0f766e);
  --set-danger: #b91c1c;
  --set-danger-soft: #fef2f2;
  --set-radius: var(--radius, 12px);
}
body[data-theme="dark"] #settings-modal {
  --set-accent: var(--mode-light, #5eead4);
  --set-on-accent: #0b1220;
  --set-track: #5b6b80;
  --set-focus: var(--mode-light, #5eead4);
  --set-danger: #fca5a5;
  --set-danger-soft: rgba(248, 113, 113, 0.12);
}

#settings-modal .modal__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

#settings-modal .set-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
}
#settings-modal .set-body > * {
  min-width: 0;
}

#settings-modal :focus-visible {
  outline: 3px solid var(--set-focus);
  outline-offset: 2px;
}

/* ---------- Sections ---------- */
.set-section {
  padding: 16px 0 12px;
  border-top: 1px solid var(--set-line);
}
.set-section:first-child {
  border-top: 0;
  padding-top: 4px;
}
.set-section__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--set-muted);
}
.set-section__title svg {
  flex: none;
  color: var(--set-accent);
}

.set-fieldset {
  margin: 0 0 14px;
  padding: 0;
  border: 0;
  min-width: 0;
}
.set-legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--set-text);
}

/* ---------- Presets (radio cards) ---------- */
.set-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.set-preset {
  position: relative;
  display: block;
  cursor: pointer;
}
.set-preset__input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.set-preset__box {
  display: grid;
  gap: 2px;
  height: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--set-line);
  border-radius: calc(var(--set-radius) - 2px);
  background: var(--set-bg);
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.set-preset:hover .set-preset__box {
  border-color: var(--set-track);
}
.set-preset__name {
  font-weight: 700;
  font-size: 0.9375rem;
}
.set-preset__nums {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.8125rem;
  color: var(--set-muted);
}
.set-preset__nums:empty {
  display: none;
}
.set-preset__desc {
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--set-muted);
}
.set-preset__input:checked + .set-preset__box {
  border-color: var(--set-accent);
  background: var(--set-soft);
  box-shadow: inset 0 0 0 1px var(--set-accent);
}
.set-preset__input:checked + .set-preset__box .set-preset__name::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin-left: 0.45em;
  vertical-align: 0.12em;
  border-radius: 50%;
  background: var(--set-accent);
}
.set-preset__input:focus-visible + .set-preset__box {
  outline: 3px solid var(--set-focus);
  outline-offset: 2px;
}

/* ---------- Durations ---------- */
.set-durations {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.set-dur {
  display: grid;
  gap: 4px;
  margin: 0;
}
.set-dur__label {
  font-size: 0.8125rem;
  color: var(--set-muted);
}

#settings-modal .set-input,
#settings-modal .set-select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1.5px solid var(--set-line);
  border-radius: 10px;
  background: var(--set-field);
  color: var(--set-text);
  font: inherit;
  font-size: 1rem;
}
#settings-modal .set-input {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}
#settings-modal .set-input:hover,
#settings-modal .set-select:hover {
  border-color: var(--set-track);
}
#settings-modal .set-input:focus-visible,
#settings-modal .set-select:focus-visible {
  border-color: var(--set-focus);
  outline-offset: 0;
}
#settings-modal .set-input--sm {
  width: 4.5rem;
  text-align: center;
}
#settings-modal .set-select {
  width: auto;
  min-width: 0;
  max-width: 100%;
  padding-right: 2rem;
  cursor: pointer;
}

/* ---------- Rows ---------- */
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 10px 0;
  min-height: 44px;
}
.set-row + .set-row {
  border-top: 1px dashed var(--set-line);
}
.set-row--stack,
.set-row--wrap {
  flex-wrap: wrap;
}
.set-row__text {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1 1 0;
  cursor: pointer;
}
.set-row--stack > .set-row__text,
.set-row--wrap > .set-row__text {
  flex: 1 1 auto;
}
.set-row__label {
  font-weight: 600;
  font-size: 0.9375rem;
}
.set-row__hint {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--set-muted);
}
.set-inline {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}
.set-unit {
  font-size: 0.875rem;
  color: var(--set-muted);
}
.set-note {
  margin: 8px 0 0;
  font-size: 0.8125rem;
  color: var(--set-muted);
}
.set-status {
  margin: 4px 0 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--set-danger-soft);
  color: var(--set-danger);
  font-size: 0.8125rem;
}

/* ---------- Switch (checkbox role="switch") ---------- */
.set-switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  background: var(--set-track);
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.set-switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s cubic-bezier(0.3, 0.7, 0.4, 1);
}
.set-switch:checked {
  background: var(--set-accent);
}
.set-switch:checked::before {
  transform: translateX(18px);
}
body[data-theme="dark"] .set-switch:checked::before {
  background: var(--set-on-accent);
}
.set-switch:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
@media (forced-colors: active) {
  .set-switch {
    border: 2px solid ButtonText;
  }
  .set-switch::before {
    background: ButtonText;
  }
  .set-switch:checked::before {
    background: Highlight;
  }
}

/* ---------- Volume range ---------- */
.set-range {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 220px;
  min-width: 0;
}
.set-range__input {
  --fill: 60%;
  flex: 1;
  min-width: 0;
  height: 28px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.set-range__input::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--set-accent) var(--fill), var(--set-line) var(--fill));
}
.set-range__input::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--set-line);
}
.set-range__input::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--set-accent);
}
.set-range__input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border: 3px solid var(--set-accent);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.set-range__input::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 3px solid var(--set-accent);
  border-radius: 50%;
  background: #fff;
}
.set-range__out {
  min-width: 3.25rem;
  text-align: right;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  color: var(--set-muted);
}

/* ---------- Buttons inside the dialog ---------- */
#settings-modal .set-test {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
}
#settings-modal .set-test:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.set-data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 6px;
}
#settings-modal .set-danger {
  color: var(--set-danger);
  border-color: currentColor;
}
#settings-modal .set-danger--solid {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}
#settings-modal .set-danger--solid:hover {
  background: #991b1b;
}
.set-confirm {
  margin-top: 10px;
  padding: 12px 14px;
  border: 1.5px solid var(--set-danger);
  border-radius: 10px;
  background: var(--set-danger-soft);
}
.set-confirm[hidden] {
  display: none;
}
.set-confirm__msg {
  margin: 0 0 10px;
  font-weight: 600;
  color: var(--set-danger);
}
.set-confirm__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Pro teaser row */
.set-pro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding: 12px 14px;
  border: 1.5px dashed var(--set-line);
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s, background-color 0.15s;
}
.set-pro:hover {
  border-color: var(--set-track);
  background: var(--set-soft);
}
.set-pro .set-row__text {
  cursor: inherit;
}
.set-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fbbf24;
  color: #422006;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

@media (max-width: 420px) {
  .set-presets {
    grid-template-columns: minmax(0, 1fr);
  }
  .set-preset__desc {
    display: none;
  }
  .set-preset__box {
    grid-template-columns: 1fr auto;
    align-items: baseline;
  }
}

/* ---------- Preset chips under the timer ---------- */
#preset-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
#preset-chips:empty {
  display: none;
}
.preset-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.preset-chip__nums {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.75em;
  opacity: 0.85;
}
#preset-chips .preset-chip[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.95);
  color: var(--mode-bg, #0f766e);
  border-color: transparent;
}
#preset-chips .preset-chip[aria-pressed="true"] .preset-chip__nums {
  opacity: 1;
}

/* ---------- Toasts ---------- */
#toast-region,
.pm-toast-region {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: min(440px, calc(100% - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}
.pm-toast-region--dialog {
  z-index: 10;
}
.pm-toast {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 12px 8px 12px 16px;
  border-radius: 12px;
  background: #111827;
  color: #f9fafb;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.2);
  font-size: 0.9375rem;
  line-height: 1.4;
  pointer-events: auto;
  animation: pm-toast-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
body[data-theme="dark"] .pm-toast {
  background: #f9fafb;
  color: #111827;
}
.pm-toast::before {
  content: "";
  flex: none;
  align-self: stretch;
  width: 4px;
  margin: -4px 0;
  border-radius: 4px;
  background: #5eead4;
}
.pm-toast--success::before {
  background: #4ade80;
}
.pm-toast--warn::before {
  background: #fbbf24;
}
body[data-theme="dark"] .pm-toast::before {
  background: #0f766e;
}
body[data-theme="dark"] .pm-toast--success::before {
  background: #15803d;
}
body[data-theme="dark"] .pm-toast--warn::before {
  background: #b45309;
}
.pm-toast.is-leaving {
  animation: pm-toast-out 0.18s ease-in forwards;
}
.pm-toast__msg {
  flex: 1 1 200px;
  margin: 0;
}
.pm-toast__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.pm-toast__btn {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
}
.pm-toast__btn:hover {
  background: rgba(127, 127, 127, 0.2);
}
.pm-toast__btn--primary {
  background: #f9fafb;
  color: #111827;
}
.pm-toast__btn--primary:hover {
  background: #e5e7eb;
}
body[data-theme="dark"] .pm-toast__btn--primary {
  background: #111827;
  color: #f9fafb;
}
body[data-theme="dark"] .pm-toast__btn--primary:hover {
  background: #1f2937;
}
.pm-toast__close {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  opacity: 0.75;
  cursor: pointer;
}
.pm-toast__close:hover {
  opacity: 1;
  background: rgba(127, 127, 127, 0.2);
}
.pm-toast :focus-visible {
  outline: 3px solid #5eead4;
  outline-offset: 2px;
}
body[data-theme="dark"] .pm-toast :focus-visible {
  outline-color: #0f766e;
}
@keyframes pm-toast-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}
@keyframes pm-toast-out {
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---------- ECG progress (fill transition + monitor dot) ---------- */
.ecg-head {
  position: absolute;
  left: 0;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.22), 0 0 12px 3px rgba(255, 255, 255, 0.65);
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: left 0.3s linear, top 0.3s linear;
}
.ecg-head[hidden] {
  display: none;
}
#ecg-progress.ecg-snap #ecg-fill,
#ecg-progress.ecg-snap .ecg-head {
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .ecg-head,
  .set-switch,
  .set-switch::before,
  .set-preset__box {
    transition: none;
  }
  .pm-toast,
  .pm-toast.is-leaving {
    animation: none;
  }
}

/* Touch targets (≥ 40px). Switches are also toggled by tapping their whole labelled row. */
.set-range__input { height: 40px; }
.pm-toast__btn { min-height: 40px; }
.pm-toast__close { width: 40px; height: 40px; }
#preset-chips .preset-chip__nums { opacity: 1; }

/* ---------- Appearance: specialty skins (picker styles live in themes.css) ---------- */
.set-skins {
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px dashed var(--set-line);
}
.set-skins__title {
  margin: 0 0 2px;
}
.set-skins__hint {
  margin-bottom: 12px;
}
#settings-modal .skin-tile {
  background: var(--set-bg);
  border-color: var(--set-line);
}
#settings-modal .skin-tile:hover {
  border-color: var(--set-track);
}
#settings-modal .skin-tile[aria-pressed="true"] {
  border-color: var(--set-accent);
  box-shadow: inset 0 0 0 1px var(--set-accent);
}
#settings-modal .skin-tile[aria-pressed="true"] .skin-tile__meta {
  color: var(--set-accent);
}
#settings-modal .skin-tile:focus-visible {
  outline: 3px solid var(--set-focus);
  outline-offset: 2px;
}
#settings-modal .skin-group__title {
  color: var(--set-muted);
}
