/* The Workbench — light bg #F3F5F7, ink #16202A, teal accent, amber for you.
   Sora (headings) + IBM Plex Sans (body) + IBM Plex Mono (code). */

:root {
  color-scheme: light;
  --bg:         #F3F5F7;
  --surface:    #FFFFFF;
  --surface-2:  #EAEFF2;
  --ink:        #16202A;
  --ink-soft:   #55606B;
  --ink-faint:  #8A96A2;
  --line:       #DDE3E8;
  --line-soft:  #E9EDF1;
  --accent:     #0F7C86;
  --accent-dk:  #0B5D65;
  --accent-wash:#E3F1F2;
  --amber:      #B36B00;
  --amber-wash: #FBF0DE;
  --danger:     #A32C24;
  --good:       #1F7A45;
  --radius:     12px;
  --radius-lg:  16px;
  --shadow:     0 1px 2px rgb(22 32 42 / 6%), 0 8px 24px rgb(22 32 42 / 6%);
  --font-head:  'Sora', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body:  'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:  'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --nav-w:      224px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg:         #0F151B;
    --surface:    #18212A;
    --surface-2:  #131B22;
    --ink:        #E8EDF2;
    --ink-soft:   #9AA7B4;
    --ink-faint:  #6C7A88;
    --line:       #2A3641;
    --line-soft:  #222C36;
    --accent:     #4FBFC9;
    --accent-dk:  #7FD6DE;
    --accent-wash:#132C30;
    --amber:      #E0A44A;
    --amber-wash: #2C2216;
    --danger:     #E4796F;
    --good:       #6FD39B;
    --shadow:     0 1px 2px rgb(0 0 0 / 30%), 0 10px 30px rgb(0 0 0 / 28%);
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-head); line-height: 1.2; margin: 0 0 .5em; letter-spacing: -0.015em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .9em; }
a  { color: var(--accent-dk); }
code, pre, .mono { font-family: var(--font-mono); }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.small { font-size: .86rem; }
.hidden, [hidden] { display: none !important; }

button { font-family: var(--font-body); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; justify-content: center;
  padding: .55rem 1rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: .9rem; text-decoration: none;
  transition: background .12s ease, border-color .12s ease, transform .12s ease;
}
.btn:hover:not(:disabled) { border-color: var(--ink-faint); transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-dk); border-color: var(--accent-dk); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #08171A; } }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); border-color: transparent; }
.btn.danger { color: var(--danger); border-color: var(--line); }
.btn.small { padding: .35rem .75rem; font-size: .82rem; }
.btn.big { padding: .75rem 1.4rem; font-size: 1rem; }
.btn.block { width: 100%; }

/* ── Centred card pages (join / locked out) ─────────────────────────────── */
body.centred { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 2.5rem; max-width: 30rem; text-align: center; box-shadow: var(--shadow);
}
.card .mark { font-size: 2rem; color: var(--accent); margin-bottom: .6rem; }
.card p { color: var(--ink-soft); }

