/*
 * Консоль PaymentFacade — тёмная тема в дизайн-языке консоли ProviderGateway.
 * Свой набор CSS-переменных и компонентов (карточки, бейджи, таблицы, модалка,
 * session-log). Без внешних UI-фреймворков — только этот файл.
 */

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #151822;
    --border: #2a2d3a;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --radius: 8px;
    --mono: 'Cascadia Code', 'Consolas', ui-monospace, monospace;
}

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

/* До монтирования Vue прячем шаблон (иначе мелькает сырой HTML экрана логина). */
[v-cloak] { display: none !important; }

body {
    font-family: 'Segoe UI', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--primary-hover); text-decoration: none; }
.mono { font-family: var(--mono); }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }

/* === Верхняя панель === */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { font-size: 16px; font-weight: 600; letter-spacing: 0.2px; }
.brand .accent { color: var(--primary-hover); }
.tag-facade {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--warning);
    border: 1px solid var(--warning);
    border-radius: 999px;
    padding: 1px 8px;
}
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--text-muted); font-size: 13px; }

/* === Табы === */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 53px;
    z-index: 15;
}
.tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 14px;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    transition: color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }

/* === Контейнер контента === */
main { padding: 20px; max-width: 1040px; margin: 0 auto; }
main.wide { max-width: 1320px; }
.tab-wide { max-width: 1320px; }
h2 { font-size: 18px; margin-bottom: 4px; }
.subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }

/* === Карточка === */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 16px;
}
.card h3 { font-size: 14px; margin-bottom: 12px; color: var(--text); font-weight: 600; }

/* Информационный баннер (например «провайдер задан конфигом») */
.banner {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: var(--text-muted);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 14px;
}
.banner b { color: var(--text); }

/* === Формы === */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-row.triple { grid-template-columns: 1fr 1fr 1fr; }
.form-row.single { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--text-dim); }
.field input, .field select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    width: 100%;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); }
.field input::placeholder { color: var(--text-dim); }
.field .with-btn { display: flex; gap: 8px; }
.field .with-btn input { flex: 1; }

details.collapsible { margin-bottom: 12px; }
details.collapsible > summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 13px;
    padding: 6px 0;
    user-select: none;
}
details.collapsible[open] > summary { color: var(--text); }

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 4px; }

/* === Кнопки === */
.btn {
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-outline:hover:not(:disabled) { border-color: var(--text-muted); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* === Бейджи статусов === */
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}
/* Внутренние статусы фасада (FacadeStatus) */
.badge-created,
.badge-registerrequested { background: #1e293b; color: #94a3b8; }
.badge-registered { background: #1a3a2a; color: #4ade80; }
.badge-payrequested,
.badge-paypending { background: #3b2f1a; color: #fbbf24; }
.badge-succeeded { background: #14532d; color: #22c55e; }
.badge-failedfinal { background: #450a0a; color: #f87171; }
.badge-manualreview,
.badge-pendingmanualreview { background: #2a1e3d; color: #c084fc; }
/* Публичные статусы (Pending/Success/Failed) */
.badge-pending { background: #3b2f1a; color: #fbbf24; }
.badge-success { background: #14532d; color: #22c55e; }
.badge-failed { background: #450a0a; color: #f87171; }
.badge-unknown { background: #1e293b; color: #94a3b8; }

/* === Статистика (dashboard) === */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}
.stat .label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.stat .value { font-size: 26px; font-weight: 700; font-family: var(--mono); }
.stat .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat.ok .value { color: var(--success); }
.stat.warn .value { color: var(--warning); }
.stat.bad .value { color: var(--danger); }

/* === Таблицы === */
.table-wrap { overflow-x: auto; }
table.payments { width: 100%; border-collapse: collapse; font-size: 13px; }
table.payments thead th {
    text-align: left;
    padding: 8px 10px;
    color: var(--text-dim);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.payments tbody td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.payments tbody tr { cursor: pointer; }
table.payments tbody tr:hover { background: var(--surface-2); }
table.payments td.amount { font-family: var(--mono); text-align: right; white-space: nowrap; }
table.payments td.mono { font-family: var(--mono); color: var(--text-muted); white-space: nowrap; }
/* Права учётки (PSY-159): бейджи скоупов с переносом — вместо неразрывной mono-строки через запятую */
table.payments td .scope-list { display: flex; flex-wrap: wrap; gap: 4px; }
.empty { color: var(--text-dim); padding: 24px; text-align: center; }

/* === Пагинация === */
.pager { display: flex; gap: 12px; align-items: center; margin-top: 12px; color: var(--text-muted); font-size: 13px; }

/* === Пара ключ-значение (детали) === */
.kv-grid { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 13px; }
.kv-grid .k { color: var(--text-dim); }
.kv-grid .v { color: var(--text); word-break: break-word; }
.kv-grid .v.mono { font-family: var(--mono); }

/* === Сообщения === */
.alert { border-radius: 6px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.alert-error { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.4); color: #fca5a5; }
.alert-ok { background: rgba(34, 197, 94, 0.1); border: 1px solid rgba(34, 197, 94, 0.4); color: #86efac; }
.alert-warn { background: rgba(245, 158, 11, 0.1); border: 1px solid rgba(245, 158, 11, 0.4); color: #fcd34d; }

/* === Session log === */
.timeline { display: flex; flex-direction: column; gap: 8px; }
.log-entry {
    display: grid;
    grid-template-columns: 64px 56px 1fr auto;
    gap: 10px;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 13px;
}
.log-entry.ok { border-left-color: var(--success); }
.log-entry.err { border-left-color: var(--danger); }
.log-entry .method { font-family: var(--mono); color: var(--primary-hover); font-weight: 600; }
.log-entry .path { font-family: var(--mono); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-entry .status { font-family: var(--mono); }
.log-entry .status.ok { color: var(--success); }
.log-entry .status.err { color: var(--danger); }
.log-entry .time { color: var(--text-dim); font-family: var(--mono); font-size: 12px; }

/* === Модалка === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    z-index: 40;
    overflow-y: auto;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 620px;
    padding: 20px 22px;
}
.modal .modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal .modal-head h3 { font-size: 15px; font-family: var(--mono); }
.modal .close-x { background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1; }
.modal .close-x:hover { color: var(--text); }
.modal pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 12px; font-size: 12px; overflow-x: auto; color: var(--text-muted); margin-top: 12px; }

/* === Экран логина === */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 340px; }
.login-card .title { text-align: center; margin-bottom: 18px; }
.login-card .field { margin-bottom: 12px; }

/* === Адаптив === */
@media (max-width: 720px) {
    .form-row, .form-row.triple { grid-template-columns: 1fr; }
    .kv-grid { grid-template-columns: 1fr; gap: 2px 0; }
    .kv-grid .k { margin-top: 6px; }
    .log-entry { grid-template-columns: 1fr auto; }
    .log-entry .path { grid-column: 1 / -1; }
    /* PSY-159: компактнее ячейки таблиц на узких экранах; остальное страхует .table-wrap (overflow-x) */
    table.payments thead th, table.payments tbody td { padding: 6px 8px; }
}
