/* settings-drawer — bottom-drawer Settings shell, sub-view containers, and
 * supporting micro-components (profile-card, section-row, field-row,
 * segmented control, save-bar, toggle-switch).
 *
 * Canonical visual contract: .tmp/settings-drawer.html (locked, Bradly-approved).
 * Canonical-system doc:      docs/design/canopy-canonical-system.md
 *
 * Consumes ONLY var(--v2-*) tokens. Raw hex is blocked by v2-raw-hex-warn.py.
 *
 * Layout notes:
 *   - .scrim and .drawer mount via position:fixed (production).
 *   - Mockup uses position:absolute within a phone frame; production uses
 *     position:fixed because there's no viewport-wrapper container.
 *   - Drawer height is 85vh capped at 720px so it never exceeds the canonical
 *     contract on tablets/desktops while still adapting on smaller phones.
 *   - .section-row is rendered as <button> in production (spec requirement,
 *     non-negotiable a11y contract); the canonical visual is preserved via the
 *     button-reset declarations below.
 */

/* ─── scrim ───────────────────────────────────────────────────────────── */
.scrim {
  position: fixed;
  inset: 0;
  background: var(--v2-bg-overlay);
  animation: settingsDrawerFadeIn 240ms ease both;
  cursor: pointer;
  z-index: 200;
}
.scrim[hidden] { display: none; }

@keyframes settingsDrawerFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ─── drawer shell ────────────────────────────────────────────────────── */
.drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: min(85vh, 720px);
  background: var(--v2-bg-panel);
  border-top-left-radius: var(--v2-radius-xl);
  border-top-right-radius: var(--v2-radius-xl);
  box-shadow: 0 -8px 32px oklch(18% 0.02 150 / 0.16),
              0 -2px 6px oklch(18% 0.02 150 / 0.08);
  display: flex;
  flex-direction: column;
  animation: settingsDrawerSlideUp 360ms var(--v2-ease-spring) both;
  overflow: hidden;
  z-index: 201;
}
.drawer[hidden] { display: none; }

@keyframes settingsDrawerSlideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.drawer-handle {
  width: 36px;
  height: 4px;
  background: var(--v2-text-tertiary);
  opacity: 0.4;
  border-radius: 999px;
  margin: 10px auto 4px;
  flex-shrink: 0;
}

.drawer-topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}
.drawer-topbar h2 {
  font-family: var(--v2-font-display);
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.01em;
  color: var(--v2-text-primary);
  margin: 0;
  flex: 1;
  text-align: center;
  outline: none;
}
.drawer-topbar h2:focus-visible {
  outline: 2px solid var(--v2-accent-botanical);
  outline-offset: 4px;
  border-radius: var(--v2-radius-xs);
}

/* a11y: 48×48 tap target; visible glyph stays 22-24px via SVG sizing */
.drawer-back {
  width: 48px;
  height: 48px;
  background: none;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--v2-text-primary);
  padding: 0;
}
.drawer-back[hidden] { display: none; }
.drawer-back:focus-visible {
  outline: 2px solid var(--v2-accent-botanical);
  outline-offset: -4px;
  border-radius: 50%;
}

