@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Clean ChatGPT-inspired Light Theme */
  --bg-main: #ffffff;
  --bg-subtle: #f9f9f8;
  --bg-user-bubble: #f4f4f2;
  --bg-composer: #f4f4f2;
  --bg-popover: #ffffff;
  --border: #e5e5e2;
  --border-focus: #d1d1cc;

  --text-primary: #0d0d0d;
  --text-secondary: #5d5d5b;
  --text-muted: #8e8e8a;

  --accent-btn: #0d0d0d;
  --accent-btn-fg: #ffffff;
  --accent-btn-hover: #2b2b2b;

  --shadow-composer: 0 2px 12px rgba(0, 0, 0, 0.04);
  --shadow-popover: 0 8px 30px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Minimal Top Bar (ChatGPT Style) */
.topbar {
  height: 54px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--bg-main);
  border-bottom: 1px solid transparent;
  z-index: 10;
  gap: 8px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.model-selector {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  max-width: 170px;
  text-overflow: ellipsis;
}

.model-selector:hover {
  background: var(--bg-user-bubble);
}

.status-label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 4px 8px;
  border-radius: 999px;
  transition: background 0.15s ease;
}

.status-label:hover {
  background: var(--bg-user-bubble);
  color: var(--text-primary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10a37f;
  flex-shrink: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-user-bubble);
  color: var(--text-primary);
}

/* Top-Right Small Version Control Badge */
.version-badge {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: -0.01em;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.version-badge:hover {
  background: var(--bg-user-bubble);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

/* Version History & Checklist Cards inside Modal */
.version-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.version-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.version-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.version-tag {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-main);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 5px;
  color: var(--text-primary);
}

.version-tag.current {
  background: #0d0d0d;
  color: #ffffff;
  border-color: #0d0d0d;
}

.version-date {
  font-size: 11px;
  color: var(--text-muted);
}

.version-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.version-summary {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.version-changes {
  margin-top: 4px;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-secondary);
}

/* Centered Scrollable Chat Thread */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 28px 16px;
  scroll-behavior: smooth;
}

.chat-column {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Message Turns */
.turn {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Assistant Turn (Left-aligned, clean borderless ChatGPT style) */
.turn.assistant {
  align-items: flex-start;
}

.assistant-wrap {
  display: flex;
  gap: 12px;
  width: 100%;
  align-items: flex-start;
}

.assistant-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.assistant-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 15.2px;
  line-height: 1.65;
  color: var(--text-primary);
  word-wrap: break-word;
}

.assistant-body p {
  margin: 0;
}

/* User Turn (Right-aligned soft pill like ChatGPT) */
.turn.user {
  align-items: flex-end;
}

.user-bubble {
  max-width: 78%;
  background: var(--bg-user-bubble);
  color: var(--text-primary);
  padding: 12px 16px;
  border-radius: 22px;
  font-size: 15.2px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Attachment Chip inside User Message or Composer */
.attachment-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.attachment-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 12.5px;
  max-width: 100%;
}

.attachment-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.attachment-thumb {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* Drag and Drop Overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 13, 13, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  pointer-events: none;
}

.drop-overlay.active {
  display: flex;
}

.drop-overlay-box {
  background: var(--bg-main);
  color: var(--text-primary);
  border: 2px dashed var(--text-primary);
  border-radius: 16px;
  padding: 28px 36px;
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow-popover);
}

.attachment-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.attachment-name {
  font-weight: 600;
  color: var(--text-primary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-meta {
  font-size: 11px;
  color: var(--text-muted);
}

/* Typing Cursor Dot during Streaming */
.streaming-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-primary);
  margin-left: 5px;
  vertical-align: middle;
  animation: pulseDot 1s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

/* Floating Jump to Bottom Pill */
.jump-btn {
  position: fixed;
  bottom: 118px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-main);
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-popover);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
}

/* Bottom Centered Composer (ChatGPT Pill Style + Safe Area Insets) */
.composer-area {
  padding: 0 16px calc(16px + env(safe-area-inset-bottom, 0px)) 16px;
  background: var(--bg-main);
  flex-shrink: 0;
}

.composer-box {
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg-composer);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 9px 12px 9px 12px;
  box-shadow: var(--shadow-composer);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  transition: border-color 0.15s ease;
}

.composer-box:focus-within {
  border-color: var(--border-focus);
}

.staged-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.plus-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-main);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.plus-btn:hover {
  background: var(--bg-subtle);
}

/* 16px font-size prevents iOS Safari from auto-zooming on focus */
.composer-textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  resize: none;
  max-height: 150px;
  min-height: 26px;
  padding: 5px 0;
  outline: none;
}

.composer-textarea::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent-btn);
  color: var(--accent-btn-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.send-btn:hover {
  background: var(--accent-btn-hover);
}

.send-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Dynamic Step-Aware Helper Chips */
.context-chips {
  max-width: var(--max-col-width);
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.context-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.context-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: #d0d0d0;
}

.context-chip.primary {
  background: #f0fdf4;
  color: #15803d;
  border-color: #bbf7d0;
  font-weight: 600;
}

.context-chip.primary:hover {
  background: #dcfce7;
}

.subfield-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.subfield-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.subfield-pill.done {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #15803d;
  font-weight: 500;
}

/* Plus Menu Popover */
.plus-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 8px;
  width: 280px;
  max-width: calc(100vw - 32px);
  background: var(--bg-popover);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-popover);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 30;
}

.plus-popover.open {
  display: flex;
}

.popover-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 6px 10px 3px 10px;
}

.popover-item {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  text-align: left;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.popover-item:hover {
  background: var(--bg-user-bubble);
}

.popover-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.composer-footer {
  max-width: 720px;
  margin: 8px auto 0 auto;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-muted);
}

/* Modal (Alternative Form, Checklist & Version History) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 12px;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: var(--bg-popover);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-popover);
  width: 540px;
  max-width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.full {
  grid-column: span 2;
}

.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  padding: 9px 11px;
  border-radius: 8px;
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--border-focus);
}

/* Mobile Responsive Optimizations */
@media (max-width: 640px) {
  .topbar {
    height: 50px;
    padding: 0 10px;
    border-bottom: 1px solid var(--border);
  }

  .topbar-left {
    gap: 6px;
  }

  .model-selector {
    font-size: 13.5px;
    padding: 5px 6px;
    max-width: 115px;
  }

  .status-label {
    font-size: 11px;
    padding: 3px 6px;
  }

  .topbar-right {
    gap: 5px;
  }

  .icon-btn {
    font-size: 11.5px;
    padding: 5px 8px;
  }

  .version-badge {
    font-size: 10px;
    padding: 4px 6px;
  }

  .chat-scroll {
    padding: 16px 12px 20px 12px;
  }

  .chat-column {
    gap: 20px;
  }

  .assistant-wrap {
    gap: 10px;
  }

  .assistant-avatar {
    width: 26px;
    height: 26px;
    font-size: 10.5px;
  }

  .assistant-body {
    font-size: 15px;
    line-height: 1.6;
  }

  .user-bubble {
    max-width: 86%;
    font-size: 15px;
    padding: 10px 15px;
  }

  .composer-area {
    padding: 0 10px calc(10px + env(safe-area-inset-bottom, 0px)) 10px;
  }

  .composer-box {
    border-radius: 22px;
    padding: 8px 10px;
  }

  .composer-footer {
    font-size: 10.5px;
    margin-top: 6px;
    padding: 0 4px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-group.full {
    grid-column: span 1;
  }
}
