/* ============================================================
   App Builder demo. The tokens and the shell come from group-structure,
   which measured them on welley.social (theme-navy).
   ============================================================ */
:root {
  --bg-main: #f1f3f6;
  --bg-primary: #ffffff;
  --bg-secondary: #f1f3f6;
  --bg-secondary-hover: #e4e7ed;
  --bg-tertiary: #f8f9fb;
  --brand: #2259f0;
  --brand-hover: #1c4ace;
  --brand-soft: #ecf0fe;
  --badge-bg: #d9e2fd;
  --badge-text: #13318c;
  --t1: #1d2236;
  --t2: #434c63;
  --t3: #7b859e;
  --t4: #a5adc0;
  --border: #e4e7ed;
  --border-strong: #cfd4de;
  --error: #f04438;
  --error-soft: #fef3f2;
  --ok: #558402;
  --ok-soft: #f4fcea;
  --warn: #b36d05;
  --warn-soft: #fff9ec;
  --r-sm: 8px;
  --r-m: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --shadow-pop: 0 8px 28px rgba(29, 34, 54, 0.16);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg-main);
  color: var(--t1);
  font-size: 14px;
  line-height: 20px;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
button:disabled { cursor: default; }
svg { display: block; flex-shrink: 0; }
ol, ul { list-style: none; }
.spacer { flex: 1; }
.muted { color: var(--t3); }
.small { font-size: 12px; line-height: 16px; }

/* ---------- demo bar (scaffolding) ---------- */
.demo-bar {
  flex: 0 0 auto; height: 52px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px dashed var(--border-strong);
}
.demo-brand { display: flex; align-items: center; gap: 10px; }
.brand-title { font-weight: 600; font-size: 15px; }
.brand-tag {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  color: var(--t3); background: var(--bg-secondary-hover); padding: 2px 8px; border-radius: 999px;
}

/* ---------- product chrome ---------- */
.app { flex: 1 1 auto; min-height: 0; display: flex; gap: 16px; padding: 16px; }

.rail {
  flex: 0 0 64px; background: var(--bg-primary); border-radius: var(--r-lg);
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 0;
}
.rail-logo { margin-bottom: 8px; }
.rail-btn {
  width: 40px; height: 40px; border-radius: var(--r-m);
  display: grid; place-items: center; color: var(--t2);
}
.rail-btn:hover { background: var(--bg-secondary); }
.rail-btn.active { background: var(--brand-soft); color: var(--brand); }
.rail-sep { width: 40px; height: 1px; background: var(--border); margin: 4px 0; }
.rail-group {
  width: 40px; height: 40px; border-radius: var(--r-m);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px;
}
.rail-group.round { border-radius: 50%; }
.rail-group.active { box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--brand); }
.blurred { filter: blur(1.5px); opacity: .45; pointer-events: none; }

/* ---------- sidebar ---------- */
.sidebar {
  flex: 0 0 320px; background: var(--bg-primary); border-radius: var(--r-lg);
  overflow-y: auto; overflow-x: hidden; padding-bottom: 16px;
}
.cover { height: 128px; position: relative; border-radius: var(--r-lg) var(--r-lg) 0 0; }
.g-avatar {
  position: absolute; left: 20px; top: 60px;
  width: 96px; height: 96px; border-radius: var(--r-xl);
  display: grid; place-items: center; color: #fff; font-size: 40px; font-weight: 700;
  box-shadow: 0 0 0 4px var(--bg-primary);
}
.g-avatar.round { border-radius: 50%; }
.title-row { margin-top: 40px; padding: 0 12px 4px 20px; }
.g-title { font-size: 16px; line-height: 24px; font-weight: 600; }
.admin-head { display: flex; align-items: center; gap: 12px; padding: 20px 20px 4px; }
.sections { padding: 0 12px; }
.sec-label {
  padding: 16px 8px 4px; font-size: 12px; line-height: 16px; font-weight: 600;
  text-transform: uppercase; color: var(--t3);
}

.row {
  display: flex; align-items: center;
  padding: 8px; margin-bottom: 4px; border-radius: var(--r-m); cursor: pointer;
}
.row:hover, .row.active { background: var(--bg-secondary); }
.row-icon { width: 24px; height: 24px; display: grid; place-items: center; flex-shrink: 0; }
.row-text { margin-left: 12px; min-width: 0; flex: 1; }
.row-title { font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small-pill { margin-left: 8px; font-size: 11px; padding: 0 6px; }

.ic-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700;
}
.ic-plain { color: var(--t3); display: grid; place-items: center; }
.ic-app {
  width: 24px; height: 24px; border-radius: 7px;
  display: grid; place-items: center; color: #fff; flex-shrink: 0;
}
.ic-app.lg { width: 40px; height: 40px; border-radius: 11px; }