/* ── App shell ──────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }

.sidebar {
  border-right: 1px solid var(--line); background: var(--surface-2);
  display: flex; flex-direction: column; gap: .25rem;
  padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: .5rem; padding: .3rem .5rem 1rem;
  font-family: var(--font-head); font-weight: 700; letter-spacing: -0.02em;
}
.brand .mark { color: var(--accent); font-size: 1.15rem; }

.project-switch { position: relative; margin-bottom: 1rem; }
.project-switch select {
  width: 100%; appearance: none; font: inherit; font-weight: 600;
  padding: .6rem 2rem .6rem .75rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer;
}
.project-switch::after {
  content: '⌄'; position: absolute; right: .85rem; top: .35rem;
  color: var(--ink-faint); pointer-events: none; font-size: 1rem;
}

.nav-item {
  display: flex; align-items: center; gap: .65rem; width: 100%;
  padding: .55rem .75rem; border-radius: var(--radius); border: none;
  background: transparent; color: var(--ink-soft); cursor: pointer;
  font-size: .93rem; font-weight: 500; text-align: left;
}
.nav-item .ic { width: 1.1rem; text-align: center; color: var(--ink-faint); }
.nav-item:hover { background: var(--surface); color: var(--ink); }
.nav-item.active { background: var(--accent-wash); color: var(--accent-dk); font-weight: 600; }
.nav-item.active .ic { color: var(--accent-dk); }
.nav-spacer { flex: 1; }

.usage-chip {
  margin-top: .75rem; padding: .6rem .7rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); font-size: .8rem; color: var(--ink-soft);
}
.usage-chip .meter { height: 4px; border-radius: 2px; background: var(--line); margin-top: .45rem; overflow: hidden; }
.usage-chip .meter i { display: block; height: 100%; background: var(--accent); }
.usage-chip.warn .meter i { background: var(--amber); }
.usage-chip.over .meter i, .usage-chip.off .meter i { background: var(--danger); }

/* ── Main pane ──────────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: 1rem clamp(1rem, 3vw, 2rem) .85rem;
  border-bottom: 1px solid var(--line); background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 1.15rem; }
.topbar .grow { flex: 1; }
.pane { padding: clamp(1rem, 3vw, 2rem); flex: 1; min-height: 0; }
.pane.flush { padding: 0; display: flex; flex-direction: column; }

.notice {
  display: flex; gap: .7rem; align-items: flex-start;
  padding: .8rem 1rem; border-radius: var(--radius); font-size: .9rem;
  background: var(--amber-wash); border: 1px solid color-mix(in srgb, var(--amber) 35%, transparent);
  color: var(--ink); margin-bottom: 1rem;
}
.notice.good { background: var(--accent-wash); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.notice.bad  { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.notice .ic { font-size: 1.05rem; line-height: 1.4; }
.notice p:last-child { margin-bottom: 0; }

/* ── Build (chat) ───────────────────────────────────────────────────────── */
.chat { flex: 1; overflow-y: auto; padding: clamp(1rem, 3vw, 2rem); display: flex; flex-direction: column; gap: .9rem; }
.chat-inner { max-width: 46rem; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: .9rem; }

.bubble {
  padding: .8rem 1rem; border-radius: var(--radius-lg); max-width: 46rem;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble.you {
  align-self: flex-end; background: var(--amber-wash);
  border-color: color-mix(in srgb, var(--amber) 30%, transparent);
}
.bubble.you .who { color: var(--amber); }
.bubble .who {
  display: block; font-family: var(--font-head); font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .09em; color: var(--accent-dk); margin-bottom: .35rem;
}
.bubble.system { background: var(--surface-2); box-shadow: none; }
.bubble.system .who { color: var(--danger); }

.activity {
  align-self: flex-start; display: flex; align-items: center; gap: .55rem;
  color: var(--ink-soft); font-size: .89rem; padding: .1rem .3rem;
}
.activity .spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .activity .spinner { animation-duration: 2.5s; } }
.activity-log { display: flex; flex-direction: column; gap: .1rem; }
.activity-log .past { color: var(--ink-faint); font-size: .84rem; }

.composer {
  border-top: 1px solid var(--line); background: var(--bg);
  padding: .85rem clamp(1rem, 3vw, 2rem) 1.1rem;
}
.composer-inner { max-width: 46rem; margin: 0 auto; display: flex; gap: .6rem; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; font: inherit; color: var(--ink);
  padding: .7rem .9rem; border-radius: var(--radius); min-height: 2.75rem; max-height: 12rem;
  border: 1px solid var(--line); background: var(--surface);
}
.composer .hint { max-width: 46rem; margin: .5rem auto 0; font-size: .8rem; color: var(--ink-faint); }

.prompt-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .9rem; }
.chip {
  padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-soft); font-size: .83rem; cursor: pointer;
}
.chip:hover { color: var(--ink); border-color: var(--ink-faint); }

/* ── Preview ────────────────────────────────────────────────────────────── */
.preview-frame {
  flex: 1; width: 100%; border: 0; background: var(--surface);
  border-top: 1px solid var(--line); min-height: 60vh;
}
.log {
  font-family: var(--font-mono); font-size: .78rem; color: var(--ink-soft);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; max-height: 16rem; overflow: auto; white-space: pre-wrap;
}

