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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #232733;
  --border: #2e3345;
  --text: #e4e7f0;
  --text-muted: #8b90a5;
  --primary: #6c8aff;
  --primary-hover: #8aa2ff;
  --accent: #c084fc;
  --success: #4ade80;
  --error: #f87171;
  --chat-user: #2a3a5c;
  --chat-ai: #1e2535;
  --tool-bg: #1a2332;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

.screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Upload Screen */
.upload-container {
  margin: auto;
  text-align: center;
  max-width: 480px;
  padding: 2rem;
}

.upload-icon {
  color: var(--primary);
  margin-bottom: 1.5rem;
}

.upload-container h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.file-label {
  display: block;
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 2.5rem 1.5rem;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 1rem;
}

.file-label:hover, .file-label.dragover {
  border-color: var(--primary);
  background: rgba(108, 138, 255, 0.05);
}

.file-label input { display: none; }

.file-label-text {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.file-label-hint {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.6;
}

.file-label.has-file .file-label-text {
  color: var(--success);
}

.file-label.has-file .file-label-hint { display: none; }

/* File List */
.file-list {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.file-list-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.file-list-item:last-child { border-bottom: none; }

.file-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.file-icon.file-docx { color: #4a90d9; }
.file-icon.file-pdf { color: #e74c3c; }

.file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.file-meta {
  color: var(--text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.file-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  transition: color 0.2s;
}

.file-remove:hover { color: var(--error); }

/* Prompt Input */
.prompt-input {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.4;
  outline: none;
  margin-bottom: 1rem;
  min-height: 44px;
  max-height: 120px;
}

.prompt-input:focus { border-color: var(--primary); }

.prompt-input::placeholder { color: var(--text-muted); opacity: 0.7; }

#upload-btn {
  width: 100%;
  padding: 0.85rem;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

#upload-btn:hover:not(:disabled) { background: var(--primary-hover); }
#upload-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.error {
  color: var(--error);
  margin-top: 1rem;
  font-size: 0.9rem;
}

#upload-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
  color: var(--text-muted);
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header h2 {
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-right {
  display: flex;
  gap: 0.5rem;
}

.btn-primary, .btn-secondary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

/* Main Layout */
.main-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Chat Panel */
.chat-panel {
  width: 45%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  font-size: 0.92rem;
  line-height: 1.6;
  max-width: 95%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message p { margin-bottom: 0.5rem; }
.message p:last-child { margin-bottom: 0; }

.message pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  overflow-x: auto;
  font-size: 0.82rem;
  margin: 0.5rem 0;
}

.message code {
  background: var(--bg);
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  font-size: 0.85em;
}

.message pre code {
  background: none;
  padding: 0;
}

.user-message {
  background: var(--chat-user);
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}

.ai-message {
  background: var(--chat-ai);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}

.system-message {
  background: transparent;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.85rem;
  align-self: center;
  padding: 0.5rem;
}

.tool-message {
  background: var(--tool-bg);
  border-left: 3px solid var(--accent);
  font-size: 0.82rem;
  color: var(--text-muted);
  align-self: flex-start;
  padding: 0.4rem 0.75rem;
}

.tool-friendly {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.tool-friendly svg {
  color: var(--accent);
  flex-shrink: 0;
}

.tool-details {
  margin-top: 0.3rem;
}

.tool-details summary {
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.5;
  cursor: pointer;
  user-select: none;
}

.tool-details summary:hover {
  opacity: 0.8;
}

.tool-details[open] summary {
  opacity: 0.7;
  margin-bottom: 0.25rem;
}

.tool-raw {
  font-family: monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.6;
  line-height: 1.4;
}

.tool-raw-name {
  color: var(--accent);
  opacity: 0.8;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.75rem 1rem;
  align-self: flex-start;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Chat Input */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.4;
  outline: none;
  max-height: 120px;
}

#chat-input:focus { border-color: var(--primary); }
#chat-input:disabled { opacity: 0.5; }

#send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

#send-btn:hover:not(:disabled) { background: var(--primary-hover); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Preview Panel */
.preview-panel {
  width: 55%;
  overflow: auto;
  background: white;
}

.doc-preview {
  min-height: 100%;
}

.preview-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  height: 300px;
  color: var(--text-muted);
}

/* docx-preview overrides */
.doc-preview .docx-wrapper {
  background: white !important;
  padding: 1rem !important;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Question Panel (bottom of chat, replaces chat input) */
.question-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: 55%;
  overflow: hidden;
}

.question-tabs {
  display: flex;
  gap: 2px;
  padding: 0.5rem 0.75rem 0;
  overflow-x: auto;
  flex-shrink: 0;
}

.q-tab {
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  position: relative;
}

.q-tab:hover { color: var(--text); background: var(--border); }

.q-tab.active {
  background: var(--bg);
  color: var(--text);
  border-color: var(--primary);
  border-bottom: 1px solid var(--bg);
  z-index: 1;
}

.q-tab.answered::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  margin-left: 0.4rem;
  vertical-align: middle;
}

.q-tab.active.answered::after {
  background: var(--success);
}

.question-body {
  padding: 0.75rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.question-text {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
  color: var(--text);
  line-height: 1.4;
}

.question-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.option-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-family: inherit;
  width: 100%;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: rgba(108, 138, 255, 0.1);
}

.option-btn.selected {
  border-color: var(--primary);
  background: rgba(108, 138, 255, 0.2);
}

.option-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.option-label {
  font-weight: 500;
  font-size: 0.88rem;
}

.option-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.option-other {
  border-style: dashed;
}

.other-input-row {
  display: flex;
  gap: 0.5rem;
}

.other-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
}

.other-input:focus {
  border-color: var(--primary);
}

.other-input-row .btn-primary {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

/* Multi-select */
.multi-check {
  color: var(--success);
  font-weight: 700;
}

.multi-confirm {
  margin-top: 0.5rem;
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 0.88rem;
}

.multi-confirm:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Download Card */
.download-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(74, 222, 128, 0.1), rgba(108, 138, 255, 0.1));
  border: 1px solid rgba(74, 222, 128, 0.3);
  align-self: flex-start;
  max-width: 95%;
}

.download-card-icon {
  color: var(--success);
  flex-shrink: 0;
  display: flex;
}

.download-card-text {
  flex: 1;
  min-width: 0;
}

.download-card-title {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--success);
}

.download-card-summary {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-card-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: 8px;
  background: var(--success);
  color: #0f1117;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.download-card-btn:hover {
  background: #5ee898;
  transform: translateY(-1px);
}

/* Resume loading */
.resume-loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
}

/* Markdown tables in chat messages */
.md-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}

.md-table th,
.md-table td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  text-align: left;
}

.md-table th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.md-table td {
  color: var(--text);
}

.md-table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

/* Field placeholders in document preview */
.field-placeholder {
  display: inline-block;
  min-width: 80px;
  height: 1.4em;
  border: 1.5px dashed #6c8aff;
  border-radius: 4px;
  background: rgba(108, 138, 255, 0.08);
  vertical-align: baseline;
}

/* Responsive */
@media (max-width: 768px) {
  .main-layout { flex-direction: column; }
  .chat-panel { width: 100%; height: 50%; border-right: none; border-bottom: 1px solid var(--border); }
  .preview-panel { width: 100%; height: 50%; }
}
