* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1117;
  --panel: #181b24;
  --panel-2: #1f2330;
  --border: #2a2f3f;
  --text: #e6e8ee;
  --muted: #9aa1b2;
  --accent: #d97748;
  --accent-hover: #e88a5c;
  --green: #4caf7d;
  --red: #e05d5d;
  --radius: 10px;
  font-size: 15px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }
.screen { height: 100vh; }

.error { color: var(--red); white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* ---------- Landing ---------- */
#landing { overflow-y: auto; }
#landing-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 40px; border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700; font-size: 1.1rem;
  display: flex; align-items: center; gap: 8px; color: var(--accent);
}
.brand svg { width: 22px; height: 22px; }
.nav-right { display: flex; align-items: center; gap: 10px; }
.nav-right select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
}
button.ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
}
button.ghost:hover { border-color: var(--accent); background: transparent; color: var(--accent); }
button.big { padding: 14px 34px; font-size: 1.05rem; }
.small-btn { padding: 6px 14px; font-size: 0.85rem; align-self: center; }

#hero {
  text-align: center; padding: 110px 20px 70px;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}
#hero h1 {
  font-size: 3rem; max-width: 700px; line-height: 1.15;
  background: linear-gradient(120deg, var(--text), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#hero p { color: var(--muted); font-size: 1.15rem; max-width: 560px; line-height: 1.5; }

#features {
  display: flex; gap: 24px; justify-content: center; flex-wrap: wrap;
  padding: 30px 40px 90px; max-width: 1050px; margin: 0 auto;
}
.feature {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; width: 290px;
  display: flex; flex-direction: column; gap: 10px;
}
.feature svg { width: 30px; height: 30px; color: var(--accent); }
.feature h3 { font-size: 1.05rem; }
.feature p { color: var(--muted); font-size: 0.92rem; line-height: 1.5; }

.auth-tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.auth-tab {
  flex: 1; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border);
}
.auth-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Onboarding ---------- */
#onboard-screen { display: flex; align-items: center; justify-content: center; }
.onboard-box {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 40px; width: 560px; max-width: 94vw;
  display: flex; flex-direction: column; gap: 18px;
}
.onboard-box h1 {
  font-size: 1.4rem; display: flex; align-items: center; gap: 10px;
}
.onboard-box h1 svg { width: 24px; height: 24px; color: var(--accent); }
#link-steps { display: flex; flex-direction: column; gap: 16px; }
.link-step { display: flex; align-items: center; gap: 12px; }
.step-no {
  width: 26px; height: 26px; min-width: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex;
  align-items: center; justify-content: center; font-size: 0.85rem; font-weight: 700;
}
#link-url { color: var(--accent); font-weight: 600; }
.code-row { display: flex; gap: 8px; flex: 1; }
.code-row input {
  flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
}
#manual-details { color: var(--muted); }
#manual-details summary { cursor: pointer; font-size: 0.9rem; }
#manual-details .code-row { margin-top: 10px; }
#user-email { margin-top: 8px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Roles ---------- */
.role-cards { display: flex; gap: 10px; margin: 6px 0 10px; }
.role-card {
  flex: 1; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; cursor: pointer;
  display: flex; flex-direction: column; gap: 5px; text-align: center; align-items: center;
}
.role-card.active { border-color: var(--accent); background: rgba(217,119,72,0.08); }
.role-card svg { width: 22px; height: 22px; color: var(--accent); }
.role-card b { font-size: 0.9rem; }
.role-card span { font-size: 0.75rem; color: var(--muted); }
.cta-row { display: flex; gap: 14px; }
.studio-tag {
  font-size: 0.62rem; background: var(--accent); color: #fff;
  border-radius: 5px; padding: 2px 6px; margin-left: 7px; vertical-align: middle;
}

