@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Manrope:wght@400;500;600;700&display=swap');

:root {
  color-scheme: light dark;
  /* Тема v2okno.shop — стекло окна на рассвете (accent) + тёплый свет
     сквозь окно (warn/teal), см. public/style.css самого сайта. */
  --bg: #11131b;
  --panel: #1a1e2b;
  --panel2: #222838;
  --border: rgba(255,255,255,.08);
  --text: #eef1f7;
  --muted: #96a0b5;
  --accent: #1fe8ab;
  --accent-tint: rgba(31,232,171,.18);
  --accent-contrast: #04160f;
  --danger: #ff5b52;
  --danger-tint: rgba(255,91,82,.18);
  --ok: #1fe8ab;
  --ok-tint: rgba(31,232,171,.18);
  --warn: #ff9d42;
  --warn-tint: rgba(255,157,66,.18);
  --input-bg: #1a1e2b;
  --teal: #ff9d42;
  font-family: 'Manrope', -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f8fa;
    --panel: #ffffff;
    --panel2: #ffffff;
    --border: rgba(17,19,27,.1);
    --text: #11131b;
    --muted: #6b7280;
    --accent: #0d9488;
    --accent-tint: rgba(13,148,136,.1);
    --accent-contrast: #ffffff;
    --danger: #dc2626;
    --danger-tint: rgba(220,38,38,.1);
    --ok: #0d9488;
    --ok-tint: rgba(13,148,136,.12);
    --warn: #c2670f;
    --warn-tint: rgba(194,103,15,.18);
    --input-bg: #ffffff;
    --teal: #c2670f;
  }
}

:root[data-theme="light"] {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel2: #ffffff;
  --border: rgba(17,19,27,.1);
  --text: #11131b;
  --muted: #6b7280;
  --accent: #0d9488;
  --accent-tint: rgba(13,148,136,.1);
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --danger-tint: rgba(220,38,38,.1);
  --ok: #0d9488;
  --ok-tint: rgba(13,148,136,.12);
  --warn: #c2670f;
  --warn-tint: rgba(194,103,15,.18);
  --input-bg: #ffffff;
  --teal: #c2670f;
}

:root[data-theme="dark"] {
  --bg: #11131b;
  --panel: #1a1e2b;
  --panel2: #222838;
  --border: rgba(255,255,255,.08);
  --text: #eef1f7;
  --muted: #96a0b5;
  --accent: #1fe8ab;
  --accent-tint: rgba(31,232,171,.18);
  --accent-contrast: #04160f;
  --danger: #ff5b52;
  --danger-tint: rgba(255,91,82,.18);
  --ok: #1fe8ab;
  --ok-tint: rgba(31,232,171,.18);
  --warn: #ff9d42;
  --warn-tint: rgba(255,157,66,.18);
  --input-bg: #1a1e2b;
  --teal: #ff9d42;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  letter-spacing: -0.01em;
}

h1, h2, h3, .display {
  font-family: 'Fraunces', serif;
  font-weight: 500;
  letter-spacing: -0.01em;
}

header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

header b { font-weight: 600; letter-spacing: -0.02em; }
header a { color: var(--accent); text-decoration: none; margin-right: 16px; font-weight: 500; }
header a:hover { opacity: .7; }

main { padding: 24px; max-width: 1240px; margin: 0 auto; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

input, button, select {
  font: inherit;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--panel2);
  color: var(--text);
  transition: opacity .15s ease, transform .1s ease, background .15s ease;
}

input, select {
  background: color-mix(in srgb, var(--text) 5%, var(--input-bg));
  border: 1px solid var(--border);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

button {
  background: var(--accent);
  border: none;
  cursor: pointer;
  color: var(--accent-contrast);
  font-weight: 590;
  border-radius: 980px;
}
button:hover { opacity: .88; }
button:active { transform: scale(.96); opacity: .8; }
button.secondary {
  background: var(--accent-tint);
  border: none;
  color: var(--accent);
}
button.danger { background: var(--danger-tint); color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; opacity: 1; }

.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 590; }
.badge.active { background: var(--ok-tint); color: var(--ok); }
.badge.pending { background: var(--warn-tint); color: var(--warn); }
.badge.revoked { background: var(--danger-tint); color: var(--danger); }

.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); margin: 8px 0; }
.ok-msg { color: var(--ok); margin: 8px 0; }

input.comment-input { width: 100%; }

/* --- Таблица роутеров: компактная, всё в одну строку без горизонтальной
   прокрутки. table-layout:fixed + узкие фиксированные колонки, остальное
   (комментарий) забирает свободное место. --- */
