:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --bg: #f5f6fb;
  --card-bg: #ffffff;
  --text: #1f2333;
  --muted: #6b7280;
  --border: #e2e4ec;
  --assistant-bg: #eef0ff;
  --candidate-bg: #f1f5f9;
  --danger: #dc2626;
  --success: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 20px;
  margin: 0;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
}
.icon-btn:hover { background: var(--assistant-bg); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.mode-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.mode-toggle-track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.15s ease;
  flex-shrink: 0;
}

.mode-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}

.mode-toggle input:checked + .mode-toggle-track {
  background: var(--primary);
}
.mode-toggle input:checked + .mode-toggle-track .mode-toggle-thumb {
  transform: translateX(16px);
}
.mode-toggle input:focus-visible + .mode-toggle-track {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.mode-toggle-label {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.settings-hint {
  font-size: 13px;
  color: var(--muted);
  background: var(--bg);
  padding: 10px 12px;
  border-radius: 8px;
}

.app-main {
  max-width: 720px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setup-panel, .dialog-panel, .report-panel, .employee-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.setup-panel { display: flex; flex-direction: column; gap: 10px; }

.setup-panel label { font-weight: 600; font-size: 14px; }

/* ---- Экран выбора сотрудника ---- */
.employee-panel h2 {
  margin: 0 0 14px;
  font-size: 16px;
}

.muted-text {
  color: var(--muted);
  font-size: 14px;
}

.employee-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.employee-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 16px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.employee-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}
.employee-card:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.employee-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: white;
  flex-shrink: 0;
}

.employee-card-name {
  font-weight: 700;
  font-size: 14px;
}

.employee-card-role {
  font-size: 12px;
  color: var(--muted);
}

.employee-card-description {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

/* ---- Шапка настройки разговора с выбранным сотрудником ---- */
.link-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }

.employee-setup-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 6px;
}

.employee-setup-header .employee-avatar {
  width: 44px;
  height: 44px;
  font-size: 22px;
}

.employee-setup-header-text .name {
  font-weight: 700;
  font-size: 15px;
}
.employee-setup-header-text .role {
  font-size: 12px;
  color: var(--muted);
}

.topic-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

select, input[type="text"], input[type="password"] {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
}

.primary-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:hover { background: var(--primary-dark); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 15px;
  cursor: pointer;
}

.dialog-history {
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
}

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
}

.bubble .speaker {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  opacity: 0.6;
  margin-bottom: 4px;
}

.bubble.assistant {
  background: var(--assistant-bg);
  align-self: flex-start;
}

.bubble.candidate {
  background: var(--candidate-bg);
  align-self: flex-end;
}

.bubble.error {
  background: #fee2e2;
  color: var(--danger);
  align-self: center;
}

.status-indicator {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 0;
  font-style: italic;
}

.controls {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.record-btn, .answer-btn {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.record-btn {
  background: var(--danger);
  color: white;
}
.record-btn.recording {
  background: #991b1b;
  animation: pulse 1.2s infinite;
}
.record-btn:disabled { opacity: 0.5; cursor: not-allowed; animation: none; }

.answer-btn {
  background: var(--success);
  color: white;
}
.answer-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.text-controls {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.or-divider {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.text-input-row {
  display: flex;
  gap: 10px;
}

.text-input-row textarea {
  flex: 1;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 14px;
}

.text-input-row .primary-btn {
  align-self: flex-end;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(153,27,27,0.5); }
  70% { box-shadow: 0 0 0 10px rgba(153,27,27,0); }
  100% { box-shadow: 0 0 0 0 rgba(153,27,27,0); }
}

.report-panel pre {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 14px;
  background: var(--bg);
  padding: 14px;
  border-radius: 8px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.settings-status {
  font-size: 13px;
  min-height: 18px;
}
.settings-status.error { color: var(--danger); }
.settings-status.success { color: var(--success); }

@media (max-width: 600px) {
  .app-main { padding: 0 10px; }
  .bubble { max-width: 95%; }
}
