/* App shell. Shared tokens, reset, scrollbars and the .key/.tag
   components live in base.css; these aliases keep the older names. */
:root {
  --bg: var(--ink); --bg-2: var(--ink-2); --card: var(--panel); --input: #10132B;
  --border: var(--line); --border-soft: var(--line-soft); --border-strong: #3A4080;
  --purple: var(--lav); --purple-4: var(--lav); --purple-soft: var(--lav-soft);
  --cyan: var(--lav); --green: var(--ok); --red: var(--bad); --yellow: var(--warn);
}
html, body { height: 100%; }
body { font-size: 15px; line-height: 1.55; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--text); font-weight: 500; text-decoration: none; cursor: pointer; transition: border-color .15s, background .15s; white-space: nowrap; }
.btn:hover { border-color: var(--border-strong); background: rgba(255,255,255,.03); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { border: 0; border-bottom: 3px solid var(--amber-deep); background: var(--amber); color: #1B1405; font-weight: 600; padding-bottom: 1px; }
.btn-primary:hover { filter: brightness(1.06); background: var(--amber); }
.btn-primary:active { transform: translateY(1px); border-bottom-width: 2px; }
.btn-ghost { background: transparent; }
.btn-sm { height: 32px; padding: 0 12px; font-size: .84rem; }
.btn-lg { height: 48px; padding: 0 24px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: rgba(255,138,138,.45); background: rgba(255,138,138,.07); }

/* ---------- app shell ---------- */
body.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.top { flex: 0 0 64px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--border-soft); background: var(--bg-2); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 600; min-width: 0; }
.brand-logo { height: 28px; width: auto; display: block; }
.brand-dev { font: 600 1.2rem/1 var(--display); color: var(--text); }
.beta { font: 500 .72rem/1 var(--sans); font-style: normal; color: var(--lav); background: var(--lav-soft); border-radius: 5px; padding: 4px 7px; }
.top-right { display: flex; align-items: center; gap: 8px; }
.top-right form { margin: 0; }
.me { color: var(--muted); font-size: .86rem; margin-right: 4px; }

.shell { flex: 1; display: grid; grid-template-columns: 250px 1fr; min-height: 0; }
.side { border-right: 1px solid var(--border-soft); padding: 14px; overflow-y: auto; background: var(--bg-2); display: flex; flex-direction: column; }
.side-search { margin-top: 10px; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--input); outline: 0; font-size: .86rem; }
.side-search:focus { border-color: var(--purple); }
.meter { margin-top: auto; padding: 12px 4px 2px; border-top: 1px solid var(--border-soft); font-size: .78rem; color: var(--muted); }
.meter-row { display: flex; justify-content: space-between; gap: 8px; margin: 4px 0; }
.meter-row b { color: var(--text-2); font-weight: 600; }
.meter-bar { height: 6px; border-radius: 999px; background: var(--border-soft); overflow: hidden; margin: 6px 0 8px; }
.meter-bar i { display: block; height: 100%; background: var(--lav); border-radius: inherit; transition: width .3s; }
.meter.warn .meter-bar i { background: var(--amber); }
.meter.full .meter-bar i { background: var(--red); }
.meter-note { margin: 8px 0 0; color: var(--dim); font-size: .72rem; line-height: 1.4; }
.side-label { margin: 20px 4px 8px; font: 600 .8rem/1.3 var(--sans); color: var(--muted); }
.new-key { width: 100%; justify-content: space-between; }
.side-empty { padding: 8px 4px; color: var(--muted); font-size: .86rem; }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.plist a { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--text-2); text-decoration: none; border-left: 2px solid transparent; }
.plist a:hover { background: rgba(255,255,255,.03); color: var(--text); }
.plist a.is-active { background: var(--panel); color: var(--text); border-left-color: var(--amber); border-radius: 2px 8px 8px 2px; }
.plist .tag { grid-row: span 2; }
.plist .pl-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.plist small { color: var(--dim); font-size: .74rem; }
.plist .run-dot { display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--amber); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.work { min-width: 0; min-height: 0; display: flex; }
/* Welcome: pick a project type from a list grouped by family. */
.welcome { width: 100%; max-width: 980px; margin: 0 auto; padding: 44px 32px 56px; overflow-y: auto; max-height: 100%; }
.welcome h2 { margin: 0 0 8px; font: 600 clamp(1.5rem, 2.4vw, 2rem)/1.15 var(--display); letter-spacing: -.01em; }
.welcome > p { margin: 0 0 32px; color: var(--muted); max-width: 46em; }
.starter { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 40px; }
.starter-group:first-child { grid-row: span 2; }
.starter-group .side-label { margin: 0 0 4px; }
.starter-grid { display: flex; flex-direction: column; }
.starter-card { display: grid; grid-template-columns: 52px 1fr; column-gap: 12px; align-items: start; padding: 13px 10px; text-align: left; border: 0; border-bottom: 1px solid var(--line-soft); background: transparent; border-radius: 0; cursor: pointer; }
.starter-card .tag { grid-row: span 2; margin-top: 2px; }
.starter-card b { font-weight: 600; }
.starter-card span { color: var(--muted); font-size: .88rem; }
.starter-card:hover { background: rgba(255,255,255,.025); }
.starter-card:hover b { color: var(--amber); }

