/* idea-sheet — "Submit an idea" as a glass bottom sheet over the current screen (#110).
 *
 * Mockup: docs/design/mockups/idea-sheet-anywhere.html (variant A), approved on
 * issue #110. Script: public/js/components/idea-sheet.js. Shared submit rules:
 * public/js/lib/idea-submit.js.
 *
 * Loaded by index.html only. The pieces look like the "Something broke" sheet and
 * the Ideas form (standalone-sheet.css, roadmap.css, changelog.css), but every
 * rule here is scoped under .idea-sheet-scrim: those files are for the standalone
 * pages and their bare names (.scrim, .field, .btn-primary) would collide with the
 * Settings drawer and style.css in the app.
 *
 * Uses ONLY var(--v2-*) tokens (defined in /css/canopy-v2.css). The only custom
 * properties are the two the script sets from the visual viewport:
 *   --idea-sheet-vvh  height of the visible area (shrinks when the keyboard opens)
 *   --idea-sheet-kb   height of the keyboard, so the sheet rides above it
 *
 * Glass: the sheet (.glass.is-thick from glass.css) is the only glass. Controls on
 * it are plain fills. Sizes: medium on open, large once the keyboard is up.
 */

/* ─── Resets for the sheet's own controls ─── */
.idea-sheet-scrim, .idea-sheet-scrim *, .idea-sheet-scrim *::before, .idea-sheet-scrim *::after { box-sizing: border-box; }
.idea-sheet-scrim button, .idea-sheet-scrim textarea { font-family: inherit; margin: 0; -webkit-tap-highlight-color: transparent; }
.idea-sheet-scrim button { cursor: pointer; }
.idea-sheet-scrim [hidden] { display: none !important; }

/* ─── Scrim and sheet ─── */
.idea-sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 1300;
  --idea-sheet-vvh: 100dvh;  /* idea-sheet.js sets both from the visual viewport while open */
  --idea-sheet-kb: 0px;
  background: var(--v2-bg-overlay);
  font-family: var(--v2-font-body);
  -webkit-font-smoothing: antialiased;
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--v2-transition-base) var(--v2-ease-out), visibility 0s linear var(--v2-transition-base);
}
.idea-sheet-scrim.open {
  visibility: visible;
  opacity: 1;
  transition: opacity var(--v2-transition-base) var(--v2-ease-out), visibility 0s;
}

.idea-sheet {
  position: absolute;
  left: calc(var(--v2-sheet-inset) + var(--v2-safe-left));
  right: calc(var(--v2-sheet-inset) + var(--v2-safe-right));
  bottom: calc(var(--v2-sheet-inset) + var(--idea-sheet-kb, 0px));
  max-width: 560px;
  margin: 0 auto;
  height: min(calc(var(--idea-sheet-vvh, 100dvh) * 0.6), 520px);
  max-height: calc(var(--idea-sheet-vvh, 100dvh) - var(--v2-safe-top) - 24px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--v2-radius-sheet);
  padding-bottom: max(calc(var(--v2-safe-bottom) - var(--v2-sheet-inset)), var(--v2-space-md));
  color: var(--v2-text-primary);
  outline: none;
  transform: translateY(calc(100% + var(--v2-sheet-inset)));
  transition: transform var(--v2-transition-base) var(--v2-ease-out);
}
.idea-sheet-scrim.open .idea-sheet { transform: translateY(0); }
.idea-sheet.is-large { height: min(calc(var(--idea-sheet-vvh, 100dvh) - var(--v2-safe-top) - 24px), 660px); }
.idea-sheet.is-compact { height: auto; }
.idea-sheet.has-keyboard { padding-bottom: var(--v2-space-md); }

