/* ═══════════════════════════════════════════════════════════════════════
   Pabbly App Builder — design tokens + component contracts.
   Ported from the AgenticAI design system (DL-14): same palette, spacing
   and visual contracts, re-expressed as CSS for the server-rendered app.
   Dark is the default theme; html.light flips it.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --primary-50:#ecfdf5; --primary-100:#d1fae5; --primary-500:#059669;
  --primary-600:#047857; --primary-700:#065f46;
  --red:#dc2626; --amber:#d97706; --blue:#2563eb;

  /* dark theme (default) */
  --bg:#1a1a1a; --panel:#2c2c2c; --surface:#383838; --surface-2:#2f2f2f;
  --border:#484848; --border-strong:#5a5a5a; --text:#e5e5e5; --text-muted:#9ca3af;
  --hover:#404040; --input-bg:#383838;
}
html.light {
  --bg:#fafafa; --panel:#ffffff; --surface:#ffffff; --surface-2:#f5f5f5;
  --border:#e5e5e5; --border-strong:#d4d4d4; --text:#171717; --text-muted:#737373;
  --hover:#f5f5f5; --input-bg:#ffffff;
}

* { box-sizing:border-box; }
html,body { height:100%; }
body {
  margin:0; font-family:Inter,system-ui,-apple-system,sans-serif;
  background:var(--bg); color:var(--text); font-size:14px; line-height:1.5;
}
a { color:var(--primary-500); text-decoration:none; }
a:hover { text-decoration:underline; }

/* ── App shell ─────────────────────────────────────────────────────── */
.shell { display:flex; flex-direction:column; height:100vh; }
.topbar {
  display:flex; align-items:center; justify-content:space-between;
  height:56px; padding:0 16px; background:var(--panel);
  border-bottom:1px solid var(--border); flex-shrink:0;
}
.brand { display:flex; align-items:center; gap:8px; font-weight:600; font-size:15px; color:var(--text); }
.brand:hover { text-decoration:none; }
.brand-mark {
  width:28px; height:28px; border-radius:8px; background:var(--primary-600);
  color:#fff; display:grid; place-items:center; font-size:14px;
}
.brand em { color:var(--primary-500); font-style:normal; }
.body { display:flex; flex:1; min-height:0; }
.sidebar {
  width:208px; flex-shrink:0; background:var(--panel);
  border-right:1px solid var(--border); padding:12px 8px; overflow-y:auto;
}
.sidebar .section { font-size:10px; font-weight:600; letter-spacing:.08em;
  color:var(--text-muted); padding:8px 10px 4px; }
.navlink {
  display:flex; align-items:center; gap:10px; padding:8px 10px; border-radius:8px;
  color:var(--text); font-size:13px; margin-bottom:2px;
}
.navlink:hover { background:var(--hover); text-decoration:none; }
.navlink.active { background:color-mix(in srgb, var(--primary-500) 15%, transparent); color:var(--primary-500); font-weight:500; }
main.content { flex:1; min-width:0; overflow-y:auto; }
.page { max-width:1000px; margin:0 auto; padding:24px 20px 48px; }
.page-head { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:20px; }
.page-head h1 { font-size:18px; margin:0 0 2px; }
.page-head p { margin:0; color:var(--text-muted); font-size:13px; }

