:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #3b82f6;
  --accent-dim: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --input-bg: #0f172a;
  --input-border: #334155;
  --btn-secondary-bg: #334155;
  --btn-secondary-hover: #3d4f63;
  --btn-ghost-border: #475569;
  --chat-bot-bg: #1e3a5f;
  --chat-user-bg: #172554;
  --table-border: #334155;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); }

.app { max-width: 720px; margin: 0 auto; min-height: 100vh; padding: 0 14px 32px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 0; position: sticky; top: 0; background: linear-gradient(180deg, var(--bg) 70%, transparent);
  z-index: 10;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.theme-switch {
  display: inline-flex;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  flex-shrink: 0;
}
.theme-switch__btn {
  width: auto;
  padding: 6px 10px;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.45;
  transition: opacity 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.theme-switch__btn:hover {
  opacity: 0.85;
}
.theme-switch__btn[aria-pressed="true"] {
  opacity: 1;
  background: rgba(59, 130, 246, 0.22);
}
.topnav { display: flex; gap: 12px; flex-wrap: wrap; }
.topnav a { color: var(--accent); text-decoration: none; font-size: 14px; }
.topnav a:hover { text-decoration: underline; }

.main { padding-top: 8px; }

h1 { font-size: 1.35rem; margin: 0 0 12px; font-weight: 700; }
h2 { font-size: 1.1rem; margin: 20px 0 10px; color: var(--muted); font-weight: 600; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border-subtle);
}

.btn {
  display: inline-block; width: 100%; text-align: center;
  padding: 14px 16px; border-radius: var(--radius); border: none;
  font-size: 16px; font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--accent); color: #fff;
  transition: background 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.btn:hover:not(:disabled) {
  background: #4f8ef7;
  box-shadow: 0 2px 12px rgba(59, 130, 246, 0.35);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn:active:not(:disabled) { transform: scale(0.99); }
.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--text);
  box-shadow: none;
  /* Чтобы при hover не появлялась «новая» рамка и кнопки не дёргались (светлая тема) */
  border: 1px solid transparent;
}
.btn-secondary:hover:not(:disabled) {
  background: var(--btn-secondary-hover);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--btn-ghost-border);
  color: var(--text);
  box-shadow: none;
}
.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  border-color: #64748b;
}
@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}
.btn-row { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--input-border);
  background: var(--input-bg); color: var(--text); font-size: 16px;
}
textarea { min-height: 100px; resize: vertical; }

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.flash-error { background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.4); color: #fecaca; }
.flash-ok { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.35); color: #bbf7d0; }

.chat-msg { margin-bottom: 10px; padding: 12px 14px; border-radius: var(--radius); max-width: 100%; line-height: 1.45; font-size: 15px; }
.chat-bot { background: var(--chat-bot-bg); align-self: flex-start; }
.chat-user { background: var(--chat-user-bg); border: 1px solid #312e81; }

.progress { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 8px; border-bottom: 1px solid var(--table-border); text-align: left; }
table.data th { color: var(--muted); font-weight: 600; }

.admin-links { display: flex; flex-direction: column; gap: 10px; }
.admin-links a { display: block; padding: 14px; background: var(--surface); border-radius: var(--radius); color: var(--text); text-decoration: none; border: 1px solid var(--border-subtle); }
.admin-links a:hover { border-color: var(--accent); }

.qr-setup { text-align: center; margin: 16px 0; }
.qr-setup svg, .qr-setup img { max-width: 220px; height: auto; }

.question-examples {
  border-style: dashed;
}
.question-examples__title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
}
.question-examples__hint {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}
.question-examples__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.question-examples__link {
  display: block;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  line-height: 0;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.question-examples__link:hover {
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.25);
  border-color: var(--accent);
}
.question-examples__link img {
  width: 100%;
  height: auto;
  max-height: 200px;
  object-fit: cover;
  vertical-align: middle;
}

/* Код аутентификатора: по одной цифре в ячейке */
.otp-digits {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  margin: 10px 0 6px;
  max-width: 340px;
  margin-left: auto;
  margin-right: auto;
}
.otp-digit {
  flex: 1 1 0;
  min-width: 0;
  max-width: 52px;
  height: 52px;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 0 6px;
  letter-spacing: 0;
}
@media (max-width: 400px) {
  .otp-digits { gap: 5px; max-width: 100%; }
  .otp-digit { height: 46px; font-size: 1.2rem; }
}

@media (min-width: 520px) {
  .btn-row.horizontal { flex-direction: row; }
  .btn-row.horizontal .btn { width: auto; flex: 1; }
}

/* Светлая тема */
:root[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
  --border-subtle: rgba(15, 23, 42, 0.1);
  --input-bg: #f8fafc;
  --input-border: #cbd5e1;
  --btn-secondary-bg: #e2e8f0;
  --btn-secondary-hover: #cbd5e1;
  --btn-ghost-border: #94a3b8;
  --chat-bot-bg: #dbeafe;
  --chat-user-bg: #e0e7ff;
  --table-border: #e2e8f0;
}
/* Светлая тема: hover отдельно от тёмной (контраст и тени) */
:root[data-theme="light"] .btn:hover:not(:disabled) {
  background: #1d4ed8;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
}
:root[data-theme="light"] .btn-secondary:hover:not(:disabled) {
  background: #cbd5e1;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.12);
}
:root[data-theme="light"] .btn-ghost:hover:not(:disabled) {
  background: rgba(37, 99, 235, 0.1);
  border-color: #2563eb;
  color: #1e3a8a;
}
:root[data-theme="light"] .topnav a:hover {
  color: #1d4ed8;
  text-decoration: underline;
}
:root[data-theme="light"] .admin-links a:hover {
  border-color: #3b82f6;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.18);
}
:root[data-theme="light"] .theme-switch__btn:hover {
  opacity: 0.95;
  background: rgba(37, 99, 235, 0.12);
}
:root[data-theme="light"] .theme-switch__btn[aria-pressed="true"] {
  background: rgba(37, 99, 235, 0.2);
}
:root[data-theme="light"] .flash-error {
  color: #991b1b;
}
:root[data-theme="light"] .flash-ok {
  color: #166534;
}
:root[data-theme="light"] .chat-user {
  border-color: #a5b4fc;
}

/* Админка: примеры к вопросу */
.qa-examples-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.qa-example-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}
.qa-example-row__thumb {
  flex-shrink: 0;
  display: block;
  line-height: 0;
  border-radius: 8px;
  overflow: hidden;
}
.qa-example-row__thumb img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  vertical-align: middle;
}
