:root {
  --bg: #1f2235;
  --ink: #23263a;
  --text: #23263a;
  --muted: #6b7088;
  --border: #dfe1e8;
  --paper: #fffdf7;
  --primary: #ff7a2f;
  --primary-dark: #e0621a;
  --blue: #2f6bff;
  --yellow: #ffc83d;
  --yellow-bg: #fff4c2;
  --red: #e8453c;
  --red-bg: #ffe2dd;
  --green: #22b866;
  --green-dark: #1a8f4f;
  --cardboard: #d29a5a;
  --cardboard-dark: #b47a3c;
  --cardboard-light: #e6b67c;
  --radius: 10px;
  --font: ui-rounded, 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-family: var(--font);
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); font-size: 14px; overflow: hidden; -webkit-font-smoothing: antialiased; }
code { font-family: var(--mono); font-size: 12px; background: #f1f2f4; padding: 1px 4px; border-radius: 4px; }
[hidden] { display: none !important; }
#sprites { position: absolute; width: 0; height: 0; overflow: hidden; }

.screen { position: fixed; inset: 0; overflow: hidden; }

#whiteout { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 50; }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.particle { position: absolute; left: 0; top: 0; border-radius: 50%; will-change: transform, opacity; }

.sound-btn { position: fixed; right: 14px; bottom: 14px; z-index: 30; width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.9); box-shadow: 0 3px 10px rgba(0,0,0,.25); font-size: 18px; cursor: pointer; }
.sound-btn:hover { transform: scale(1.08); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 80vw; }
.toast.error { background: var(--red); }

/* ---------- Buttons & forms ---------- */
.btn { border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 8px; padding: 7px 14px; font: inherit; font-weight: 600;
  cursor: pointer; transition: transform .12s, background .12s, box-shadow .12s; white-space: nowrap; }
