/* Design tokens mirror Mission Control's dark theme (default Sandstone palette)
   so the PWA reads as part of the same product family — same warm taupe bg,
   same coral-orange accent, same radii, same Inter typography. Source of
   truth: public/index.html :root + [data-theme="dark"] in MC repo. */
:root {
  --bg: #1a1916;
  --surface: #242220;
  --surface-raised: #2c2a27;
  --border: #3a3733;
  --border-light: #32302c;
  --text: #e8e4de;
  --text-secondary: #a8a29e;
  --text-muted: #78716c;
  --accent: #e07a56;
  --accent-light: #2e2218;
  --accent-hover: #f08a66;
  --success: #5cb87a;
  --success-light: #1c2e22;
  --error: #e05656;
  --warning: #e0a056;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 3px rgba(0,0,0,0.25), 0 1px 2px rgba(0,0,0,0.15);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  /* Lock horizontal pan on touch devices — Paul reported the whole canvas
     drifting left/right when dragging on iPhone. `overflow-x: hidden` plus
     `touch-action: pan-y` together prevent the rubber-band horizontal pan
     and the iOS bounce in the cross-axis. */
  overflow-x: hidden;
  touch-action: pan-y;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* Header aligns to the same 480px-wide content column as main: same max-width,
   same internal horizontal padding, same centering. Critical detail — the
   28px padding lives on `.header-inner` (not on `header`), so the content
   area reduces to 480 - 56 = 424px exactly like main's, and the logo sits
   flush with the form labels below it on every viewport size. */
header {
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 0 0;
  width: 100%;
}

.header-inner {
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 10px;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

header .logo {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}

header .logo svg {
  width: 16px;
  height: 16px;
}

.settings-btn__icon svg {
  width: 14px;
  height: 14px;
  display: block;
}

/* Main fills the remaining viewport (header + main = 100dvh) and overflows
   are hidden — the form layout itself is responsible for fitting the visible
   area, no page scrolling required. Horizontal padding is generous (~7-8% on
   phone) so content doesn't run edge-to-edge. */
main {
  flex: 1;
  min-height: 0;
  padding: 14px 28px calc(env(safe-area-inset-bottom, 0px) + 14px);
  display: flex;
  flex-direction: column;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

#dumpForm {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.field { display: flex; flex-direction: column; gap: 8px; }

/* The notes field stretches to absorb whatever vertical space is left after
   header + project chips + URL + Send button — so the form fills the phone
   viewport exactly, no scroll. Capped at 320px so on tall desktop browsers
   the textarea doesn't stretch into a comically deep void; the bottom of
   the form just leaves blank space (which is fine on desktop). */
.field--notes {
  flex: 1;
  min-height: 0;
  max-height: 320px;
}

.field--notes textarea {
  flex: 1;
  min-height: 80px;
  height: auto;
}

/* Send button gets a touch of breathing room from the textarea above. */
.send-btn { margin-top: 4px; flex-shrink: 0; }

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.radio-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.radio-group input[type="radio"] { display: none; }

.radio-group label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  line-height: 1.4;
}

.radio-group input[type="radio"]:checked + label {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

input[type="url"],
textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  /* 16px prevents iOS Safari auto-zoom on focus — anything smaller triggers
     a viewport zoom that breaks the layout. */
  font-size: 16px;
  padding: 11px 14px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
  resize: none;
  -webkit-appearance: none;
}

input[type="url"]:focus,
textarea:focus {
  border-color: var(--accent);
}

input[type="url"]::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

textarea {
  line-height: 1.5;
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  padding: 16px;
  width: 100%;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.2px;
}

.send-btn:active { transform: scale(0.98); }
.send-btn:disabled { background: var(--border); color: var(--text-muted); cursor: default; }
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }

/* ── Send button states + internal pieces ──────────────────────────────────
   The Send button is the single, always-visible status surface. Its label
   text swaps through four states: idle ("Send") → sending → processing
   ("Polsk processing…" with elapsed counter) → filed ("Filed in <project>"
   with final time, green). After 3s in filed it auto-reverts to idle. */

.send-btn__icon {
  display: none;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}

/* Glowing orb shown during sending + processing — radial-gradient pulsing
   circle, mirrors the kbThinkPulse pattern used inside MC's Workshop chat. */
.send-btn__icon--orb {
  display: inline-flex;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 30%, rgba(255,255,255,0.55) 70%);
  animation: send-orb-pulse 1.4s ease-in-out infinite;
}

