/* ============================================================
   PromptCraft — AI app builder (Ollama local backend)
   ============================================================ */

:root {
  --bg: #06060c;
  --bg-soft: #0c0c16;
  --panel: rgba(18, 18, 30, 0.72);
  --panel-solid: #101019;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef0f6;
  --muted: #9598ad;
  --faint: #6c6f85;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --accent-3: #ff5ca8;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

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

/* ---------- ambient halo ---------- */
.halo {
  position: fixed;
  pointer-events: none;
  filter: blur(90px);
  opacity: .42;
  z-index: 0;
  border-radius: 50%;
}
.halo-1 { width: 46vw; height: 46vw; left: -8vw; top: -14vw; background: #6d28d9; }
.halo-2 { width: 40vw; height: 40vw; right: -10vw; top: 8vh;  background: #db2777; opacity: .32; }
.halo-3 { width: 52vw; height: 34vw; left: 22vw; bottom: -18vw; background: #0ea5e9; opacity: .22; }

/* ---------- topbar ---------- */
.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 40px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  box-shadow: 0 6px 22px rgba(124, 92, 255, .45);
}
.brand-name { font-weight: 700; letter-spacing: -.02em; font-size: 17px; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, .16);
}
.dot.ok   { background: var(--ok);   box-shadow: 0 0 0 3px rgba(52, 211, 153, .16); }
.dot.bad  { background: var(--danger); box-shadow: 0 0 0 3px rgba(248, 113, 113, .16); }

.ghost-link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: .15s;
}
.ghost-link:hover { color: var(--text); border-color: var(--border); background: rgba(255,255,255,.04); }

/* ---------- home / hero ---------- */
.home {
  position: relative;
  z-index: 2;
  min-height: calc(100vh - 68px);
  display: flex;
  flex-direction: column;
  padding: 0 clamp(16px, 4vw, 40px);
}

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4vh 0 6vh;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 18px;
  font-size: 12.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent-2);
  opacity: .85;
}

h1 {
  margin: 0;
  font-size: clamp(38px, 7vw, 74px);
  line-height: 1.02;
  letter-spacing: -.035em;
  font-weight: 800;
}

.gradient-text {
  background: linear-gradient(100deg, #a78bfa 0%, #f472b6 42%, #facc15 78%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sub {
  margin: 20px 0 34px;
  max-width: 620px;
  font-size: clamp(15px, 1.7vw, 17.5px);
  line-height: 1.6;
  color: var(--muted);
}

/* ---------- composer ---------- */
.composer {
  width: 100%;
  text-align: left;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within {
  border-color: rgba(124, 92, 255, .6);
  box-shadow: 0 24px 70px rgba(0,0,0,.6), 0 0 0 4px rgba(124, 92, 255, .14);
}

.composer textarea {
  width: 100%;
  border: 0;
  outline: 0;
  resize: vertical;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.55;
  padding: 6px 8px 14px;
  min-height: 78px;
}
.composer textarea::placeholder { color: var(--faint); }

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  flex-wrap: wrap;
}
.composer-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
}
.select-label { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); }
.select-wrap select {
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
  max-width: 190px;
}
.select-wrap select option { background: #14141f; color: var(--text); }

.hint { font-size: 12.5px; color: var(--faint); font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, .07);
  cursor: pointer;
  transition: transform .12s, background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, .12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #5b8cff);
  border-color: transparent;
  box-shadow: 0 8px 26px rgba(91, 140, 255, .34);
}
.btn-primary:hover { background: linear-gradient(135deg, #8b6dff, #6c98ff); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
  padding: 8px 12px;
  font-size: 13px;
}
.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,.07); border-color: var(--border-strong); }

.btn-mini {
  padding: 3px 8px;
  font-size: 12px;
  background: rgba(255,255,255,.06);
  color: var(--muted);
}
.btn-danger { background: rgba(248,113,113,.16); border-color: rgba(248,113,113,.4); color: #fecaca; }
.btn-danger:hover { background: rgba(248,113,113,.26); }

/* ---------- chips ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  margin-top: 22px;
}
.chip {
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .04);
  color: var(--muted);
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: .15s;
}
.chip:hover {
  color: var(--text);
  border-color: rgba(124, 92, 255, .55);
  background: rgba(124, 92, 255, .14);
  transform: translateY(-1px);
}

.note {
  margin-top: 20px;
  min-height: 20px;
  font-size: 13.5px;
  color: var(--muted);
}
.note.warn { color: var(--warn); }
.note.error { color: #fca5a5; }

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 18px 0 26px;
  font-size: 12.5px;
  color: var(--faint);
  text-align: center;
}
.foot strong { color: var(--muted); font-weight: 600; }
.foot-sep { opacity: .5; }

/* ---------- workspace ---------- */
.workspace {
  position: relative;
  z-index: 2;
  height: calc(100vh - 68px);
  display: flex;
  flex-direction: column;
  padding: 0 clamp(8px, 2vw, 20px) clamp(8px, 2vw, 16px);
}

.ws-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 12px;
  flex-wrap: nowrap;
}