.drawer-close {
  font-family: var(--v2-font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--v2-text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 12px 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  min-height: 44px;
}
.drawer-close:focus-visible {
  outline: 2px solid var(--v2-accent-botanical);
  outline-offset: 2px;
  border-radius: var(--v2-radius-xs);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px 32px;
  transition: opacity 180ms ease;
}

/* ─── profile header card ─────────────────────────────────────────────── */
.profile-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--v2-bg-card);
  border: 1px solid var(--v2-border-soft);
  border-radius: var(--v2-radius-md);
  padding: 16px;
  margin-bottom: 24px;
}
.profile-card .avatar-lg {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--v2-pop-sage-bg);
  color: var(--v2-accent-botanical);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--v2-font-display);
  font-weight: 500;
  font-size: 24px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.profile-card .meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.profile-card .name {
  font-family: var(--v2-font-display);
  font-weight: 500;
  font-size: 18px;
  color: var(--v2-text-primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-card .email {
  font-size: 12px;
  color: var(--v2-text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-card .chevron {
  color: var(--v2-text-tertiary);
  flex-shrink: 0;
}

/* ─── section grouping ────────────────────────────────────────────────── */
.section-label {
  font-family: var(--v2-font-body);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--v2-text-stone);
  font-weight: 600;
  margin: 8px 4px 8px;
}

.section-group {
  background: var(--v2-bg-card);
  border: 1px solid var(--v2-border-soft);
  border-radius: var(--v2-radius-md);
  overflow: hidden;
  margin-bottom: 24px;
}

/* .section-row is rendered as <button> in production; reset UA defaults,
 * then apply the canonical row layout. */
.section-row {
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  text-align: left;
  width: 100%;
  display: flex;
  align-items: center;
  padding: 14px 16px;
  min-height: 48px;
  border-bottom: 1px solid var(--v2-border-soft);
  cursor: pointer;
  gap: 12px;
}
.section-row:focus-visible {
  outline: 2px solid var(--v2-accent-botanical);
  outline-offset: -2px;
  border-radius: var(--v2-radius-xs);
}
.section-row:last-child { border-bottom: none; }

.section-row .row-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--v2-radius-xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--v2-text-secondary);
}
.section-row .row-label {
  font-family: var(--v2-font-body);
  font-size: 15px;
  font-weight: 500;
  color: var(--v2-text-primary);
  flex: 1;
}
.section-row .row-value {
  font-family: var(--v2-font-body);
  font-size: 13px;
  color: var(--v2-text-secondary); /* A11y WARN Gap 3: was text-tertiary (~3.0:1), now ~4.7:1 */
}
.section-row .row-value.sage {
  color: var(--v2-pop-sage);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.08em;
}
.section-row .chevron {
  color: var(--v2-text-muted);
  flex-shrink: 0;
}
.section-row.danger .row-label { color: var(--v2-pop-coral); }
.section-row.action .row-label {
  color: var(--v2-accent-botanical);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ─── field row (sub-view editable field) ─────────────────────────────── */
.field-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  border-bottom: 1px solid var(--v2-border-soft);
}
.field-row:last-child { border-bottom: none; }
.field-row .input-label {
  font-family: var(--v2-font-body);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--v2-text-stone);
  font-weight: 500;
}
.field-row .value-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.field-row .value {
  font-family: var(--v2-font-display);
  font-size: 20px;
  font-weight: 500;
  color: var(--v2-text-primary);
}
.field-row .edit-btn {
  font-family: var(--v2-font-body);
  font-size: 11px;
  font-weight: 500;
  color: var(--v2-text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-decoration: underline;
  padding: 8px 0;
  min-height: 44px;
}

/* ─── segmented control ───────────────────────────────────────────────── */
.segmented {
  display: flex;
  background: var(--v2-bg-secondary);
  border-radius: var(--v2-radius-sm);
  padding: 4px;
  gap: 4px;
  margin-top: 8px;
}
.segmented button {
  flex: 1;
  height: 36px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  font-family: var(--v2-font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--v2-text-secondary);
  cursor: pointer;
  letter-spacing: 0.02em;
}
.segmented button.selected {
  background: var(--v2-pop-sage-bg);
  border-color: var(--v2-accent-botanical);
  color: var(--v2-accent-botanical);
}
.segmented button:focus-visible {
  outline: 2px solid var(--v2-accent-botanical);
  outline-offset: 2px;
}

/* ─── save bar (sticky bottom of sub-views) ──────────────────────────── */
.save-bar {
  padding: 16px 24px 24px;
  background: var(--v2-bg-panel);
  border-top: 1px solid var(--v2-border-soft);
  flex-shrink: 0;
}
.save-bar[hidden] { display: none; }

.primary-cta {
  width: 100%;
  height: 52px;
  background: var(--v2-accent-botanical);
  color: var(--v2-text-on-dark);
  border: none;
  border-radius: var(--v2-radius-sm);
  font-family: var(--v2-font-body);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 48px;
}
.primary-cta:focus-visible {
  outline: 2px solid var(--v2-accent-botanical);
  outline-offset: 2px;
}

/* ─── toggle switch (canonical extension — see canopy-canonical-system §2.9) */
.toggle-switch {
  appearance: none;
  -webkit-appearance: none;
  background: var(--v2-border-strong);
  border: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  inset: -9px;
}
.toggle-switch[aria-checked="true"] { background: var(--v2-accent-botanical); }
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  background: var(--v2-bg-card);
  border-radius: 50%;
  transition: transform 220ms var(--v2-ease-spring);
}
.toggle-switch[aria-checked="true"] .toggle-thumb { transform: translateX(18px); }
.toggle-switch:focus-visible {
  outline: 2px solid var(--v2-accent-botanical);
  outline-offset: 2px;
}

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

/* ─── hydration error fallback ────────────────────────────────────────── */
.hydration-error {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  align-items: center;
  text-align: center;
  color: var(--v2-text-secondary);
}
.hydration-error p {
  font-family: var(--v2-font-body);
  font-size: 14px;
  margin: 0;
}

