/* Каркас админ-UI Telegram Gateway.
   Токены и базовые компоненты взяты из docs/admin-ui-mockup.html: экраны из следующих
   задач подключают этот же styles.css и должны выглядеть как утверждённый макет. */

:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-alt: #f7f9fb;
  --border: #cfd8e3;
  --border-soft: #e6ebf1;
  --text: #1b2430;
  --muted: #4b5764;
  --primary: #0b5cab;
  --primary-dark: #084a8a;
  --primary-soft: #e6f1fb;
  --danger: #9e1b20;
  --danger-dark: #7f1014;
  --danger-soft: #fdecec;
  --danger-text: #8a1418;
  --success-soft: #e7f4ea;
  --success-text: #0f5c34;
  --warn-soft: #fff4d6;
  --warn-text: #6b4700;
  --info-soft: #e6f1fb;
  --info-text: #0a4a80;
  --neutral-soft: #eceff3;
  --neutral-text: #33404d;
  --header-bg: #16283d;
  --header-text: #f2f6fa;
  --header-link: #dbe6f1;
  --focus: #0b5cab;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 10px 28px rgba(16, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 24px; letter-spacing: -.01em; }
h2 { font-size: 17px; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }
a { color: var(--primary); }
ul { line-height: 1.55; }
code {
  font-family: var(--mono);
  font-size: .86em;
  background: var(--surface-alt);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 0 4px;
}
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  background: var(--surface);
  color: var(--primary);
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.skip-link:focus { top: 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.nowrap { white-space: nowrap; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; font-weight: 400; }
.hint-inline { color: var(--muted); font-size: 12px; }

/* ── шапка ─────────────────────────────────────────────── */
.app-header { background: var(--header-bg); color: var(--header-text); }
.app-header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.brand {
  background: none;
  border: 0;
  padding: 0;
  color: #ffffff;
  font-family: var(--font);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.01em;
  cursor: pointer;
  text-decoration: none;
}
.brand span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--header-link);
  margin-left: 6px;
}
.app-header :focus-visible { outline-color: #8fbbe8; }
.main-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-link {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--header-link);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  text-decoration: none;
}
.nav-link:hover { background: #22374f; color: #ffffff; }
.nav-link.is-active { color: #ffffff; border-bottom-color: #8fbbe8; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.session-note { color: var(--header-link); font-size: 12px; }

/* ── каркас ────────────────────────────────────────────── */
main {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 20px 48px;
}
main:focus, main:focus-visible { outline: none; }
.boot-note { color: var(--muted); padding: 24px 0; text-align: center; }
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head .muted { margin: 0; }
.head-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 0; }
.head-actions .hint { margin: 0; }
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.linklike {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.linklike:hover { color: var(--primary-dark); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card:last-child { margin-bottom: 0; }
.card-danger { border-color: #e3b6b8; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.grid-2 .card { margin-bottom: 0; }

/* ── таблицы ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; vertical-align: top; }
th {
  background: #f2f6fa;
  color: #35424f;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  font-size: 14px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-soft);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-alt); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── бейджи ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); }
.badge-warn { background: var(--warn-soft); color: var(--warn-text); }
.badge-info { background: var(--info-soft); color: var(--info-text); }
.badge-neutral { background: var(--neutral-soft); color: var(--neutral-text); }

/* ── кнопки ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: #ffffff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-secondary { background: var(--surface); border-color: #b9c4d0; color: var(--text); }
.btn-secondary:hover { background: var(--surface-alt); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #ffffff; }
.btn-danger:hover { background: var(--danger-dark); border-color: var(--danger-dark); }
.btn-danger-ghost { background: var(--surface); border-color: #e3b6b8; color: var(--danger-text); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-header { background: transparent; border-color: #41566f; color: var(--header-link); }
.btn-header:hover { background: #22374f; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn.is-active { background: var(--primary); border-color: var(--primary); color: #ffffff; }
.btn:disabled { background: #e4e8ec; border-color: #d8dde3; color: #5b6670; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ── формы ─────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #b9c4d0;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--primary);
}
input::placeholder { color: #6b7783; opacity: 1; }
.field-error { color: var(--danger-text); font-size: 13px; margin: 4px 0 0; font-weight: 600; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; }
.check input { margin-top: 3px; width: 16px; height: 16px; }
.check label { font-weight: 400; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 165px; }

/* ── вкладки ───────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 12px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

/* ── врезки и баннеры ──────────────────────────────────── */
.banner {
  border: 1px solid;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  margin: 12px 0;
}
.banner:first-child { margin-top: 0; }
.banner-error { background: var(--danger-soft); border-color: #e3b6b8; color: var(--danger-text); }
.banner-warn { background: var(--warn-soft); border-color: #e8d49a; color: var(--warn-text); }
.banner-info { background: var(--info-soft); border-color: #bcd8ee; color: var(--info-text); }
.banner-success { background: var(--success-soft); border-color: #b7d9c1; color: var(--success-text); }
.banner .btn { margin-left: 6px; }

/* ── вход ──────────────────────────────────────────────── */
.login-screen { display: grid; place-items: center; min-height: 58vh; }
.login-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; }
.login-card form { margin: 18px 0 14px; }
.eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 6px;
}

/* ── пусто и скелетоны ─────────────────────────────────── */
.empty {
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--muted);
  text-align: center;
  padding: 24px 16px;
  margin: 8px 0 0;
}
.empty strong { color: var(--text); }
.empty .btn { margin-top: 10px; }
.filter-empty { margin-top: 14px; }
.skeleton { background: #e6ebf1; border-radius: 6px; height: 14px; }
.skeleton + .skeleton { margin-top: 10px; }
.skeleton.w40 { width: 40%; }
.skeleton.w60 { width: 60%; }
.skeleton.w80 { width: 80%; }
.skeleton-row { display: flex; gap: 12px; align-items: center; padding: 10px 0; }
.skeleton-row .skeleton { margin-top: 0; }

/* ── пары «ключ — значение» ────────────────────────────── */
.kv { margin: 12px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-size: 14px; word-break: break-word; }

/* ── health ────────────────────────────────────────────── */
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-bottom: 18px; }
.health-card { margin-bottom: 0; }
.health-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 6px; }
.health-head h2 { margin: 0; }

/* ── модалки ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(16, 24, 40, .55);
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
}
.modal {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(16, 24, 40, .3);
  padding: 24px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.modal h2 { margin-bottom: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.secret-row { display: flex; gap: 8px; align-items: stretch; }
.secret-row input { flex: 1; font-family: var(--mono); letter-spacing: .04em; }

/* ── тост ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 80;
  background: #1b2430;
  color: #ffffff;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  box-shadow: 0 12px 30px rgba(16, 24, 40, .35);
  max-width: calc(100vw - 32px);
}

/* ── подвал ────────────────────────────────────────────── */
.app-footer {
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px 26px;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  flex-wrap: wrap;
}
.app-footer p { margin: 0; }

@media (prefers-reduced-motion: no-preference) {
  .skeleton { animation: pulse 1.6s ease-in-out infinite; }
  @keyframes pulse { 50% { background: #dbe3ec; } }
}

@media (max-width: 760px) {
  main { padding: 20px 14px 36px; }
  .app-header-inner { padding: 10px 14px; gap: 12px; }
  .session-note { display: none; }
  .header-right { margin-left: 0; }
  .page-head { flex-direction: column; }
  .card { padding: 16px; }
  .filters .field { min-width: 100%; }
}