/* One of several whole-sheet views: the form and the discard question. */
.idea-sheet__view { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.idea-sheet__grabber {
  width: 36px;
  height: 5px;
  flex-shrink: 0;
  margin: 8px auto 0;
  border-radius: var(--v2-radius-full);
  background: var(--v2-sheet-handle-bg);
}
.idea-sheet__bar { display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 4px 12px 0; flex-shrink: 0; }
.idea-sheet__bar-spacer { width: var(--v2-space-touch); flex: 0 0 var(--v2-space-touch); }
.idea-sheet__close {
  width: var(--v2-space-touch);
  height: var(--v2-space-touch);
  flex: 0 0 var(--v2-space-touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--v2-radius-full);
  background: var(--v2-glass-control-fill);
  color: var(--v2-text-primary);
}
.idea-sheet__close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.idea-sheet__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  font-family: var(--v2-font-display);
  font-weight: 600;
  font-size: var(--v2-font-size-body);
  letter-spacing: -0.01em;
  text-align: center;
  white-space: nowrap;
}
.idea-sheet__send {
  min-width: 72px;
  height: var(--v2-space-touch);
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--v2-radius-full);
  background: var(--v2-accent-botanical);
  color: var(--v2-text-on-accent);
  font-family: var(--v2-font-body);
  font-size: var(--v2-font-size-subhead);
  font-weight: 700;
}
.idea-sheet__send[aria-disabled="true"] { background: var(--v2-glass-control-fill); color: var(--v2-text-support); cursor: default; }
.idea-sheet__close:active, .idea-sheet__send:active { opacity: 0.8; }
.idea-sheet__send[aria-disabled="true"]:active { opacity: 1; }
.idea-sheet__close:focus-visible, .idea-sheet__send:focus-visible { outline: 2px solid var(--v2-accent-text); outline-offset: 2px; }

.idea-sheet__body {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 20px 4px;
}

.idea-sheet__spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: idea-sheet-spin 800ms linear infinite;
}
@keyframes idea-sheet-spin { to { transform: rotate(360deg); } }

/* ─── The form ─── */
.idea-sheet__form { display: grid; gap: 4px; margin: 0; }
.idea-sheet__field { margin-bottom: 14px; }
.idea-sheet__label {
  display: block;
  margin: 0 0 6px;
  font-size: var(--v2-font-size-footnote);
  font-weight: 600;
  color: var(--v2-text-support);
}
.idea-sheet__text {
  display: block;
  width: 100%;
  min-height: 104px;
  resize: none;
  margin: 0;
  padding: 12px 14px;
  border: 1.5px solid var(--v2-edge);
  border-radius: var(--v2-radius-md);
  background: var(--v2-bg-primary);
  color: var(--v2-text-primary);
  font-family: var(--v2-font-body);
  font-size: var(--v2-font-size-body);
  line-height: 1.45;
  outline: none;
  overflow-wrap: anywhere;
}
.idea-sheet.is-large .idea-sheet__text { min-height: clamp(104px, calc(var(--idea-sheet-vvh, 100dvh) * 0.3), 150px); }
.idea-sheet__text::placeholder { color: var(--v2-text-support); opacity: 1; }
.idea-sheet__text:focus-visible { border-color: var(--v2-accent-text); box-shadow: 0 0 0 3px var(--v2-focus-ring); }
.idea-sheet__text.is-invalid { border-color: var(--v2-pop-coral); }
.idea-sheet__text[readonly] { opacity: 0.6; }

