/* style.css */

/* ── Reset & base ─────────────────────────────────────────────────────── */

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

:root {
  --bg:        #000;
  --surface:   #111;
  --surface2:  #1a1a1a;
  --surface3:  #232323;
  --border:    rgba(255,255,255,0.08);
  --text:      rgba(255,255,255,0.9);
  --text-sub:  rgba(255,255,255,0.45);
  --text-muted:rgba(255,255,255,0.28);
  --accent:    #bf5af2;
  --accent-b:  #32ade6;
  --radius:    12px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono:      'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, monospace;

  /* Apple Intelligence gradient */
  --ai-grad: linear-gradient(90deg,
    #bf5af2 0%,
    #ff375f 20%,
    #ff9f0a 40%,
    #30d158 60%,
    #32ade6 80%,
    #bf5af2 100%
  );
}

html, body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Page content (AI builds here) ───────────────────────────────────── */

#page-content {
  min-height: 100vh;
  width: 100%;
  position: relative;
}

/* ── Build overlay ────────────────────────────────────────────────────── */

#build-overlay {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: var(--bg);
  transition: opacity 0.45s ease;
  pointer-events: none;
}

#build-overlay[hidden] { display: none; }
#build-overlay.fade-out { opacity: 0; }

#build-status {
  font-size: 13px;
  color: var(--text-sub);
  letter-spacing: 0.015em;
  min-height: 1.4em;
  text-align: center;
  max-width: 320px;
  transition: color 0.3s;
}

#progress-container {
  width: 260px;
  height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 99px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: var(--ai-grad);
  background-size: 200% 100%;
  animation: ai-shimmer 2.5s linear infinite;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes ai-shimmer {
  from { background-position: 0% 0%; }
  to   { background-position: -200% 0%; }
}

/* ── Model picker overlay ─────────────────────────────────────────────── */

#model-picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

#model-picker-overlay[hidden] { display: none; }

.picker-box {
  width: min(460px, calc(100vw - 40px));
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7);
  animation: picker-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes picker-in {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.picker-logo {
  display: flex;
  align-items: center;
  justify-content: center;
}

.picker-logo-bar {
  width: 48px;
  height: 4px;
  border-radius: 99px;
  background: var(--ai-grad);
  background-size: 200% 100%;
  animation: ai-shimmer 2.5s linear infinite;
}

.picker-title {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  letter-spacing: -0.02em;
}

.picker-sub {
  text-align: center;
  color: var(--text-sub);
  font-size: 13px;
  margin-top: -12px;
}

.picker-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.picker-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.picker-field textarea {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 12px 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.5;
}

.picker-field textarea:focus {
  border-color: rgba(191,90,242,0.5);
}

.picker-field textarea::placeholder { color: var(--text-muted); }

.picker-models {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface3);
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
  user-select: none;
}

.model-option:not(.disabled):hover {
  border-color: rgba(191,90,242,0.35);
  background: rgba(191,90,242,0.05);
}

.model-option input[type="radio"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.model-option.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.model-option-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.model-name { font-weight: 500; font-size: 14px; }
.model-sub  { font-size: 12px; color: var(--text-sub); }

.model-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 99px;
  flex-shrink: 0;
}

