/* Вёрстка «Кошелька». Одна точка останова — 600 px: ниже неё включается
   мобильная вёрстка.
   Никаких препроцессоров и сборщиков: обычный CSS, который видно
   в DevTools как есть. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1d21;
  --muted: #6b7280;
  --line: #dfe3e8;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #c62828;
  --topup: #1b7f4b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Шапка -------------------------------------------------------------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.brand { font-weight: 700; font-size: 18px; }

.balance-block { display: flex; align-items: baseline; gap: 10px; }
.balance-label { color: var(--muted); font-size: 14px; }
.balance-value { font-size: 24px; font-weight: 700; }
.header-meta { color: var(--muted); font-size: 14px; margin-left: auto; }

.app-header--desktop .link-button { margin-left: 12px; }
.app-header--plain { justify-content: space-between; }

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

/* --- Навигация ---------------------------------------------------------- */

.app-nav {
  display: flex;
  gap: 4px;
  margin: 12px 0 20px;
  flex-wrap: wrap;
}

.app-nav a {
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
}

.app-nav a:hover { background: #e9ecf2; }
.app-nav a.active { background: var(--accent); color: var(--accent-text); }

/* --- Экран -------------------------------------------------------------- */

.screen { flex: 1; }

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

.card--narrow { max-width: 420px; }

.card h1 { font-size: 22px; margin: 0 0 16px; }
.card h2 { font-size: 18px; margin: 0; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* --- Формы -------------------------------------------------------------- */

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

.field input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.field-error {
  color: var(--danger);
  font-size: 14px;
  margin: 0 0 14px;
}

.hint { color: var(--muted); font-size: 14px; margin: 0 0 14px; }

.button {
  display: inline-block;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* --- Операции ----------------------------------------------------------- */

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.filter {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}

.filter.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.operations { width: 100%; border-collapse: collapse; }
.operations th, .operations td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); }
.operations th { color: var(--muted); font-weight: 600; font-size: 14px; }
.operations td.amount { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.amount--TOPUP { color: var(--topup); }

.operations-list { list-style: none; margin: 0; padding: 0; }
.operation-card { border-bottom: 1px solid var(--line); padding: 12px 0; }
.operation-card__top { display: flex; justify-content: space-between; font-weight: 600; }
.operation-card__bottom { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; margin-top: 4px; }

.empty { color: var(--muted); margin: 12px 0; }
.counter { color: var(--muted); font-size: 14px; }
.more-box { display: flex; align-items: center; gap: 14px; margin-top: 16px; }

/* --- Тарифы ------------------------------------------------------------- */

.tariffs-text {
  margin: 0;
  padding: 16px;
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 15px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

/* --- Ассистент ---------------------------------------------------------- */

.chat {
  min-height: 180px;
  max-height: 380px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  background: #fbfbfd;
}

.chat-message { margin-bottom: 10px; padding: 8px 12px; border-radius: 8px; max-width: 80%; }
.chat-message--user { background: #e6efff; margin-left: auto; }
.chat-message--assistant { background: #eef0f4; }

/* --- Подвал ------------------------------------------------------------- */

.app-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 14px;
}

.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.footer-links a { color: var(--muted); }

/* --- Всплывающие сообщения ---------------------------------------------- */

/* Снизу справа, а не сверху: сверху уведомление накрывало «Выйти» в шапке. */
.toasts {
  position: fixed;
  bottom: 16px;
  right: 16px;
  top: auto;
  left: auto;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #1b1d21;
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  font-size: 15px;
}

/* --- Мобильная вёрстка ---------------------------------------------------- */

@media (max-width: 599px) {
  .page { padding: 12px 12px 28px; }

  .app-header--mobile {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 12px 14px;
  }

  .balance-compact { display: flex; align-items: baseline; gap: 8px; }
  .balance-value { font-size: 20px; }
  .header-meta { margin-left: 0; font-size: 13px; }

  .app-nav {
    margin: 10px 0 14px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .app-nav a { white-space: nowrap; padding: 8px 12px; font-size: 14px; }

  .logout-standalone { display: block; margin: 0 0 12px auto; }

  .card { padding: 14px; }
  .card h1 { font-size: 19px; }
  .card--narrow { max-width: none; }

  .actions { flex-direction: column; align-items: stretch; }
  .actions .button { text-align: center; }

  .button { padding: 12px 18px; }

  .toasts { left: 12px; right: 12px; top: auto; bottom: 12px; }

  .app-footer { flex-direction: column; gap: 8px; }

  .tariffs-text { font-size: 13px; padding: 12px; }
}

/* ── SQL-консоль (2.7) ───────────────────────────────────────────── */

.sql-hint {
  color: var(--muted);
  margin: 0 0 16px;
}

.sql-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 24px;
  align-items: start;
}

.sql-main label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

#sql-input {
  width: 100%;
  box-sizing: border-box;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  line-height: 1.5;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}

#sql-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.sql-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 16px;
}

.sql-copied {
  color: var(--topup);
  font-size: 14px;
}

.sql-meta {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 8px;
}

.sql-notice {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 8px;
}

.sql-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table.sql-result {
  border-collapse: collapse;
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

table.sql-result th,
table.sql-result td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.sql-result th {
  background: var(--bg);
  font-weight: 600;
}

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

td.sql-null {
  color: var(--muted);
  font-style: italic;
}

.sql-schema {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--bg);
}

.sql-schema h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 12px;
}

.sql-table + .sql-table {
  margin-top: 16px;
}

.sql-table h3 {
  font-size: 15px;
  margin: 0 0 6px;
}

.sql-schema ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sql-schema li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-size: 13px;
}

.sql-type {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .sql-layout {
    grid-template-columns: 1fr;
  }
}

/* Класс .button задаёт display, поэтому атрибут hidden сам по себе
   его не прячет — возвращаем ожидаемое поведение. */
.sql-actions [hidden] {
  display: none;
}

/* История запросов SQL-консоли. */
.sql-history { margin-top: 24px; }
.sql-history h2 { font-size: 15px; margin: 0 0 8px; }
.sql-history-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.sql-history-item {
  /* Блочная кнопка: у строчной маркер списка съезжает к нижней строке,
     когда длинный запрос переносится. */
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 2px 0;
  text-align: left;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--link, #2f6fed);
  cursor: pointer;
}
.sql-history-item:hover { text-decoration: underline; }
