/* =============================================
   PromptCompiler V2 — ChatGPT-Style UI
   style.css
   ============================================= */

/* ---- Tokens ---- */
:root {
  /* Core colors — mirroring ChatGPT dark theme */
  --sidebar-bg:    #171717;
  --sidebar-hover: #2a2a2a;
  --sidebar-active:#2a2a2a;
  --main-bg:       #212121;
  --surface:       #2f2f2f;
  --surface-hover: #3a3a3a;
  --input-bg:      #2f2f2f;
  --border:        rgba(255,255,255,0.08);
  --border-light:  rgba(255,255,255,0.05);

  /* Accent — ChatGPT green */
  --accent:        #10a37f;
  --accent-hover:  #0d8a6a;
  --accent-dim:    rgba(16,163,127,0.15);
  --accent-border: rgba(16,163,127,0.3);

  /* Prompt card accents */
  --plan-color:     #5b8af0;
  --plan-dim:       rgba(91,138,240,0.1);
  --plan-border:    rgba(91,138,240,0.25);

  --build-color:    #10a37f;
  --build-dim:      rgba(16,163,127,0.1);
  --build-border:   rgba(16,163,127,0.25);

  --opt-color:      #f0a050;
  --opt-dim:        rgba(240,160,80,0.1);
  --opt-border:     rgba(240,160,80,0.25);

  /* Text */
  --text-primary:   #ececec;
  --text-secondary: #b4b4b4;
  --text-muted:     #6b6b6b;
  --text-dim:       #8e8ea0;

  /* Sizing */
  --sidebar-w:      260px;
  --topbar-h:       56px;
  --input-max:      720px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;

  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--main-bg);
  color: var(--text-primary);
  height: 100%;
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; font-family: var(--font); border: none; outline: none; }
select { font-family: var(--font); cursor: pointer; outline: none; }
textarea { font-family: var(--font); resize: none; outline: none; border: none; }

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  border-right: 1px solid var(--border);
  transition: transform 0.25s ease;
  z-index: 50;
}

.sidebar-top {
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
}

.logo-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.logo-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.logo-v2 {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 2px;
}

/* New Chat Button */
.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.new-chat-btn:hover {
  background: var(--sidebar-hover);
  border-color: rgba(255,255,255,0.15);
}

/* Sidebar section */
.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.sidebar-section::-webkit-scrollbar { width: 4px; }
.sidebar-section::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 6px 6px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.15s ease;
  text-decoration: none;
}

.history-item:hover { background: var(--sidebar-hover); }
.history-item.active { background: var(--sidebar-active); }

.history-item svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

.history-item-text {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
}

.supported-models {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
}

/* =============================================
   MAIN LAYOUT
   ============================================= */
.main-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---- Topbar (mobile + desktop options) ---- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--main-bg);
  flex-shrink: 0;
}

.topbar-menu {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: var(--r-sm);
  transition: all 0.15s ease;
  display: none; /* hidden on desktop */
}

.topbar-menu:hover {
  background: var(--surface);
  color: var(--text-primary);
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: none; /* hidden on desktop */
}

.topbar-options {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.top-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 28px 6px 10px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: all 0.15s ease;
}

.top-select:hover, .top-select:focus {
  border-color: rgba(255,255,255,0.2);
  color: var(--text-primary);
}

/* =============================================
   CHAT AREA
   ============================================= */
.chat-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar { width: 6px; }
.chat-area::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
}
.chat-area::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.15);
}

/* ---- Welcome Screen ---- */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 60px 24px 40px;
  text-align: center;
}

.welcome-icon {
  width: 64px; height: 64px;
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  border-radius: var(--r-xl);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
}

.welcome-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
  letter-spacing: -0.5px;
}

.welcome-sub {
  font-size: 15px;
  color: var(--text-dim);
  margin-bottom: 44px;
  max-width: 400px;
}

/* Suggestion chips */
.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 640px;
  width: 100%;
}

.suggestion-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.2s ease;
}

.suggestion-chip:hover {
  background: var(--surface-hover);
  border-color: rgba(255,255,255,0.15);
  transform: translateY(-1px);
}

.chip-icon {
  font-size: 22px;
  line-height: 1;
  margin-bottom: 6px;
}

.chip-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.chip-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* =============================================
   MESSAGES
   ============================================= */
.messages-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 28px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* User message */
.msg-user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 24px;
  animation: msg-in 0.25s ease;
}

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

