/* CSS Variables for theming */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --background: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --border-focus: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  --transition: 150ms ease;
}

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

/* Utility classes */
.hidden {
  display: none !important;
}

/* Base */
html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* App Container */
.app {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 1rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
}

/* Icon Button */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.icon-btn:hover {
  background: var(--border);
  color: var(--text);
}

.icon-btn.small {
  width: 32px;
  height: 32px;
}

/* Main Content */
.main {
  flex: 1;
  padding-bottom: 2rem;
}

/* Progress Bar */
.progress-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 2rem;
  padding: 0 1rem;
}

.progress-step {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--border);
  color: var(--text-secondary);
  transition: all var(--transition);
  flex-shrink: 0;
}

.progress-step.active {
  background: var(--primary);
  color: white;
}

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

.progress-line {
  height: 3px;
  width: 40px;
  background: var(--border);
  flex-shrink: 0;
}

/* Steps */
.step {
  animation: fadeIn 0.3s ease;
}

.step.hidden {
  display: none;
}

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

.step h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.step-desc {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

/* Back Button */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  margin-bottom: 1rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition);
}

.back-btn:hover {
  color: var(--text);
}

/* Options Grid */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

.option-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.option-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.option-card:active {
  transform: translateY(0);
}

.option-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-icon {
  font-size: 2rem;
  line-height: 1;
}

.option-label {
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--text);
}

.option-desc {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Location Section */
.location-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.location-toggle {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.toggle-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.toggle-btn:hover {
  border-color: var(--primary);
}

.toggle-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.location-selects {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.select-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.select-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.select-group select,
.select-group input {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition);
}

.select-group select:focus,
.select-group input:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* Question Section */
.question-section {
  margin-bottom: 1.5rem;
}

.question-section textarea {
  width: 100%;
  padding: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 150px;
  transition: border-color var(--transition);
}

.question-section textarea:focus {
  outline: none;
  border-color: var(--border-focus);
}

.question-section textarea::placeholder {
  color: var(--text-secondary);
}

.helper-text {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

/* Primary Button */
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
}

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

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

.primary-btn.large {
  padding: 1rem 2rem;
  font-size: 1.0625rem;
}

.danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: transparent;
  color: var(--danger);
  border: 2px solid var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
  margin-top: 1rem;
}

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

/* Response Section */
.response-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.response-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--background);
}

.response-header h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.response-actions {
  display: flex;
  gap: 0.5rem;
}

.response-content {
  padding: 1.25rem;
  min-height: 200px;
}

.response-text {
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: 0.9375rem;
}

.response-text h1,
.response-text h2,
.response-text h3 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.response-text h1:first-child,
.response-text h2:first-child,
.response-text h3:first-child {
  margin-top: 0;
}

.response-text p {
  margin-bottom: 1em;
}

.response-text ul,
.response-text ol {
  margin-bottom: 1em;
  padding-left: 1.5em;
}

.response-text li {
  margin-bottom: 0.5em;
}

.response-text strong {
  font-weight: 600;
}

/* Loading Spinner */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 3rem;
}

.loading-spinner.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-spinner p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

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

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-content {
  padding: 1.25rem;
}

/* Settings */
.setting-group {
  margin-bottom: 1.5rem;
}

.setting-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--text);
}

.setting-desc {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.provider-options {
  display: flex;
  gap: 0.75rem;
}

.provider-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0.5rem;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.provider-btn:hover {
  border-color: var(--primary);
}

.provider-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.provider-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--border);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text);
}

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

.provider-btn span:last-child {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}

/* API Key Input */
.api-key-input-wrapper {
  display: flex;
  gap: 0.5rem;
}

.api-key-input-wrapper input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color var(--transition);
}

.api-key-input-wrapper input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.security-note {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.75rem;
  padding: 0.5rem;
  background: var(--background);
  border-radius: var(--radius-sm);
}

.security-note svg {
  flex-shrink: 0;
  color: var(--success);
}

.welcome-text {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

/* Error Message */
.error-message {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  padding: 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: toastIn 0.3s ease;
}

.toast.hidden {
  display: none;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Responsive */
@media (max-width: 600px) {
  .header h1 {
    font-size: 1.125rem;
  }

  .step h2 {
    font-size: 1.25rem;
  }

  .options-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .option-card {
    padding: 1rem 0.75rem;
  }

  .option-icon {
    font-size: 1.5rem;
  }

  .option-label {
    font-size: 0.8125rem;
  }

  .option-desc {
    display: none;
  }

  .progress-bar {
    padding: 0;
  }

  .progress-step {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
  }

  .progress-line {
    width: 24px;
  }

  .provider-options {
    flex-direction: column;
  }

  .provider-btn {
    flex-direction: row;
    padding: 0.75rem 1rem;
  }

  .location-toggle {
    flex-direction: column;
  }
}

/* Login Screen */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--background);
}

.login-screen.hidden {
  display: none;
}

.login-container {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.login-header p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-form input {
  padding: 0.875rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
  transition: border-color var(--transition);
}

.login-form input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.login-error {
  color: var(--danger);
  font-size: 0.875rem;
  text-align: center;
  margin: 0;
}

.login-error.hidden {
  display: none;
}

/* Disabled Screen */
.disabled-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--background);
}

.disabled-screen.hidden {
  display: none;
}

.disabled-container {
  text-align: center;
  max-width: 400px;
}

.disabled-icon {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.disabled-container h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.disabled-container p {
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Setting Divider */
.setting-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* Password Change Form */
.password-change-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.password-change-form input {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color var(--transition);
}

.password-change-form input:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* Secondary Button */
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

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

/* Text Button */
.text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: none;
  color: var(--text-secondary);
  border: none;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: color var(--transition);
  width: 100%;
}

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

/* Header actions */
.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* User Question Display */
.user-question-display {
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  border-left: 4px solid var(--primary);
}

.user-question-display.followup {
  background: #f0fdf4;
  border-left-color: var(--success);
}

.question-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.question-text {
  font-size: 1rem;
  color: var(--text);
  line-height: 1.5;
}

/* Follow-up Section */
.followup-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1.5rem;
}

.followup-section h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.followup-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.followup-questions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.followup-btn {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.875rem 1rem;
  text-align: left;
  font-size: 0.9375rem;
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
  line-height: 1.4;
}

.followup-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.followup-btn.selected {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.followup-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.followup-input-group textarea {
  width: 100%;
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  transition: border-color var(--transition);
}

.followup-input-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Follow-up Response */
.followup-response {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* History Modal */
.modal-large {
  max-width: 600px;
}

.history-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.history-list {
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.history-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 2rem;
  font-style: italic;
}

.history-item {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}

.history-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.history-item-topic {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.history-item-date {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.history-item-question {
  font-size: 0.9375rem;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-item-delete {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem;
  margin-left: 0.5rem;
  border-radius: 4px;
  transition: all var(--transition);
}

.history-item-delete:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.text-btn.danger {
  color: var(--danger);
}

.text-btn.danger:hover {
  color: var(--danger-hover);
}

/* Print styles - hide UI elements */
@media print {
  .header,
  .progress-bar,
  .back-btn,
  .primary-btn,
  .response-actions,
  .modal-overlay,
  .followup-section {
    display: none !important;
  }

  .response-container {
    border: none;
    box-shadow: none;
  }

  .response-content {
    padding: 0;
  }
}
