/*────────────────────────────────────────
  TOKENS
────────────────────────────────────────*/
:root {
  --bg:        #0f0e1a;
  --bg2:       #16152a;
  --surface:   #1d1c35;
  --surface2:  #252440;
  --surface3:  #2e2c52;
  --border:    #312f58;
  --border2:   #403d70;
  --orange:    #ff6b35;
  --orange2:   #ff8c5a;
  --orange-dim:rgba(255,107,53,.12);
  --orange-glow:rgba(255,107,53,.25);
  --green:     #00d97e;
  --green-dim: rgba(0,217,126,.1);
  --red:       #ff5252;
  --blue:      #5b9eff;
  --white:     #f0effe;
  --muted:     #7b78b0;
  --muted2:    #5a578a;
  --font:      'Sora', sans-serif;
  --mono:      'JetBrains Mono', monospace;
  --r:         10px;
  --r-sm:      6px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/*────────────────────────────────────────
  RESET & BASE
────────────────────────────────────────*/
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; overscroll-behavior: none; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--white);
  height: 100%;
  overflow: hidden;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/*────────────────────────────────────────
  LAYOUT SHELL
────────────────────────────────────────*/
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh; /* dynamic viewport height for mobile */
}

/* ── TOP BAR ── */
#topbar {
  height: 48px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 6px;
  flex-shrink: 0;
  z-index: 50;
  overflow-x: auto;
  scrollbar-width: none;
}
#topbar::-webkit-scrollbar { display: none; }

.logo {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--white);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.logo em { color: var(--orange); font-style: normal; }
.logo svg { flex-shrink: 0; }

.logo-badge {
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: .06em;
  background: var(--orange-dim);
  border: 1px solid var(--orange);
  color: var(--orange);
  padding: 2px 6px;
  border-radius: 20px;
  flex-shrink: 0;
  display: none;
}
@media (min-width: 600px) { .logo-badge { display: inline-block; } }

.tb-spacer { flex: 1; min-width: 4px; }

.icon-btn {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 14px;
  transition: all .15s;
  flex-shrink: 0;
}
.icon-btn:hover, .icon-btn.active { border-color: var(--orange); color: var(--orange); background: var(--orange-dim); }
@media (min-width: 600px) {
  #topbar { padding: 0 12px; gap: 10px; height: 52px; }
  .icon-btn { width: 36px; height: 36px; font-size: 16px; }
}

/* ── MAIN AREA ── */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/*────────────────────────────────────────
  MOBILE: TAB VIEWS
────────────────────────────────────────*/
.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform .3s ease, opacity .3s ease;
}

/* Chat view (default) */
#view-chat { transform: translateX(0); z-index: 2; }
#view-chat.slide-left { transform: translateX(-100%); }

/* Code view */
#view-code { transform: translateX(100%); z-index: 1; }
#view-code.slide-in { transform: translateX(0); z-index: 2; }
#view-code.slide-left { transform: translateX(-100%); }

/* Preview view */
#view-preview { transform: translateX(100%); z-index: 1; }
#view-preview.slide-in { transform: translateX(0); z-index: 2; }

/* Desktop: show all three side by side */
@media (min-width: 900px) {
  #main { gap: 1px; background: var(--border); }
  .view {
    position: relative !important;
    transform: none !important;
    opacity: 1 !important;
    flex: 1;
  }
  #view-chat { flex: 0 0 340px; }
  #view-code { flex: 1; }
  #view-preview { flex: 1; }
  #bottom-nav { display: none !important; }
}

/*────────────────────────────────────────
  CHAT VIEW
────────────────────────────────────────*/
#view-chat { background: var(--bg2); }

.view-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  background: var(--bg2);
}
.view-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 1;
}

/* Messages */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#messages::-webkit-scrollbar { width: 3px; }
#messages::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* Bubbles */
.msg { display: flex; flex-direction: column; gap: 5px; animation: msgIn .22s ease; }
@keyframes msgIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }

.msg-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 4px;
}
.msg.user .msg-label { color: var(--orange); text-align: right; }

.msg-bubble {
  font-size: 14px;
  line-height: 1.65;
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--surface);
  color: var(--white);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 92%;
}
.msg.user { align-items: flex-end; }
.msg.user .msg-bubble {
  background: var(--orange-dim);
  border-color: rgba(255,107,53,.25);
  border-bottom-right-radius: 3px;
}
.msg.assistant .msg-bubble { border-bottom-left-radius: 3px; }

.msg-bubble code {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg);
  color: var(--orange2);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Streaming cursor */
.stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--orange);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink .6s ease infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
.msg-bubble.streaming {
  min-height: 40px;
}