.msg-user-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px 18px 4px 18px;
  padding: 12px 18px;
  max-width: 75%;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* AI response row */
.msg-ai {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 32px;
  animation: msg-in 0.3s ease;
}

.msg-ai-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  color: #fff;
}

.msg-ai-body {
  flex: 1;
  min-width: 0;
}

.msg-ai-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}

/* ---- Thinking indicator ---- */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
}

.thinking-dot {
  width: 7px; height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: think-bounce 1.2s ease-in-out infinite;
}

.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes think-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* ---- Prompt Cards ---- */
.prompt-cards-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prompt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.prompt-card:hover { border-color: rgba(255,255,255,0.14); }

/* Card top strip */
.card-strip {
  height: 3px;
}
.strip-plan    { background: var(--plan-color); }
.strip-build   { background: var(--build-color); }
.strip-opt     { background: var(--opt-color); }

/* Card header */
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-num {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.num-plan  { background: var(--plan-dim);  color: var(--plan-color);  border: 1px solid var(--plan-border); }
.num-build { background: var(--build-dim); color: var(--build-color); border: 1px solid var(--build-border); }
.num-opt   { background: var(--opt-dim);   color: var(--opt-color);   border: 1px solid var(--opt-border); }

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.card-copy-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  transition: all 0.15s ease;
}

.card-copy-btn:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
  border-color: rgba(255,255,255,0.15);
}

.card-copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-dim);
}

/* Card body */
.card-body {
  padding: 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.85;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
}

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

/* Card toggle (expand/collapse) */
.card-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px;
  background: transparent;
  border-top: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.card-toggle:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
}

/* Stats bar */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0 0;
  flex-wrap: wrap;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.stat-item svg { flex-shrink: 0; }

.confidence-badge {
  color: var(--accent);
}

.confidence-badge svg {
  color: var(--accent);
}

.ai-analysis {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--r-md);
  padding: 12px 16px;
  margin-bottom: 14px;
  font-style: italic;
}

/* Copy All */
.copy-all-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.copy-all-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  border-radius: var(--r-md);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 11px 20px;
  transition: all 0.2s ease;
}

.copy-all-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.regen-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 11px 16px;
  transition: all 0.2s ease;
}

.regen-btn:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
  border-color: rgba(255,255,255,0.15);
}

/* =============================================
   INPUT BAR
   ============================================= */
.input-bar-wrapper {
  padding: 12px 24px 20px;
  background: var(--main-bg);
  flex-shrink: 0;
}

.input-bar {
  max-width: var(--input-max);
  margin: 0 auto;
  background: var(--input-bg);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--r-xl);
  padding: 12px 14px 10px;
  transition: border-color 0.2s ease;
}

.input-bar:focus-within {
  border-color: rgba(255,255,255,0.22);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

/* Options strip */
.input-options {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.option-pill-group {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px 10px;
}

.option-pill-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.option-pill-select {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 0 14px 0 4px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0 center;
}

.option-pill-select:focus { color: var(--text-primary); }

.detected-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  border-radius: 100px;
  padding: 4px 10px;
  margin-left: 2px;
}

.detected-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

#detected-text {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

/* Textarea row */
.textarea-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat-input {
  flex: 1;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
  padding: 2px 0;
  max-height: 200px;
  overflow-y: auto;
  caret-color: var(--accent);
}

.chat-input::placeholder {
  color: var(--text-muted);
}

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

/* Send Button */
.send-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  transform-origin: center;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.send-btn:disabled {
  background: var(--surface-hover);
  color: var(--text-muted);
  cursor: not-allowed;
}

.send-btn.loading {
  background: var(--surface-hover);
  cursor: not-allowed;
}

.send-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 2px 0;
  text-align: center;
}

.input-hint kbd {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 3px;
  padding: 0 4px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
}

/* =============================================
   TOAST
   ============================================= */
.toast {
  position: fixed;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 9999;
  background: var(--surface-hover);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--r-md);
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    z-index: 50;
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.show {
    display: block;
  }

  .topbar-menu,
  .topbar-title { display: flex; }

  .topbar-options { display: none; }

  .suggestion-grid {
    grid-template-columns: 1fr;
  }

  .welcome-title { font-size: 20px; }

  .input-bar-wrapper {
    padding: 8px 12px 16px;
  }

  .input-options {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
  }

  .input-options::-webkit-scrollbar { height: 0; }
}

@media (min-width: 769px) {
  .topbar {
    display: none; /* hide topbar on desktop — sidebar handles nav */
  }
}