/* ── Buttons (visual contract: h-36/32, rounded-lg, Title Case) ─────── */
.btn {
  display:inline-flex; align-items:center; gap:6px; height:36px; padding:0 16px;
  border-radius:10px; border:1px solid transparent; font-size:13px; font-weight:600;
  cursor:pointer; background:var(--surface); color:var(--text); text-decoration:none;
  transition:filter .12s ease, background .12s ease;
}
.btn:hover { text-decoration:none; filter:brightness(1.08); }
.btn:disabled { opacity:.5; cursor:not-allowed; }
.btn-primary { background:var(--primary-600); color:#fff; }
.btn-secondary { background:transparent; border-color:var(--border-strong); color:var(--text); }
.btn-danger { background:transparent; border-color:color-mix(in srgb, var(--red) 40%, transparent); color:var(--red); }
.btn-sm { height:32px; padding:0 12px; border-radius:8px; }
.btn-icon {
  display:inline-flex; align-items:center; justify-content:center; width:32px; height:32px;
  border-radius:8px; background:transparent; border:0; color:var(--text-muted); cursor:pointer;
}
.btn-icon:hover { background:var(--hover); color:var(--text); }
.only-dark, .only-light { display:inline-flex; align-items:center; }
html.light .only-dark { display:none; }
html:not(.light) .only-light { display:none; }

/* ── Pills (one locked look, tone varies) ──────────────────────────── */
.pill {
  display:inline-flex; align-items:center; gap:4px; height:24px; padding:0 10px;
  border-radius:999px; font-size:11px; font-weight:600; white-space:nowrap;
  background:var(--surface-2); color:var(--text-muted);
}
.pill-positive { background:color-mix(in srgb,var(--primary-500) 18%, transparent); color:var(--primary-500); }
.pill-negative { background:color-mix(in srgb,var(--red) 18%, transparent); color:var(--red); }
.pill-warning  { background:color-mix(in srgb,var(--amber) 18%, transparent); color:var(--amber); }

/* ── Cards / KPI ────────────────────────────────────────────────────── */
.card {
  background:var(--panel); border:1px solid var(--border); border-radius:16px;
  padding:20px; box-shadow:0 1px 2px rgba(0,0,0,.25);
}
.kpis { display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:14px; margin-bottom:22px; }
.kpi .label { font-size:12px; color:var(--text-muted); display:flex; gap:6px; align-items:center; }
.kpi .value { font-size:26px; font-weight:700; margin-top:4px; }

/* ── Tables (canonical chrome) ─────────────────────────────────────── */
.table-card { background:var(--panel); border:1px solid var(--border); overflow:hidden; border-radius:12px; }
.table-scroll { overflow-x:auto; }
table.tbl { width:100%; border-collapse:collapse; }
.tbl thead { background:var(--surface-2); }
.tbl th { text-align:left; padding:14px 16px; font-size:11px; font-weight:600;
  letter-spacing:.06em; text-transform:uppercase; color:var(--text-muted); }
.tbl td { padding:14px 16px; font-size:13px; border-top:1px solid var(--border); vertical-align:middle; }
.tbl tr.click { cursor:pointer; }
.tbl tr.click:hover td { background:var(--hover); }
.tbl .sub { font-size:12px; color:var(--text-muted); }

/* ── Forms ──────────────────────────────────────────────────────────── */
label.fld { display:block; font-size:12px; color:var(--text-muted); margin:12px 0 4px; }
input.in, textarea.in, select.in {
  width:100%; padding:9px 12px; border-radius:10px; border:1px solid var(--border-strong);
  background:var(--input-bg); color:var(--text); font-size:13px; font-family:inherit;
}
input.in:focus, textarea.in:focus, select.in:focus {
  outline:none; border-color:var(--primary-500);
  box-shadow:0 0 0 3px color-mix(in srgb, var(--primary-500) 18%, transparent);
}
.err { color:var(--red); font-size:12px; min-height:16px; margin-top:6px; }
.hint { color:var(--text-muted); font-size:12px; }

/* ── Modal ──────────────────────────────────────────────────────────── */
.modal-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.55); z-index:50;
  display:grid; place-items:center; padding:20px; }
.modal { background:var(--panel); border:1px solid var(--border); border-radius:16px;
  padding:22px; width:100%; max-width:440px; box-shadow:0 20px 60px rgba(0,0,0,.5); }
.modal h2 { margin:0 0 4px; font-size:15px; }

/* ── Tabs (TabStrip contract: rail + underline + semibold active) ──── */
.tabs { display:flex; gap:20px; border-bottom:1px solid var(--border); }
.tab { padding:0 2px 10px; margin-bottom:-1px; border-bottom:2px solid transparent;
  color:var(--text-muted); font-size:13px; font-weight:500; cursor:pointer; background:none; border-top:0; border-left:0; border-right:0; }
.tab:hover { color:var(--text); text-decoration:none; }
.tab.active { color:var(--text); font-weight:600; border-bottom-color:var(--text); }

/* ── Builder layout ────────────────────────────────────────────────── */
.builder { display:flex; height:100%; min-height:0; padding:14px; gap:0; }
.bpanel { background:var(--panel); border-radius:14px; box-shadow:0 4px 14px rgba(0,0,0,.25);
  display:flex; flex-direction:column; overflow:hidden; min-width:0; height:100%; }
#chat-panel { flex:0 0 var(--chat-w, 58%); }
#split-handle { flex:0 0 12px; display:flex; align-items:center; justify-content:center; cursor:col-resize; }
#split-handle .grip { width:4px; height:64px; border-radius:99px; background:var(--border-strong); transition:background .12s; }
#split-handle:hover .grip, #split-handle.active .grip { background:var(--primary-500); }
#app-panel { flex:1; }
.bhead { display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding:12px 16px; border-bottom:1px solid var(--border); flex-shrink:0; }
.bhead h1 { font-size:14px; margin:0; }
.bhead .sub { font-size:12px; color:var(--text-muted); }

