/* =========================================================================
   Base reset + primitives (buttons, inputs, scrollbars, utilities).
   ========================================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body,
#app {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizelegibility;
  overflow: hidden;
  /* Every scroller is internal; a drag past the top of one must not chain to
     the page, where Chrome on Android reads it as pull-to-refresh and reloads
     the app mid-session. */
  overscroll-behavior: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

ul {
  list-style: none;
}

a {
  color: var(--accent);
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::selection {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}

/* Thin, unobtrusive scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--gray-300) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: var(--r-full);
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
  background-clip: content-box;
  border: 3px solid transparent;
}

/* ---- Icons ------------------------------------------------------------ */
.icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex: none;
  color: currentColor;
}
.icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
.icon--sm {
  width: 16px;
  height: 16px;
}
.icon--lg {
  width: 24px;
  height: 24px;
}

/* ---- Buttons ---------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  user-select: none;
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--gray-300);
}
.btn:active {
  transform: translateY(0.5px);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn--primary:active {
  background: var(--accent-active);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
}
.btn--ghost:hover {
  background: var(--surface-3);
  border-color: transparent;
}

.btn--danger {
  color: var(--danger-ink);
  background: transparent;
  border-color: transparent;
}
.btn--danger:hover {
  background: var(--danger-soft);
  color: var(--danger-ink);
}

.btn--block {
  width: 100%;
}

/* Icon-only square button */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  color: var(--text-2);
  background: transparent;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.icon-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}
.icon-btn:active {
  background: var(--surface-3);
  transform: translateY(0.5px);
}
.icon-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* Dim helper for secondary words inside a label (e.g. the custom-recurrence
   dialog's "occurrences" suffix). */
.muted {
  color: var(--text-3);
}

/* ---- Segmented control ------------------------------------------------ */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-3);
  border-radius: var(--r-md);
}
.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-base);
  font-weight: 550;
  color: var(--text-2);
  /* "4 Day" must never wrap into two clipped lines inside the 30px button
     when the header gets tight. */
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.segmented button:hover {
  color: var(--text);
}
.segmented button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---- Form controls ---------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.field__label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-2);
}
.input,
.textarea,
.select {
  width: 100%;
  height: 38px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: var(--fs-md);
  transition: border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}
.textarea {
  height: auto;
  min-height: 76px;
  padding: var(--sp-3);
  resize: vertical;
  line-height: var(--lh-normal);
}
.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--text-3);
}
.select {
  appearance: none;
  cursor: pointer;
  /* Neutral-gray chevron that reads on both light and dark surfaces. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
}
/* iOS Safari auto-zooms into any focused form control whose font-size is under
   16px, and on a phone that zoom shifts the event modal so its footer buttons
   (Save/Cancel) scroll out of reach. The controls are 14px for a compact
   desktop look; bump them to 16px on small screens to suppress the zoom. */
@media (max-width: 720px) {
  .input,
  .textarea,
  .select {
    font-size: 16px;
  }
}

/* Toggle switch */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 40px;
  height: 24px;
  flex: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.switch__track {
  position: absolute;
  inset: 0;
  border-radius: var(--r-full);
  /* A UI component needs 3:1 against its ground; --gray-300 sat at 1.8:1 in
     the light theme and 2:1 in the dark, so an off switch was a faint blur. */
  background: var(--switch-off);
  transition: background var(--dur) var(--ease);
}
.switch__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked ~ .switch__track {
  background: var(--accent);
}
.switch input:checked ~ .switch__thumb {
  transform: translateX(16px);
}
/* The <input> is invisible (opacity 0), so this track IS the focus indicator
   — and the translucent --ring only reached 2.3:1 (1.9:1 dark). Use the same
   solid accent outline every other control gets. */
.switch input:focus-visible ~ .switch__track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Utilities -------------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--gray-200);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