/* ---------- Store ---------- */
#store-page { flex: 1; display: flex; flex-direction: column; height: 100vh; }
#store-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--border);
}
#store-heading { padding: 22px 30px 0; font-size: 1.15rem; }
#store-grid {
  flex: 1; overflow-y: auto; padding: 20px 30px 40px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px; align-content: start;
}
.store-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; cursor: pointer; transition: border-color 0.12s;
}
.store-card:hover { border-color: var(--accent); }
.store-card .app-icon { width: 58px; height: 58px; min-width: 58px; border-radius: 15px; }
.store-card .app-icon svg { width: 28px; height: 28px; }
.store-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.store-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.store-desc {
  font-size: 0.82rem; line-height: 1.35; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.store-open { min-width: 38px; }
button.gold { background: #b98a2e; }
button.gold:hover { background: #d3a13d; }

/* ---------- Plans ---------- */
.price { font-size: 2.4rem; font-weight: 700; color: var(--accent); }
.price span { font-size: 1rem; color: var(--muted); font-weight: 400; }
.benefits { list-style: none; display: flex; flex-direction: column; gap: 6px; margin: 8px 0; padding: 0; }
.benefits li { color: var(--text); font-size: 0.92rem; }
.benefits li::before { content: '— '; color: var(--green); }

#plans { padding: 20px 40px 90px; max-width: 1050px; margin: 0 auto; text-align: center; }
#plans h2 { font-size: 1.6rem; margin-bottom: 20px; }
.plan-tabs {
  display: flex; gap: 8px; justify-content: center; margin-bottom: 28px;
}
.plan-tab {
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border); padding: 10px 26px; border-radius: 30px;
  font-size: 0.95rem;
}
.plan-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.plan-tabs.in-app-tabs { margin: 30px 0 0; }
.plan-choose.current { background: var(--panel-2); color: var(--green); border: 1px solid var(--green); }
.plans-row { display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
.plan-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 30px 26px; width: 280px; position: relative;
  display: flex; flex-direction: column; gap: 10px; align-items: center; text-align: center;
}
.plan-card.featured { border-color: var(--accent); box-shadow: 0 0 24px rgba(217,119,72,0.15); }
.plan-badge {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; font-size: 0.72rem; font-weight: 700;
  padding: 4px 12px; border-radius: 20px;
}
.plan-card h3 { font-size: 1.05rem; color: var(--muted); }
.plan-card .benefits { text-align: left; }
.plan-cta, .plan-choose {
  margin-top: auto; width: 100%; padding: 12px;
}
.plan-cta.ghost { background: transparent; border: 1px solid var(--border); }
.plan-cta.ghost:hover { border-color: var(--accent); color: var(--accent); background: transparent; }
.center-note { margin-top: 22px; text-align: center; }

#plans-page { flex: 1; display: flex; flex-direction: column; height: 100vh; overflow-y: auto; }
#plans-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--border);
}
#plans-header h2 { font-size: 1.05rem; }
.plans-row.in-app { padding: 40px 20px 10px; }

/* ---------- Layout ---------- */
#app-screen { display: flex; }
#main-view { display: flex; flex: 1; min-width: 0; overflow: hidden; }
.sidebar-tools { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  background: transparent; border: none; font-size: 1.05rem;
  padding: 4px 6px; cursor: pointer; border-radius: 6px;
}
.icon-btn:hover { background: var(--panel-2); }

/* ---------- Apps page ---------- */
#apps-page { flex: 1; display: flex; flex-direction: column; height: 100vh; }
#apps-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
#apps-header h2 { font-size: 1.05rem; }
#apps-grid {
  flex: 1; overflow-y: auto; padding: 34px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 22px; align-content: start;
}
.app-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  cursor: pointer; padding: 16px 8px; border-radius: 14px; position: relative;
}
.app-card:hover { background: var(--panel-2); }
.app-icon {
  width: 74px; height: 74px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 20px;
  transition: transform 0.12s;
}
.app-icon svg { width: 36px; height: 36px; }
.app-card:hover .app-icon { transform: scale(1.06); }
.icon-btn svg { width: 18px; height: 18px; display: block; color: var(--muted); }
.icon-btn:hover svg { color: var(--text); }
.app-name {
  font-size: 0.85rem; text-align: center; max-width: 116px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-dot {
  position: absolute; top: 14px; right: 22px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--green); border: 2px solid var(--panel);
}

#sidebar {
  width: 270px; min-width: 270px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px;
  gap: 14px;
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; }
.sidebar-header h2 { font-size: 1.1rem; }
#lang-select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px;
}

button {
  background: var(--accent); color: #fff; border: none;
  border-radius: 8px; padding: 10px 16px; font-size: 0.95rem;
  cursor: pointer; transition: background 0.15s;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

#project-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.project-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.project-item .project-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.project-item:hover { background: var(--panel-2); }
.project-item.active { background: var(--panel-2); border-color: var(--accent); }
.project-running-dot {
  width: 8px; height: 8px; min-width: 8px; border-radius: 50%;
  background: var(--accent);
  animation: project-dot-pulse 1.4s infinite;
}
@keyframes project-dot-pulse {
  0% { box-shadow: 0 0 0 0 rgba(217,119,72,0.5); }
  70% { box-shadow: 0 0 0 6px rgba(217,119,72,0); }
  100% { box-shadow: 0 0 0 0 rgba(217,119,72,0); }
}

/* ---------- Chat ---------- */
#chat-area { flex: 1; display: flex; flex-direction: column; height: 100vh; min-width: 0; overflow: hidden; }
#empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; color: var(--muted);
}
#chat-view { flex: 1; display: flex; flex-direction: column; height: 100vh; min-width: 0; overflow: hidden; }
.msg.assistant pre { max-width: 100%; }
.msg.assistant code { overflow-wrap: anywhere; word-break: break-all; }
.msg :not(pre) { max-width: 100%; }
.msg img { max-width: 100%; height: auto; }
.msg.assistant table { display: block; max-width: 100%; overflow-x: auto; }

