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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0f0f0f;
  color: #f4f4f5;
  overflow: hidden;
}

/* ── Auth overlay ────────────────────────────────────────────────────────── */

.auth-overlay {
  position: fixed;
  inset: 0;
  background: #0f0f0f;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.auth-card {
  width: 360px;
  background: #18181b;
  border: 1px solid #27272a;
  border-radius: 12px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-align: center;
  color: #f4f4f5;
}

.auth-tagline {
  font-size: 13px;
  color: #71717a;
  text-align: center;
  margin-top: -12px;
}

.auth-tabs {
  display: flex;
  border: 1px solid #27272a;
  border-radius: 8px;
  overflow: hidden;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  color: #71717a;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.auth-tab.active {
  background: #27272a;
  color: #f4f4f5;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-form input {
  padding: 9px 12px;
  border-radius: 8px;
  background: #09090b;
  border: 1px solid #3f3f46;
  color: #f4f4f5;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.auth-form input::placeholder { color: #52525b; }
.auth-form input:focus { border-color: #71717a; }

.auth-form button {
  padding: 10px;
  border-radius: 8px;
  background: #f4f4f5;
  color: #18181b;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 4px;
}

.auth-form button:hover { background: #e4e4e7; }

.auth-error {
  font-size: 12px;
  color: #f87171;
  min-height: 16px;
}

/* ── App shell ───────────────────────────────────────────────────────────── */

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid #27272a;
  flex-shrink: 0;
  gap: 12px;
}

.logo { font-weight: 600; letter-spacing: -0.02em; }

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

.header-user {
  font-size: 12px;
  color: #a1a1aa;
}

.credits-badge {
  font-size: 12px;
  color: #34d399;
  background: rgba(6,78,59,0.3);
  border: 1px solid rgba(6,95,70,0.4);
  border-radius: 20px;
  padding: 2px 10px;
}

.logout-btn {
  font-size: 12px;
  color: #71717a;
  background: none;
  border: 1px solid #3f3f46;
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.logout-btn:hover { color: #f4f4f5; border-color: #71717a; }

#ws-status { font-size: 12px; }
.status-connecting  { color: #facc15; }
.status-connected   { color: #34d399; }
.status-disconnected{ color: #71717a; }
.status-error       { color: #f87171; }

/* ── Body layout ─────────────────────────────────────────────────────────── */

.body { display: flex; flex: 1; overflow: hidden; }

/* ── Projects sidebar ────────────────────────────────────────────────────── */

.projects-sidebar {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #27272a;
  background: #0f0f0f;
  overflow: hidden;
  transition: width 0.2s ease;
}

.projects-sidebar.collapsed {
  width: 37px;
}
.projects-sidebar.collapsed .sidebar-title,
.projects-sidebar.collapsed .new-project-btn,
.projects-sidebar.collapsed .project-list {
  display: none;
}
.projects-sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 12px 6px 10px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 10px;
  border-bottom: 1px solid #27272a;
  flex-shrink: 0;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sidebar-toggle-btn {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: none;
  border: 1px solid #3f3f46;
  color: #71717a;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  padding: 0;
}
.sidebar-toggle-btn:hover { color: #f4f4f5; border-color: #71717a; }

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #52525b;
}

.new-project-btn {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: none;
  border: 1px solid #3f3f46;
  color: #71717a;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  padding: 0;
}
.new-project-btn:hover { color: #f4f4f5; border-color: #71717a; }

.project-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.project-item {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 6px;
  margin: 0 6px 2px;
  transition: background 0.12s;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
}
.project-item:hover { background: #18181b; }
.project-item.active { background: #27272a; }

.project-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.project-name {
  font-size: 12px;
  color: #d4d4d8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.project-item.active .project-name { color: #f4f4f5; }

.project-date {
  font-size: 10px;
  color: #52525b;
}

.project-rename-btn {
  opacity: 0;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: none;
  border: none;
  color: #71717a;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  padding: 0;
}
.project-item:hover .project-rename-btn { opacity: 1; }
.project-rename-btn:hover { color: #f4f4f5; background: #3f3f46; }

.project-rename-input {
  width: 100%;
  background: #27272a;
  border: 1px solid #52525b;
  border-radius: 4px;
  color: #f4f4f5;
  font-size: 12px;
  font-family: inherit;
  padding: 2px 4px;
  outline: none;
}
.project-rename-input:focus { border-color: #71717a; }

.project-empty {
  padding: 20px 12px;
  font-size: 12px;
  color: #52525b;
  text-align: center;
}

/* ── Chat pane ───────────────────────────────────────────────────────────── */

.chat-pane {
  width: 420px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #27272a;
}

.chat-header {
  padding: 8px 16px;
  border-bottom: 1px solid #27272a;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 500;
  color: #a1a1aa;
  min-height: 37px;
  display: flex;
  align-items: center;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: #71717a;
  gap: 12px;
  user-select: none;
}
.empty-state .icon { font-size: 36px; }
.empty-state p { font-size: 14px; max-width: 240px; }

.msg-row { display: flex; }
.msg-row.user      { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.bubble {
  max-width: 85%;
  border-radius: 18px;
  padding: 10px 16px;
  font-size: 14px;
  line-height: 1.5;
}
.bubble.user {
  background: #f4f4f5;
  color: #18181b;
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  background: #27272a;
  color: #f4f4f5;
  border-bottom-left-radius: 4px;
}

.msg-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #71717a;
  padding: 2px 0;
}

.status-timer {
  font-size: 11px;
  color: #52525b;
  margin-left: 2px;
}
.msg-error {
  font-size: 12px;
  color: #f87171;
  background: rgba(127,29,29,0.4);
  border: 1px solid rgba(153,27,27,0.3);
  border-radius: 8px;
  padding: 8px 12px;
}
.msg-waiting {
  font-size: 12px;
  color: #fbbf24;
  background: rgba(120,53,15,0.3);
  border: 1px solid rgba(146,64,14,0.3);
  border-radius: 8px;
  padding: 8px 12px;
}
.msg-complete {
  font-size: 12px;
  color: #34d399;
  background: rgba(6,78,59,0.3);
  border: 1px solid rgba(6,95,70,0.3);
  border-radius: 8px;
  padding: 8px 12px;
}

.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 1.5px solid #52525b;
  border-top-color: #a1a1aa;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.question-banner {
  margin: 0 16px 8px;
  padding: 8px 12px;
  background: rgba(120,53,15,0.5);
  border: 1px solid rgba(146,64,14,0.5);
  border-radius: 8px;
  color: #fde68a;
  font-size: 13px;
}
.question-banner strong { font-weight: 600; }

.input-area {
  padding: 16px;
  border-top: 1px solid #27272a;
  display: flex;
  gap: 8px;
}

textarea {
  flex: 1;
  resize: none;
  border-radius: 8px;
  background: #18181b;
  border: 1px solid #3f3f46;
  color: #f4f4f5;
  font-size: 14px;
  font-family: inherit;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
}
textarea::placeholder { color: #71717a; }
textarea:focus { border-color: #71717a; }
textarea:disabled { opacity: 0.4; }

.send-btn {
  align-self: flex-end;
  padding: 8px 16px;
  border-radius: 8px;
  background: #f4f4f5;
  color: #18181b;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.send-btn:hover:not(:disabled) { background: #e4e4e7; }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Preview pane ────────────────────────────────────────────────────────── */

.preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #09090b;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid #27272a;
  background: #18181b;
  flex-shrink: 0;
}

.traffic-lights { display: flex; gap: 6px; flex-shrink: 0; }
.traffic-lights span { width: 12px; height: 12px; border-radius: 50%; background: #3f3f46; }

.url-bar {
  flex: 1;
  margin: 0 8px;
  padding: 4px 12px;
  border-radius: 4px;
  background: #27272a;
  font-size: 12px;
  color: #a1a1aa;
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: all;
}

.toolbar-btn {
  background: none;
  border: none;
  color: #71717a;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 0.15s;
  text-decoration: none;
  line-height: 1;
}
.toolbar-btn:hover { color: #e4e4e7; }
.toolbar-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.preview-area { position: relative; flex: 1; overflow: hidden; }

.preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #52525b;
  gap: 8px;
  user-select: none;
}
.preview-empty .icon { font-size: 48px; }
.preview-empty p { font-size: 14px; }

.preview-processing {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #71717a;
  gap: 12px;
  z-index: 10;
  background: rgba(9,9,11,0.8);
  backdrop-filter: blur(4px);
}
.spinner-large {
  width: 32px; height: 32px;
  border: 2px solid #3f3f46;
  border-top-color: #d4d4d8;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.preview-processing p { font-size: 14px; }

#preview-iframe { width: 100%; height: 100%; border: 0; display: none; }