.routers-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
.routers-table th, .routers-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  overflow-wrap: break-word;
}
.routers-table thead th { border-bottom: 1px solid var(--border); vertical-align: middle; }
.routers-table th { color: var(--muted); font-weight: 590; font-size: 11px; text-transform: uppercase; letter-spacing: .02em; }
.routers-table th:nth-child(1), .routers-table td:nth-child(1) { width: 34%; }
.routers-table th:nth-child(2), .routers-table td:nth-child(2) { width: 15%; }
.routers-table th:nth-child(3), .routers-table td:nth-child(3) { width: 12%; }
.routers-table th:nth-child(4), .routers-table td:nth-child(4) { width: 18%; }
.routers-table th:nth-child(5), .routers-table td:nth-child(5) { width: auto; }

.routers-table input, .routers-table select, .routers-table button {
  font-size: 11px;
  padding: 4px 8px;
  width: 100%;
  border-radius: 8px;
}
.routers-table button { width: auto; }

/* Индикатор состояния (онлайн/pending/офлайн) — зелёный/жёлтый/красный */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.dot.green { background: var(--ok); }
.dot.yellow { background: var(--warn); }
.dot.red { background: var(--danger); }

/* Устройство: статус + модель + MAC + аптайм, один карандашик на весь блок */
.device-cell { line-height: 1.35; }
.device-head { display: flex; align-items: center; gap: 4px; }
.device-model { font-weight: 590; }
.device-mac { font-family: ui-monospace, "SF Mono", Consolas, monospace; color: var(--muted); font-size: 10px; }
.device-head .pencil { margin-left: auto; }

/* Комментарий — своя строка, свой карандашик, переключается независимо
   от общего конфига ниже (см. startCommentEdit). Не часть field-row-сетки:
   свой flex на всю ширину блока устройства, текст другим (Fraunces) шрифтом,
   чтобы визуально отличаться от полей с сетевыми данными. */
.comment-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.comment-row label { flex: none; width: 70px; color: var(--muted); font-size: 9px; white-space: nowrap; }
.comment-row .field-view { flex: 1; min-width: 0; }
.comment-text { font-family: 'Fraunces', serif; font-style: italic; font-size: 13px; overflow-wrap: anywhere; }
.comment-row .comment-edit-input { flex: 1; min-width: 0; display: none; }
.comment-row.editing .field-view { display: none; }
.comment-row.editing .comment-edit-input { display: inline-block; }
.comment-pencil { flex: none; }

/* Сеть: LAN/WAN/Wi-Fi/прошивка — коротко подписанные строки друг под другом.
   field-input скрыт, пока не нажат карандашик (см. .device-cell.editing).
   resize позволяет руками расширить блок, если подписанные значения не
   помещаются в узкую колонку. */
.net-cell {
  display: grid;
  gap: 1px;
  margin-top: 4px;
  resize: horizontal;
  overflow: auto;
  min-width: 100%;
  max-width: 640px;
}
/* Каждое поле — 2 колонки данных: слева то, что в базе (baseline), справа
   цветом морской волны — то, что реально прислал роутер (reported_*), если
   отличается. Карандашик у шапки устройства делает левую колонку
   редактируемой сразу для всех полей; сохранение/отмена — общей дискетой/
   крестиком внизу страницы (см. #editBar), не тут. */