/* Apply button */
.apply-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 4px;
}
.apply-btn {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .05em;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--green);
  color: var(--green);
  background: var(--green-dim);
  cursor: pointer;
  transition: all .12s;
}
.apply-btn:hover { background: var(--green); color: #000; }
.apply-btn.secondary { border-color: var(--border2); color: var(--muted); background: transparent; }
.apply-btn.secondary:hover { border-color: var(--orange); color: var(--orange); background: var(--orange-dim); }

/* Typing dots */
.typing {
  display: flex; gap: 5px; align-items: center;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  border-bottom-left-radius: 3px;
  width: fit-content;
}
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: tdot 1.2s ease infinite;
}
.typing span:nth-child(2){ animation-delay:.2s }
.typing span:nth-child(3){ animation-delay:.4s }
@keyframes tdot { 0%,60%,100%{transform:translateY(0);opacity:.5} 30%{transform:translateY(-5px);opacity:1} }

/* Quick prompts */
#quick-prompts {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  cursor: grab;
}
#quick-prompts:active { cursor: grabbing; }
#quick-prompts::-webkit-scrollbar { display: none; }

.qp {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .04em;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all .12s;
  flex-shrink: 0;
}
.qp:hover, .qp:active { border-color: var(--orange); color: var(--orange); background: var(--orange-dim); }

/*────────────────────────────────────────
  TEMPLATE GALLERY
────────────────────────────────────────*/
#template-gallery {
  padding: 4px 0 16px;
  animation: fadeIn .4s ease;
}
@keyframes fadeIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:none} }

.tg-header {
  text-align: center;
  padding: 8px 16px 16px;
}
.tg-greeting {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.02em;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--orange), var(--orange2), #ffb347);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tg-sub {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.tg-categories {
  display: flex;
  gap: 6px;
  padding: 0 14px 14px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
}
.tg-categories::after {
  content: '';
  flex-shrink: 0;
  width: 40px;
}
.tg-categories:active { cursor: grabbing; }
.tg-categories::-webkit-scrollbar { display: none; }

.tg-cat {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .06em;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all .15s;
}
.tg-cat:hover { border-color: var(--orange); color: var(--orange); }
.tg-cat.active {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
}

.tg-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 14px;
}

.tg-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  cursor: pointer;
  transition: all .2s ease;
  position: relative;
  overflow: hidden;
}
.tg-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,107,53,.05), transparent);
  opacity: 0;
  transition: opacity .2s;
}
.tg-card:hover {
  border-color: var(--orange);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(255,107,53,.1);
}
.tg-card:hover::before { opacity: 1; }
.tg-card:active { transform: scale(.98); }
.tg-card.hidden { display: none; }

.tg-card-icon {
  font-size: 28px;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.tg-card-body { flex: 1; min-width: 0; }
.tg-card-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 3px;
  color: var(--white);
}
.tg-card-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tg-card-tag {
  display: none;
}

.tg-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 14px;
}

@media (min-width: 600px) {
  .tg-greeting { font-size: 26px; }
}

/* Input area */
#input-area {
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}

#input-row { display: flex; gap: 8px; align-items: flex-end; }

#chat-input {
  flex: 1;
  min-height: 44px;
  max-height: 130px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--white);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  padding: 10px 14px;
  outline: none;
  resize: none;
  overflow-y: auto;
  transition: border-color .15s;
  -webkit-overflow-scrolling: touch;
}
#chat-input:focus { border-color: var(--orange); }
#chat-input::placeholder { color: var(--muted2); }

#send-btn {
  width: 44px; height: 44px;
  border-radius: var(--r);
  border: none;
  background: var(--orange);
  color: #fff;
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all .12s;
  -webkit-appearance: none;
}
#send-btn:hover { background: var(--orange2); }
#send-btn:active { transform: scale(.95); }
#send-btn:disabled { opacity: .4; }

/* Mic button */
.mic-btn {
  width: 44px !important; height: 44px !important;
  border-radius: var(--r) !important;
  border: 1px solid var(--border) !important;
  background: transparent !important;
  color: var(--muted) !important;
  font-size: 18px !important;
  cursor: pointer;
  transition: all .15s;
}
.mic-btn:hover { border-color: var(--orange) !important; color: var(--orange) !important; }
.mic-btn.recording {
  background: rgba(255,82,82,.15) !important;
  border-color: var(--red) !important;
  color: var(--red) !important;
  animation: micPulse 1s ease infinite;
}
@keyframes micPulse { 0%,100%{box-shadow:0 0 0 0 rgba(255,82,82,.3)} 50%{box-shadow:0 0 0 8px rgba(255,82,82,0)} }
.mic-btn.hidden { display: none !important; }

