:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --bg-sidebar-active: #334155;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --text-sidebar: #e2e8f0;
  --text-sidebar-muted: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #dbeafe;
  --accent-subtle: #eff6ff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --error: #dc2626;
  --error-light: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 150ms ease;
  --sidebar-width: 280px;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.06);
  z-index: 100;
}

.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.logo-text {
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  letter-spacing: -0.01em;
}

.sidebar-sessions {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-sessions::-webkit-scrollbar {
  width: 4px;
}

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

.sidebar-empty {
  padding: 24px 16px;
  text-align: center;
}

.sidebar-empty p {
  color: var(--text-sidebar-muted);
  font-size: 13px;
}

.sidebar-empty .text-muted {
  font-size: 12px;
  margin-top: 4px;
  opacity: 0.6;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-sidebar);
  font-size: 13px;
  transition: background var(--transition);
  position: relative;
}

.session-item:hover {
  background: var(--bg-sidebar-hover);
}

.session-item.active {
  background: var(--bg-sidebar-active);
}

.session-item-info {
  flex: 1;
  min-width: 0;
}

.session-item-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item-meta {
  font-size: 11px;
  color: var(--text-sidebar-muted);
  margin-top: 2px;
}

.session-item-delete {
  visibility: hidden;
  background: none;
  border: none;
  color: var(--text-sidebar-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  flex-shrink: 0;
}

.session-item:hover .session-item-delete {
  visibility: visible;
}

.session-item-delete:hover {
  color: var(--error);
  background: rgba(220,38,38,0.15);
}

.session-status {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
}

.session-status.active { background: var(--success); }
.session-status.completed { background: var(--accent); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.diagnostics-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-sm);
}

.diag-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.diag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-sidebar-muted);
  transition: background 0.3s ease;
}

.diag-dot.ok {
  background: #22c55e;
  box-shadow: 0 0 4px rgba(34,197,94,0.4);
}

.diag-dot.fail {
  background: #ef4444;
  box-shadow: 0 0 4px rgba(239,68,68,0.4);
}

.diag-label {
  font-size: 11px;
  color: var(--text-sidebar-muted);
  white-space: nowrap;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  padding: 8px 16px;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 12px;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-sm {
  font-size: 12px;
  padding: 6px 12px;
}

.btn-lg {
  font-size: 15px;
  padding: 12px 24px;
  border-radius: var(--radius-lg);
}

.btn-icon {
  padding: 8px;
}

.btn-sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px;
  cursor: pointer;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.empty-state-content {
  text-align: center;
  max-width: 520px;
}

.empty-icon-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-subtle);
  margin-bottom: 20px;
}

.empty-icon {
  width: 36px;
  height: 36px;
  color: var(--accent);
}

.empty-state h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.empty-state .text-muted {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 24px;
}

/* ===== LANGUAGE SELECTION ===== */
.language-selection {
  margin-bottom: 24px;
}

.language-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.language-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.lang-btn {
  display: inline-flex;
  align-items: center;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: 24px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.lang-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.lang-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.section-preview {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 28px;
}

.section-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--bg-tertiary);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}

.section-tag-required {
  background: var(--accent-subtle);
  border-color: #bfdbfe;
  color: var(--accent);
}

.section-key {
  font-weight: 600;
  font-size: 11px;
}

.section-name {
  font-weight: 400;
}

/* ===== CHAT VIEW ===== */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-wrap: wrap;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.chat-header h3 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.section-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--accent);
  padding: 3px 10px;
  background: var(--accent-subtle);
  border-radius: 20px;
  font-weight: 500;
}

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

.chat-header-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* ===== SECTION PROGRESS ===== */
.section-progress {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 8px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 40px;
  position: relative;
}

.progress-step::after {
  content: '';
  position: absolute;
  top: 7px;
  left: 50%;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.progress-step:last-child::after {
  display: none;
}

.progress-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-primary);
  border: 2px solid var(--border);
  z-index: 1;
  transition: all 0.3s ease;
}

.progress-step.active .progress-dot {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.progress-step.completed .progress-dot {
  border-color: var(--success);
  background: var(--success);
}

.progress-step.completed::after {
  background: var(--success);
}

.progress-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.progress-step.active .progress-label {
  color: var(--accent);
}

.progress-step.completed .progress-label {
  color: var(--success);
}

/* ===== CHAT MESSAGES ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 720px;
  animation: messageIn 0.25s ease-out;
}

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

.message-assistant {
  align-self: flex-start;
}

.message-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}

.message-assistant .message-avatar {
  background: var(--accent-light);
  color: var(--accent);
}

.message-user .message-avatar {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.message-assistant .message-bubble {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-top-left-radius: var(--radius-sm);
}

.message-user .message-bubble {
  background: var(--accent);
  color: #fff;
  border-top-right-radius: var(--radius-sm);
}

.message-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.message-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typingBounce 1.2s infinite;
}

.message-typing span:nth-child(2) { animation-delay: 0.15s; }
.message-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ===== QUICK REPLIES ===== */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 4px 44px;
  animation: messageIn 0.25s ease-out;
}

.quick-reply-btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: 20px;
  color: var(--accent);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.quick-reply-btn:hover {
  background: var(--accent);
  color: #fff;
}

.quick-reply-btn:active {
  transform: scale(0.96);
  background: var(--accent-hover);
  color: #fff;
}

.quick-reply-btn.explain-more {
  background: transparent;
  border: 1px dashed var(--text-tertiary);
  color: var(--text-tertiary);
  font-style: italic;
}

.quick-reply-btn.explain-more:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: transparent;
}

@media (max-width: 768px) {
  .quick-replies {
    padding-left: 12px;
    gap: 6px;
  }

  .quick-reply-btn {
    padding: 10px 18px;
    font-size: 14px;
  }
}

/* ===== CHAT INPUT ===== */
.chat-input-wrapper {
  padding: 12px 20px 16px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
}

.chat-input-form {
  max-width: 720px;
  margin: 0 auto;
}

.chat-input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px 6px 6px 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input-container:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  background: transparent;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  padding: 6px 0;
}

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

.btn-mic {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  color: var(--text-tertiary);
  position: relative;
}

.btn-mic:hover {
  color: var(--accent);
}

.btn-mic.recording {
  color: #fff;
  background: var(--error);
  animation: pulse-recording 1.5s ease-in-out infinite;
}

@keyframes pulse-recording {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}

.btn-send {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.input-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 6px;
  text-align: center;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-secondary);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.summary-section {
  margin-bottom: 16px;
}

.summary-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.summary-section-key {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-subtle);
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.summary-section-content {
  font-size: 13px;
  color: var(--text-secondary);
  padding-left: 4px;
  line-height: 1.6;
}

.summary-section-empty {
  font-style: italic;
  color: var(--text-tertiary);
}

.summary-section-required {
  font-size: 10px;
  color: var(--warning);
  font-weight: 500;
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 600;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  animation: toastIn 0.2s ease-out;
  box-shadow: var(--shadow-md);
}

.toast-success { background: var(--success); }
.toast-error { background: var(--error); }
.toast-info { background: var(--accent); }

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

/* ===== LOADING ===== */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.text-muted { color: var(--text-secondary); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 300;
  }

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

  .btn-sidebar-toggle {
    display: flex;
  }

  .chat-header {
    padding-left: 52px;
  }

  .section-progress {
    padding: 8px 12px;
  }

  .progress-label {
    font-size: 9px;
  }

  .chat-messages {
    padding: 16px 12px;
  }

  .message {
    max-width: 100%;
  }

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

  .modal {
    max-height: 90vh;
    border-radius: var(--radius-lg);
  }
}