@keyframes send-orb-pulse {
  0%, 100% { transform: scale(0.7); opacity: 0.55; }
  50%      { transform: scale(1.1); opacity: 1; }
}

.send-btn__icon--check {
  display: inline-flex;
}

.send-btn__elapsed {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 500;
  opacity: 0.85;
  margin-left: auto;
}

.send-btn__elapsed:empty { display: none; }

/* Sending + processing — keep the button orange even though it's disabled
   mid-submit. (Default :disabled rule below would otherwise grey it out.) */
.send-btn.send-btn--sending,
.send-btn.send-btn--sending:disabled,
.send-btn.send-btn--processing,
.send-btn.send-btn--processing:disabled {
  background: var(--accent) !important;
  color: #fff;
}

/* Filed state — green background, locks in the final round-trip duration.
   Wins over :disabled with !important so the green stays visible even while
   the button is briefly disabled at the tail of the submit handler. */
.send-btn.send-btn--filed,
.send-btn.send-btn--filed:disabled {
  background: var(--success) !important;
  color: #fff;
}

.send-btn.send-btn--filed:hover { background: var(--success) !important; }

/* Error state — red background. */
.send-btn.send-btn--error,
.send-btn.send-btn--error:disabled {
  background: var(--error) !important;
  color: #fff;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  animation: toast-in 0.2s ease;
  z-index: 9999;
}

.toast--success { border-color: var(--success); color: var(--success); }
.toast--offline { border-color: var(--warning); color: var(--warning); }
.toast--error   { border-color: var(--error); color: var(--error); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Setup modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: flex-end;
  z-index: 1000;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 24px calc(env(safe-area-inset-bottom, 0px) + 24px);
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* min-width:0 prevents long URLs/keys from blowing out the flex container */
  min-width: 0;
}

.modal h2 { font-size: 17px; font-weight: 600; }
.modal p  { font-size: 14px; color: var(--text-muted); line-height: 1.5; }

.modal input[type="text"],
.modal input[type="url"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  /* Monospace + smaller font fits long URLs and 64-char hex keys
     in the visible width without scrolling out of view. */
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
  /* min-width:0 prevents the input from forcing the flex parent wider than viewport */
  min-width: 0;
}

.modal input:focus { border-color: var(--accent); }

.modal-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  display: block;
}

.modal-field { display: flex; flex-direction: column; }

.modal-save-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  padding: 13px;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}

.modal-save-btn:hover { background: var(--accent-hover); }
.modal-save-btn:disabled { background: var(--border); color: var(--text-muted); }

/* Settings button — lives inside the header flex flow so it can never be
   hidden by the iPhone status bar. Has both an icon and a visible "Settings"
   label so it's obvious to non-coder users. */
.settings-btn {
  margin-left: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.settings-btn:hover { border-color: var(--accent); color: var(--accent); }
.settings-btn:active { background: var(--bg); }

.settings-btn__icon { font-size: 14px; line-height: 1; }
.settings-btn__label { font-size: 13px; }

/* (Send status pill removed — status now lives inside the Send button itself.
   See `.send-btn__icon`, `.send-btn__elapsed` and `.send-btn--*` state classes
   above.) */

/* Queue badge */
.queue-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--warning);
  padding: 4px 10px;
  background: rgba(224, 160, 86, 0.1);
  border: 1px solid rgba(224, 160, 86, 0.3);
  border-radius: 20px;
  cursor: pointer;
  user-select: none;
}

.queue-badge:empty { display: none; }