/* AI status pill */
#status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .06em;
  transition: opacity .3s;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted2);
  transition: background .3s;
}
.status-dot.thinking { background: var(--orange); animation: pulse .9s ease infinite; }
.status-dot.done     { background: var(--green); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* Agent step progress */
#agent-steps {
  display: none;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--muted);
  max-height: 120px;
  overflow-y: auto;
}
#agent-steps.show { display: block; }
.step-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  transition: color .2s;
}
.step-item.active { color: var(--orange); }
.step-item.done { color: var(--green); }
.step-item.error { color: var(--red); }
.step-icon { width: 14px; text-align: center; flex-shrink: 0; }

/*────────────────────────────────────────
  CODE VIEW
────────────────────────────────────────*/
#view-code { background: var(--bg); }

.code-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.code-tabs::-webkit-scrollbar { display: none; }

.code-tab {
  font-family: var(--mono);
  font-size: 11px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all .12s;
  letter-spacing: .03em;
}
.code-tab.active { color: var(--white); border-bottom-color: var(--orange); }
.code-tab:hover:not(.active) { color: var(--white); }

#code-editor {
  flex: 1;
  background: var(--bg);
  color: #d4d0ff;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.75;
  padding: 16px;
  border: none;
  outline: none;
  resize: none;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
  -webkit-overflow-scrolling: touch;
}
#code-editor::-webkit-scrollbar { width: 4px; height: 4px; }
#code-editor::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

.code-footer {
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.code-stat {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .04em;
}

/*────────────────────────────────────────
  PREVIEW VIEW
────────────────────────────────────────*/
#view-preview { background: var(--surface); }

#preview-iframe {
  flex: 1;
  border: none;
  background: #fff;
  width: 100%;
}

.preview-bar {
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.preview-url-box {
  flex: 1;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.small-btn {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .05em;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all .12s;
}
.small-btn:hover { border-color: var(--orange); color: var(--orange); background: var(--orange-dim); }
.small-btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.small-btn.primary:hover { background: var(--orange2); }

/*────────────────────────────────────────
  BOTTOM NAV (mobile only)
────────────────────────────────────────*/
#bottom-nav {
  height: calc(58px + var(--safe-bottom));
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  padding-top: 6px;
  z-index: 50;
  flex-shrink: 0;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .06em;
  transition: color .15s;
  position: relative;
}
.nav-tab.active { color: var(--orange); }
.nav-tab .nav-icon { font-size: 20px; line-height: 1; }
.nav-tab .nav-label { text-transform: uppercase; }

.nav-badge {
  position: absolute;
  top: 4px; right: calc(50% - 18px);
  min-width: 16px; height: 16px;
  background: var(--orange);
  border-radius: 20px;
  font-size: 9px;
  font-family: var(--mono);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  display: none;
}
.nav-badge.show { display: flex; }

/*────────────────────────────────────────
  PROJECTS DRAWER
────────────────────────────────────────*/
#drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  display: none;
  backdrop-filter: blur(3px);
}
#drawer-overlay.open { display: block; }

#projects-drawer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-height: 85dvh;
  background: var(--bg2);
  border-top: 1px solid var(--border2);
  border-radius: 20px 20px 0 0;
  z-index: 201;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform .3s ease;
  padding-bottom: var(--safe-bottom);
}
#projects-drawer.open { transform: none; }

.drawer-handle {
  width: 36px; height: 4px;
  background: var(--border2);
  border-radius: 4px;
  margin: 12px auto 0;
  flex-shrink: 0;
}
.drawer-head {
  padding: 14px 18px 6px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.drawer-title { font-size: 20px; font-weight: 800; }
.drawer-count {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .06em;
  padding: 0 18px 12px;
}
.drawer-close { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; padding: 4px; }

#projects-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
}

