/* AppsV4 design system. Mobile-first: the base rules are the phone layout (360px), media queries widen it.
   No inline styles anywhere (the CSP forbids them), so everything visual lives here. */
:root {
  --bg: #f7f7fb; --surface: #ffffff; --surface-2: #f0f1f7; --text: #14151a; --muted: #5b5f6e;
  --line: #e2e4ee; --brand: #4f46e5; --brand-ink: #ffffff; --brand-soft: #eceafe; --ok: #0f7b4b;
  --warn-bg: #fff6db; --warn-ink: #6b4e00; --danger: #b3261e;
  --r-s: 8px; --r-m: 14px; --r-l: 22px; --shadow: 0 1px 2px rgba(20, 21, 26, .06), 0 6px 20px rgba(20, 21, 26, .06);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --tabbar-h: 60px; --maxw: 1080px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1014; --surface: #181a20; --surface-2: #20232b; --text: #f1f2f6; --muted: #a3a7b7;
    --line: #2a2d38; --brand: #8b85ff; --brand-ink: #0f1014; --brand-soft: #24224a; --ok: #5fd39b;
    --warn-bg: #3a3010; --warn-ink: #ffe08a; --danger: #ff8a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: var(--brand); text-underline-offset: 3px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 var(--s3); letter-spacing: -.01em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 var(--s4); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: var(--s4); top: var(--s4); background: var(--surface); padding: var(--s2) var(--s3); z-index: 20; }

/* top bar */
.bar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
.bar-in { max-width: var(--maxw); margin: 0 auto; padding: var(--s3) var(--s4); display: flex; align-items: center; gap: var(--s4); }
.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.bar-nav { display: none; margin-left: auto; gap: var(--s2); align-items: center; }
.bar-nav a { color: var(--muted); text-decoration: none; padding: var(--s2) var(--s3); border-radius: var(--r-s); font-weight: 500; }
.bar-nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }

/* bottom tab bar (phones) */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; min-height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .72rem; font-weight: 600; color: var(--muted); text-decoration: none;
}
.tabs a[aria-current="page"] { color: var(--brand); }
.tabs svg { width: 24px; height: 24px; }

