/* Панель BorzoiHost — стили поверх токенов (css/tokens.css) и шрифтов (css/fonts.css).
   Канон: docs/BRZ-FRONTEND-US-DESIGN-BRIEF.md — Unbounded/Golos Text/JetBrains Mono,
   обводка 2px, радиусы: кнопки/инпуты 16px, карточки 25px. */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: "Golos Text", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
#app { min-height: 100vh; }
a { color: var(--link-idle); }
a:hover { color: var(--link-hover); }
h1, h2, h3, h4 { font-family: "Unbounded", sans-serif; line-height: 1.25; }
code, .mono { font-family: "JetBrains Mono", monospace; }

/* ---------- Каркас ---------- */
.app-shell { display: grid; grid-template-columns: 250px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  border-bottom: 2px solid var(--ink);
  background: var(--header-bg);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand img { height: 30px; }
.brand .brand-name { font-family: "Unbounded", sans-serif; font-size: 1rem; font-weight: 700; }
.menu-toggle { display: none; }
.spacer { flex: 1; }
.user-menu { display: flex; align-items: center; gap: 10px; font-size: .85rem; }
.user-menu .user-email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar {
  border-right: 2px solid var(--ink);
  background: var(--surface);
  padding: 18px 12px;
  position: sticky; top: 57px; height: calc(100vh - 57px);
  overflow-y: auto;
}
.nav-group { margin-bottom: 18px; }
.nav-group-title {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 0 10px; margin: 0 0 6px; font-weight: 700;
}
.nav-link {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 12px; border: 2px solid transparent;
  text-decoration: none; color: var(--ink); font-weight: 600; font-size: .88rem;
}
.nav-link:hover { background: var(--surface-soft); }
.nav-link.active { background: var(--ink); color: var(--page); }
.nav-link.active:hover { color: var(--page); }

.page { padding: 26px 24px 60px; max-width: 1180px; width: 100%; }
.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px; margin-bottom: 22px; }
.page-header h2 { margin: 0; font-size: 1.25rem; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border: 2px solid var(--ink); border-radius: var(--radius-control);
  background: var(--surface); color: var(--ink);
  font: 700 .88rem "Golos Text", sans-serif; text-decoration: none; cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
}
.btn:hover { background: var(--surface-soft); }
.btn-primary { background: var(--ink); color: var(--page); }
.btn-primary:hover { opacity: .88; background: var(--ink); }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: var(--on-color); }
.btn-sm { padding: 5px 11px; font-size: .78rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
/* Тихая текстовая кнопка для вторичных действий (переключение форм и т.п.) */
.btn-link {
  padding: 0; border: none; background: none; color: var(--ink);
  font: 700 .88rem "Golos Text", sans-serif; text-decoration: underline; cursor: pointer;
}
.btn-link:hover { opacity: .7; background: none; }
/* Во всех формах кнопки одной высоты с полями ввода */
.inline-form .btn, .stack-form .btn { min-height: 44px; }
.auth-actions { display: flex; justify-content: center; gap: 16px; }

/* ---------- Контролы форм: панель создаёт bare <input>/<select>/<textarea> ---------- */
/* Дизайн-система стилизует классы .input/.select/.textarea, но JS-панель классы не ставит —
   без этой стилизации контролы были браузерными дефолтами (корень жалоб «разные размеры форм»). */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="range"]),
select, textarea {
  width: 100%; min-width: 0; min-height: 44px;
  border: 2px solid var(--ink); border-radius: var(--radius-control);
  background: var(--surface); padding: 0 14px; outline: 0;
  font: 500 .92rem "Golos Text", sans-serif; color: var(--ink);
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}
textarea { min-height: 110px; padding: 12px 14px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus {
  border-color: var(--aqua);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--aqua) 24%, transparent);
}
input:disabled, select:disabled, textarea:disabled { opacity: .5; cursor: not-allowed; }
select {
  appearance: none; padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2308050e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
[data-theme="night"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23f7f4ec' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
.theme-toggle { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--ink); background: var(--surface); cursor: pointer; font-size: 1rem; line-height: 1; }
.theme-toggle:hover { background: var(--surface-soft); }

/* ---------- Карточки, метрики ---------- */
.card {
  padding: 16px; border: 2px solid var(--ink); border-radius: var(--radius-card);
  background: var(--surface); display: grid; gap: 8px; align-content: start;
}
.card-title { margin: 0; font-size: .95rem; }
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 24px; }
.metric-card { padding: 16px; border: 2px solid var(--ink); border-radius: var(--radius-card); background: var(--surface); }
.metric-value { display: block; font-family: "Unbounded", sans-serif; font-size: 1.6rem; }
.metric-label { color: var(--muted); font-size: .82rem; }
.section { margin-bottom: 26px; }
.section > h3 { margin: 0 0 12px; font-size: 1rem; }
.card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }

