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

:root {
  --bg: #0e1116;
  --panel: #151a22;
  --panel-2: #1b2230;
  --line: #232b39;
  --text: #e7ecf3;
  --muted: #8a95a8;
  --accent: #3d7dfb;
  --ok: #2e9e5b;
  --warn: #c98a1a;
  --danger: #c8433f;
  --row-hover: #1d2531;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.db-access-status { margin: 12px 0; }
.db-access-credentials { margin: 14px 0; padding: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.db-access-row { display: grid; grid-template-columns: 85px minmax(0, 1fr); gap: 12px; padding: 5px 0; }
.db-access-row code { overflow-wrap: anywhere; user-select: all; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ── Вход ── */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, #182234, var(--bg) 70%);
}

.login-box {
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 24px;
}

.login-box h1 { font-size: 20px; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 12px; margin-bottom: 18px; }
.login-error {
  margin-top: 12px;
  padding: 9px 11px;
  border-radius: 8px;
  background: rgba(200, 67, 63, .14);
  border: 1px solid rgba(200, 67, 63, .4);
  font-size: 12px;
}

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; color: var(--muted); font-size: 11.5px; margin-bottom: 5px; }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #101620;
  color: var(--text);
  font: inherit;
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 120px; resize: vertical; }
input[type="checkbox"] { width: auto; }
.setting-switch { position: relative; display: inline-flex; flex-shrink: 0; width: 46px; height: 26px; margin: 4px 0; }
.setting-switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.setting-switch-track { display: block; width: 46px; height: 26px; border-radius: 20px; background: #374151; transition: background .18s ease; }
.setting-switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .18s ease; }
.setting-switch input:checked + .setting-switch-track { background: var(--accent); }
.setting-switch input:checked + .setting-switch-track::after { transform: translateX(20px); }
.setting-switch input:focus-visible + .setting-switch-track { outline: 2px solid var(--text); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { .setting-switch-track, .setting-switch-track::after { transition: none; } }

/* ── Каркас ── */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 214px;
  flex: 0 0 214px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { padding: 16px 18px; font-size: 15px; font-weight: 700; border-bottom: 1px solid var(--line); }
.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 11px;
  margin-bottom: 2px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--line); }
.sidebar-foot .btn { margin-top: 8px; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 { font-size: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.view { padding: 18px 20px 60px; }

/* ── Кнопки ── */

.btn {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 6px 11px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--text);
  white-space: nowrap;
}

.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 3px 8px; font-size: 11.5px; }

/* ── Панели, сетки ── */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.card > h2 { font-size: 13.5px; margin-bottom: 12px; color: var(--accent); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.grow { flex: 1 1 220px; min-width: 180px; }
.toolbar input[type="file"] { width: auto; max-width: 280px; }

#bc-count.warn { color: var(--warn); }

.fmt-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0 0 8px;
}
.fmt-bar .btn { min-width: 32px; }

.bc-media { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bc-media input[type="file"] { width: auto; max-width: 100%; }
.bc-file-info { margin-top: 8px; }
.bc-thumb {
  display: block;
  max-height: 140px;
  max-width: 240px;
  border-radius: 8px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
}

.bc-preview {
  min-height: 72px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px dashed var(--line);
  background: #101620;
  white-space: pre-wrap;
  word-break: break-word;
}
.bc-preview b, .bc-preview strong { font-weight: 700; }
.bc-preview i, .bc-preview em { font-style: italic; }
.bc-preview u { text-decoration: underline; }
.bc-preview s, .bc-preview del { text-decoration: line-through; }
.bc-preview code, .bc-preview pre {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: #1b2230;
  padding: 1px 5px;
  border-radius: 4px;
}
.bc-preview a { color: #6ea8ff; }
.bc-preview blockquote {
  margin: 6px 0;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.bc-preview .tg-spoiler {
  background: #2a3344;
  color: transparent;
  border-radius: 4px;
  filter: blur(6px);
  user-select: none;
  cursor: help;
}
.bc-preview .tg-spoiler:hover {
  filter: none;
  color: inherit;
  background: rgba(61, 125, 251, .16);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}

.stat b { display: block; font-size: 21px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 11.5px; }
.stat.hint b { font-size: 15px; }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }

/* ── Таблицы ── */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); }

th, td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tbody tr:hover { background: var(--row-hover); }
tbody tr.clickable { cursor: pointer; }
td.actions { white-space: nowrap; }
td.actions .btn { margin-right: 4px; }

.kind-switch {
  display: inline-flex;
  gap: 3px;
  margin-right: 6px;
  vertical-align: middle;
}
.kind-switch .btn { margin-right: 0; }
.cell-title { font-weight: 600; }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ingest-log {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text);
  max-width: 720px;
}

.pager { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.pager > button, .pager > select { flex-shrink: 0; }

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
}