.field-row { display: grid; grid-template-columns: 70px 118px minmax(0,1fr); gap: 4px; align-items: center; }
.field-row label { color: var(--muted); font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field-row input, .field-row select { min-width: 0; width: 100%; }
.field-base { min-width: 0; }
.field-text { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
/* Комментарий — исключение: показываем целиком, не обрезаем многоточием
   (выше по специфичности .field-text, т.к. два класса). */
.field-text.comment-text { display: inline; max-width: none; overflow: visible; text-overflow: clip; white-space: normal; }
.field-input { display: none; }
.device-cell.editing .field-text { display: none; }
.device-cell.editing .field-input { display: inline-block; }
.device-cell.editing .field-new-col { visibility: hidden; }
.field-new-col { min-width: 0; font-size: 10px; }
.field-new {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  color: var(--teal);
  cursor: pointer;
  border-bottom: 1px dashed var(--teal);
}
.field-new:hover { opacity: .8; }
/* Пока конфиг устройства открыт на редактирование — рамка-подсказка,
   т.к. карандашик больше не превращается в 💾 (сохранение теперь общим
   баром внизу страницы, см. #editBar). */
.device-cell.editing { outline: 2px solid var(--accent); border-radius: 10px; padding: 4px; margin: -4px; }

/* Подсветка всей строки роутера по живому статусу — зелёный насыщеннее */
tr.row-online { background: var(--ok-tint); }
tr.row-offline { background: var(--danger-tint); }
tr.row-pending { background: var(--warn-tint); }

/* Несовпадение baseline vs то, что прислал сам роутер */
.mismatch-banner {
  margin-top: 4px;
  padding: 5px 8px;
  border-radius: 8px;
  background: var(--warn-tint);
  border: none;
  font-size: 10px;
}
.mismatch-banner button { margin-top: 3px; font-size: 10px; padding: 3px 8px; width: auto; }

/* Порты: старый сервер и rt.v2okno.shop друг под другом, разделены чертой */
.port-links-col { display: flex; flex-direction: column; gap: 6px; }
.port-divider { width: 100%; border: none; border-top: 1px solid var(--border); margin: 0; }
.port-group { display: flex; flex-direction: column; gap: 2px; }
/* НАЙДЕНО ВЖИВУЮ (2026-09-16, "мам+ksu"): та же причина, что у .manage-cell
   button (см. комментарий выше) - flex-элементы по умолчанию min-width:auto,
   не сжимаются. .port-btn с white-space:nowrap на длинной vless-подписке
   (URL) не мог ни сжаться, ни перенестись - вылезал за колонку и
   накладывался на соседний контент. flex-wrap:wrap на строке + normal/
   break-word на самой ссылке чинят оба симптома разом. */
.port-btn-row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-width: 0; }
.port-btn {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-contrast);
  text-decoration: none;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 590;
  white-space: normal;
  overflow-wrap: anywhere;
  min-width: 0;
}
.port-btn:hover { opacity: .88; }
.copy-btn { padding: 3px 6px; font-size: 10px; line-height: 1; width: auto; border-radius: 8px; }

.pencil {
  background: transparent;
  border: none;
  cursor: pointer;
  width: auto;
  padding: 3px 6px;
  font-size: 12px;
  line-height: 1;
  border-radius: 999px;
}
.pencil:hover { background: var(--accent-tint); opacity: 1; }

/* DPI-обход: Zapret / Zapret2 / ByeDPI — чекбокс + значение, компактно.
   resize — так же, как у .net-cell, на случай длинных значений стратегий. */
.dpi-cell { display: grid; gap: 4px; resize: horizontal; overflow: auto; min-width: 100%; max-width: 480px; }
.dpi-row { display: flex; align-items: center; gap: 4px; }
.dpi-row label { display: flex; align-items: center; gap: 3px; font-size: 10px; white-space: nowrap; flex: none; }
.dpi-value { flex: 1; min-width: 0; }
.dpi-value:disabled { opacity: .4; }

/* Подписка / TG */
.sub-cell { display: grid; gap: 4px; }
.checkbox-line { display: flex; align-items: center; gap: 4px; font-size: 10px; }
.checkbox-line input { width: auto; accent-color: var(--accent); }

/* Управление: бэкап/прошивка/действия — кнопки друг под другом */
.manage-cell { display: grid; gap: 4px; min-width: 0; }
/* НАЙДЕНО ВЖИВУЮ (2026-09-16): grid-элементы по умолчанию min-width:auto -
   не сжимаются УЖЕ содержимого, только РАСТЯГИВАЮТ колонку под самый
   длинный текст. У лайт-роутеров кнопки заметно длиннее ("📡 Статус VPN
   (LITE, вручную)" и т.п.) - без min-width:0 они распирали .manage-cell
   и вылезали за границы ячейки таблицы, у форкоп-роутеров с более
   короткими подписями кнопок это было незаметно. min-width:0 позволяет
   сжаться до колонки, white-space:normal - переносить длинный текст
   кнопки на вторую строку вместо распирания. */
.manage-cell button, .manage-cell > div { display: block; min-width: 0; white-space: normal; }

/* Переключатель темы */
.theme-toggle {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 11px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  width: auto;
}
.theme-toggle-corner { position: fixed; top: 16px; right: 16px; }

/* Общий бар сохранения/отмены редактирования конфига устройства — внизу
   страницы, зафиксирован, появляется только пока открыт карандашик у
   какого-то одного роутера (см. toggleDeviceEdit/saveEditBar/cancelEditBar). */
.edit-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 24px rgba(0,0,0,.18);
}
.edit-bar button { width: auto; }

.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

textarea {
  background: var(--bg);
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea:focus { outline: none; border-color: var(--accent, #5b8def); }
