/* RexPay — спокойный, доверительный инструмент для счетов.
   Один акцент (глубокий изумрудный — тот же, что был, не меняем бренд),
   нейтральная база (zinc), светлая и тёмная тема через prefers-color-scheme.
   Системные шрифты — без внешних запросов к сторонним хостингам (как и раньше).

   Дизайн-токены: одна шкала радиусов на весь проект —
     --radius-card   карточки/панели
     --radius-ctl    поля, кнопки, превью QR
     999px (pill)    бейджи, значки статуса — единственное исключение, задокументировано здесь. */

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-sunken: #f4f4f3;
  --border: #e4e4e7;
  --text: #18181b;
  --text-muted: #6b7280;
  --accent: #0d9488;
  --accent-600: #0f766e;
  --accent-strong: #0f766e;
  --accent-strong-hover: #115e59;
  --accent-text: #ffffff;
  --accent-soft: #ccfbf1;
  --ring: rgb(13 148 136 / 0.35);
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warn: #92400e;
  --warn-soft: #fef3c7;

  --radius-card: 20px;
  --radius-ctl: 10px;

  --shadow-sm: 0 1px 2px rgb(24 24 27 / 0.05);
  --shadow-card:
    0 1px 2px rgb(13 148 136 / 0.04),
    0 16px 40px -8px rgb(24 24 27 / 0.10);

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1a1a1c;
    --surface-sunken: #141415;
    --border: #2c2c30;
    --text: #f4f4f5;
    --text-muted: #a1a1aa;
    --accent: #2dd4bf;
    --accent-600: #5eead4;
    --accent-strong: #2dd4bf;
    --accent-strong-hover: #5eead4;
    --accent-text: #042f2b;
    --accent-soft: #0f3a36;
    --ring: rgb(45 212 191 / 0.4);
    --danger: #fca5a5;
    --danger-soft: #3f1d1d;
    --warn: #fcd34d;
    --warn-soft: #3f2d0f;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-card:
      0 1px 2px rgb(45 212 191 / 0.05),
      0 20px 48px -8px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

@media (prefers-reduced-motion: no-preference) {
  .auth-card, .invoice-card, .panel {
    animation: fade-up 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
  }
  .panel:nth-of-type(2) { animation-delay: 0.06s; }
}

/* -------------------------------- Вход ---------------------------------- */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(60% 50% at 50% 0%, rgb(13 148 136 / 0.06), transparent 70%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 36px 32px;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 16px;
  border-radius: var(--radius-ctl);
  background: var(--accent-soft);
  color: var(--accent-600);
}

.brand-mark .icon { width: 22px; height: 22px; }

.auth-card h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-align: center;
  margin: 0 0 4px;
}

.auth-card .subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 24px;
}

/* ------------------------------- Формы ----------------------------------- */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--surface-sunken);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder { color: var(--text-muted); opacity: 0.8; }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.field .hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 16px;
  border: none;
  border-radius: var(--radius-ctl);
  background: var(--accent-strong);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), background 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover { background: var(--accent-strong-hover); box-shadow: 0 6px 16px rgb(13 148 136 / 0.22); }
.btn:active { transform: scale(0.98); }

.alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-ctl);
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-error { background: var(--danger-soft); color: var(--danger); }

/* ------------------------------- Админка --------------------------------- */
.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 32px;
}

.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }

.page-header a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-ctl);
  transition: background 0.15s ease, color 0.15s ease;
}

.page-header a .icon { width: 16px; height: 16px; }
.page-header a:hover { color: var(--text); background: var(--surface-sunken); }

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

.panel h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

.form-grid .field.full { grid-column: 1 / -1; }

table.invoices {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.invoices th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 8px 10px;
  border-bottom: 1px solid var(--border);
}

table.invoices td {
  padding: 13px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.invoices tr:last-child td { border-bottom: none; }

table.invoices tr { transition: background 0.1s ease; }
table.invoices tbody tr:hover { background: var(--surface-sunken); }

table.invoices a.open-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

table.invoices a.open-link::after {
  content: "→";
  display: inline-block;
  margin-left: 3px;
  transition: transform 0.15s ease;
}

table.invoices a.open-link:hover::after { transform: translateX(2px); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.badge-new::before, .badge-extracting::before {
  box-shadow: 0 0 0 0 currentColor;
}

@media (prefers-reduced-motion: no-preference) {
  .badge-new::before, .badge-extracting::before {
    animation: status-pulse 1.6s ease-out infinite;
  }
}

@keyframes status-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); }
  70%  { box-shadow: 0 0 0 6px color-mix(in srgb, currentColor 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 0%, transparent); }
}

.badge-new, .badge-extracting { background: var(--warn-soft); color: var(--warn); }
.badge-ready { background: var(--accent-soft); color: var(--accent-600); }
.badge-paid { background: var(--accent-strong); color: var(--accent-text); }
.badge-expired { background: var(--border); color: var(--text-muted); }
.badge-error { background: var(--danger-soft); color: var(--danger); }

.empty-row { color: var(--text-muted); text-align: center; padding: 32px 0; }

/* --------------------------- Публичный счёт ------------------------------ */
.invoice-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(60% 50% at 50% 0%, rgb(13 148 136 / 0.06), transparent 70%),
    var(--bg);
}

.invoice-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 36px 32px;
  text-align: center;
}

.invoice-card .client { font-size: 14px; color: var(--text-muted); margin-bottom: 4px; }
.invoice-card .description { font-size: 16px; margin-bottom: 20px; }

.invoice-card .amount {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-bottom: 24px;
}

.invoice-card .amount .cur { font-size: 20px; font-weight: 600; color: var(--text-muted); }

.invoice-card .qr {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 0 auto 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  padding: 10px;
  background: #fff;
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

a:has(> .qr):hover .qr { transform: scale(1.02); }

.invoice-card .qr::before,
.invoice-card .qr::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent);
  opacity: 0.55;
}

.invoice-card .qr::before { top: -2px; left: -2px; border-right: none; border-bottom: none; border-top-left-radius: 6px; }
.invoice-card .qr::after { bottom: -2px; right: -2px; border-left: none; border-top: none; border-bottom-right-radius: 6px; }

.invoice-card .qr img { width: 100%; height: 100%; display: block; }

.invoice-card .trust-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.invoice-card .trust-line .icon { width: 14px; height: 14px; }

.invoice-card .status-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-muted);
}

.invoice-card .status-line .icon { width: 16px; height: 16px; color: var(--accent); }

.invoice-card .waiting {
  padding: 32px 0 8px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  .btn { transition: none; }
  .auth-card, .invoice-card, .panel { animation: none; }
}

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

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  table.invoices { font-size: 13px; }
  table.invoices th:nth-child(4),
  table.invoices td:nth-child(4) { display: none; }
}