/* ─── reduced motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .drawer       { animation-duration: 0.01ms; }
  .scrim        { animation-duration: 0.01ms; }
  .drawer-body  { transition-duration: 0.01ms; }
  .toggle-thumb { transition-duration: 0.01ms; }
}

/* ─── dirty-state confirm sheet ───────────────────────────────────────── */
.dirty-confirm {
  padding: 16px 24px 24px;
  background: var(--v2-bg-panel);
  border-top: 1px solid var(--v2-border-soft);
}
.dirty-confirm p {
  font-family: var(--v2-font-display);
  font-weight: 500;
  font-size: 18px;
  color: var(--v2-text-primary);
  margin: 0 0 12px;
}
.dirty-confirm .dirty-actions {
  display: flex;
  gap: 12px;
}
.dirty-confirm .dirty-discard {
  flex: 1;
  height: 48px;
  background: none;
  border: 1px solid var(--v2-pop-coral);
  color: var(--v2-pop-coral);
  border-radius: var(--v2-radius-sm);
  font-family: var(--v2-font-body);
  font-weight: 500;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  min-height: 48px;
}
.dirty-confirm .dirty-discard:focus-visible {
  outline: 2px solid var(--v2-pop-coral);
  outline-offset: 2px;
}
.dirty-confirm .dirty-keep {
  flex: 1;
}

/* ─── app-shell deferred-failure toast ────────────────────────────────── */
/* The legacy <div id="app-toast"> in index.html sits empty until showAppToast()
 * populates it. Without :empty hiding, the new v2 styling below paints the
 * empty container as a dark pill on every surface. Bug fix 2026-05-23. */
.app-toast:empty { display: none; }

.app-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--v2-text-primary);
  color: var(--v2-text-on-dark);
  padding: 12px 20px;
  border-radius: var(--v2-radius-md);
  font-family: var(--v2-font-body);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 220;
  animation: appToastIn 240ms ease both;
  max-width: 90vw;
  box-shadow: 0 4px 16px oklch(18% 0.02 150 / 0.18);
}
.app-toast-action {
  background: var(--v2-accent-botanical);
  color: var(--v2-text-on-dark);
  border: none;
  border-radius: var(--v2-radius-xs);
  padding: 6px 12px;
  font-family: var(--v2-font-body);
  font-weight: 500;
  font-size: 12px;
  cursor: pointer;
  min-height: 32px;
}
@keyframes appToastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ─── save-bar feedback (Saved chip + error toast) ────────────────────── */
.save-chip-flash {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  background: var(--v2-pop-sage-bg);
  color: var(--v2-pop-sage);
  font-family: var(--v2-font-body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--v2-radius-xs);
  animation: saveChipFlashIn 220ms var(--v2-ease-spring) both;
}
@keyframes saveChipFlashIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}
.save-error-toast {
  display: block;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--v2-pop-coral-bg, oklch(95% 0.025 30));
  color: var(--v2-pop-coral);
  border-left: 2px solid var(--v2-pop-coral);
  font-family: var(--v2-font-body);
  font-size: 12px;
  border-radius: var(--v2-radius-xs);
}

/* ─── notifications disclosure chip ───────────────────────────────────── */
.phase4-chip {
  font-family: var(--v2-font-body);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--v2-text-stone);
  background: var(--v2-bg-secondary);
  padding: 4px 8px;
  border-radius: var(--v2-radius-xs);
  flex-shrink: 0;
}

/* ─── zip-lookup error + zone-confirm ─────────────────────────────────── */
.zip-error {
  font-family: var(--v2-font-body);
  font-size: 13px;
  color: var(--v2-pop-coral);
  padding: 8px 0;
}
.manual-coords {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
}
.zone-confirm {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  background: var(--v2-pop-sage-bg);
  border: 1px solid var(--v2-accent-botanical);
  border-radius: var(--v2-radius-sm);
  animation: zoneConfirmIn 280ms var(--v2-ease-spring) both;
}
@keyframes zoneConfirmIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.zone-confirm .pin {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--v2-accent-botanical);
  color: var(--v2-text-on-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.zone-confirm .location {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.zone-confirm .city {
  font-family: var(--v2-font-display);
  font-weight: 500;
  font-size: 15px;
  color: var(--v2-text-primary);
  letter-spacing: -0.01em;
}
.zone-confirm .zone {
  font-family: var(--v2-font-body);
  font-size: 12px;
  color: var(--v2-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

/* ─── reduced motion (Stage I additions) ──────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .save-chip-flash { animation-duration: 0.01ms; }
  .zone-confirm    { animation-duration: 0.01ms; }
  .app-toast       { animation-duration: 0.01ms; }
}