.badge {
  display: inline-block; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 12px; line-height: 20px; font-weight: 600; text-align: center;
}
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; line-height: 16px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: var(--bg-secondary); color: var(--t2); white-space: nowrap;
}
.pill.brand { background: var(--badge-bg); color: var(--badge-text); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

/* "Just changed" highlight, shown once after a render. */
.flash { animation: flash 1.8s ease-out; }
@keyframes flash {
  0%, 35% { box-shadow: 0 0 0 2px var(--brand); background-color: var(--brand-soft); }
  100% { box-shadow: 0 0 0 2px transparent; }
}

/* ---------- content pane ---------- */
.content {
  flex: 1 1 auto; min-width: 0; background: var(--bg-primary); border-radius: var(--r-lg);
  overflow-y: auto; display: flex; flex-direction: column;
}
.view-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-primary); z-index: 1;
}
.view-head .row-icon { transform: scale(1.25); }
.view-title { font-size: 19px; line-height: 24px; font-weight: 600; }
.view-sub { color: var(--t3); font-size: 13px; }
.view-body { padding: 20px 24px 32px; max-width: 760px; }
.view-body.wide { max-width: none; }
.note-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--r-m);
  padding: 12px 14px; color: var(--t2);
}
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  color: var(--t4); padding: 64px 24px;
}
.empty p { color: var(--t3); max-width: 340px; }

.tabs { display: flex; align-items: center; gap: 20px; padding: 0 24px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 12px 0 10px; font-weight: 600; color: var(--t3);
  border-bottom: 2px solid transparent; display: flex; align-items: center; gap: 6px;
}
.tab.active { color: var(--t1); border-bottom-color: var(--t1); }

.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.app-card, .sub-card {
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.app-card-top { display: flex; align-items: center; gap: 12px; }
.app-name { font-weight: 600; font-size: 16px; line-height: 24px; }
.app-desc { color: var(--t2); flex: 1; }
.banner {
  display: flex; align-items: center; gap: 14px; margin-bottom: 16px;
  padding: 16px; border-radius: var(--r-lg); background: var(--brand-soft);
}

.timeline { display: flex; flex-wrap: wrap; gap: 8px 20px; padding-top: 4px; border-top: 1px solid var(--border); }
.timeline li { display: flex; align-items: center; gap: 6px; padding-top: 10px; color: var(--t3); font-weight: 500; }
.timeline li.done svg { color: var(--ok); }
.timeline li.current { color: var(--warn); }

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--t3);
  padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--t2); }
.table td.right { text-align: right; }
.table tr.flash td { animation: flash-cell 1.8s ease-out; }
@keyframes flash-cell { 0%, 35% { background: var(--brand-soft); } 100% { background: transparent; } }
.cell-app { display: flex; align-items: center; gap: 10px; color: var(--t1); }

/* ---------- App Builder: stage 1 ---------- */
.studio-wrap { overflow: hidden; }
.pick { padding: 28px 24px; display: flex; flex-direction: column; gap: 16px; max-width: 980px; }
.pick h1 { font-size: 24px; line-height: 32px; font-weight: 600; }
.pick > p { margin-top: -8px; }
.scope-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.scope {
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px; cursor: pointer;
  display: flex; flex-direction: column; gap: 8px;
}
.scope:hover { border-color: var(--border-strong); }
.scope.selected { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); background: #fbfcff; }
.scope-top { display: flex; align-items: center; justify-content: space-between; }
.scope-check { color: var(--brand); }
.scope-name { font-weight: 600; font-size: 16px; line-height: 24px; }
.scope-text { color: var(--t2); font-size: 13px; line-height: 18px; flex: 1; }
.scope-extra { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; color: var(--t2); }
.scope-extra.note { flex-direction: row; align-items: center; gap: 6px; color: var(--ok); }
.scope-extra .select { height: 34px; }
.type-ic {
  width: 36px; height: 36px; border-radius: 10px; background: var(--bg-secondary);
  display: grid; place-items: center; color: var(--t2);
}

/* ---------- App Builder: stage 2 ---------- */
.studio { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(320px, 2fr) 3fr; }
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.chat-log { flex: 1; overflow-y: auto; padding: 20px 20px 8px; display: flex; flex-direction: column; gap: 14px; }

.m { display: flex; gap: 10px; align-items: flex-start; }
.m.user { justify-content: flex-end; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 4px 16px 16px 16px; background: var(--bg-secondary); }
.m.user .bubble { background: var(--brand); color: #fff; border-radius: 16px 4px 16px 16px; }
.bubble p + *, .build + p { margin-top: 8px; }
.bot {
  width: 28px; height: 28px; border-radius: 9px; background: var(--brand); color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
}
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--t4); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

.build {
  background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--r-m);
  padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; font-size: 13px;
}
.build-head { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--t3); }
.bl { display: flex; align-items: center; gap: 8px; color: var(--t2); }
.bl.done svg { color: var(--ok); }
.spin { animation: spin 1s linear infinite; color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }

.outcome {
  margin-top: 10px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--r-m);
  padding: 12px; display: flex; flex-direction: column; gap: 12px;
}
.outcome-top { display: flex; align-items: center; gap: 12px; }
.outcome-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.composer { padding: 10px 20px 16px; border-top: 1px solid var(--border); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--badge-bg);
  background: var(--brand-soft); color: var(--badge-text); font-size: 13px; font-weight: 500; text-align: left;
}
.chip:hover { border-color: var(--brand); }
.chat-form { display: flex; gap: 8px; }
.chat-form .input:disabled { background: var(--bg-tertiary); }

.panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel-tabs { padding: 0 20px; }
.panel-body { flex: 1; overflow: auto; padding: 16px 20px 24px; }

/* On a narrow screen the sidebar sits above the content, the chat sits above the preview,
   and the document itself scrolls. Mobile browsers handle page scrolling far more reliably
   than scrolling inside a fixed-height container. */
@media (max-width: 900px) {
  html, body { height: auto; }
  body { display: block; }
  .app { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-content: start; gap: 12px; padding: 12px; }
  .rail { grid-row: 1 / span 2; align-self: start; position: sticky; top: 12px; }
  .sidebar, .content, .studio-wrap { overflow: visible; }
  .view-head { flex-wrap: wrap; }
  .studio { flex: none; grid-template-columns: minmax(0, 1fr); }
  .chat { height: 70vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .panel-body { overflow: visible; }
}

.details { display: flex; flex-direction: column; gap: 2px; max-width: 620px; }
.details-top { display: flex; align-items: center; gap: 12px; padding: 4px 6px 12px; border-radius: var(--r-m); }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 12px; padding: 10px 6px; border-top: 1px solid var(--border); border-radius: var(--r-sm); }
.dl > span { color: var(--t3); font-weight: 500; }
.perms { display: flex; flex-direction: column; gap: 10px; }
.perms li { display: flex; gap: 10px; align-items: flex-start; }
.perms li svg { color: var(--t2); margin-top: 2px; }

/* ---------- the board ---------- */
.board-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; min-height: 20px; }
.kboard { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 8px; }
.kcol {
  flex: 1 0 150px; max-width: 300px; background: var(--bg-secondary); border-radius: var(--r-m);
  padding: 8px; display: flex; flex-direction: column; gap: 8px;
}
.kcol.drop { box-shadow: inset 0 0 0 2px var(--brand); }
.kcol-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px; font-weight: 600; }
.kcount { color: var(--t3); font-size: 12px; font-weight: 600; }
.kcards { display: flex; flex-direction: column; gap: 8px; min-height: 8px; }
.kcard {
  background: var(--bg-primary); border-radius: 10px; padding: 10px; cursor: grab;
  box-shadow: 0 1px 2px rgba(29, 34, 54, .08), 0 0 0 1px var(--border);
}
.kcard:hover { box-shadow: 0 2px 6px rgba(29, 34, 54, .12), 0 0 0 1px var(--border-strong); }
.kcard.dragging { opacity: .4; }
.kcard-title { font-weight: 500; }
.kcard-meta { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.kdue { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--t3); font-weight: 500; }
.kdue.over { color: var(--error); }
.klabel { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--t2); font-weight: 500; }
.klabel i { width: 8px; height: 8px; border-radius: 50%; }
.person {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 11px;
}
.kadd-btn {
  display: flex; align-items: center; gap: 6px; padding: 6px 4px; border-radius: var(--r-sm);
  color: var(--t3); font-weight: 500;
}
.kadd-btn:hover { background: var(--bg-secondary-hover); color: var(--t1); }
.kadd { display: flex; flex-direction: column; gap: 6px; }
.kadd .input { height: 36px; }
.kadd-actions { display: flex; gap: 6px; }

/* ---------- controls ---------- */
.btn {
  height: 40px; padding: 0 16px; border-radius: var(--r-m); font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn.small { height: 32px; padding: 0 12px; border-radius: var(--r-sm); font-size: 12px; }
.btn.square { width: 40px; padding: 0; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); }
.btn.secondary { background: var(--bg-secondary); color: var(--t1); }
.btn.secondary:hover { background: var(--bg-secondary-hover); }
.btn.done-btn { background: var(--ok-soft); color: var(--ok); }
.btn.danger-text { color: var(--error); }
.btn:disabled { background: var(--bg-secondary); color: var(--t4); }
.icon-btn {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  display: grid; place-items: center; color: var(--t3);
}
.icon-btn:hover { background: var(--bg-secondary); color: var(--t1); }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--r-m);
  background: var(--bg-primary); padding: 0 12px; height: 40px; font-size: 14px; outline: none;
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 20px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-weight: 500; color: var(--t2); }

/* ---------- modal ---------- */
.modal {
  margin: auto; border: 0; border-radius: var(--r-lg); width: min(480px, calc(100vw - 32px));
  box-shadow: var(--shadow-pop); padding: 0; color: var(--t1);
}
.modal::backdrop { background: rgba(241, 243, 246, 0.7); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.modal-head h2 { font-size: 17px; line-height: 24px; font-weight: 600; }
.modal-body { padding: 10px 20px 6px; }
.modal-body > p { color: var(--t2); margin-bottom: 14px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 10px 20px 20px; }

/* ---------- toasts ---------- */
.toast-stack {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 60; align-items: center;
}
.toast {
  background: #292929; color: #fff; padding: 10px 16px; border-radius: var(--r-m);
  font-size: 14px; box-shadow: var(--shadow-pop); animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