/* chat */
#chat-scroll { flex:1; overflow-y:auto; padding:16px; background:var(--bg); display:flex; flex-direction:column; gap:12px; }
.msg { display:flex; }
.msg.user { justify-content:flex-end; }
.bubble { max-width:85%; border-radius:14px; padding:10px 14px; font-size:13px; }
.msg.user .bubble { background:var(--primary-600); color:#fff; }
.msg.assistant .bubble { background:var(--panel); border:1px solid var(--border); }
.bubble .md p { margin:.4em 0; } .bubble .md p:first-child { margin-top:0; } .bubble .md p:last-child { margin-bottom:0; }
.bubble .md code { background:var(--surface-2); padding:1px 5px; border-radius:5px; font-size:12px; }
.bubble .md pre { background:var(--surface-2); padding:10px; border-radius:8px; overflow-x:auto; }
.bubble .userr { white-space:pre-wrap; }
.tool-card { display:flex; align-items:center; gap:8px; margin:6px 0; padding:8px 12px;
  border:1px solid var(--border); border-radius:10px; background:var(--surface-2);
  font-size:12px; font-family:ui-monospace,Menlo,monospace; }
.tool-card .st { flex-shrink:0; width:14px; text-align:center; }
.tool-card.running .st { color:var(--primary-500); animation:spin 1s linear infinite; display:inline-block; }
.tool-card.done .st { color:var(--primary-500); }
.tool-card.failed .st { color:var(--red); }
@keyframes spin { to { transform:rotate(360deg); } }
.att-chip { display:inline-flex; align-items:center; gap:6px; padding:4px 9px; margin:0 6px 6px 0;
  border-radius:9px; border:1px solid rgba(255,255,255,.25); background:rgba(255,255,255,.12);
  color:inherit; font-size:11px; font-weight:500; cursor:pointer; }
.att-chip:hover { background:rgba(255,255,255,.2); text-decoration:none; }
.activity { display:inline-flex; align-items:center; gap:8px; padding:8px 12px; width:fit-content;
  border:1px solid var(--border); border-radius:10px; background:var(--panel);
  font-size:12px; color:var(--text-muted); }
.activity .spin { color:var(--primary-500); animation:spin 1s linear infinite; display:inline-block; }
.msg-error { color:var(--red); font-size:12px; white-space:pre-wrap; margin-top:6px; }

/* composer */
.composer-wrap { padding:12px 16px 16px; border-top:1px solid var(--border); flex-shrink:0; }
.composer { border:2px solid var(--border-strong); border-radius:14px; background:var(--surface);
  overflow:hidden; transition:border-color .12s; }
.composer:focus-within { border-color:var(--primary-500); }
.composer textarea { display:block; width:100%; border:0; outline:none; background:transparent;
  color:var(--text); resize:none; font:inherit; font-size:13.5px; padding:12px 14px 6px; max-height:190px; }
.composer .row { display:flex; align-items:center; justify-content:space-between; padding:0 8px 8px; }
.composer .chips { display:flex; flex-wrap:wrap; gap:6px; padding:10px 12px 0; }
.chip { display:inline-flex; align-items:center; gap:6px; padding:4px 9px; border-radius:9px;
  border:1px solid var(--border); background:var(--surface-2); font-size:11px; }
.chip button { background:none; border:0; color:var(--text-muted); cursor:pointer; padding:0; }
.chip button:hover { color:var(--red); }
.queued { display:flex; align-items:center; gap:8px; padding:7px 12px; margin-bottom:8px;
  border:1px dashed var(--border-strong); border-radius:10px; font-size:11px; color:var(--text-muted); }

/* files/explorer */
.explorer { width:240px; flex-shrink:0; border-right:1px solid var(--border);
  display:flex; flex-direction:column; min-height:0; }
.explorer .bar { display:flex; align-items:center; justify-content:space-between;
  padding:7px 10px; border-bottom:1px solid var(--border); font-size:10px; font-weight:600;
  letter-spacing:.08em; color:var(--text-muted); }
.explorer .list { flex:1; overflow-y:auto; padding:4px; font-family:ui-monospace,Menlo,monospace; font-size:12px; }
.frow { display:flex; align-items:center; gap:6px; width:100%; text-align:left; padding:3px 6px;
  border-radius:6px; background:none; border:0; color:var(--text); cursor:pointer; font:inherit; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.frow:hover { background:var(--hover); }
.frow.active { background:color-mix(in srgb,var(--primary-500) 18%, transparent); color:var(--primary-500); }
.frow.frozen { opacity:.45; }
.frow .ic { flex-shrink:0; }
#code-host { flex:1; min-width:0; min-height:0; }
.files-wrap { display:flex; flex:1; min-height:0; }

/* preview */
#preview-frame { width:100%; height:100%; border:0; background:#fff; }
.center-note { display:grid; place-items:center; height:100%; color:var(--text-muted); font-size:13px; padding:20px; text-align:center; }

/* auth pages */
.auth-wrap { min-height:100vh; display:grid; place-items:center; padding:20px; }
.auth-card { width:100%; max-width:380px; }

/* misc */
.mut { color:var(--text-muted); }
.right { text-align:right; }
.spacer { flex:1; }
::-webkit-scrollbar { width:10px; height:10px; }
::-webkit-scrollbar-thumb { background:var(--border-strong); border-radius:6px; }
::-webkit-scrollbar-track { background:transparent; }