.proj-row {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  gap: 10px;
  transition: all .15s ease;
}
.proj-row:hover {
  border-color: var(--orange);
  background: var(--surface2);
}
.proj-row-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  min-width: 0;
}
.proj-row-icon {
  font-size: 18px;
  flex-shrink: 0;
}
.proj-row-text {
  min-width: 0;
  flex: 1;
}
.proj-row-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.proj-row-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .04em;
  margin-top: 2px;
}
.proj-row-del {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.proj-row-del:hover {
  background: rgba(255,80,80,.12);
  color: var(--red);
}

.empty-projects {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}
.empty-projects .ep-icon { font-size: 3rem; margin-bottom: .75rem; }

/* Delete confirmation modal */
.del-confirm-sheet {
  max-width: 380px;
  margin: auto;
  text-align: center;
}
.del-confirm-target {
  font-weight: 800;
  font-size: 16px;
  color: var(--orange);
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 12px 0;
  word-break: break-word;
}
.modal-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--white);
  font-family: var(--font);
  font-size: 15px;
  padding: 12px 14px;
  border-radius: var(--r);
  outline: none;
  transition: border-color .12s;
  -webkit-appearance: none;
  margin-bottom: 4px;
}
.modal-input:focus {
  border-color: var(--orange);
}
.btn-danger {
  width: 100%;
  padding: 14px;
  background: var(--red, #e53e3e);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  margin-top: 12px;
  transition: opacity .15s;
}
.btn-danger:disabled {
  opacity: .35;
  cursor: not-allowed;
}
.btn-danger:not(:disabled):hover {
  opacity: .85;
}
.btn-cancel {
  width: 100%;
  padding: 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
  transition: all .15s;
}
.btn-cancel:hover {
  border-color: var(--muted);
  color: var(--white);
}

/*────────────────────────────────────────
  SAVE / SETTINGS MODALS
────────────────────────────────────────*/
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 300;
  display: none;
  align-items: flex-end;
  backdrop-filter: blur(4px);
  overflow-y: auto;
}
.modal-bg.open { display: flex; }

@media (min-width: 600px) {
  .modal-bg { align-items: center; justify-content: center; }
}

.modal-sheet {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 20px 20px 0 0;
  padding: 0 20px 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: sheetIn .25s ease;
}

@media (min-width: 600px) {
  .modal-sheet {
    border-radius: 16px;
    max-width: 440px;
    padding: 24px;
  }
}

@keyframes sheetIn { from{opacity:0;transform:translateY(30px)} to{opacity:1;transform:none} }

.modal-handle {
  width: 36px; height: 4px;
  background: var(--border2);
  border-radius: 4px;
  margin: 12px auto 16px;
}
@media (min-width: 600px) { .modal-handle { display: none; } }

.modal-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.modal-desc { font-size: 13px; color: var(--muted); margin-bottom: 20px; line-height: 1.6; }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.field label { font-family: var(--mono); font-size: 10px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.field input, .field textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--white);
  font-family: var(--font);
  font-size: 15px;
  padding: 12px 14px;
  border-radius: var(--r);
  outline: none;
  width: 100%;
  transition: border-color .12s;
  -webkit-appearance: none;
}
.field input:focus, .field textarea:focus { border-color: var(--orange); }
.field textarea { resize: vertical; min-height: 80px; font-size: 13px; font-family: var(--mono); }

.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-btn {
  flex: 1; padding: 14px;
  border-radius: var(--r);
  font-family: var(--mono);
  font-size: 12px; font-weight: 600;
  letter-spacing: .06em;
  border: 1px solid var(--border2);
  background: transparent; color: var(--muted);
  cursor: pointer; transition: all .12s;
}
.modal-btn:hover { border-color: var(--white); color: var(--white); }
.modal-btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.modal-btn.primary:hover { background: var(--orange2); }

