/* Studio: one page, iPhone first. System font, big tap targets, light and dark from the system. */
:root {
  color-scheme: light dark;
  --bg: #f4f3f8;
  --surface: #ffffff;
  --surface-2: #ececf3;
  --text: #16161c;
  --muted: #6f6f7c;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #5b4bd6;
  --accent-text: #ffffff;
  --me: #5b4bd6;
  --me-text: #ffffff;
  --ok: #1f9d55;
  --warn: #c7731a;
  --bad: #d14343;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(20, 16, 60, 0.08);
  --radius: 18px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101014;
    --surface: #1b1b22;
    --surface-2: #26262f;
    --text: #f2f2f6;
    --muted: #9a9aa8;
    --line: rgba(255, 255, 255, 0.09);
    --accent: #8b7cf6;
    --me: #6d5de8;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, system-ui, "SF Pro Text", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  touch-action: manipulation;
}
#app { height: 100dvh; display: flex; flex-direction: column; }
button, textarea, input { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: default; }
a { color: var(--accent); }
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Buttons: a press shrinks a little, like a native control. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 20px; border-radius: 14px;
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 16px;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.2s ease;
  user-select: none; -webkit-user-select: none;
}
.btn:active { transform: scale(0.96); opacity: 0.85; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.wide { width: 100%; }
.btn.quiet { background: transparent; color: var(--muted); font-weight: 500; }
.btn.danger { color: var(--bad); }

/* Full-screen states: join, sign in, loading, error. */
.sheet {
  flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px;
  padding: calc(var(--sat) + 32px) 28px calc(var(--sab) + 32px);
  max-width: 440px; width: 100%; margin: 0 auto;
}
.sheet h1 { font-size: 30px; line-height: 1.15; margin: 8px 0 0; letter-spacing: -0.01em; }
.sheet p { margin: 0; color: var(--muted); font-size: 17px; }
.sheet .mark { width: 72px; height: 72px; border-radius: 22px; box-shadow: var(--shadow); }
.sheet .actions { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.sheet .error { color: var(--bad); font-size: 15px; min-height: 1.4em; }

/* The space: header, timeline, composer. */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
.top h1 { font-size: 17px; margin: 0; font-weight: 600; }
.top .sub { font-size: 13px; color: var(--muted); display: block; font-weight: 500; }
.top .who {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.12s ease;
}
.top .who:active { transform: scale(0.92); }

.timeline {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 8px;
  scroll-behavior: smooth;
}
.timeline > * { animation: rise 0.22s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg { max-width: 82%; padding: 10px 14px; border-radius: var(--radius); line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--me); color: var(--me-text); border-bottom-right-radius: 6px; }
.msg.desk { align-self: flex-start; background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 6px; }
.msg.note { font-size: 15px; }
.msg.me.note::before { content: "Change: "; opacity: 0.8; font-weight: 600; }
.msg.pending { opacity: 0.7; }
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.2s; } .typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.line { align-self: center; font-size: 13px; color: var(--muted); text-align: center; padding: 4px 12px; }
.line.update { background: var(--surface-2); border-radius: 12px; padding: 7px 14px; font-size: 14px; color: var(--text); }
.line.update b { font-weight: 600; }
.line.update button { color: var(--accent); font-weight: 600; margin-left: 6px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--accent); font-size: 13px; font-weight: 600; margin: 6px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--accent); opacity: 0.4; }
.day { align-self: center; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 8px; }

/* Job cards live in the timeline where the brief arrived. */
.card {
  align-self: stretch; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow);
  padding: 14px 16px 14px; display: flex; flex-direction: column; gap: 10px;
  transition: box-shadow 0.3s ease;
}
.card.flash { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.card .head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card h2 { font-size: 18px; margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; flex-shrink: 0;
}
.chip.active { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.chip.good { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.chip.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.chip .spin { width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.card p { margin: 0; }
.card .meta { font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.card .meta b { color: var(--text); font-weight: 600; }
.card .reason { font-size: 14px; color: var(--bad); }
.card .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.card .actions .btn { flex: 1 1 auto; min-height: 44px; padding: 0 14px; font-size: 15px; }
.card .revise { display: flex; flex-direction: column; gap: 8px; }
.card .revise textarea {
  width: 100%; min-height: 72px; resize: none; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); padding: 10px 12px; font-size: 16px; outline: none;
}
.card .revise textarea:focus { border-color: var(--accent); }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; margin: 2px -4px 0; padding: 0 4px 4px; }
.gallery::-webkit-scrollbar { display: none; }
.gallery button { flex: 0 0 auto; scroll-snap-align: start; border-radius: 14px; overflow: hidden; background: var(--surface-2); transition: transform 0.12s ease; }
.gallery button:active { transform: scale(0.97); }
.gallery img { display: block; height: 220px; width: auto; aspect-ratio: 9 / 19.5; object-fit: cover; }
.gallery .cap { display: block; font-size: 12px; color: var(--muted); padding: 4px 6px 6px; text-align: left; }

/* Full-screen viewer: swipe between screenshots. */
.viewer { position: fixed; inset: 0; background: #000; z-index: 10; display: flex; flex-direction: column; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.viewer .strip { flex: 1; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
.viewer .strip::-webkit-scrollbar { display: none; }
.viewer figure { flex: 0 0 100%; scroll-snap-align: center; margin: 0; display: flex; align-items: center; justify-content: center; padding: calc(var(--sat) + 56px) 12px calc(var(--sab) + 56px); }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 12px; }
.viewer .bar { position: absolute; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; color: #fff; }
.viewer .bar.topbar { top: calc(var(--sat) + 8px); }
.viewer .bar.bottombar { bottom: calc(var(--sab) + 12px); justify-content: center; font-size: 14px; color: rgba(255,255,255,0.75); }
.viewer .close { color: #fff; font-size: 16px; font-weight: 600; min-height: 44px; padding: 0 14px; border-radius: 12px; background: rgba(255,255,255,0.14); }

/* Composer pinned to the bottom, above the home indicator. */
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px calc(var(--sab) + 8px);
  background: var(--bg); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; min-height: 44px; max-height: 140px; resize: none; border: 1px solid var(--line); border-radius: 22px;
  background: var(--surface); padding: 11px 16px; font-size: 17px; line-height: 1.3; outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.composer .send {
  width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; transition: transform 0.12s ease, opacity 0.12s ease;
}
.composer .send:active { transform: scale(0.9); }
.composer .send svg { width: 20px; height: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--sab) + 84px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 15px; z-index: 20;
  box-shadow: var(--shadow); animation: rise 0.2s ease; max-width: 90vw; text-align: center;
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
