:root {
  --ink: #171512;
  --ink-soft: #5c564f;
  --mist: #8a837a;
  --paper: #f4f0ea;
  --paper-soft: #fbf9f6;
  --line: #e4ddd4;
  --bronze: #9b6a4d;
  --bronze-deep: #7d533c;
  --danger: #a33a2b;
  --warn-bg: #fbf1dd;
  --warn: #7a5512;
  --err-bg: #f8e3df;
  --radius: 14px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper-soft);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-family: var(--display); font-weight: 500; letter-spacing: -0.01em; }
.muted { color: var(--mist); font-size: 0.875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button { font: inherit; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  min-height: 44px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.btn.primary { background: var(--bronze); border-color: var(--bronze); color: #fff; }
.btn.primary:hover { background: var(--bronze-deep); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.danger { color: var(--danger); }
.link { background: none; border: none; color: var(--bronze-deep); cursor: pointer; padding: 0.5rem; min-height: 44px; }
.link.danger { color: var(--danger); }
.error { color: var(--danger); font-size: 0.9rem; }

/* login */
body.login { justify-content: center; align-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px 24px; display: flex; flex-direction: column; gap: 10px;
}
.login-card h1 { margin: 0; }
.login-card p { margin: 0 0 10px; }
.login-card input { font: inherit; padding: 0.7rem; border: 1px solid var(--line); border-radius: 10px; min-height: 44px; }

/* header + draft bar stay visible together */
.sticky-top { position: sticky; top: 0; z-index: 5; }
.top {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 8px 16px; background: var(--paper); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip { font-size: 0.75rem; color: var(--ink-soft); background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }
.top nav { display: flex; }

/* draft bar */
.draft {
  padding: 10px 16px; background: var(--paper-soft);
  border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.draft .status { flex: 1 1 100%; font-size: 0.9rem; color: var(--ink-soft); }
.draft .status b { color: var(--ink); }
.draft a.btn { text-decoration: none; display: inline-flex; align-items: center; }

/* transcript */
.transcript { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 14px; max-width: 760px; width: 100%; margin: 0 auto; }
.welcome { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 18px 10px; color: var(--ink-soft); }
.welcome h2 { color: var(--ink); }
.welcome li { margin: 4px 0; }
.msg { max-width: 92%; border-radius: var(--radius); padding: 10px 14px; overflow-wrap: anywhere; }
.msg p { margin: 0 0 0.6em; }
.msg p:last-child { margin-bottom: 0; }
.msg.user { align-self: flex-end; background: var(--ink); color: var(--paper-soft); }
.msg.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--line); }
.msg.system { align-self: center; background: transparent; color: var(--mist); font-size: 0.85rem; text-align: center; padding: 4px 8px; }
.msg .meta { font-size: 0.72rem; color: var(--mist); margin-top: 6px; }
.msg.user .meta { color: rgba(251, 249, 246, 0.6); }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.issues { margin: 10px 0 0; padding: 8px 12px; border-radius: 10px; font-size: 0.88rem; list-style: none; }
.issues.errors { background: var(--err-bg); color: var(--danger); }
.issues.warnings { background: var(--warn-bg); color: var(--warn); }
.issues li + li { margin-top: 4px; }

.shots { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 12px; }
@media (min-width: 640px) { .shots { grid-template-columns: 1fr 1fr; } }
.shot { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--paper); }
.shot-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; font-size: 0.8rem; gap: 6px; }
.toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.toggle button { border: none; background: #fff; padding: 6px 10px; min-height: 36px; cursor: pointer; font-size: 0.8rem; }
.toggle button[aria-pressed='true'] { background: var(--ink); color: #fff; }
.shot-img { display: block; max-height: 520px; overflow: auto; background: #fff; }
.shot-img img { width: 100%; display: block; }

/* live job */
.job { margin: 0 auto 8px; max-width: 760px; width: calc(100% - 32px); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.job-head { display: flex; align-items: center; gap: 10px; }
.job-head strong { flex: 1; }
.job-lines { margin: 6px 0 0; padding: 0; list-style: none; font-size: 0.85rem; color: var(--ink-soft); max-height: 30vh; overflow: auto; }
.job-lines li { padding: 2px 0; }
.job-lines li.text { color: var(--ink); }
.job-lines li.tool::before { content: '· '; color: var(--bronze); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--bronze); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* composer */
.composer {
  position: sticky; bottom: 0; background: var(--paper); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; max-width: 760px; margin: 0 auto; }
.composer textarea {
  flex: 1; font: inherit; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 0.6rem 0.8rem;
  min-height: 44px; max-height: 40vh; background: #fff;
}
.attach { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--ink-soft); cursor: pointer; flex: none; }
.pending { display: flex; flex-wrap: wrap; gap: 8px; max-width: 760px; margin: 0 auto 8px; }
.pending:empty { display: none; }
.pending .item { position: relative; width: 64px; height: 64px; }
.pending img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.pending .item.loading img { opacity: 0.4; }
.pending .item.failed img { outline: 2px solid var(--danger); }
.pending .remove { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: none; background: var(--ink); color: #fff; cursor: pointer; line-height: 24px; padding: 0; }

/* history */
.sheet { width: min(640px, 100% - 24px); max-height: 85dvh; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.sheet::backdrop { background: rgba(23, 21, 18, 0.4); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.history-list { list-style: none; padding: 0; margin: 0; }
.history-list li { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); }
.history-list .what { font-size: 0.92rem; }
.history-list .when { font-size: 0.75rem; color: var(--mist); }
.msg ul { margin: 0 0 0.6em; padding-left: 1.2em; }
.msg li + li { margin-top: 2px; }
.msg p { white-space: pre-line; }
