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

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --success-color: #16a34a;
  --error-color: #dc2626;
  --warning-color: #f59e0b;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --bg-primary: #f9fafb;
  --bg-card: #ffffff;
  --border-color: #e5e7eb;
  --border-focus: #2563eb;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px;
}

header {
  text-align: center;
  margin-bottom: 32px;
}

header h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 16px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.help-text {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.help-text code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 13px;
}

/* Form Elements */
.form-group {
  position: relative;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"],
input[type="tel"],
textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
input[type="tel"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea {
  resize: vertical;
  min-height: 120px;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.5;
}

/* Dropdown */
.dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
  margin-top: 4px;
}

.dropdown.hidden {
  display: none;
}

.dropdown-item {
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.15s;
}

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

.dropdown-item:hover {
  background-color: #f3f4f6;
}

.dropdown-item .student-name {
  font-weight: 500;
  color: var(--text-primary);
}

.dropdown-item .student-email {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.dropdown-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
}

/* Student Info */
.student-info {
  margin-top: 16px;
  padding: 16px;
  background: #f8fafc;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.student-info.hidden {
  display: none;
}

.info-row {
  display: flex;
  margin-bottom: 8px;
}

.info-row:last-child {
  margin-bottom: 0;
}

.info-row .label {
  font-weight: 500;
  color: var(--text-secondary);
  width: 80px;
  flex-shrink: 0;
}

/* Context Fields - Chips Container */
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chips-container.hidden {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 16px;
  font-size: 13px;
  color: var(--primary-color);
  max-width: 100%;
}

.chip-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chip-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-value {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.chip-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  transition: background-color 0.15s, color 0.15s;
  flex-shrink: 0;
}

.chip-remove:hover {
  background: #dbeafe;
  color: var(--primary-color);
}

/* Context Fields - Wrapper and Select */
.context-fields-wrapper {
  margin-top: 8px;
}

.context-fields-wrapper.hidden {
  display: none;
}

.field-select-wrapper {
  position: relative;
}

/* Field Dropdown Items */
.dropdown-item.field-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dropdown-item.field-item .field-name {
  font-weight: 500;
  color: var(--text-primary);
  font-size: 14px;
}

.dropdown-item.field-item .field-value {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-item.field-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #f9fafb;
}

.dropdown-item.field-item.disabled:hover {
  background: #f9fafb;
}

/* Context Preview */
.context-preview {
  margin-top: 16px;
  padding: 16px;
  background: #1f2937;
  border-radius: var(--radius);
}

.context-preview.hidden {
  display: none;
}

.context-preview h3 {
  color: #9ca3af;
  margin-bottom: 12px;
}

.context-preview pre {
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 13px;
  color: #e5e7eb;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Variables Hint */
.variables-hint {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  font-size: 13px;
}

.variables-hint.hidden {
  display: none;
}

.hint-label {
  font-weight: 500;
  color: #92400e;
}

#variables-list {
  color: #78350f;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
}

/* Phone Input */
.phone-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.phone-input-wrapper input {
  padding-right: 40px;
}

.validation-icon {
  position: absolute;
  right: 12px;
  font-size: 18px;
}

.validation-icon.valid::after {
  content: '✓';
  color: var(--success-color);
}

.validation-icon.invalid::after {
  content: '✗';
  color: var(--error-color);
}

.error-text {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--error-color);
}

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

.formatted-text {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--success-color);
}

.formatted-text.hidden {
  display: none;
}

/* Call Button */
.call-section {
  text-align: center;
}

.call-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 48px;
  font-size: 18px;
  font-weight: 600;
  color: white;
  background: var(--primary-color);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

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

.call-button:active:not(:disabled) {
  transform: scale(0.98);
}

.call-button:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

.call-button .button-icon {
  font-size: 22px;
}

.error-message {
  margin-top: 16px;
  padding: 12px 16px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  color: var(--error-color);
  font-size: 14px;
}

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

/* Loading States */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  color: var(--text-secondary);
}

.loading.hidden {
  display: none;
}

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

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

/* Call Status */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.status-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.status-icon.pending {
  background: var(--warning-color);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-icon.in-progress {
  background: var(--primary-color);
  animation: pulse 1s ease-in-out infinite;
}

.status-icon.completed {
  background: var(--success-color);
}

.status-icon.failed {
  background: var(--error-color);
}

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

#status-text {
  font-weight: 500;
}

/* Progress Bar */
.call-progress {
  margin-bottom: 24px;
}

.progress-bar {
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary-color);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
}

/* Call Results */
.call-results {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
}

.call-results.hidden {
  display: none;
}

.result-section {
  margin-bottom: 24px;
}

.result-section:last-child {
  margin-bottom: 0;
}

.audio-player {
  width: 100%;
  margin-top: 8px;
}

#call-summary {
  font-size: 15px;
  color: var(--text-primary);
  line-height: 1.7;
}

#call-transcript {
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
  padding: 16px;
  background: #f8fafc;
  border-radius: 6px;
  margin-top: 8px;
}

details summary {
  cursor: pointer;
  padding: 8px 12px;
  background: #f3f4f6;
  border-radius: 6px;
  font-weight: 500;
  font-size: 14px;
  color: var(--text-secondary);
}

details summary:hover {
  background: #e5e7eb;
}

.call-details {
  padding: 16px;
  background: #f8fafc;
  border-radius: 6px;
}

.detail-row {
  display: flex;
  margin-bottom: 8px;
}

.detail-row:last-child {
  margin-bottom: 0;
}

.detail-row .label {
  font-weight: 500;
  color: var(--text-secondary);
  width: 100px;
}

/* Secondary Button */
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 500;
  color: var(--primary-color);
  background: white;
  border: 1px solid var(--primary-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.2s;
  margin-top: 16px;
}

.secondary-button:hover {
  background: #eff6ff;
}

.secondary-button.hidden {
  display: none;
}

/* Footer */
footer {
  text-align: center;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
}

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

/* Hidden utility */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 640px) {
  .container {
    padding: 16px 12px;
  }

  .card {
    padding: 16px;
  }

  .context-fields {
    grid-template-columns: 1fr;
  }

  .call-button {
    width: 100%;
    padding: 14px 24px;
  }
}
