/* App chrome. Tokens from docs/plan/11-design-system.md — the LIVE-verified set.
 *
 * This is OUR design language, and it appears ONLY here, in the app.
 * 06-development-plan.md §8: "Our design language never enters a customer's
 * site, at any tier." The preview iframe renders the customer's theme; nothing
 * in this file reaches it.
 *
 * 04-components.md §2.25: the editor gets no mark. There is no logo in the
 * editor chrome, deliberately.
 */

:root {
  --brand: #20c2d2;
  --brand-lift: #4fd6e4;
  --brand-deep: #12707a; /* 3D shadow faces only, never text — 3.48:1 fails AA */
  --bg: #05070a;
  --bg-raised: #0b0f15;
  --bg-card: #11161e;
  --border: #1e2630;
  --text: #f2f5f8;
  --text-muted: #8b97a6;
  --danger: #ff6b4a;

  --radius-sm: 4px;
  --radius-md: 10px;
  --radius-pill: 999px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-fast: 0.2s;

  --font-display: "Space Grotesk", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Target size: 44pt iOS / 48dp Android / 24 CSS px web. Three numbers, not
     one (01-editing-surfaces.md §1). This is the web number, floored at 44 for
     touch because the same build runs on a phone. */
  --target: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
p { margin: 0 0 1rem; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* Controls. CONTRAST FIX from 11-design-system.md: --border cannot bound a
   control (1.32:1). Control boundaries use --text-muted (6.11-6.79:1);
   --border is for decorative separators only. */
button, input, textarea, select {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--text-muted);
  border-radius: var(--radius-md);
}
button { cursor: pointer; min-height: var(--target); padding: 0 1rem; transition: background var(--dur-fast) var(--ease); }
button:hover:not(:disabled) { background: var(--bg-card); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn-primary { background: var(--brand); color: #04191c; border-color: var(--brand); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--brand-lift); }
.btn-ghost { border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-card); }
.btn-danger { border-color: var(--danger); color: var(--danger); }

textarea, input[type="text"] { width: 100%; padding: 0.75rem; background: var(--bg-raised); }
textarea { resize: vertical; min-height: 7rem; }

/* --------------------------------------------------------------------- */
/* Screen scaffolding                                                     */
/* --------------------------------------------------------------------- */

#app { height: 100%; display: flex; flex-direction: column; }
.screen { display: none; flex: 1; min-height: 0; }
.screen[data-active] { display: flex; flex-direction: column; }

.pad { padding: 1.5rem 1.25rem; max-width: 620px; margin: 0 auto; width: 100%; }
.center { flex: 1; display: flex; flex-direction: column; justify-content: center; min-height: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0 1.25rem; }
.chip {
  border-radius: var(--radius-pill); padding: 0.4rem 0.9rem; min-height: 36px;
  font-size: 0.85rem; color: var(--text-muted); background: var(--bg-card);
  border: 1px solid var(--border); text-align: left;
}
.chip:hover { color: var(--text); }

.row { display: flex; gap: 0.6rem; align-items: center; }
.row--end { justify-content: flex-end; }
.grow { flex: 1; }

/* Progress — "2 of 3". A 3-step flow with no indicator feels unbounded. */
.progress { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.25rem; }
.progress__bar { flex: 1; height: 3px; background: var(--border); border-radius: var(--radius-pill); overflow: hidden; }
.progress__fill { height: 100%; background: var(--brand); transition: width var(--dur-fast) var(--ease); }

.option {
  display: block; width: 100%; text-align: left; padding: 0.9rem 1rem; margin-bottom: 0.6rem;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.option[aria-pressed="true"] { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.option__label { font-weight: 600; }

/* A3 — generating. Stable skeletons at real section heights, aria-busy, no
   flicker (02-screens.md A3). */
.steps { list-style: none; padding: 0; margin: 0 0 1.5rem; }
.steps li { display: flex; gap: 0.7rem; align-items: center; padding: 0.4rem 0; color: var(--text-muted); }
.steps li[data-state="done"] { color: var(--text); }
.steps li[data-state="active"] { color: var(--brand); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.skeleton { background: var(--bg-card); border-radius: var(--radius-md); margin-bottom: 0.75rem; }

/* --------------------------------------------------------------------- */
/* B1 Editor                                                              */
/* --------------------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0.9rem;
  background: var(--bg-raised); border-bottom: 1px solid var(--border); flex: none;
}
.topbar__title { font-family: var(--font-display); font-size: 0.95rem; }

.editor { flex: 1; display: flex; min-height: 0; }

/* Desktop: three panes — outline rail 280px, preview centred at device width,
   editor panel 380px right (01-editing-surfaces.md §1, 02-screens.md B1). */
.rail { width: 280px; flex: none; border-right: 1px solid var(--border); background: var(--bg-raised); overflow: auto; padding: 0.75rem; }
.stage { flex: 1; min-width: 0; overflow: auto; display: flex; justify-content: center; padding: 1rem; background: #000; }
.panel { width: 380px; flex: none; border-left: 1px solid var(--border); background: var(--bg-raised); overflow: auto; padding: 1rem; }

#preview { width: 100%; max-width: 430px; height: 100%; border: 1px solid var(--border); border-radius: var(--radius-md); background: #fff; }
.stage[data-width="desktop"] #preview { max-width: 1440px; }
.stage[data-width="tablet"] #preview { max-width: 768px; }

.railitem { display: flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0; }
.railitem__name { flex: 1; text-align: left; border: none; background: none; color: inherit; padding: 0.4rem 0.5rem; border-radius: var(--radius-sm); min-height: 36px; }
.railitem__name:hover { background: var(--bg-card); }
.railitem[data-hidden] .railitem__name { color: var(--text-muted); text-decoration: line-through; }
.tag { font-size: 0.7rem; color: var(--text-muted); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 0 0.4rem; }
/* ▲▼ are FIRST-CLASS controls, not a screen-reader fallback. WCAG 2.2 AA:
   "Don't make dragging the only way to reorder." Often faster on a phone. */
.nudge { width: 32px; min-height: 32px; padding: 0; font-size: 0.7rem; border-color: var(--border); }

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem; }

.verbs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.verbs button { justify-content: flex-start; font-size: 0.9rem; }

.swatches { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.swatch { padding: 0.6rem; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--bg-card); text-align: left; min-height: 56px; }
.swatch[aria-pressed="true"] { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.swatch__dots { display: flex; gap: 3px; margin-bottom: 0.35rem; }
.swatch__dot { width: 14px; height: 14px; border-radius: 3px; border: 1px solid #0003; }

.banner { padding: 0.6rem 0.9rem; background: var(--bg-card); border-bottom: 1px solid var(--border); font-size: 0.85rem; color: var(--text-muted); }
.banner strong { color: var(--text); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 1.25rem; z-index: 40;
  background: var(--bg-card); border: 1px solid var(--text-muted); border-radius: var(--radius-md);
  padding: 0.6rem 1rem; display: flex; gap: 0.75rem; align-items: center; font-size: 0.9rem;
  box-shadow: 0 8px 30px #000a;
}
.toast[hidden] { display: none; }

/* --------------------------------------------------------------------- */
/* Surface 3 — the instruction bar and the review bar                      */
/* 01-editing-surfaces.md §3. Review mode must READ as distinct from        */
/* editing mode, so the review bar is raised and brand-ruled while the      */
/* instruction bar is quiet.                                               */
/* --------------------------------------------------------------------- */

.instruct {
  display: flex; gap: 0.5rem; align-items: center;
  padding: 0.6rem 1rem; border-top: 1px solid var(--border); background: var(--bg-raised);
}
.instruct[hidden] { display: none; }
.instruct input {
  flex: 1; min-height: 44px; padding: 0 0.75rem; font: inherit;
  color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.instruct[aria-busy='true'] input {
  background-image: linear-gradient(90deg, transparent, #20c2d222, transparent);
  background-size: 200% 100%; animation: instruct-busy 1.1s linear infinite;
}
@keyframes instruct-busy { to { background-position: -200% 0; } }

.review {
  border-top: 2px solid var(--brand, #20c2d2); background: var(--bg-raised);
  max-height: 45vh; overflow: auto;
}
.review[hidden] { display: none; }
.review__bar {
  display: flex; gap: 0.5rem; align-items: center;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-raised);
}
.review__bar > * { white-space: nowrap; }
.review__list { padding: 0.5rem 1rem 1rem; }

@media (max-width: 420px) {
  /* A wrapped "1 of 4" reads as two facts rather than one (§3's review bar). */
  .review__bar { padding: 0.5rem 0.6rem; gap: 0.35rem; font-size: 0.85rem; }
  .review__bar .btn-ghost, .review__bar .btn-primary { padding: 0 0.6rem; }
}

.change {
  display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 0.5rem;
  padding: 0.5rem; border-radius: var(--radius-md); border: 1px solid transparent;
}
.change[data-current] { border-color: #20c2d2; }
.change[data-rejected] { opacity: 0.5; }
.change[data-rejected] .change__text { text-decoration: line-through; }
.change__text {
  grid-column: 1; text-align: left; background: none; border: none; color: var(--text);
  font: inherit; padding: 0; cursor: pointer;
}
.change__was { grid-column: 1; }
.change__toggle {
  grid-row: 1 / span 2; grid-column: 2; min-width: 44px; min-height: 44px;
  background: none; border: 1px solid var(--border); border-radius: var(--radius-md);
  color: var(--text); cursor: pointer;
}
.change--declined { border-color: var(--border); background: var(--bg); margin-top: 0.5rem; }

.promo {
  margin-top: 1.25rem; padding: 0.9rem; border-radius: var(--radius-md);
  border: 1px solid var(--brand, #20c2d2); background: var(--bg-card);
}
.promo p { margin: 0.35rem 0 0.75rem; }
.promo--paid { border-color: var(--border); }

.btn-link {
  background: none; border: none; padding: 0; color: var(--brand, #20c2d2);
  font: inherit; text-decoration: underline; cursor: pointer;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* --------------------------------------------------------------------- */
/* Phone — the sheet, and the pane collapse                               */
/* --------------------------------------------------------------------- */

.sheet { display: none; }

@media (max-width: 900px) {
  .rail { display: none; }
  .rail[data-open] {
    display: block; position: fixed; inset: 0; z-index: 30; width: auto;
    border: none; padding: 1rem;
  }
  .panel { display: none; }
  .stage { padding: 0; }
  #preview { max-width: none; border: none; border-radius: 0; }

  /* Bottom sheet: rises from the bottom edge over --dur-fast on --ease,
     occupying ~45% of viewport height (01-editing-surfaces.md §1).
     Same CONTENTS AND ORDER as the desktop panel — only the container moves. */
  .sheet {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    max-height: 45vh; overflow: auto; padding: 1rem 1rem 1.5rem;
    background: var(--bg-raised); border-top: 1px solid var(--border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    transform: translateY(100%); transition: transform var(--dur-fast) var(--ease);
    box-shadow: 0 -10px 40px #000c;
  }
  .sheet[data-open] { transform: translateY(0); }
  .sheet[hidden] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