main { max-width: var(--maxw); margin: 0 auto; padding: var(--s5) var(--s4) var(--s6); }
.stack > * + * { margin-top: var(--s4); }
.lead { font-size: 1.1rem; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .875rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: var(--s4); box-shadow: var(--shadow); }
.grid { display: grid; gap: var(--s3); grid-template-columns: 1fr; }
.grid.two { grid-template-columns: 1fr 1fr; }
.hero { background: linear-gradient(140deg, var(--brand-soft), var(--surface)); border: 1px solid var(--line); border-radius: var(--r-l); padding: var(--s5) var(--s4); }
.hero h1 { font-size: 2rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 48px; padding: 0 var(--s5);
  border-radius: 999px; border: 1px solid transparent; background: var(--brand); color: var(--brand-ink);
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer; width: 100%;
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.actions { display: flex; flex-direction: column; gap: var(--s3); margin-top: var(--s4); }

.chip { display: inline-flex; align-items: center; min-height: 26px; padding: 0 var(--s3); border-radius: 999px; font-size: .78rem; font-weight: 650; background: var(--surface-2); color: var(--muted); }
.chip.ok { background: var(--brand-soft); color: var(--brand); }
.chip.soon { background: var(--warn-bg); color: var(--warn-ink); }
.row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: var(--s3) 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list a { display: block; color: var(--text); text-decoration: none; font-weight: 600; }
.list a span { display: block; font-weight: 400; color: var(--muted); font-size: .9rem; }

.notice { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--r-m); padding: var(--s3) var(--s4); font-size: .92rem; }
.error { background: transparent; border: 1px solid var(--danger); color: var(--danger); border-radius: var(--r-m); padding: var(--s3) var(--s4); }
.empty { text-align: center; padding: var(--s7) var(--s4); }
.empty svg { width: 56px; height: 56px; color: var(--muted); }
.check { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) 0; }
.check input { width: 24px; height: 24px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; font-weight: 700; flex: none; }
.who { display: flex; align-items: center; gap: var(--s4); }
.legal h2 { margin-top: var(--s5); }
.foot { margin-top: var(--s6); padding-top: var(--s4); border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.foot a { color: var(--muted); margin-right: var(--s3); display: inline-block; padding: var(--s1) 0; }

/* store */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
a.chip { text-decoration: none; }
.app-icon { width: 56px; height: 56px; border-radius: 22%; object-fit: cover; flex: none; background: var(--surface-2); border: 1px solid var(--line); }
.app-icon.ph { display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.4rem; color: var(--brand); background: var(--brand-soft); }
.app-icon.big { width: 96px; height: 96px; font-size: 2.4rem; }
.app-card { display: flex; gap: var(--s3); align-items: center; color: var(--text); text-decoration: none; min-height: 88px; }
.app-card:hover, .cat-card:hover { border-color: var(--brand); }
.app-card-text { display: flex; flex-direction: column; min-width: 0; }
.app-card-text > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-card.gone { opacity: .7; }
.cat-card { display: block; color: var(--text); text-decoration: none; }
.cat-card h3 { margin: 0; }
.app-head { display: flex; gap: var(--s4); align-items: center; }
.app-head h1 { margin-bottom: var(--s1); overflow-wrap: anywhere; }
.app-head p { margin: 0; }
.rating { display: inline-flex; align-items: center; gap: var(--s1); }
.rating svg { width: 16px; height: 16px; color: #e0a100; }
.stars { color: #e0a100; letter-spacing: 2px; white-space: nowrap; }
.stars .off { color: var(--line); }
.shots { display: flex; gap: var(--s3); overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: var(--s2); -webkit-overflow-scrolling: touch; }
.shots img { height: 320px; width: auto; max-width: 85vw; object-fit: contain; border-radius: var(--r-m); border: 1px solid var(--line); scroll-snap-align: start; background: var(--surface-2); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.review .reply { margin: var(--s2) 0 0 var(--s4); padding-left: var(--s3); border-left: 3px solid var(--line); }
.review .reply p, .review p { margin-bottom: var(--s2); }
.review.is-hidden { opacity: .6; }
.reason { color: var(--danger); }

/* forms */
.field { display: block; margin: 0 0 var(--s4); border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { display: block; font-weight: 600; margin-bottom: var(--s1); padding: 0; }
.field .small { font-weight: 400; margin-top: var(--s1); }
input[type="text"], input[type="url"], input[type="search"], input[type="number"], input[type="file"], select, textarea {
  width: 100%; min-height: 48px; padding: var(--s3); font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-s);
}
textarea { min-height: 96px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--brand); }
.small-btn { min-height: 36px; padding: 0 var(--s3); font-size: .85rem; width: auto; }
.error ul { margin: 0; padding-left: var(--s5); }
.subtabs { display: flex; gap: var(--s2); border-bottom: 1px solid var(--line); }
.subtabs a { padding: var(--s3) var(--s4); color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; min-height: 48px; }
.subtabs a[aria-current="page"] { color: var(--brand); border-bottom-color: var(--brand); }
.media-list { list-style: none; margin: 0 0 var(--s4); padding: 0; display: flex; flex-wrap: wrap; gap: var(--s3); }
.media-item { display: flex; flex-direction: column; gap: var(--s1); align-items: flex-start; }
.media-item img { max-width: 160px; height: auto; max-height: 200px; border-radius: var(--r-s); border: 1px solid var(--line); }
.upload { margin-bottom: var(--s4); }
.steps li { margin-bottom: var(--s3); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; overflow-wrap: anywhere; }
code.token { display: inline-block; margin-top: var(--s1); padding: var(--s2) var(--s3); user-select: all; }

/* admin */
.facts { display: grid; grid-template-columns: 1fr; gap: var(--s1) var(--s4); margin: 0 0 var(--s4); }
.facts dt { font-weight: 600; color: var(--muted); font-size: .85rem; }
.facts dd { margin: 0 0 var(--s2); overflow-wrap: anywhere; }
.precheck { list-style: none; margin: 0 0 var(--s4); padding: 0; }
.precheck li { padding: var(--s2) var(--s3); border-radius: var(--r-s); margin-bottom: var(--s1); background: var(--surface-2); }
.precheck li.flag { background: var(--warn-bg); color: var(--warn-ink); }
.decide { border-top: 1px solid var(--line); padding-top: var(--s4); }

@media (min-width: 600px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .grid.three { grid-template-columns: repeat(3, 1fr); }
  .btn { width: auto; }
  .actions { flex-direction: row; flex-wrap: wrap; }
  .hero { padding: var(--s7) var(--s6); }
  .hero h1 { font-size: 2.6rem; }
}
@media (min-width: 860px) {
  body { padding-bottom: 0; }
  .tabs { display: none; }
  .bar-nav { display: flex; }
  .grid.five { grid-template-columns: repeat(5, 1fr); }
  .facts { grid-template-columns: 160px 1fr; }
  .narrow { max-width: 640px; margin-left: auto; margin-right: auto; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .bar-nav a { transition: filter .15s ease, background-color .15s ease; }
}

/* M3: hosting */
.review-frame { display: block; width: 100%; height: 70vh; min-height: 420px; border: 2px dashed #b45309; border-radius: 12px; background: #fff; }
pre.code { margin: 0; padding: 16px; overflow: auto; max-height: 75vh; background: #14151a; color: #e7e8ee; border-radius: 12px; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; tab-size: 2; }
.files { list-style: none; margin: 0; padding: 0; columns: 2 280px; }
.files li { padding: 2px 0; break-inside: avoid; overflow-wrap: anywhere; }
.findings li { overflow-wrap: anywhere; }
.releases li > * + * { margin-top: 6px; }

/* ---- builder chat (M4a). The thread is the page; the composer stays above the tab bar; settings one tap away. */
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.chat { max-width: var(--maxw); margin: 0 auto; }
.chat-head h1 { font-size: 1.4rem; margin: 0; min-width: 0; overflow-wrap: anywhere; }
.chat-head .row { margin-bottom: var(--s2); }
.chat-meter { display: inline-block; margin: 0 0 var(--s3); padding: var(--s1) var(--s3); border-radius: 999px; background: var(--brand-soft); color: var(--text); font-size: .85rem; font-weight: 600; }
.chat-cols { display: grid; gap: var(--s5); grid-template-columns: minmax(0, 1fr); }
.chat-thread { min-width: 0; }
.msgs { list-style: none; margin: 0 0 var(--s3); padding: 0; display: flex; flex-direction: column; gap: var(--s3); }
.msg { max-width: min(92%, 640px); padding: var(--s3) var(--s4); border-radius: var(--r-l); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); animation: msg-in .18s ease; }
.msg-creator { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-color: transparent; border-bottom-right-radius: var(--r-s); }
.msg-planner { align-self: flex-start; border-bottom-left-radius: var(--r-s); }
.msg-system { align-self: center; max-width: 100%; width: 100%; background: var(--surface-2); box-shadow: none; border-radius: var(--r-m); font-size: .92rem; }
.msg.kind-plan { border-color: var(--brand); border-width: 2px; }
.msg.kind-preview { background: var(--brand-soft); border-color: var(--brand); }
.msg.kind-notice { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.msg-who { font-size: .75rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; opacity: .75; margin-bottom: var(--s1); }
.msg-text { line-height: 1.5; }
.msg-links { margin-top: var(--s3); }
.msg-meta { display: flex; gap: var(--s3); justify-content: flex-end; margin-top: var(--s2); font-size: .75rem; }
.msg-creator .msg-meta, .msg.kind-notice .msg-meta { color: inherit; opacity: .8; }
.msg-cost { font-variant-numeric: tabular-nums; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
.chat-status { min-height: 1.5em; margin: 0 0 var(--s3); color: var(--muted); font-size: .92rem; }
.chat-status.busy::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: var(--s2); border-radius: 50%; background: var(--brand); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.chat-build { border: 2px solid var(--brand); margin-bottom: var(--s3); }
.chat-build p { margin-bottom: var(--s2); }
.chat-cancel, .chat-delete { margin: 0 0 var(--s3); }
.upgrade { border: 2px solid var(--brand); margin-bottom: var(--s3); }
.composer { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s2)); z-index: 5; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2); align-items: end; padding: var(--s2); margin-bottom: var(--s3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow); }
.composer textarea { min-height: 48px; max-height: 220px; resize: none; border-color: transparent; background: transparent; }
.composer .btn { min-height: 48px; width: auto; padding: 0 var(--s5); }
.composer .error { grid-column: 1 / -1; margin: 0; }
.composer-first textarea { min-height: 140px; }
.chat-settings { align-self: start; scroll-margin-top: 80px; }
.chat-settings .field, .chat-settings .facts { margin-bottom: var(--s3); }
@media (min-width: 600px) {
  .composer { bottom: var(--s4); }
}
@media (min-width: 900px) {
  .chat-cols { grid-template-columns: minmax(0, 1fr) 340px; }
  .chat-settings { position: sticky; top: 84px; max-height: calc(100vh - 110px); overflow: auto; }
  .chat-head .small-btn { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .msg, .chat-status.busy::before { animation: none; }
}