.ws-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ws-actions { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.status.busy { color: var(--accent-2); border-color: rgba(34,211,238,.35); background: rgba(34,211,238,.09); }
.status.err  { color: #fca5a5; border-color: rgba(248,113,113,.4); background: rgba(248,113,113,.1); }

.spinner {
  width: 11px; height: 11px;
  border: 2px solid rgba(255,255,255,.22);
  border-top-color: currentColor;
  border-radius: 50%;
  opacity: 0;
}
.spinner.on { opacity: 1; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- split panes ---------- */
.ws-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* left pane: tabs + panels */
.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.025);
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,.06); }
.tab.is-active { color: var(--text); background: rgba(255,255,255,.1); }
.badge {
  min-width: 17px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  text-align: center;
}
.tab-meta {
  margin-left: auto;
  padding-right: 6px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--faint);
  white-space: nowrap;
}

.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.code {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 14px 16px 26px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.6px;
  line-height: 1.62;
  color: #cdd3e6;
  background:
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px) 0 0 / 100% 100%,
    var(--panel-solid);
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 2;
}
.code::-webkit-scrollbar { width: 10px; height: 10px; }
.code::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
.code::-webkit-scrollbar-track { background: transparent; }

.caret {
  display: inline-block;
  width: 7px;
  height: 14px;
  margin-left: 1px;
  vertical-align: -2px;
  background: var(--accent-2);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* light syntax colours */
.tok-tag   { color: #f472b6; }
.tok-attr  { color: #fbbf24; }
.tok-str   { color: #86efac; }
.tok-kw    { color: #93c5fd; }
.tok-com   { color: #6b7280; font-style: italic; }
.tok-num   { color: #c4b5fd; }

/* chat panel */
.panel-chat { padding: 0; }
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel-solid);
}
.chat-empty {
  margin: auto 0;
  text-align: center;
  color: var(--faint);
  font-size: 13.5px;
  line-height: 1.7;
}
.chat-empty em { color: var(--muted); font-style: normal; }

.msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 13px;
  font-size: 13.7px;
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(124,92,255,.9), rgba(91,140,255,.85));
  border-color: transparent;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,.055);
  border-bottom-left-radius: 4px;
  color: var(--text);
}
.msg.meta {
  align-self: center;
  background: transparent;
  border: 0;
  color: var(--faint);
  font-size: 12.5px;
  padding: 2px;
}
.msg.error { align-self: center; background: rgba(248,113,113,.12); border-color: rgba(248,113,113,.4); color: #fecaca; font-size: 13px; }

.chat-form {
  display: flex;
  gap: 8px;
  padding: 11px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,.025);
}
.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0,0,0,.3);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: 0;
}
.chat-form input:focus { border-color: rgba(124,92,255,.6); }
.chat-form input::placeholder { color: var(--faint); }

/* right pane: preview */
.pane-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.025);
}
.pane-dots { display: inline-flex; gap: 5px; }
.pane-dots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255,255,255,.16); display: block; }
.pane-dots i:nth-child(1) { background: #ff5f57; }
.pane-dots i:nth-child(2) { background: #febc2e; }
.pane-dots i:nth-child(3) { background: #28c840; }
.pane-url {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-wrap { position: relative; flex: 1; min-height: 0; background: #fff; }
#preview { width: 100%; height: 100%; border: 0; display: block; background: #fff; }

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--panel-solid);
  color: var(--faint);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}
.preview-placeholder p { margin: 0; }
.preview-placeholder .big-spark { font-size: 40px; opacity: .8; }
.preview-placeholder.off { display: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  z-index: 50;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(20, 20, 32, .96);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: .22s;
  box-shadow: 0 14px 40px rgba(0,0,0,.55);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .ws-body { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .workspace { height: calc(100vh - 68px); }
  .ws-actions .btn-ghost { padding: 7px 9px; font-size: 12.5px; }
  .ws-title { display: none; }
  .status { font-size: 11.5px; padding: 5px 9px; }
}

@media (max-width: 640px) {
  .topbar { padding: 13px 16px; }
  .ghost-link { display: none; }
  .hero { padding-top: 2vh; }
  .composer-bar { gap: 8px; }
  .composer-left { width: 100%; justify-content: space-between; }
  .composer-bar .btn-primary { width: 100%; }
  .select-wrap select { max-width: 150px; }
  .foot-sep { display: none; }
  .ws-actions #copyBtn, .ws-actions #downloadBtn { display: none; }
}