/* Connected Accounts */
.settings-section {
  margin: 16px 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.settings-section-title {
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 12px;
  color: var(--white);
}
.connected-account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.connected-account:last-of-type { border-bottom: none; }
.connected-account-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.connected-account-icon { font-size: 20px; }
.connected-account-name { font-weight: 600; font-size: 13px; color: var(--white); }
.connected-account-status { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.connected-account-status.connected { color: var(--green); }
.connected-account-btn {
  padding: 6px 14px;
  background: none;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--muted);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.connected-account-btn:hover { border-color: var(--orange); color: var(--orange); }
.connected-account-btn.disconnect { color: var(--red); border-color: var(--red); }
.connected-account-btn.disconnect:hover { background: rgba(255,80,80,.1); }

/*────────────────────────────────────────
  TOAST
────────────────────────────────────────*/
#toast {
  position: fixed;
  bottom: calc(72px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface3);
  border: 1px solid var(--border2);
  color: var(--white);
  font-family: var(--mono);
  font-size: 12px;
  padding: 10px 20px;
  border-radius: 30px;
  z-index: 999;
  opacity: 0;
  transition: all .3s ease;
  pointer-events: none;
  white-space: nowrap;
  letter-spacing: .04em;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
@media (min-width: 900px) {
  #toast { bottom: 24px; }
}

/*────────────────────────────────────────
  SUBSCRIPTION GATE
────────────────────────────────────────*/
#sub-gate {
  position: fixed; inset: 0;
  background: rgba(15,14,26,.96);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(8px);
}
#sub-gate.show { display: flex; }

.sub-card {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 32px 24px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  animation: sheetIn .3s ease;
}
.sub-icon { font-size: 3rem; margin-bottom: 1rem; }
.sub-title { font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.sub-desc { font-size: 14px; color: var(--muted); line-height: 1.7; margin-bottom: 24px; }

.plan-cards { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.plan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; transition: border-color .15s;
  text-align: left;
}
.plan-card.featured { border-color: var(--orange); background: var(--orange-dim); }
.plan-card.best-value { border-color: var(--green); background: rgba(0,217,126,.06); position: relative; }
.plan-card.best-value:hover { border-color: var(--green); }
.plan-badge {
  position: absolute;
  top: -9px; right: 12px;
  background: var(--green);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  letter-spacing: .03em;
}
.plan-card:hover { border-color: var(--orange); }
.plan-info { flex: 1; }
.plan-name { font-weight: 600; font-size: 15px; }
.plan-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.plan-price { font-size: 22px; font-weight: 800; color: var(--orange); white-space: nowrap; }
.plan-price span { font-size: 12px; color: var(--muted); font-weight: 400; }

.sub-note { font-size: 12px; color: var(--muted2); line-height: 1.6; }

/*────────────────────────────────────────
  ONBOARDING
────────────────────────────────────────*/
#onboarding {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
}
.ob-logo { font-size: 40px; font-weight: 800; margin-bottom: 8px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.ob-logo em { color: var(--orange); font-style: normal; }
.ob-logo svg { flex-shrink: 0; }
.ob-tagline { font-size: 15px; color: var(--muted); margin-bottom: 24px; line-height: 1.6; }
.ob-feature { display: flex; align-items: flex-start; gap: 10px; text-align: left; margin-bottom: 10px; }
.ob-feature-icon { font-size: 20px; flex-shrink: 0; margin-top: 2px; }
.ob-feature-text h4 { font-size: 14px; font-weight: 600; margin-bottom: 1px; }
.ob-feature-text p { font-size: 12px; color: var(--muted); line-height: 1.4; }
.ob-cta {
  width: 100%; padding: 16px;
  background: var(--orange);
  border: none; border-radius: var(--r);
  color: #fff; font-family: var(--font);
  font-size: 16px; font-weight: 700;
  cursor: pointer; margin-top: 32px;
  transition: background .12s;
}
.ob-cta:hover { background: var(--orange2); }
.ob-name-field {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--white);
  font-family: var(--font);
  font-size: 16px;
  padding: 14px;
  border-radius: var(--r);
  outline: none;
  margin-top: 12px;
  text-align: center;
  transition: border-color .12s;
  -webkit-appearance: none;
}
.ob-name-field:focus { border-color: var(--orange); }

/*────────────────────────────────────────
  AUTH SCREEN
────────────────────────────────────────*/
#auth-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 32px 24px;
  padding-bottom: calc(32px + var(--safe-bottom));
  text-align: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#auth-screen.hidden { display: none; }

.auth-card {
  width: 100%;
  max-width: 380px;
  padding-bottom: 40px;
}
.auth-tabs {
  display: flex;
  margin-bottom: 24px;
  border-radius: var(--r);
  overflow: hidden;
  border: 1px solid var(--border);
}
.auth-tab {
  flex: 1;
  padding: 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .06em;
  cursor: pointer;
  transition: all .15s;
}
.auth-tab.active {
  background: var(--orange);
  color: #fff;
}
.auth-error {
  background: rgba(255,82,82,.1);
  border: 1px solid var(--red);
  color: var(--red);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  margin-bottom: 14px;
  display: none;
}
.auth-error.show { display: block; }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted2);
  font-size: 12px;
  font-family: var(--mono);
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.auth-footer {
  margin-top: 20px;
  font-size: 13px;
  color: var(--muted);
}
.auth-footer a {
  color: var(--orange);
  cursor: pointer;
  text-decoration: none;
}
.auth-footer a:hover { text-decoration: underline; }

/* Google auth button */
.google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  margin-top: 24px;
  border-radius: var(--r);
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--white);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  -webkit-appearance: none;
}
.google-btn:hover {
  border-color: var(--white);
  background: var(--surface2);
}
.google-btn:active { transform: scale(.98); }
.google-btn svg { flex-shrink: 0; }

/* User pill in topbar */
.user-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .04em;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.user-pill .tier-badge {
  font-size: 8px;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--orange-dim);
  color: var(--orange);
  border: 1px solid rgba(255,107,53,.3);
  text-transform: uppercase;
  letter-spacing: .08em;
}