.model-badge.available   { background: rgba(48,209,88,0.15);  color: #30d158; }
.model-badge.unavailable { background: rgba(255,55,55,0.12);  color: #ff453a; }

.ollama-row { padding: 0 4px; }
.ollama-row.hidden { display: none; }

.ollama-row select {
  width: 100%;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  cursor: pointer;
}

/* ── Shared button styles ─────────────────────────────────────────────── */

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

.btn-primary:hover  { opacity: 0.88; }
.btn-primary:active { transform: scale(0.97); }
.btn-generate { width: 100%; padding: 13px; }

/* ── Warning overlay ──────────────────────────────────────────────────── */

#warning-overlay {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
  overflow-y: auto;
}

#warning-overlay[hidden] { display: none; }

.warning-box {
  max-width: 540px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 8px 0;
}

.warning-icon { font-size: 28px; color: #ff9f0a; }

.warning-box h2 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.warning-box p { color: var(--text-sub); line-height: 1.6; }

.warning-section {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.warning-section h3 {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(255,255,255,0.08);
  color: var(--text-sub);
}

.warning-section ol {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--text-sub);
  font-size: 13px;
}

.warning-section li { line-height: 1.5; }
.warning-section a { color: var(--accent-b); text-decoration: none; }
.warning-section a:hover { text-decoration: underline; }

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(255,255,255,0.07);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ── Chat box ─────────────────────────────────────────────────────────── */

#chat-box {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 850;
  width: 380px;
  max-height: 540px;
  display: flex;
  flex-direction: column;
  background: rgba(18,18,18,0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.03) inset;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
}

#chat-box[hidden] { display: none !important; }
#chat-box.visible { opacity: 1; transform: translateY(0) scale(1); }

#chat-box.collapsed .chat-body,
#chat-box.collapsed #chat-footer { display: none; }

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.chat-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  background: var(--ai-grad);
  background-size: 200% 100%;
  animation: ai-shimmer 3s linear infinite;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-header-right select {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 11px;
  padding: 4px 7px;
  outline: none;
  cursor: pointer;
  max-width: 140px;
}

.chat-header-right button {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-sub);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.chat-header-right button:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 4px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 99px; }

.chat-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 20px 0;
}

.chat-message { display: flex; flex-direction: column; gap: 5px; }
.chat-message.user      { align-items: flex-end; }
.chat-message.assistant { align-items: flex-start; }

.msg-bubble {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 14px 14px 4px 14px;
  padding: 9px 13px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 90%;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-content {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  max-width: 100%;
  word-break: break-word;
}

.msg-content.streaming { color: rgba(255,255,255,0.75); }

.cursor {
  display: inline-block;
  animation: blink 0.8s step-end infinite;
  opacity: 0.7;
  font-size: 0.85em;
}

@keyframes blink {
  0%, 100% { opacity: 0.7; }
  50%       { opacity: 0; }
}

.reasoning-wrap { max-width: 100%; margin-bottom: 3px; }

.reasoning-streaming {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 0;
  font-style: italic;
}

.reasoning-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  padding: 3px 0;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s;
  text-align: left;
}

.reasoning-toggle:hover { color: var(--text-sub); }
.reasoning-toggle .toggle-arrow { font-size: 8px; }

.reasoning-body {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 10px;
  border-left: 1.5px solid var(--surface3);
}

.reasoning-body.hidden { display: none; }

.thinking-block {
  font-size: 12px;
  color: var(--text-sub);
  font-style: italic;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.tool-use-row { display: flex; flex-direction: column; gap: 4px; }

.tool-use-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  padding: 2px 0;
  display: flex;
  align-items: center;
  gap: 5px;
  text-align: left;
  transition: color 0.15s;
}

.tool-use-toggle:hover { color: var(--text-sub); }
.tool-use-toggle code  { color: #bf5af2; font-size: 11px; }
.tool-pending          { color: var(--text-muted); font-style: italic; }

.tool-use-body {
  padding: 8px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-use-body.hidden { display: none; }

.tl {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 3px;
}

.tool-use-body pre {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-sub);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.msg-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 5px;
  transition: color 0.15s, background 0.15s;
}

.msg-action-btn:hover {
  color: var(--text-sub);
  background: rgba(255,255,255,0.05);
}

.chat-message.user      .msg-action-btn { align-self: flex-end; }
.chat-message.assistant .msg-action-btn { align-self: flex-start; }

#chat-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  resize: none;
  min-height: 38px;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.18s;
  line-height: 1.45;
  scrollbar-width: thin;
}

#chat-input:focus       { border-color: rgba(191,90,242,0.4); }
#chat-input::placeholder { color: var(--text-muted); }

#chat-send {
  background: var(--accent);
  border: none;
  border-radius: 9px;
  color: #fff;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.12s;
}

#chat-send:hover  { opacity: 0.85; }
#chat-send:active { transform: scale(0.93); }
#chat-send svg    { width: 14px; height: 14px; }

@media (max-width: 480px) {
  #chat-box { right: 10px; bottom: 10px; left: 10px; width: auto; }
}