.quota-bar { height: 10px; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; background: var(--surface-soft); }
.quota-fill { height: 100%; background: var(--aqua); }
.quota-fill.quota-high { background: var(--yellow); }
.quota-fill.quota-over { background: var(--red); }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; border: 2px solid var(--ink); border-radius: var(--radius-card); background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; min-width: 520px; }
.data-table th, .data-table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Бейджи ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: uppercase; background: var(--surface-soft); white-space: nowrap; }
.badge-active, .badge-paid, .badge-approved, .badge-running, .badge-resolved { background: var(--aqua); color: var(--on-color); }
.badge-unpaid, .badge-pending, .badge-onhold, .badge-paused { background: var(--yellow); color: var(--on-color); }
.badge-suspended, .badge-cancelled, .badge-error, .badge-failed, .badge-overdue, .badge-stopped { background: var(--red); color: var(--on-color); }
.badge-open, .badge-processing { background: var(--blue); color: var(--on-color); }
.badge-closed, .badge-draft { background: var(--surface-soft); color: var(--ink); }

/* ---------- Формы ---------- */
.field { display: grid; gap: 5px; }
.field-label { font-size: .82rem; font-weight: 700; }
input, select, textarea {
  padding: 10px 12px; border: 2px solid var(--ink); border-radius: var(--radius-control);
  background: var(--page); color: var(--ink); font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--focus-ring); outline-offset: 1px; }
textarea { min-height: 110px; resize: vertical; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 18px; }
.inline-form .field { min-width: 160px; flex: 1; }
.stack-form { display: grid; gap: 13px; max-width: 620px; margin-bottom: 24px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.hint { font-size: .8rem; color: var(--muted); margin: 0; }
.checkbox-line { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.checkbox-line input { width: auto; }

/* ---------- Состояния ---------- */
.state-block { display: flex; align-items: center; gap: 14px; padding: 26px 16px; color: var(--muted); justify-content: center; flex-wrap: wrap; }
.state-error { color: var(--red); }
.state-empty { font-style: italic; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.alert { padding: 12px 16px; border-radius: var(--radius-alert); margin-top: 12px; font-size: .88rem; }
.alert-err { background: color-mix(in srgb, var(--red) 12%, var(--surface)); color: var(--red); border: 2px solid var(--red); }
.alert-info { background: var(--surface-soft); border: 2px solid var(--ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Логин ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth-card { width: 100%; max-width: 430px; padding: 34px; border: 2px solid var(--ink); border-radius: var(--radius-panel); background: var(--surface); box-shadow: 6px 6px 0 var(--card-shadow); }
.auth-card .brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth-card .brand-row img { height: 40px; }
.auth-card h1 { font-size: 1.15rem; margin: 0; }
.auth-card form { display: grid; gap: 13px; margin-top: 18px; }

/* ---------- Модалки ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgb(0 0 0 / 50%); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: 24px; border: 2px solid var(--ink); border-radius: var(--radius-panel); background: var(--surface); box-shadow: 6px 6px 0 var(--card-shadow); }
.modal-title { margin: 0 0 10px; font-size: 1.05rem; }
.modal-message { margin: 0 0 12px; }
.modal-form { display: grid; gap: 12px; margin-top: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- Тосты ---------- */
.toast-box { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 200; }
.toast { padding: 12px 18px; border: 2px solid var(--ink); border-radius: var(--radius-alert); background: var(--surface); box-shadow: 4px 4px 0 var(--card-shadow); font-weight: 600; font-size: .88rem; opacity: 0; transform: translateY(8px); transition: all var(--t-fast) var(--ease); max-width: 340px; }
.toast.show { opacity: 1; transform: none; }
.toast-success { border-color: var(--aqua); }
.toast-error { border-color: var(--red); color: var(--red); }

/* ---------- Тикеты ---------- */
.ticket-messages { display: grid; gap: 12px; margin: 16px 0; }
.ticket-message { padding: 14px; border: 2px solid var(--ink); border-radius: var(--radius-card); background: var(--surface); max-width: 720px; }
.ticket-message.msg-admin { border-color: var(--blue); margin-left: 40px; }
.ticket-message.msg-client { margin-right: 40px; }
.ticket-message .msg-meta { font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
.ticket-message .msg-body { white-space: pre-wrap; }

/* ---------- Файловый менеджер ---------- */
.breadcrumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; font-size: .9rem; }
.breadcrumbs a { font-weight: 600; }
.file-grid-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }

/* ---------- Пагинация ---------- */
.pagination { display: flex; align-items: center; gap: 10px; margin-top: 14px; }

/* ---------- Адаптив ---------- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 270px; height: 100vh; z-index: 90;
    transform: translateX(-105%); transition: transform var(--t-nav) var(--ease);
    border-right: 2px solid var(--ink); box-shadow: 8px 0 24px rgb(0 0 0 / 25%);
  }
  .sidebar.open { transform: none; }
  .sidebar-close { display: inline-flex !important; margin-bottom: 10px; }
  .page { padding: 18px 14px 60px; }
  .ticket-message.msg-admin { margin-left: 0; }
  .ticket-message.msg-client { margin-right: 0; }
  .user-menu .user-email { max-width: 110px; }
}
.sidebar-close { display: none; }