#chat-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel);
}
#chat-title { font-weight: 600; }
#header-actions { display: flex; align-items: center; gap: 8px; }
button.mini {
  padding: 5px 10px; font-size: 0.8rem; border-radius: 6px;
}
button.mini.danger { background: transparent; border: 1px solid var(--border); color: var(--muted); }
button.mini.danger:hover { border-color: var(--red); color: var(--red); background: transparent; }
.mini-link {
  padding: 5px 10px; font-size: 0.8rem; border-radius: 6px;
  background: var(--green); color: #fff; text-decoration: none;
}
#run-logs {
  max-height: 140px; overflow-y: auto; margin: 0;
  padding: 10px 20px; background: #12141c; color: var(--muted);
  font-size: 0.75rem; border-bottom: 1px solid var(--border);
  font-family: ui-monospace, monospace; white-space: pre-wrap;
}
.status { font-size: 0.8rem; padding: 3px 10px; border-radius: 20px; }
.status.idle { background: #2a2f3f; color: var(--muted); }
.status.working { background: rgba(217,119,72,0.15); color: var(--accent); }

#messages {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}

.msg {
  max-width: 80%; padding: 12px 16px; border-radius: var(--radius);
  line-height: 1.5; overflow-wrap: anywhere; min-width: 0;
}
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child, .msg.assistant ul:last-child, .msg.assistant ol:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 8px; padding-left: 22px; }
.msg.assistant li { margin: 2px 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3, .msg.assistant h4 {
  margin: 10px 0 6px; font-size: 1rem;
}
.msg.assistant h1 { font-size: 1.15rem; }
.msg.assistant h2 { font-size: 1.05rem; }
.msg.assistant a { color: var(--accent); }
.msg.assistant blockquote {
  border-left: 3px solid var(--border); padding-left: 10px;
  color: var(--muted); margin: 6px 0;
}
.msg.assistant table { border-collapse: collapse; margin: 8px 0; font-size: 0.88rem; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--border); padding: 5px 10px; }
.msg.assistant hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.msg.tool {
  align-self: flex-start; background: transparent; color: var(--muted);
  font-size: 0.82rem; padding: 2px 16px; font-family: ui-monospace, monospace;
}
.msg.system { align-self: center; color: var(--muted); font-size: 0.85rem; }
.msg.error { align-self: center; color: var(--red); font-size: 0.9rem; }

.msg.assistant code, .msg.assistant pre {
  font-family: ui-monospace, SFMono-Regular, monospace;
  background: #12141c; border-radius: 6px;
}
.msg.assistant pre { padding: 10px; overflow-x: auto; margin: 8px 0; }
.msg.assistant code { padding: 1px 5px; }
.msg.assistant pre code { padding: 0; }

#composer {
  display: flex; gap: 10px; padding: 16px 20px;
  border-top: 1px solid var(--border); background: var(--panel);
}
#msg-input {
  flex: 1; resize: none; padding: 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); font-size: 0.95rem; font-family: inherit;
}
#stop-btn { background: var(--red); }

/* ---------- Preview pane / visual editor ---------- */
#chat-area.with-preview { flex-direction: row; }
#chat-area.with-preview #chat-view { flex: 1; min-width: 340px; }
#preview-pane {
  width: 48%; min-width: 420px; height: 100vh;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border); background: var(--panel);
}
#preview-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
#preview-toolbar .toolbar-right { margin-left: auto; display: flex; gap: 4px; }
#editor-hint { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#edit-mode-btn.editing { background: #5b8def; }
#preview-frame { flex: 1; border: none; background: #fff; }
#editor-bar {
  border-top: 1px solid var(--border); padding: 10px 14px;
  display: flex; flex-direction: column; gap: 8px; background: var(--panel);
}
#editor-bar.collapsed #sel-chips:empty { display: none; }
#sel-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sel-chip {
  background: rgba(91,141,239,0.12); border: 1px solid #5b8def55;
  color: #9db9f5; border-radius: 6px; padding: 3px 8px;
  font-size: 0.75rem; font-family: ui-monospace, monospace;
  display: inline-flex; align-items: center; gap: 6px;
}
.sel-chip button {
  background: none; border: none; color: #9db9f5; padding: 0;
  font-size: 0.9rem; line-height: 1; cursor: pointer;
}
#editor-prompt {
  flex: 1; padding: 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; width: 420px;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-box label { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }
.modal-box input {
  padding: 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
#modal-cancel { background: var(--panel-2); }

@media (max-width: 700px) {
  #sidebar { width: 200px; min-width: 200px; }
  .msg { max-width: 95%; }
}
