/* TBCC UI: единая палитра кабинета мерчанта и админки.
   Без JavaScript и фронтенд-сборщика. */

:root {
  --brand-primary: #102a43;
  --brand-primary-2: #176b87;
  --brand-accent: #2dd4bf;
  --brand-ink: #172b4d;
  --brand-muted: #60758a;
  --brand-line: #d7e2ea;
  --brand-th: #eaf8f6;
  --bg: #f4f8fb;
  --surface: #ffffff;
  --danger: #b3261e;
  --warn: #9a6700;
  --ok-bg: #e4f8f3;
  --ok-fg: #087864;
  --fail-bg: #fdeceb;
  --wait-bg: #fdf3e0;
  --neutral-bg: #eef1f4;
  --row-alt-bg: #fbfdfc;
  --flash-border: #bfe3d3;
  --error-border: #f5c6c2;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PT Sans", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--brand-ink);
  background: var(--bg);
}

/* ---- Шапка: цвет отличает периметры, чтобы сотрудник банка с двумя
   открытыми вкладками не спутал чужие деньги со своими ---- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  min-height: 64px; padding: 10px 20px; color: #fff;
  background: linear-gradient(120deg, #102a43 0%, #164e63 100%);
  border-bottom: 2px solid var(--brand-accent);
}
body.admin .topbar { background: var(--brand-ink); }
.topbar .brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: 1.2px; }
.topbar .brand img { border-radius: 9px; box-shadow: 0 4px 12px rgb(0 0 0 / 18%); }
.topbar .scope { font-size: 13px; opacity: .85; }
.topbar .spacer { flex: 1; }
.topbar .user { font-size: 13px; opacity: .9; }

/* ---- Каркас ---- */
.shell { display: flex; align-items: flex-start; gap: 24px; padding: 20px; }
.sidebar {
  flex: 0 0 200px; background: var(--surface); border: 1px solid var(--brand-line);
  border-radius: var(--radius); padding: 8px; position: sticky; top: 20px;
}
.sidebar a {
  display: block; padding: 8px 10px; margin-bottom: 2px; border-radius: var(--radius);
  color: var(--brand-ink); text-decoration: none; font-size: 14px;
}
.sidebar a:hover { background: var(--brand-th); }
.sidebar a.active { background: var(--brand-primary); color: #fff; font-weight: 600; }
.content {
  flex: 1 1 auto; min-width: 0; background: var(--surface);
  border: 1px solid var(--brand-line); border-radius: var(--radius); padding: 20px 24px;
}

/* ---- Типографика ---- */
h1 { font-size: 22px; margin: 0 0 16px; color: var(--brand-primary); }
body.admin h1 { color: var(--brand-ink); }
h2 { font-size: 17px; margin: 24px 0 10px; }
a { color: var(--brand-primary-2); }

/* ---- Таблицы: основное содержимое обоих приложений ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--brand-line); }
th {
  background: var(--brand-th); font-weight: 600; white-space: nowrap;
}
tbody tr:nth-child(even) { background: var(--row-alt-bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- Статусные бейджи: цвет задаётся функцией шаблона statusClass ---- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.wait { background: var(--wait-bg); color: var(--warn); }
.badge.fail { background: var(--fail-bg); color: var(--danger); }
.badge.neutral { background: var(--neutral-bg); color: var(--brand-muted); }

/* ---- Формы ---- */
form.stack { display: flex; flex-direction: column; gap: 12px; max-width: 420px; }
form.stack.wide { max-width: 620px; }
form.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
form.inline-form { display: inline; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--brand-muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--brand-ink); }
label.check input { width: 16px; height: 16px; }
input, textarea, select {
  font: inherit; padding: 7px 9px; border: 1px solid var(--brand-line);
  border-radius: var(--radius); background: #fff; color: var(--brand-ink);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand-accent); outline-offset: 1px; }

button {
  font: inherit; font-weight: 600; padding: 8px 16px; border-radius: var(--radius);
  border: 1px solid var(--brand-primary); background: var(--brand-primary); color: #fff;
  cursor: pointer;
}
button:hover { background: var(--brand-primary-2); border-color: var(--brand-primary-2); }
button.secondary { background: #fff; color: var(--brand-primary); }
button.secondary:hover { background: var(--brand-th); }
button.danger { background: var(--danger); border-color: var(--danger); }
button.danger:hover { filter: brightness(1.1); }
.button-link {
  display: inline-flex; align-items: center; justify-content: center; min-height: 38px;
  padding: 7px 14px; border: 1px solid var(--brand-primary); border-radius: var(--radius);
  background: var(--brand-primary); color: #fff; font-weight: 600; text-decoration: none;
}
.button-link:hover { background: var(--brand-primary-2); }
.button-link.secondary { background: #fff; color: var(--brand-primary); }
.page-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-heading h1 { min-width: 0; margin-bottom: 0; overflow-wrap: anywhere; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.workflow-actions form + form { margin-top: 18px; }
.danger-zone { border-top: 1px solid var(--error-border); padding-top: 18px; }
.details-grid { display: grid; grid-template-columns: minmax(130px, 190px) minmax(0, 1fr); gap: 7px 18px; margin: 0; }
.details-grid dt { color: var(--brand-muted); }
.details-grid dd { margin: 0; overflow-wrap: anywhere; }
.qr-presentment { display: flex; flex-wrap: wrap; align-items: center; gap: 24px; }
.qr-presentment .stack { max-width: 360px; }
.qr-presentment-image {
  display: block; width: min(384px, 100%); height: auto; padding: 12px;
  border: 1px solid var(--brand-line); border-radius: var(--radius); background: #fff;
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 0 0 18px; }
.card { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--brand-line); border-radius: var(--radius); background: var(--row-alt-bg); }
.card strong { font-size: 22px; color: var(--brand-primary); font-variant-numeric: tabular-nums; }
.card span { color: var(--brand-muted); font-size: 13px; }
code { overflow-wrap: anywhere; }
.audit-event { padding: 0 0 24px; margin: 0 0 24px; border-bottom: 2px solid var(--brand-line); }
.audit-event:last-child { border-bottom: 0; margin-bottom: 0; }
.staff-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.staff-card { padding: 16px; border: 1px solid var(--brand-line); border-radius: var(--radius); background: var(--row-alt-bg); }
.staff-card .page-heading { margin-bottom: 12px; }
.compact-form { margin-top: 16px; }

/* ---- Сообщения ---- */
.flash, .error {
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px;
}
.flash { background: var(--ok-bg); color: var(--ok-fg); border: 1px solid var(--flash-border); }
.error { background: var(--fail-bg); color: var(--danger); border: 1px solid var(--error-border); }
.notice { padding: 12px 14px; border: 1px solid var(--brand-line); border-radius: var(--radius); background: var(--brand-th); }
.notice.warning { border-color: #d8a514; background: #fff8dc; }
.notice h2 { margin-top: 0; }
.recovery-codes { columns: 2 220px; padding-left: 28px; }
.recovery-codes li { margin: 6px 20px 6px 0; break-inside: avoid; }
.recovery-codes code { font-size: 15px; letter-spacing: .04em; }

/* ---- Страница входа: без меню, форма по центру ---- */
body.login .shell { justify-content: center; padding-top: 60px; }
body.login .content { max-width: 380px; }
.sso-button { width: 100%; margin-bottom: 12px; }
.auth-separator { display: flex; align-items: center; gap: 10px; color: var(--brand-muted); font-size: 12px; }
.auth-separator::before, .auth-separator::after { content: ""; flex: 1; border-top: 1px solid var(--brand-line); }

/* ---- Узкий экран ---- */
@media (max-width: 900px) {
  /* align-items: flex-start у .shell в колоночном флексе управляет горизонталью:
     .content шёл по ширине содержимого, а не контейнера, и страница ловила
     собственный горизонтальный скролл вместо прокрутки .table-wrap. */
  .shell { flex-direction: column; align-items: stretch; }
  .sidebar { position: static; width: 100%; flex: none; display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar a { flex: 0 0 auto; }
  /* Тот же переход на колонку меняет ось justify-content у формы входа с
     горизонтальной на вертикальную: без этого override форма прижималась влево. */
  body.login .shell { align-items: center; }
}

@media (max-width: 520px) {
  .content { padding: 16px; }
  .details-grid { grid-template-columns: minmax(100px, 120px) minmax(0, 1fr); gap: 7px 12px; }
  .form-actions > * { width: 100%; }
}