/* ── Lists / rows ───────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: .5rem; max-width: 46rem; }
.row {
  display: flex; align-items: center; gap: .9rem; padding: .85rem 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { font-size: .82rem; color: var(--ink-faint); }
.row.current { border-color: var(--accent); background: var(--accent-wash); }
.badge {
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  padding: .18rem .5rem; border-radius: 999px; background: var(--accent); color: #fff;
}
@media (prefers-color-scheme: dark) { .badge { color: #08171A; } }

/* ── Files ──────────────────────────────────────────────────────────────── */
.files-layout { display: grid; grid-template-columns: minmax(180px, 260px) 1fr; gap: 1rem; align-items: start; }
@media (max-width: 780px) { .files-layout { grid-template-columns: 1fr; } }
.tree { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem; max-height: 70vh; overflow: auto; }
.tree ul { list-style: none; margin: 0; padding-left: .85rem; }
.tree > ul { padding-left: 0; }
.tree button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--ink-soft); cursor: pointer; padding: .22rem .4rem; border-radius: 6px;
  font-size: .87rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree button:hover { background: var(--surface-2); color: var(--ink); }
.tree button.active { background: var(--accent-wash); color: var(--accent-dk); font-weight: 600; }
.tree .dirname { font-weight: 600; color: var(--ink); }
.viewer { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.viewer header { padding: .6rem .9rem; border-bottom: 1px solid var(--line); font-weight: 600; font-size: .9rem; display: flex; gap: .6rem; align-items: center; }
.viewer pre { margin: 0; max-height: 66vh; overflow: auto; font-size: .82rem; line-height: 1.6; }
.viewer pre code { padding: .9rem !important; display: block; }

/* ── Forms / dialogs ────────────────────────────────────────────────────── */
.form-grid { display: flex; flex-direction: column; gap: 1rem; max-width: 34rem; }
label.field { display: block; }
label.field > span { display: block; font-weight: 600; font-size: .87rem; margin-bottom: .35rem; }
input[type=text], input[type=email], textarea, select {
  width: 100%; font: inherit; color: var(--ink); padding: .65rem .8rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
textarea { resize: vertical; }

.starter-grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.starter {
  text-align: left; padding: 1rem; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.starter.selected { border-color: var(--accent); background: var(--accent-wash); }
.starter strong { display: block; font-family: var(--font-head); margin-bottom: .25rem; }
.starter span { font-size: .84rem; color: var(--ink-soft); }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.5rem;
  background: var(--surface); color: var(--ink); max-width: 34rem; width: calc(100% - 2rem);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(22 32 42 / 45%); backdrop-filter: blur(2px); }

/* ── Help ───────────────────────────────────────────────────────────────── */
.help-grid { display: grid; gap: 1.2rem; max-width: 52rem; }
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 1.3rem;
}
.status-line { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; }
.tick { width: 1.15rem; height: 1.15rem; border-radius: 50%; display: grid; place-items: center; font-size: .7rem; color: #fff; flex: none; }
.tick.on  { background: var(--good); }
.tick.off { background: var(--ink-faint); }
@media (prefers-color-scheme: dark) { .tick { color: #08171A; } }
.glossary dt { font-weight: 600; margin-top: .7rem; }
.glossary dd { margin: 0; color: var(--ink-soft); font-size: .9rem; }
.connect-out {
  font-family: var(--font-mono); font-size: .78rem; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem;
  max-height: 12rem; overflow: auto; white-space: pre-wrap; color: var(--ink-soft);
}
.code-box {
  font-family: var(--font-mono); font-size: 1.35rem; font-weight: 600; letter-spacing: .12em;
  padding: .7rem 1rem; background: var(--accent-wash); border: 1px dashed var(--accent);
  border-radius: var(--radius); display: inline-block; color: var(--accent-dk);
}

/* ── Mobile: bottom tab bar ─────────────────────────────────────────────── */
.tabbar { display: none; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line);
    padding: .7rem .9rem; flex-direction: row; align-items: center; gap: .7rem;
  }
  .sidebar .nav-item, .sidebar .nav-spacer, .sidebar .usage-chip { display: none; }
  .sidebar .brand { padding: 0; }
  .project-switch { margin: 0; flex: 1; }
  .main { padding-bottom: 4.6rem; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
  }
  .tabbar button {
    flex: 1; border: 0; background: transparent; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: .1rem;
    padding: .35rem .2rem; color: var(--ink-faint); font-size: .68rem; font-weight: 600;
  }
  .tabbar button .ic { font-size: 1.1rem; }
  .tabbar button.active { color: var(--accent-dk); }
  .chat, .pane { padding: 1rem; }
  .composer { padding: .7rem 1rem 1rem; }
  .bubble { max-width: 100%; }
  .files-layout { grid-template-columns: 1fr; }
}