.project { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.phead { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border-soft); }
.pname { flex: 1; min-width: 0; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 6px 8px; font-size: 1.05rem; font-weight: 700; }
.pname:hover, .pname:focus { border-color: var(--border); outline: 0; background: var(--input); }
.ptype { white-space: nowrap; }
.pactions { display: flex; gap: 6px; }
.pkeep { color: var(--dim); font-size: .74rem; white-space: nowrap; }
.banner { padding: 9px 16px; background: rgba(248,113,113,.1); border-bottom: 1px solid rgba(248,113,113,.3); color: #fecaca; font-size: .86rem; }

.split { flex: 1; display: grid; grid-template-columns: minmax(340px, 38%) 1fr; min-height: 0; }
.chat { position: relative; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border-soft); }
.drop { position: absolute; inset: 8px; z-index: 5; display: grid; place-items: center; border: 2px dashed var(--purple); border-radius: 14px; background: rgba(10,10,20,.85); color: var(--purple-4); font-weight: 600; pointer-events: none; }
.msg.auto { align-self: center; padding: 3px 12px; border-radius: 999px; background: rgba(251,191,36,.1); color: var(--yellow); font-size: .78rem; }
.compile { margin-top: 10px; padding: 8px 10px; border-radius: 8px; font-size: .84rem; white-space: normal; }
.compile.ok { background: rgba(52,211,153,.08); border: 1px solid rgba(52,211,153,.3); color: #a7f3d0; }
.compile.bad { background: rgba(248,113,113,.08); border: 1px solid rgba(248,113,113,.35); color: #fecaca; }
.compile details { margin-top: 6px; }
.compile summary { cursor: pointer; color: var(--muted); font-size: .76rem; }
.compile pre { margin: 6px 0 0; max-height: 220px; overflow: auto; font: .74rem/1.5 var(--mono); white-space: pre-wrap; color: var(--text-2); }
.msg code { font: .84em var(--mono); padding: 1px 5px; border-radius: 5px; background: rgba(255,255,255,.07); }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; }
.attach-list:not(:empty) { margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 9px; border-radius: 999px; background: var(--purple-soft); color: var(--purple-4); font: .74rem var(--mono); }
.chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: .95rem; line-height: 1; padding: 0 4px; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 100%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; font-size: .93rem; }
.msg.user { align-self: flex-end; max-width: 88%; background: var(--lav-soft); border: 1px solid rgba(190,197,249,.22); }
.msg.assistant { background: var(--card); border: 1px solid var(--border-soft); }
.msg.error { border-color: rgba(248,113,113,.4); color: #fca5a5; }
.msg .meta { display: block; margin-top: 6px; color: var(--dim); font: .7rem var(--mono); white-space: normal; }
.tools { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tool { font: .7rem var(--mono); padding: 2px 7px; border-radius: 6px; background: rgba(255,255,255,.05); color: var(--muted); }
.tool.w { color: #6ee7b7; background: rgba(52,211,153,.1); }
.working { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .86rem; }
.working::before { content: ''; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--purple-4); border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-chat { margin: auto; max-width: 340px; text-align: center; color: var(--muted); font-size: .9rem; }
.empty-chat b { display: block; color: var(--text); font-size: 1rem; margin-bottom: 6px; }
.examples { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.examples button { text-align: left; padding: 8px 10px; border: 1px solid var(--border-soft); border-radius: 8px; background: rgba(255,255,255,.02); color: var(--text-2); font-size: .84rem; cursor: pointer; }
.examples button:hover { border-color: var(--purple); color: var(--text); }

.composer { flex: 0 0 auto; border-top: 1px solid var(--border-soft); padding: 10px 12px 12px; }
.composer textarea { width: 100%; resize: vertical; min-height: 64px; max-height: 260px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--input); outline: 0; }
.composer textarea:focus { border-color: var(--purple); }
.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.composer-bar .icon-btn { font-size: 1.15rem; }
.composer textarea:disabled { opacity: .6; }
.hint { flex: 1; color: var(--dim); font-size: .78rem; }

.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { flex: 0 0 auto; display: flex; align-items: center; gap: 2px; padding: 6px 8px; border-bottom: 1px solid var(--border-soft); }
.tab { padding: 6px 12px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 600; font-size: .86rem; cursor: pointer; }
.tab.is-active { background: var(--purple-soft); color: var(--purple-4); }
.tabs-end { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.mini-select { height: 30px; max-width: 160px; padding: 0 8px; border: 1px solid var(--border-soft); border-radius: 7px; background: var(--input); font-size: .8rem; }
.seg { display: inline-flex; border: 1px solid var(--border-soft); border-radius: 7px; overflow: hidden; }
.seg button { width: 30px; height: 28px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.seg button.is-active { background: var(--purple-soft); color: var(--purple-4); }
.icon-btn { display: inline-grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--border-soft); border-radius: 7px; background: transparent; color: var(--muted); text-decoration: none; cursor: pointer; }
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.pane { flex: 1; min-height: 0; position: relative; }
.pane iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.stage { height: 100%; display: flex; justify-content: center; background: #1a1a2e; overflow: auto; }
.stage iframe { flex: 0 0 auto; max-width: 100%; transition: width .2s; }
.pane-note { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); background: var(--bg); }
.pane-note > div, .pane-note > p { max-width: 440px; }
.files { display: grid; grid-template-columns: 250px 1fr; }
.ftree-wrap { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border-soft); padding: 8px; gap: 6px; }
.ftree { list-style: none; margin: 0; padding: 0; overflow-y: auto; font: .8rem var(--mono); }
.ftree li { display: flex; justify-content: space-between; gap: 6px; padding: 5px 8px; border-radius: 6px; cursor: pointer; color: var(--text-2); white-space: nowrap; }
.ftree li span { overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left; }
.ftree li.muted { cursor: default; color: var(--muted); }
.ftree li:hover { background: rgba(255,255,255,.04); }
.ftree li.is-active { background: var(--purple-soft); color: var(--purple-4); }
.ftree li small { color: var(--dim); flex: 0 0 auto; }
.editor { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.editor-bar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--border-soft); }
.editor-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: .8rem var(--mono); color: var(--text-2); }
.code { flex: 1; margin: 0; padding: 14px 16px; overflow: auto; font: .8rem/1.6 var(--mono); color: var(--text-2); white-space: pre; tab-size: 4; border: 0; outline: 0; resize: none; background: transparent; }
.editor-media { flex: 1; display: grid; place-items: center; padding: 16px; overflow: auto; background: repeating-conic-gradient(#171a38 0 25%, #11142c 0 50%) 0 0 / 20px 20px; }
.editor-media img { max-width: 100%; max-height: 100%; }
.editor-empty { flex: 1; display: grid; place-items: center; padding: 24px; color: var(--muted); font-size: .9rem; text-align: center; }
.history { overflow-y: auto; padding: 14px 16px; }
.history-note { margin: 0 0 12px; color: var(--muted); font-size: .84rem; }
.vlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.vlist li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--border-soft); border-radius: var(--r); background: rgba(255,255,255,.02); }
.vlist li > div { min-width: 0; }
.vlist b { display: block; font-weight: 600; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vlist small { color: var(--dim); font: .72rem var(--mono); }
.plus { color: var(--green); } .minus { color: var(--red); }
.badge { font: 500 .74rem/1 var(--sans); padding: 5px 8px; border-radius: 5px; background: rgba(123,224,167,.12); color: var(--ok); }

dialog { width: min(560px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
dialog h3 { margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .86rem; color: var(--muted); }
.field input { height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--input); color: var(--text); outline: 0; }
.field input:focus { border-color: var(--purple); }
.types { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 50vh; overflow-y: auto; padding-right: 2px; }
.types label { display: flex; align-items: flex-start; gap: 8px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-size: .88rem; }
.types label span { display: flex; flex-direction: column; min-width: 0; }
.types label small { color: var(--muted); font-size: .74rem; line-height: 1.35; }
.types input { margin-top: 4px; }
.types label:has(input:checked) { border-color: var(--purple); background: var(--purple-soft); }
.types input { accent-color: var(--purple); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
dialog.wide { width: min(980px, calc(100vw - 32px)); }
.dlg-body { padding: 20px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 10px; }
.stats div { padding: 12px 14px; border: 1px solid var(--border-soft); border-radius: var(--r); background: rgba(255,255,255,.02); }
.stats small { display: block; color: var(--muted); font-size: .76rem; }
.stats b { font-size: 1.1rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border-soft); border-radius: var(--r); }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
td small { display: block; color: var(--dim); font-size: .74rem; }
tbody tr:last-child td { border-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

.toast { position: fixed; right: 16px; bottom: 16px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); padding: 10px 14px; border-radius: 10px; background: var(--card); border: 1px solid var(--border-strong); box-shadow: 0 12px 30px -12px rgba(0,0,0,.7); font-size: .88rem; animation: toastIn .18s ease-out; }
.toast.bad { border-color: rgba(248,113,113,.5); color: #fecaca; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 1000px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { max-height: 150px; border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .side-label { margin-top: 10px; }
  .split { grid-template-columns: 1fr; grid-template-rows: 1fr 45vh; }
  .chat { border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .starter { grid-template-columns: 1fr; }
  .me, .pkeep { display: none; }
  .files { grid-template-columns: 1fr; grid-template-rows: 150px 1fr; }
  .ftree-wrap { border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .types { grid-template-columns: 1fr; }
  .phead { flex-wrap: wrap; }
}
/* Phones: the page scrolls as a whole instead of squeezing fixed panes. */
@media (max-width: 700px) {
  body.app { height: auto; min-height: 100vh; overflow: visible; }
  .top { position: sticky; top: 0; z-index: 10; }
  .shell { display: block; }
  .side { max-height: none; }
  .plist { max-height: 180px; overflow-y: auto; }
  .meter { margin-top: 10px; }
  .work, .project { display: block; }
  .phead { position: sticky; top: 64px; z-index: 9; background: var(--bg); flex-wrap: wrap; }
  .pactions { width: 100%; overflow-x: auto; }
  .split { display: block; }
  .chat { height: 78vh; border-bottom: 1px solid var(--border-soft); }
  .viewer { height: 85vh; }
  .welcome { max-height: none; }
}
@media (max-width: 560px) {
  .top { padding: 0 10px; gap: 6px; }
  .brand { gap: 5px; }
  .brand-logo { height: 15px; }
  .brand-dev { font-size: .95rem; }
  .beta, #billingLink, #adminBtn { display: none; }
  .pactions .btn { padding: 0 8px; }
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