/* Error and counter lines: icon plus words, never colour alone. */
.idea-sheet__note {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 8px 0 0;
  font-size: var(--v2-font-size-footnote);
  font-weight: 500;
  line-height: 1.4;
}
.idea-sheet__note svg { width: 16px; height: 16px; margin-top: 1px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.idea-sheet__error { color: var(--v2-pop-coral-text); }
.idea-sheet__count { color: var(--v2-text-support); justify-content: flex-end; text-align: right; }
.idea-sheet__count svg { display: none; }
.idea-sheet__count.is-limit { color: var(--v2-pop-coral-text); justify-content: flex-start; text-align: left; }
.idea-sheet__count.is-limit svg { display: block; }

/* Screenshot picker and the chosen file */
.idea-sheet__pick, .idea-sheet__file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 4px 4px 4px 16px;
  border: 1.5px dashed var(--v2-border-strong);
  border-radius: var(--v2-radius-md);
  background: var(--v2-bg-card);
  color: var(--v2-text-primary);
  font-size: var(--v2-font-size-callout);
  font-weight: 500;
  cursor: pointer;
}
.dark .idea-sheet__pick, .dark .idea-sheet__file { background: var(--v2-bg-secondary); }
.idea-sheet__pick svg { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.idea-sheet__pick:focus-visible, .idea-sheet__clear:focus-visible { outline: 2px solid var(--v2-accent-text); outline-offset: 2px; }
.idea-sheet__input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.idea-sheet__file { border-style: solid; cursor: default; min-height: 68px; padding: 6px 6px 6px 8px; }
.idea-sheet__thumb {
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: var(--v2-radius-sm);
  background: var(--v2-pop-sage-bg);
}
.idea-sheet__file-text { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.idea-sheet__file-name { font-weight: 600; font-size: var(--v2-font-size-callout); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.idea-sheet__file-size { font-weight: 500; color: var(--v2-text-support); font-size: var(--v2-font-size-footnote); }
.idea-sheet__clear {
  width: var(--v2-space-touch);
  height: var(--v2-space-touch);
  flex: 0 0 var(--v2-space-touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--v2-radius-full);
  background: var(--v2-glass-control-fill);
  color: var(--v2-text-primary);
}
.idea-sheet__clear svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.idea-sheet__submitter {
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--v2-bg-secondary);
  border-radius: var(--v2-radius-md);
  font-size: var(--v2-font-size-footnote);
  color: var(--v2-text-support);
}
.idea-sheet__submitter strong { color: var(--v2-text-primary); font-weight: 600; }

/* ─── Sent ─── */
.idea-sheet__done { padding-top: 12px; }
.idea-sheet__trust {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 8px;
  padding: 14px 16px;
  background: var(--v2-pop-sage-bg);
  border: 1px solid var(--v2-accent-botanical);
  border-radius: var(--v2-radius-md);
}
.idea-sheet__trust-icon {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--v2-accent-botanical);
  color: var(--v2-text-on-accent);
}
.idea-sheet__trust-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.idea-sheet__trust-copy { flex: 1; font-size: var(--v2-font-size-callout); font-weight: 500; line-height: 1.3; color: var(--v2-text-primary); }
.idea-sheet__thanks { margin: 4px 4px 16px; text-align: center; color: var(--v2-text-support); font-size: var(--v2-font-size-subhead); }

/* ─── Buttons under a message: Done and Keep Editing style ─── */
.idea-sheet__actions { display: grid; gap: 8px; padding: 0 0 4px; }
.idea-sheet__primary, .idea-sheet__secondary, .idea-sheet__discard {
  width: 100%;
  min-height: 50px;
  border-radius: var(--v2-radius-full);
  font-size: var(--v2-font-size-callout);
  font-weight: 700;
}
.idea-sheet__primary { border: none; background: var(--v2-accent-terracotta); color: var(--v2-text-on-accent); }
.idea-sheet__secondary { display: flex; align-items: center; justify-content: center; text-decoration: none; border: none; background: var(--v2-glass-control-fill); color: var(--v2-text-primary); }
.idea-sheet__discard { border: 1px solid var(--v2-pop-coral); background: transparent; color: var(--v2-pop-coral-text); }
.idea-sheet__primary:active, .idea-sheet__secondary:active, .idea-sheet__discard:active { opacity: 0.8; }
.idea-sheet__primary:focus-visible, .idea-sheet__secondary:focus-visible, .idea-sheet__discard:focus-visible { outline: 2px solid var(--v2-accent-text); outline-offset: 2px; }

/* ─── Discard question ─── */
.idea-sheet__confirm { padding-top: 20px; }
.idea-sheet__confirm-title { margin: 12px 20px 2px; font-family: var(--v2-font-display); font-weight: 600; font-size: var(--v2-font-size-title3); text-align: center; }
.idea-sheet__confirm-text { margin: 0 20px 16px; font-size: var(--v2-font-size-subhead); line-height: 1.4; text-align: center; color: var(--v2-text-support); }
.idea-sheet__confirm .idea-sheet__actions { padding: 0 16px 4px; }

/* ─── Docked draft (#790, mockup bug-report-draft-790.html) ───
 * A swipe down with words typed docks the sheet above the tab bar: grabber, bar (× and
 * Send) and the first line. The page behind takes taps again. Script: js/lib/sheet-dock.js. */
.idea-sheet-scrim.is-docked { background: transparent; pointer-events: none; }
.idea-sheet-scrim.is-docked .idea-sheet {
  pointer-events: auto;
  height: auto;
  bottom: calc(var(--v2-nav-bottom) + var(--v2-tabbar-height) + var(--v2-space-sm));
  padding-bottom: var(--v2-space-sm);
  cursor: pointer;
}
.idea-sheet-scrim.is-docked .idea-sheet__body,
.idea-sheet-scrim.is-docked .idea-sheet__confirm { display: none; }
.idea-sheet__peek {
  display: block;
  width: 100%;
  min-height: var(--v2-space-touch);
  padding: 0 var(--v2-space-md);
  border: none;
  background: transparent;
  color: var(--v2-text-secondary);
  font: 400 14px/1.4 var(--v2-font-body);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reduce Motion: no travel, no spinning. The sheet appears in place. */
@media (prefers-reduced-motion: reduce) {
  .idea-sheet-scrim, .idea-sheet-scrim.open, .idea-sheet { transition: none; }
  .idea-sheet__spinner { animation: none; }
}