.tag-ok { background: rgba(46, 158, 91, .17); border-color: rgba(46, 158, 91, .5); color: #7bdca4; }
.tag-warn { background: rgba(201, 138, 26, .17); border-color: rgba(201, 138, 26, .5); color: #ecc37a; }
.tag-danger { background: rgba(200, 67, 63, .17); border-color: rgba(200, 67, 63, .5); color: #f1948f; }
.tag-accent { background: rgba(61, 125, 251, .17); border-color: rgba(61, 125, 251, .5); color: #9dbcff; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px 4px 2px 8px;
  font-size: 11.5px;
}

.chip button {
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
  padding: 0 3px;
}

.empty { padding: 30px; text-align: center; color: var(--muted); }
.loading { padding: 24px; text-align: center; color: var(--muted); }

pre.json {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
}

.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 7px; }
.checks label { display: flex; align-items: center; gap: 7px; color: var(--text); }

.bar { height: 8px; background: var(--panel-2); border-radius: 6px; overflow: hidden; margin: 8px 0; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.bar.live > i {
  background-image: linear-gradient(90deg, var(--accent) 0%, #6bb4ff 50%, var(--accent) 100%);
  background-size: 220% 100%;
  animation: ingest-live 1.4s linear infinite;
}
.bar.warm > i { background: #ecc37a; }
.bar.hot > i { background: #f1948f; }

.mon-row {
  display: grid;
  grid-template-columns: 140px 1fr minmax(140px, auto);
  gap: 8px;
  align-items: center;
  margin: 6px 0;
}
.mon-lab { font-size: 12px; color: var(--muted); }
.mon-val { font-size: 12px; color: var(--text); text-align: right; }
.mon-bar { margin: 0; height: 10px; }
.mon-cores {
  display: flex;
  gap: 4px;
  align-items: flex-end;
  height: 56px;
  margin: 8px 0 12px;
}
.mon-core {
  flex: 1;
  min-width: 10px;
  height: 100%;
  background: var(--panel-2);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
.mon-core i {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--accent);
}
.mon-core.warm i { background: #ecc37a; }
.mon-core.hot i { background: #f1948f; }
.mon-core span {
  position: absolute;
  left: 0; right: 0; bottom: 2px;
  text-align: center;
  font-size: 9px;
  color: var(--muted);
}

@keyframes ingest-live {
  from { background-position: 200% 0; }
  to { background-position: 0 0; }
}

.danger-zone { border-color: rgba(200, 67, 63, .45); }
.danger-zone > h2 { color: #f1948f; }

/* ── Модальное окно ── */

.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-start; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .62); }

.modal-body {
  position: relative;
  width: min(940px, calc(100vw - 40px));
  margin: 40px 0;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 { font-size: 15px; }
.modal-content { padding: 16px; overflow-y: auto; }

/* ── Уведомления ── */

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }

.toast {
  min-width: 240px;
  max-width: 380px;
  padding: 10px 13px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 12.5px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .38);
}

.toast.ok { border-color: rgba(46, 158, 91, .6); }
.toast.warn { border-color: rgba(201, 138, 26, .7); }
.toast.err { border-color: rgba(200, 67, 63, .6); }

.ticket-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(340px, 1.1fr);
  gap: 16px;
  align-items: start;
}
.ticket-list { min-width: 0; }
.ticket-pane { min-height: 480px; display: flex; flex-direction: column; }
.ticket-head {
  display: flex; justify-content: space-between; gap: 10px;
  align-items: flex-start; margin-bottom: 12px;
}
.ticket-log {
  flex: 1; overflow-y: auto; max-height: 52vh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 4px 2px 12px;
}
.bubble {
  max-width: 86%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.me { align-self: flex-end; background: rgba(61, 125, 251, .16); }
.bubble.them { align-self: flex-start; }
.bubble-meta { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.ticket-compose { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.ticket-compose textarea { min-height: 80px; }
tr.unread-row { background: rgba(61, 125, 251, .07); }
tr.active-row { outline: 1px solid var(--accent); }
.ad-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; white-space: nowrap;
}
.ad-toggle.on { border-color: rgba(46, 158, 91, .5); background: rgba(46, 158, 91, .12); }
.ad-toggle.dim { opacity: .65; }
.ad-toggle input { margin: 0; }
.filmbox-log {
  height: 380px;
  overflow: auto;
  margin: 0;
  background: #101620;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

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

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: column; }
  .nav { display: flex; flex-wrap: wrap; }
  .nav-item { width: auto; }
}
.application-review { margin: 16px 0; }
.application-review dl { display: grid; grid-template-columns: minmax(140px, 1fr) minmax(0, 3fr); gap: 10px 16px; margin: 16px 0; }
.application-review dt { color: var(--muted, #9ba6b6); }
.application-review dd { margin: 0; overflow-wrap: anywhere; }
.application-review label { display: block; margin-top: 12px; }
.application-review input, .application-review textarea { display: block; width: 100%; margin-top: 6px; }
@media (max-width: 650px) { .application-review dl { grid-template-columns: 1fr; gap: 6px; } .application-review dd { margin-bottom: 10px; } }
