/* Сайт переводчика. Светлая и тёмная тема — по настройке системы.
   Цвета сервисов (DeepL — синий, Google — оранжевый) проверены на различимость,
   в том числе при дальтонизме; статусы всегда с текстом, не только цветом */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #16181d;
  --muted: #5f6470;
  --line: #e2e4ea;
  --input: #ffffff;
  --primary: #2a78d6;
  --primary-text: #ffffff;
  --deepl: #2a78d6;
  --google: #eb6834;
  --azure: #1baf7a;
  --good: #0a7d0a;
  --warning: #9a6a00;
  --critical: #c22f2f;
  --good-bg: rgba(12, 163, 12, 0.12);
  --warning-bg: rgba(250, 178, 25, 0.18);
  --critical-bg: rgba(208, 59, 59, 0.12);
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121316;
    --card: #1b1c20;
    --text: #f1f1f3;
    --muted: #a0a3ad;
    --line: #2c2e35;
    --input: #22242a;
    --primary: #3987e5;
    --deepl: #3987e5;
    --google: #d95926;
    --azure: #199e70;
    --good: #4cc94c;
    --warning: #fab219;
    --critical: #ef6b6b;
    --good-bg: rgba(12, 163, 12, 0.18);
    --warning-bg: rgba(250, 178, 25, 0.16);
    --critical-bg: rgba(208, 59, 59, 0.2);
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1 { margin: 0; font-size: 22px; }
h2 { margin: 0 0 12px; font-size: 15px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.error { color: var(--critical); margin: 0; }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; }

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--critical); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Вход */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.auth-card p { margin: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; white-space: nowrap; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 16px;
}

/* Шапка */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button {
  font: inherit;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--text); font-weight: 600; }
.who { display: flex; align-items: center; gap: 10px; white-space: nowrap; }

.content { max-width: 1180px; margin: 0 auto; padding: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.filters { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.filters input[type="search"] { width: 260px; }

.panel {
  padding: 18px 20px;
  margin-bottom: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.region { margin-top: 12px; }
.region input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.good { color: var(--good); background: var(--good-bg); }
.pill.warning { color: var(--warning); background: var(--warning-bg); }
.pill.critical { color: var(--critical); background: var(--critical-bg); }

/* Карточки сервисов */
.providers { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 16px; }
.provider {
  padding: 18px 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--provider);
  border-radius: 12px;
}
.provider[data-provider="Azure"] { --provider: var(--azure); }
.provider[data-provider="DeepL"] { --provider: var(--deepl); }
.provider[data-provider="Google"] { --provider: var(--google); }
.provider-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.provider-name { font-size: 18px; font-weight: 700; }
.provider-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.meter { height: 8px; margin: 8px 0 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.meter > div { height: 100%; border-radius: 999px; background: var(--provider); }
.meter.warn > div { background: var(--warning); }
.meter.stop > div { background: var(--critical); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin-top: 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
/* Поле ключа — на всю ширину карточки, кнопки под ним: в три колонки иначе поле слишком узкое */
.key-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.key-form input { flex: 1 1 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }

/* Таблицы */
.table-wrap { overflow-x: auto; margin-bottom: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.table tr:last-child td { border-bottom: 0; }
.table tr.removed td { opacity: 0.55; }
.chat-title { font-weight: 600; }
.chat-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }

/* Переключатель «перевод вкл/выкл» */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.15s;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Расход */
.chips { display: flex; gap: 6px; }
.chip {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.chip.selected { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, var(--card)); font-weight: 600; }
.chart { position: relative; }
.chart svg { display: block; }
.chart .grid { stroke: var(--line); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .base { stroke: var(--muted); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: color-mix(in srgb, var(--primary) 10%, transparent); }
.legend { display: flex; gap: 16px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; }
.chart-tip {
  position: fixed;
  z-index: 20;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
  pointer-events: none;
}
.chart-tip b { display: block; }
.bar-row { display: grid; grid-template-columns: minmax(140px, 260px) 1fr 110px; align-items: center; gap: 12px; padding: 5px 0; }
.bar-row .track { height: 10px; border-radius: 0 4px 4px 0; background: var(--primary); min-width: 2px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
}
.toast.error { background: var(--critical); color: #fff; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .tabs { order: 3; flex-basis: 100%; }
  .content { padding: 16px; }
  .providers, .grid3, .grid4 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters input[type="search"] { width: 100%; }
  .bar-row { grid-template-columns: 110px 1fr 80px; }
}
