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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f0f4f8;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

/* ── Card ── */
.card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 28px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 700px;
  height: 84vh;
  min-height: 420px;
  overflow: hidden;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: #1d4ed8;
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: -0.02em;
}

header h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.01em;
}

#reset-btn {
  font-size: 0.78rem;
  padding: 0.32rem 0.7rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#reset-btn:hover {
  background: #f3f4f6;
  color: #374151;
}

/* ── Stage indicator ── */
#stage-indicator {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 1.25rem;
  border-bottom: 1px solid #e5e7eb;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#stage-indicator::-webkit-scrollbar {
  display: none;
}

.stage-step {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 500;
  color: #94a3b8;
  padding: 0.5rem 0.75rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  cursor: pointer;
  user-select: none;
  font-family: inherit;
}

.stage-step:hover {
  color: #475569;
  background: #f8fafc;
}

.stage-step.active {
  color: #1d4ed8;
  border-bottom-color: #1d4ed8;
  background: transparent;
}

/* ── Chat log ── */
#chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.25rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

/* ── Message wrappers ── */
.message-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
}

.assistant-wrapper {
  align-self: flex-start;
  max-width: 78%;
}

.message {
  padding: 0.7rem 1rem;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 0.95rem;
  white-space: pre-wrap; /* typewriter phase */
}

/* Once markdown is rendered, switch to normal flow */
.message.rendered {
  white-space: normal;
}

.message.rendered p  { margin: 0 0 0.4rem; }
.message.rendered br { display: block; margin: 0.1rem 0; }
.message.rendered strong { font-weight: 600; }
.message.rendered em { font-style: italic; }

.message.rendered h4,
.message.rendered h5,
.message.rendered h6 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0.6rem 0 0.2rem;
  color: #1e293b;
}

.message.rendered ul,
.message.rendered ol {
  margin: 0.3rem 0 0.3rem 1.2rem;
  padding: 0;
}

.message.rendered li {
  margin-bottom: 0.2rem;
  line-height: 1.5;
}

.message.user {
  align-self: flex-end;
  max-width: 72%;
  background: #1d4ed8;
  color: #fff;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

.message.assistant {
  background: #f1f5f9;
  color: #111827;
  border-bottom-left-radius: 4px;
  flex: 1;
}

/* ── Clarification button ── */
.clarify-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #94a3b8;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  margin-bottom: 2px;
  transition: color 0.15s, border-color 0.15s;
}

.assistant-wrapper:hover .clarify-btn {
  display: flex;
}

.clarify-btn:hover {
  color: #1d4ed8;
  border-color: #1d4ed8;
}

/* ── Per-message TTS controls ── */
.assistant-wrapper {
  flex-direction: column;
  align-items: flex-start;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  width: 100%;
}

.tts-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #94a3b8;
  font-size: 0.72rem;
  cursor: pointer;
  flex-shrink: 0;
  margin-bottom: 2px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.assistant-wrapper:hover .tts-btn {
  display: flex;
}

.tts-btn.active {
  display: flex;
  color: #1d4ed8;
  border-color: #1d4ed8;
  background: #eff6ff;
}

.tts-btn:hover {
  color: #1d4ed8;
  border-color: #1d4ed8;
}

.tts-controls {
  display: flex;
  gap: 0.3rem;
  padding: 0.25rem 0.5rem;
  margin-top: 0.2rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  align-self: flex-start;
}

.tts-controls.hidden {
  display: none;
}

.tts-controls button {
  background: none;
  border: none;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
  color: #475569;
  transition: background 0.12s, color 0.12s;
}

.tts-controls button:hover {
  background: #e2e8f0;
  color: #1d4ed8;
}

/* ── Tab switch modal ── */
#tab-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

#tab-modal.hidden {
  display: none;
}

.tab-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.tab-modal-box {
  position: relative;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  padding: 1.5rem;
  max-width: 360px;
  width: calc(100% - 2rem);
  z-index: 1;
}

.tab-modal-box p {
  font-size: 0.92rem;
  color: #374151;
  line-height: 1.55;
  margin-bottom: 1.1rem;
}

.tab-modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

#tab-modal-confirm {
  padding: 0.45rem 1rem;
  background: #1d4ed8;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

#tab-modal-confirm:hover {
  background: #1e40af;
}

