:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242736;
  --border: #2e3247;
  --text: #e8eaf6;
  --text-muted: #8b90a8;
  --primary: #5c6bc0;
  --primary-hover: #7986cb;
  --primary-light: rgba(92, 107, 192, 0.15);
  --success: #43a047;
  --success-light: rgba(67, 160, 71, 0.15);
  --warning: #f57f17;
  --warning-light: rgba(245, 127, 23, 0.15);
  --danger: #e53935;
  --danger-light: rgba(229, 57, 53, 0.15);
  --radius: 12px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

header {
  background: linear-gradient(135deg, #1a1d27 0%, #242736 100%);
  border-bottom: 1px solid var(--border);
  padding: 20px 24px;
}
.header-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.5px; }
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 2px; }

.btn-history {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.btn-history:hover, .btn-history.active {
  background: var(--primary-light);
  color: var(--primary-hover);
  border-color: var(--primary);
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  padding: 20px 24px;
}
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-group label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  min-width: 160px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}
select:focus { border-color: var(--primary); }

.lang-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.lang-btn {
  background: var(--surface2);
  border: none;
  color: var(--text-muted);
  padding: 8px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  border-right: 1px solid var(--border);
  white-space: nowrap;
}
.lang-btn:last-child { border-right: none; }
.lang-btn:hover { background: var(--border); color: var(--text); }
.lang-btn.active { background: var(--primary); color: #fff; font-weight: 600; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-primary svg { width: 16px; height: 16px; }

.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--border); }

.question-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge.subject { background: var(--primary-light); color: var(--primary-hover); }
.badge.topic { background: var(--surface2); color: var(--text-muted); }

.question-card h2 { font-size: 1.15rem; font-weight: 600; line-height: 1.5; margin-bottom: 20px; }

.answer-section label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 12px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.6;
}
textarea:focus { border-color: var(--primary); }
.answer-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.char-count { font-size: 0.8rem; color: var(--text-muted); }

/* Feedback */
.feedback-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.feedback-header h3 { display: flex; align-items: center; gap: 8px; font-size: 1rem; font-weight: 700; }
.feedback-header svg { width: 18px; height: 18px; color: var(--primary-hover); }
.feedback-header-right { display: flex; align-items: center; gap: 8px; }

.lang-badge {
  font-size: 0.75rem;
  background: var(--primary-light);
  color: var(--primary-hover);
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}

/* Swiss grade badge */
.grade-badge {
  font-size: 1rem;
  font-weight: 800;
  padding: 4px 14px;
  border-radius: 20px;
  letter-spacing: 0.3px;
}
.grade-badge.grade-good { background: var(--success-light); color: #66bb6a; }
.grade-badge.grade-ok { background: var(--warning-light); color: #ffb74d; }
.grade-badge.grade-poor { background: var(--danger-light); color: #ef5350; }

.feedback-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 0;
  color: var(--text-muted);
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.feedback-content { font-size: 0.95rem; line-height: 1.75; color: var(--text); white-space: pre-wrap; }
.feedback-content strong { color: var(--primary-hover); }

/* Empty state */
.empty-state { text-align: center; padding: 64px 24px; }
.empty-icon { font-size: 4rem; margin-bottom: 16px; }
.empty-state h2 { font-size: 1.4rem; margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); margin-bottom: 24px; }

/* History */
.history-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.history-header h3 { font-size: 1.1rem; font-weight: 700; }
.history-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface2);
  padding: 3px 10px;
  border-radius: 20px;
}

.history-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}
.history-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.history-card-header:hover { background: var(--border); }
.history-card-meta { flex: 1; min-width: 0; }
.history-card-subject {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--primary-hover);
}
.history-card-topic {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 1px;
}
.history-card-question {
  font-size: 0.88rem;
  color: var(--text);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.history-timestamp {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.history-chevron {
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.history-card.open .history-chevron { transform: rotate(180deg); }

.history-card-body {
  display: none;
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}
.history-card.open .history-card-body { display: block; }

.history-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin: 14px 0 6px;
}
.history-text {
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  white-space: pre-wrap;
}
.history-text strong { color: var(--primary-hover); }

.history-empty {
  text-align: center;
  padding: 40px 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* FAB */
.fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 1.5rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(92,107,192,0.5);
  transition: background 0.2s, transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:hover { background: var(--primary-hover); transform: scale(1.08); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal { width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.15s;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.form-group input[type="text"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input[type="text"]:focus { border-color: var(--primary); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 90px;
  right: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  z-index: 2000;
  animation: slideIn 0.25s ease;
  max-width: 320px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@media (max-width: 600px) {
  .filter-bar { flex-direction: column; align-items: stretch; }
  .form-row { grid-template-columns: 1fr; }
  .lang-btn { padding: 8px 10px; font-size: 0.8rem; }
  .header-inner { gap: 12px; }
}