.btn:hover { background: #f4f5f8; }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary-dark); color: #fff; box-shadow: 0 3px 0 var(--primary-dark); }
.btn.primary:hover { background: #ff8a45; }
.btn.approve { background: var(--green); border-color: var(--green-dark); color: #fff; box-shadow: 0 3px 0 var(--green-dark); }
.btn.reject { background: var(--red); border-color: #b9302a; color: #fff; box-shadow: 0 3px 0 #b9302a; }
.btn.danger { color: #c9372c; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.ghost { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.btn.ghost:hover { background: rgba(255,255,255,.22); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.icon-btn { margin-left: auto; border: none; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.link-btn { border: none; background: none; color: var(--blue); padding: 0; font: inherit; cursor: pointer; text-decoration: underline; }

select, input, textarea { font: inherit; color: inherit; border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; background: #fff; width: 100%; }
textarea { resize: vertical; }
label { display: block; font-weight: 700; font-size: 12px; color: #4a4f66; margin-bottom: 12px; }
label input, label textarea, label select { margin-top: 4px; font-weight: 400; font-size: 14px; }
label small { font-weight: 400; color: var(--muted); }
.path-row { display: flex; gap: 8px; margin-top: 4px; }
.path-row input { margin: 0; }
.muted { color: var(--muted); }
.warn { color: #ae2e24; background: var(--red-bg); border-radius: 6px; padding: 8px 10px; }

/* ---------- Dialogs ---------- */
.dialog { border: none; border-radius: 16px; padding: 20px 24px; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.4); background: var(--paper); color: var(--text); }
.dialog.wide { width: min(1000px, 96vw); max-height: 92vh; }
.dialog::backdrop { background: rgba(20,22,40,.55); backdrop-filter: blur(2px); }
.dialog[open] { animation: dialog-in .28s cubic-bezier(.34,1.56,.64,1); }
@keyframes dialog-in { from { transform: translateY(24px) scale(.94); opacity: 0; } }
.dialog h3 { margin: 0 0 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.dialog-actions .spacer { flex: 1; }

/* ---------- Task view (ported from tracker) ---------- */
.card-id { color: var(--muted); font-size: 12px; font-weight: 700; }
.badge { display: inline-block; border-radius: 5px; padding: 1px 7px; font-size: 11px; font-weight: 700; }
.badge.needs_clarification { background: var(--yellow); color: #3d2e00; }
.badge.rejected { background: var(--red); color: #fff; }
.badge.muted { background: #e4e5ec; color: #4a4f66; }
.badge.draft { background: #e9f2ff; color: #0055cc; border: 1px dashed #85b8ff; }
.pill { border-radius: 10px; padding: 2px 10px; font-size: 12px; font-weight: 700; background: #e4e5ec; }
.pill.status-in_progress { background: #cce0ff; color: #0055cc; }
.pill.status-review { background: #dfd8fd; color: #5e4db2; }
.pill.status-done { background: #baf3db; color: #216e4e; }

.task-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.task-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.task-title-row h3 { margin: 0 0 6px; font-size: 20px; }
.description { white-space: pre-wrap; margin: 12px 0 16px; line-height: 1.5; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.description a, .comment-body a { color: var(--blue); word-break: break-all; }
.notice { border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; border-left: 4px solid; }
.notice.yellow { background: var(--yellow-bg); border-color: var(--yellow); }
.notice.red { background: var(--red-bg); border-color: var(--red); }
.notice.draft { background: #e9f2ff; border-color: #85b8ff; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.notice.review { background: #f3f0ff; border-color: #a593f5; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.notice .comment-body { margin: 6px 0; }

.task-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.task-columns h4:not(.md-h), .images-head h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; color: var(--muted); }
.comments { display: flex; flex-direction: column; gap: 8px; max-height: 380px; overflow-y: auto; margin-bottom: 8px; }
.comment { border-radius: 8px; padding: 8px 10px; background: #f7f8f9; border: 1px solid var(--border); }
.comment.agent { background: #f0f6ff; }
.comment.kind-question { background: var(--yellow-bg); border-color: var(--yellow); }
.comment.kind-feedback { background: var(--red-bg); border-color: var(--red); }
.comment.kind-summary { background: #effbf5; border-color: #7ee2b8; }
.comment-meta { display: flex; gap: 8px; align-items: center; font-size: 12px; margin-bottom: 4px; }
.comment-meta .kind { background: rgba(9,30,66,.08); border-radius: 4px; padding: 0 5px; }
.comment-meta .time { color: var(--muted); margin-left: auto; }
.comment-body { white-space: pre-wrap; line-height: 1.45; word-break: break-word; }
.comment-form { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

.log { list-style: none; padding: 0 0 0 12px; margin: 0; border-left: 2px solid var(--border); max-height: 470px; overflow-y: auto; }
.log-entry { position: relative; padding: 0 0 12px 12px; }
.log-entry::before { content: ''; position: absolute; left: -19px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: #a5adba; border: 2px solid #fff; }
.log-entry.actor-agent::before { background: var(--blue); }
.log-entry.type-rejected::before { background: var(--red); }
.log-entry.type-approved::before { background: var(--green); }
.log-entry.type-question::before { background: var(--yellow); }
.log-meta { font-size: 11px; color: var(--muted); }
.log-type { font-weight: 800; text-transform: uppercase; color: #4a4f66; }
.log-msg { white-space: pre-wrap; word-break: break-word; }
.commits { margin: 4px 0 0; padding-left: 16px; font-size: 12px; }
.files { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.task-footer { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.task-footer label { margin: 0; display: flex; align-items: center; gap: 8px; }
.task-footer select { width: auto; margin: 0; }
.edit-form { margin-bottom: 12px; }

.field-label { font-weight: 700; font-size: 12px; color: #4a4f66; margin-bottom: 4px; }
.dropzone { border: 2px dashed var(--border); border-radius: 10px; padding: 10px; margin-bottom: 14px; background: #fff; }
.dropzone-hint { color: var(--muted); font-size: 12px; text-align: center; padding: 6px 0; }
.drop-hover { outline: 3px dashed var(--primary); outline-offset: -3px; background: #fff4ec; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; margin: 0; width: 120px; height: 90px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: #f7f8f9; }
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.thumb-del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: none; background: rgba(9,30,66,.7); color: #fff; font-size: 11px; cursor: pointer; opacity: 0; transition: opacity .15s; }
.thumb:hover .thumb-del { opacity: 1; }
.images-section { margin-bottom: 16px; }
.images-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.images-head h4 { margin: 0; }
.lightbox { border: none; padding: 0; background: transparent; max-width: 94vw; max-height: 94vh; cursor: zoom-out; }
.lightbox::backdrop { background: rgba(9,30,66,.85); }
.lightbox img { display: block; max-width: 94vw; max-height: 94vh; border-radius: 6px; }

.qa-presets { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.radio { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 400; color: var(--text); margin: 0; cursor: pointer; }
.radio input { width: auto; margin: 0; }
.qa-result, .list-rows { max-height: 300px; overflow-y: auto; padding-left: 18px; margin: 8px 0; line-height: 1.6; }
.list-rows a { color: var(--blue); cursor: pointer; }

@media (max-width: 900px) { .task-columns { grid-template-columns: 1fr; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .truck, .cloud { display: none; }
}

/* ---------- Markdown ---------- */
.md { white-space: normal; word-break: break-word; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .6em; }
.md .md-h { margin: .9em 0 .35em; line-height: 1.25; color: #23263a; }
.md h3.md-h { font-size: 1.15em; }
.md h4.md-h { font-size: 1.05em; }
.md h5.md-h, .md h6.md-h { font-size: 1em; }
.md ul, .md ol { margin: 0 0 .6em; padding-left: 1.4em; }
.md li { margin: .15em 0; }
.md code { font-family: var(--mono); font-size: .88em; background: rgba(35,38,58,.08); border-radius: 4px; padding: 1px 5px; word-break: break-word; }
.md pre { background: #23263a; color: #e6e9ff; border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 0 0 .7em; white-space: pre; }
.md pre code { background: none; padding: 0; color: inherit; font-size: 12px; }
.md a { color: var(--blue); word-break: break-all; }
.md hr { border: none; border-top: 1px dashed var(--border); margin: .8em 0; }
.md strong { font-weight: 800; }
.log-msg.md p { margin-bottom: .3em; }

/* ---------- Complexity chip / legend / warehouse day list ---------- */
.cx-chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px 1px 6px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap;
  background: color-mix(in srgb, var(--cx) 22%, transparent); box-shadow: inset 0 0 0 1.5px var(--cx); color: inherit; vertical-align: middle; }
.cx-chip i { font-style: normal; color: var(--cx); letter-spacing: -1px; text-shadow: 0 0 1px rgba(0,0,0,.35); }
.cx-chip.est { box-shadow: inset 0 0 0 1.5px var(--cx); border: 1px dashed transparent; }
.cx-legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 6px 0 12px; font-size: 12px; }
.cx-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cx-legend b { width: 18px; height: 11px; border-radius: 3px; background: var(--cx); }
.wh-day { margin-bottom: 14px; padding: 8px 10px; border-radius: 10px; }
.wh-day.hit { background: rgba(255,200,61,.14); box-shadow: inset 0 0 0 2px rgba(255,200,61,.5); }
.wh-day h4 { margin: 0 0 6px; }
.wh-rows li { border-left: 4px solid var(--cx); padding-left: 8px; margin: 3px 0; }
.wh-rows { padding-left: 0; list-style: none; max-height: none; overflow: visible; }
.cx-row { display: flex; align-items: center; gap: 8px; margin: -6px 0 12px; flex-wrap: wrap; }
.cx-row select { width: auto; margin: 0; padding: 2px 6px; font-size: 12px; }
.wh-head { position: sticky; top: -20px; z-index: 1; margin: -20px -24px 0; padding: 20px 24px 4px; background: var(--paper); }
