:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #141414; --ink-2: #5d5b57; --line: #e6e3dd;
  --accent: #ff5a1f; --accent-ink: #fff; --ok: #1a8d5f; --warn: #b7791f; --bad: #c53030;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overscroll-behavior: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
a { color: inherit; }
img, video { max-width: 100%; display: block; }

.logo { display: flex; align-items: center; gap: 8px; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.logo .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(255,90,31,.18); }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 14px; font-weight: 550; transition: transform .05s, background .15s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.big { padding: 14px 18px; font-size: 16px; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px; font-size: 18px; display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: rgba(0,0,0,.05); }
.icon-btn.light { color: #fff; }
.pill { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; white-space: nowrap; }

/* ---------- auth ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 18px calc(24px + var(--safe-b)); background:
  radial-gradient(1200px 500px at 80% -10%, rgba(255,90,31,.14), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; }
.auth h1 { font-size: clamp(32px, 8vw, 44px); line-height: 1.05; letter-spacing: -.03em; margin: 28px 0 10px; }
.auth h1 em { font-style: normal; color: var(--accent); }
.auth .sub { color: var(--ink-2); line-height: 1.5; margin: 0 0 24px; }
.tabs { display: flex; gap: 4px; background: #ebe8e2; padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.tab { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--ink-2); }
.tab.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
form label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }
form input { display: block; width: 100%; margin-top: 6px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 16px; }
form input:focus, textarea:focus { outline: 2px solid rgba(255,90,31,.35); border-color: var(--accent); }
.error { color: var(--bad); font-size: 14px; margin: 4px 0 12px; }
.auth.login .only-signup { display: none; }

/* ---------- app shell ---------- */
.app { height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 14px 10px; border-bottom: 1px solid var(--line); background: rgba(246,245,242,.92); backdrop-filter: blur(10px); position: relative; z-index: 5; }
.spacer { flex: 1; }
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 280px minmax(0, 1fr) minmax(0, 460px); }
.layout:not(.has-detail) { grid-template-columns: 280px minmax(0, 1fr); }
.layout:not(.has-detail) .detail-pane { display: none; }
.projects-pane { border-right: 1px solid var(--line); overflow-y: auto; padding: 14px; }
.pane-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.pane-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); margin: 0; }
.project-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.project-list li button { width: 100%; text-align: left; border: 1px solid transparent; background: transparent; padding: 10px 12px; border-radius: 12px; display: grid; gap: 4px; }
.project-list li button:hover { background: rgba(0,0,0,.035); }
.project-list li button.active { background: var(--panel); border-color: var(--line); box-shadow: var(--shadow); }
.project-list .t { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-list .m { font-size: 12px; color: var(--ink-2); display: flex; gap: 6px; align-items: center; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: #eeebe5; color: var(--ink-2); text-transform: capitalize; }
.badge.working { background: #fff1e9; color: #c2410c; }
.badge.working::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1s infinite alternate; }
.badge.awaiting_client { background: #e9f6ef; color: var(--ok); }
.badge.failed { background: #fdecec; color: var(--bad); }
@keyframes pulse { from { opacity: .3 } to { opacity: 1 } }
.empty { color: var(--ink-2); font-size: 14px; line-height: 1.5; }

/* ---------- chat ---------- */
.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.messages { flex: 1; overflow-y: auto; padding: 20px max(16px, calc((100% - 760px) / 2)); display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 88%; line-height: 1.5; font-size: 15px; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; }
.msg.assistant p { margin: 0 0 8px; } .msg.assistant p:last-child { margin: 0; }
.msg.assistant ul { margin: 4px 0 8px; padding-left: 20px; }
.msg .via { font-size: 11px; color: var(--ink-2); margin-top: 4px; }
.msg.user .via { color: rgba(255,255,255,.6); }
.msg .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg .chip { font-size: 12px; background: #eeebe5; padding: 3px 9px; border-radius: 999px; border: 0; }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #b9b5ad; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s } .typing i:nth-child(3) { animation-delay: .4s }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }
.welcome { margin: auto 0; padding: 20px 0; }
.welcome h2 { font-size: clamp(26px, 5vw, 34px); letter-spacing: -.025em; margin: 0 0 8px; line-height: 1.1; }
.welcome p { color: var(--ink-2); margin: 0; line-height: 1.5; }
.suggestions { display: flex; gap: 8px; overflow-x: auto; padding: 0 max(16px, calc((100% - 760px) / 2)) 10px; scrollbar-width: none; }
.suggestions button { flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 8px 13px; font-size: 13px; white-space: nowrap; }
.composer { display: flex; align-items: flex-end; gap: 6px; margin: 0 max(12px, calc((100% - 776px) / 2)) calc(12px + var(--safe-b)); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 6px 6px 6px 14px; box-shadow: var(--shadow); }
.composer textarea { flex: 1; border: 0; resize: none; background: transparent; padding: 9px 0; font-size: 16px; line-height: 1.4; min-height: 40px; height: 40px; max-height: 160px; outline: none; overflow-y: hidden; }
.composer .send { background: var(--ink); color: #fff; border-radius: 12px; }
.composer .send:disabled { opacity: .35; }
.composer .mic { border-radius: 12px; }

/* ---------- detail ---------- */
.detail-pane { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; min-width: 0; }
.detail { padding: 18px 18px calc(28px + var(--safe-b)); }
.detail-head { display: flex; align-items: flex-start; gap: 10px; }
.detail-head h2 { font-size: 21px; letter-spacing: -.02em; margin: 0 0 6px; line-height: 1.2; }
.detail-head .close { margin-left: auto; }
.steps { display: flex; gap: 4px; margin: 14px 0 16px; }
.steps div { flex: 1; text-align: center; font-size: 11px; font-weight: 650; color: #a8a49c; }
.steps div::before { content: ""; display: block; height: 4px; border-radius: 2px; background: #ebe8e2; margin-bottom: 6px; }
.steps div.done { color: var(--ink-2); } .steps div.done::before { background: var(--ink); }
.steps div.now { color: var(--accent); } .steps div.now::before { background: var(--accent); }
.banner { border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.45; margin-bottom: 14px; background: #f4f2ee; }
.banner.working { background: #fff4ed; }
.banner.failed { background: #fdecec; color: var(--bad); }
.banner b { display: block; margin-bottom: 2px; }
.section { margin: 18px 0; }
.section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); margin: 0 0 10px; }
dl.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--ink-2); } dl.kv dd { margin: 0; }
.quote { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.quote .row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 14px; font-size: 14px; border-bottom: 1px solid var(--line); }
.quote .row.total { font-weight: 700; background: #faf9f6; border: 0; }
.notes { font-size: 13px; color: var(--ink-2); line-height: 1.45; padding-left: 18px; }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions-row .btn { flex: 1 1 auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr)); gap: 12px; align-items: start; }
.card { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--panel); display: flex; flex-direction: column; }
.card .media { background: #efede8; display: grid; place-items: center; }
.card .media img, .card .media video { width: 100%; height: auto; cursor: zoom-in; }
.card .body { padding: 10px 12px 12px; display: grid; gap: 6px; font-size: 13px; line-height: 1.45; flex: 1; }
.card .body b { font-size: 14px; }
.card .body .muted { color: var(--ink-2); }
.card .body .btn { margin-top: auto; }
.card .foot { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 13px; }
.skeleton { aspect-ratio: 1; border-radius: 14px; background: linear-gradient(90deg, #eeebe5 0%, #f7f5f1 50%, #eeebe5 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { from { background-position: 200% 0 } to { background-position: -200% 0 } }
.script { white-space: pre-wrap; background: #faf9f6; border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.5; }
details.versions summary { cursor: pointer; font-size: 13px; color: var(--ink-2); }
.timeline { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; color: var(--ink-2); display: grid; gap: 4px; }
textarea.fb { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 15px; resize: vertical; min-height: 70px; }

/* ---------- modal / toast / lightbox ---------- */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,20,20,.45); }
.modal-body { padding: 20px; display: grid; gap: 12px; }
.modal-body h3 { margin: 0; font-size: 18px; }
.modal-body p { margin: 0; color: var(--ink-2); font-size: 14px; line-height: 1.5; }
.modal-body code, .modal-body pre { font-size: 12px; background: #f4f2ee; border-radius: 8px; padding: 2px 6px; word-break: break-all; }
.modal-body pre { padding: 10px; white-space: pre-wrap; margin: 0; }
.keys { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 14px; }
.keys li { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
.lightbox { position: fixed; inset: 0; background: rgba(10,10,10,.92); z-index: 60; display: grid; place-items: center; padding: 16px; }
.lightbox img, .lightbox video { max-height: 100%; max-width: 100%; border-radius: 8px; }

/* ---------- voice ---------- */
.voice { position: fixed; inset: 0; z-index: 40; background: radial-gradient(900px 600px at 50% 30%, #2a1a12, #0d0d0d 70%); color: #fff; display: flex; flex-direction: column; padding: calc(14px + var(--safe-t)) 18px calc(22px + var(--safe-b)); }
.voice-top { display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: rgba(255,255,255,.75); }
.orb-wrap { flex: 1; display: grid; place-items: center; min-height: 180px; }
.orb { width: min(46vw, 220px); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffb38f, var(--accent) 45%, #7a1f00 100%); box-shadow: 0 0 80px rgba(255,90,31,.45); transition: transform .12s; }
.orb.thinking { animation: breathe 1.4s infinite ease-in-out; }
@keyframes breathe { 50% { transform: scale(.92); filter: brightness(.85); } }
.captions { max-height: 34vh; overflow-y: auto; display: grid; gap: 8px; margin: 0 auto 18px; width: 100%; max-width: 640px; font-size: 16px; line-height: 1.45; }
.captions .u { color: rgba(255,255,255,.6); text-align: right; }
.captions .a { color: #fff; }
.voice-controls { display: flex; gap: 14px; justify-content: center; }
.round { border: 0; border-radius: 999px; padding: 14px 26px; font-weight: 650; background: rgba(255,255,255,.12); color: #fff; min-width: 110px; }
.round.on { background: #fff; color: #111; }
.round.end { background: #e5484d; }

/* ---------- responsive ---------- */
.mobile-only { display: none !important; }
@media (max-width: 899px) {
  .mobile-only { display: flex !important; }
  .layout, .layout:not(.has-detail) { display: block; position: relative; }
  .projects-pane, .chat-pane, .detail-pane { position: absolute; inset: 0; border: 0; display: none; }
  .layout[data-view="chat"] .chat-pane { display: flex; }
  .layout[data-view="projects"] .projects-pane { display: block; }
  .layout[data-view="detail"] .detail-pane { display: block !important; }
  .detail-head .close { display: none; }
  .tabbar { border-top: 1px solid var(--line); background: rgba(246,245,242,.96); backdrop-filter: blur(10px); padding: 6px 8px calc(6px + var(--safe-b)); justify-content: space-around; }
  .tabbar button { border: 0; background: transparent; display: grid; justify-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--ink-2); padding: 4px 18px; border-radius: 10px; }
  .tabbar button span { font-size: 19px; }
  .tabbar button.active { color: var(--ink); }
  .composer { margin-bottom: 10px; }
  .msg { max-width: 92%; }
  .topbar .logo { font-size: 14px; }
  .toast { bottom: calc(90px + var(--safe-b)); }
}
@media (min-width: 900px) and (max-width: 1180px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr) minmax(0, 400px); }
  .layout:not(.has-detail) { grid-template-columns: 240px minmax(0, 1fr); }
}

.mobile-only[hidden], [hidden] { display: none !important; }
