/* ============================================================
   AI Gateway — дизайн-система (тёмная тема)
   ============================================================ */

:root {
  --bg: #0a0a0b;
  --bg-soft: #101012;
  --card: #141416;
  --card-2: #1a1a1d;
  --card-3: #202024;
  --border: #232327;
  --border-2: #2e2e33;
  --text: #ececee;
  --muted: #9c9ca5;
  --dim: #6c6c75;
  --accent: #f2c14e;
  --accent-2: #f6cd6e;
  --accent-ink: #201a05;
  --green: #3ecf8e;
  --red: #f26d6d;
  --amber: #f2b04e;
  --blue: #6ea8fe;
  --violet: #b48cf2;
  --radius: 14px;
  --radius-sm: 10px;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: Inter, ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(242, 193, 78, .28); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2c2c31; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #3a3a40; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.dim { color: var(--dim); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---------- карточки ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card + .card { margin-top: 14px; }
.card-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  font-size: 14.5px;
  margin-bottom: 14px;
}
.card-title svg { color: var(--accent); flex: none; }

/* ---------- кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--card-2);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .14s, border-color .14s, transform .05s, opacity .14s;
  user-select: none;
}
.btn:hover { background: var(--card-3); border-color: #3a3a41; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { flex: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }

.btn-danger {
  background: transparent;
  border-color: rgba(242, 109, 109, .35);
  color: var(--red);
}
.btn-danger:hover { background: rgba(242, 109, 109, .09); border-color: rgba(242, 109, 109, .5); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--card-2); color: var(--text); }

.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; gap: 6px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-icon { width: 32px; padding: 0; }
.btn-block { width: 100%; }

.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid rgba(242, 193, 78, .45);
  outline-offset: 1px;
}

/* ---------- поля ввода ---------- */

.field { margin-bottom: 13px; }
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 550;
}
.field .hint { font-size: 11.5px; color: var(--dim); margin-top: 5px; line-height: 1.45; }

.input, select.input, textarea.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--bg-soft);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  transition: border-color .14s;
}
textarea.input { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus { border-color: rgba(242, 193, 78, .55); outline: none; }
.input::placeholder { color: var(--dim); }
.input.mono { font-family: var(--mono); font-size: 12.5px; }

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239c9ca5' stroke-width='2.4' 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;
  padding-right: 32px;
  cursor: pointer;
}

.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row .fixed { flex: none; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- пилюли и чипы ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2.5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.pill-green { background: rgba(62, 207, 142, .13); color: var(--green); }
.pill-red { background: rgba(242, 109, 109, .13); color: var(--red); }
.pill-amber { background: rgba(242, 176, 78, .14); color: var(--amber); }
.pill-blue { background: rgba(110, 168, 254, .13); color: var(--blue); }
.pill-gray { background: var(--card-3); color: var(--muted); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--card-2);
  border: 1px solid var(--border);
  font-size: 12px;
  font-family: var(--mono);
  white-space: nowrap;
}
.chip .x {
  cursor: pointer;
  color: var(--dim);
  display: inline-flex;
  border: 0;
  background: none;
  padding: 0;
}
.chip .x:hover { color: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip .coeff { color: var(--accent); font-weight: 600; }

/* ---------- таблицы ---------- */

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  background: var(--card);
}
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid #1d1d21;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #17171a; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- прогресс ---------- */

.progress {
  height: 6px;
  border-radius: 999px;
  background: #232328;
  overflow: hidden;
  min-width: 90px;
}
.progress > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #ee9d4e);
  transition: width .3s;
}
.progress.ok > i { background: linear-gradient(90deg, #3ecf8e, #2fb377); }
.progress.full > i { background: linear-gradient(90deg, #f26d6d, #e05555); }

/* ---------- переключатель ---------- */

.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--card-3);
  border: 1px solid var(--border-2);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .15s, background .15s;
}
.switch input:checked + .track { background: rgba(242, 193, 78, .25); border-color: rgba(242, 193, 78, .5); }
.switch input:checked + .track::after { transform: translateX(16px); background: var(--accent); }

/* ---------- макет админки ---------- */

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

.sidebar {
  width: 224px;
  flex: none;
  padding: 16px 12px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 16px;
}
.brand .logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-ink);
  flex: none;
}
.brand .name { font-weight: 700; font-size: 14.5px; line-height: 1.2; }
.brand .sub { font-size: 11px; color: var(--dim); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  border: 0;
  background: none;
  width: 100%;
  text-align: left;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--card); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--card-2); color: var(--text); }