#tab-modal-cancel {
  padding: 0.45rem 1rem;
  background: transparent;
  color: #6b7280;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  font-size: 0.88rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

#tab-modal-cancel:hover {
  background: #f3f4f6;
}

/* ── Decision buttons ── */
#decision-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.5rem 1.25rem 0.75rem;
}

#decision-buttons.hidden {
  display: none;
}

.decision-btn {
  text-align: left;
  padding: 0.65rem 1rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  background: #fff;
  color: #1e293b;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.decision-btn:hover {
  border-color: #1d4ed8;
  background: #eff6ff;
  color: #1d4ed8;
}

/* ── Status bar ── */
#status-bar {
  padding: 0.35rem 1.25rem;
  font-size: 0.78rem;
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border-top: 1px solid #f1f5f9;
}

#status-bar.hidden {
  display: none;
}

#status-bar::before {
  content: '◉';
  font-size: 0.6rem;
  color: #94a3b8;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Upload confirm banner ── */
#upload-confirm {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  background: #fffbeb;
  border-top: 1px solid #fde68a;
  font-size: 0.83rem;
  color: #92400e;
}

#upload-confirm.hidden {
  display: none;
}

#upload-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-confirm-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

#upload-confirm-btn {
  padding: 0.3rem 0.75rem;
  background: #16a34a;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

#upload-confirm-btn:hover {
  background: #15803d;
}

#upload-cancel-btn {
  padding: 0.3rem 0.75rem;
  background: transparent;
  color: #92400e;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

#upload-cancel-btn:hover {
  background: #fef3c7;
}

/* ── Input form ── */
#chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  padding: 0.7rem 1rem;
  border-top: 1px solid #e5e7eb;
}

#upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

#upload-btn:hover {
  color: #1d4ed8;
  background: #eff6ff;
}

#mic-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

#mic-btn:hover {
  color: #1d4ed8;
  background: #eff6ff;
}

#mic-btn.recording {
  color: #dc2626;
  background: #fef2f2;
  animation: mic-pulse 1s ease-in-out infinite;
}

#mic-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@keyframes mic-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

#user-input {
  flex: 1;
  resize: none;
  border: 1px solid #d1d5db;
  border-radius: 9px;
  padding: 0.6rem 0.85rem;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
  max-height: 130px;
  overflow-y: auto;
}

#user-input:focus {
  border-color: #1d4ed8;
}

#user-input:disabled {
  background: #f9fafb;
}

#send-btn {
  padding: 0.6rem 1.1rem;
  background: #1d4ed8;
  color: #fff;
  border: none;
  border-radius: 9px;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  height: 36px;
  display: flex;
  align-items: center;
}

#send-btn:hover {
  background: #1e40af;
}

#send-btn:disabled {
  background: #93c5fd;
  cursor: not-allowed;
}

/* ── Download resume button ── */
.download-resume-btn {
  display: inline-block;
  margin: 0.1rem 0 0.6rem 0;
  padding: 0.55rem 1rem;
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 10px;
  color: #166534;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  max-width: 78%;
  text-align: left;
}

.download-resume-btn:hover {
  background: #dcfce7;
  border-color: #4ade80;
}

.download-resume-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

/* ── Resume preview card ── */
.resume-preview-card {
  align-self: flex-start;
  max-width: 78%;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 0.88rem;
  color: #374151;
}

.resume-preview-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 0.5rem;
}

.resume-preview-header .file-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.resume-preview-snippet {
  color: #64748b;
  font-size: 0.82rem;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

.resume-preview-full {
  color: #475569;
  font-size: 0.8rem;
  line-height: 1.55;
  white-space: pre-wrap;
  max-height: 240px;
  overflow-y: auto;
  border-top: 1px solid #e2e8f0;
  padding-top: 0.5rem;
  margin-top: 0.25rem;
}

.resume-preview-full.hidden {
  display: none;
}

.resume-preview-toggle {
  background: none;
  border: none;
  color: #1d4ed8;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

.resume-preview-toggle:hover {
  text-decoration: underline;
}

/* ── Scrollbar ── */
#chat-log::-webkit-scrollbar {
  width: 5px;
}
#chat-log::-webkit-scrollbar-track {
  background: transparent;
}
#chat-log::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 99px;
}