.nav-item svg { flex: none; opacity: .85; }
.nav-item .count {
  margin-left: auto;
  font-size: 11px;
  background: var(--card-3);
  border-radius: 999px;
  padding: 1px 7px;
  color: var(--muted);
}

.sidebar .spacer { flex: 1; }
.sidebar .foot {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding-left: 6px;
  padding-right: 6px;
}
.sidebar .foot .who { flex: 1; min-width: 0; }
.sidebar .foot .who .u { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .foot .who .r { font-size: 11px; color: var(--dim); }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--card-3);
  border: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex: none;
}

.main { flex: 1; min-width: 0; padding: 20px 24px 40px; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  min-height: 38px;
}
.topbar h1 { flex: 1; }
.page-max { max-width: 1160px; }

/* ---------- статистика ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
}
.stat .label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.stat .label svg { color: var(--dim); }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.stat .value .unit { font-size: 13px; color: var(--dim); font-weight: 500; margin-left: 3px; }
.stat .sub { font-size: 11.5px; color: var(--dim); margin-top: 3px; }

/* ---------- график ---------- */

.chart-wrap { width: 100%; }
.chart-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- модальные окна ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 6, .66);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal {
  background: var(--card);
  border: 1px solid var(--border-2);
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
  animation: modal-in .16s ease-out;
}
.modal.wide { max-width: 720px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 0;
}
.modal-head h2 { flex: 1; }
.modal-head .x { border: 0; background: none; color: var(--dim); cursor: pointer; padding: 4px; border-radius: 8px; display: flex; }
.modal-head .x:hover { color: var(--text); background: var(--card-2); }
.modal-body { padding: 14px 18px 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 12px 18px 16px; }

/* ---------- тосты ---------- */

#toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  max-width: 380px;
}
.toast {
  background: var(--card-2);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--blue);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  animation: toast-in .18s ease-out;
  word-break: break-word;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- вкладки (сегменты) ---------- */

.seg {
  display: inline-flex;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.seg button.active { background: var(--card-3); color: var(--text); }

/* ---------- код ---------- */

.code {
  position: relative;
  background: #0d0d10;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  overflow-x: auto;
}
.code pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: #d4d4dc;
  white-space: pre;
}
.code .copy {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: .6;
}
.code:hover .copy { opacity: 1; }

/* ---------- прочее ---------- */

.empty {
  text-align: center;
  color: var(--dim);
  padding: 34px 16px;
  font-size: 13px;
}
.empty svg { width: 30px; height: 30px; margin-bottom: 10px; opacity: .5; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
  vertical-align: -4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}
.banner svg { flex: none; margin-top: 1px; }
.banner-warn { background: rgba(242, 176, 78, .09); border: 1px solid rgba(242, 176, 78, .3); color: var(--amber); }
.banner-err { background: rgba(242, 109, 109, .09); border: 1px solid rgba(242, 109, 109, .3); color: var(--red); }
.banner-ok { background: rgba(62, 207, 142, .08); border: 1px solid rgba(62, 207, 142, .3); color: var(--green); }

.copyable {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 8px 8px 12px;
}
.copyable .val {
  flex: 1;
  font-family: var(--mono);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;
  text-align: left;
}
.copyable .btn { flex: none; }

.kbd {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--card-3);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 1px 6px;
}

.filters { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 13px; }
.filters .input, .filters select.input { height: 36px; width: auto; min-width: 130px; flex: none; }
.filters .input.grow { flex: 1; min-width: 180px; }

.pagination { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; font-size: 12.5px; color: var(--muted); }

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #1d1d21;
}
.list-row:last-child { border-bottom: 0; }

.upstream-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); margin-bottom: 12px; }
.upstream-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.upstream-head .ttl { flex: 1; min-width: 0; }
.upstream-head .ttl .n { font-weight: 650; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.upstream-head .ttl .u { font-family: var(--mono); font-size: 11.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.upstream-body { padding: 0 16px 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- авторизация ---------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { justify-content: center; padding-bottom: 20px; }
.auth-card .brand .name { font-size: 17px; }

/* ---------- адаптив ---------- */

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
  }
  .brand { padding: 4px 8px; }
  .brand .sub { display: none; }
  .nav-item { width: auto; padding: 8px 11px; }
  .nav-item .count { display: none; }
  .sidebar .spacer { display: none; }
  .sidebar .foot { border-top: 0; padding: 0 4px 0 0; margin-left: auto; }
  .sidebar .foot .who { display: none; }
  .main { padding: 16px 14px 32px; }
  .grid-2 { grid-template-columns: 1fr; }
  .row { flex-direction: column; align-items: stretch; }
  .row .fixed { flex: 1; }
}
