:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #1b1f24; --muted: #6b7380;
  --line: #e3e6ea; --ok: #1f9d55; --warn: #c27c0e; --bad: #d23b3b;
  --accent: #2f6fde; --chip: #eef1f5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --card: #181c22; --text: #e6e9ee; --muted: #8b94a3;
    --line: #2a3039; --ok: #3ccf7a; --warn: #e3a33a; --bad: #ff6b6b;
    --accent: #6ea2ff; --chip: #232a33;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* вход */
body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 340px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box p { margin: 0 0 4px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; }
button { font: inherit; cursor: pointer; }
.login-box button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 11px; font-weight: 600; }
.error { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; }

/* шапка */
.top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; }
.top-right { display: flex; align-items: center; gap: 12px; }
.top-right form { margin: 0; }
button.link { background: none; border: 0; color: var(--accent); padding: 4px; }

main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 32px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.bots { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 12px; }
@media (min-width: 820px) { .bots { grid-template-columns: 1fr 1fr; } }

.totals { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 620px) { .totals { grid-template-columns: repeat(4, 1fr); } }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); }

.bot-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bot-head h2 { margin: 0; font-size: 18px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.badge.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.online { background: var(--ok); } .dot.connecting { background: var(--warn); } .dot.offline { background: var(--bad); }
.note { font-size: 13px; color: var(--muted); margin: 0 0 8px; word-break: break-word; }

.rows { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0; }
.rows .k { color: var(--muted); font-size: 13px; }
.rows .v { text-align: right; font-variant-numeric: tabular-nums; word-break: break-word; }

.attn { margin: 8px 0 0; padding: 8px 10px; border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 12%, transparent); font-size: 14px; }
.attn.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); }
.attn div + div { margin-top: 2px; }

details.log { margin-top: 10px; }
details.log summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.log-lines { margin-top: 6px; max-height: 320px; overflow: auto; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  background: var(--bg); border-radius: 8px; padding: 6px 8px; }
.log-lines div { white-space: pre-wrap; word-break: break-word; }
.log-lines .warning { color: var(--warn); } .log-lines .error { color: var(--bad); }
.log-lines .t { color: var(--muted); margin-right: 6px; }

/* вкладки */
.tabs { position: sticky; top: 49px; z-index: 1; display: flex; gap: 4px; padding: 6px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 6px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.tabs a.on { background: var(--chip); color: var(--text); font-weight: 600; }
.small { font-size: 12px; }
.hint { margin: 10px 0 0; }

/* заказы: панель фильтров */
.controls { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.controls input[type=search] { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px;
  padding: 4px 10px; font-size: 13px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sort { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }

/* заказы: карточки (телефон) */
.ocard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.ocard.problem { border-left: 4px solid var(--warn); }
.ocard.bad { border-left: 4px solid var(--bad); }
.ohead { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ohead b { font-variant-numeric: tabular-nums; }
.ogpu { margin: 2px 0; }
.ogrid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; margin: 6px 0; font-size: 14px; }
.ogrid .k { color: var(--muted); font-size: 12px; }
.ogrid .v { font-variant-numeric: tabular-nums; }
.oline { font-size: 13px; margin-top: 2px; }
.k-offline, .h-offline, .h-missing, .w-flag, .g-red { color: var(--bad); }
.k-spot_wait, .k-server_busy, .k-own_demand, .w-on, .g-on, .h-wait { color: var(--warn); }
.h-online { color: var(--ok); }
.odetail { white-space: pre-wrap; font-size: 12px; color: var(--muted); margin-top: 6px; border-top: 1px dashed var(--line); padding-top: 6px; }

/* таблицы (ПК) */
.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th, table.t td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.t th { position: sticky; top: 0; background: var(--card); color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tr.problem td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.t tr.bad td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
table.t td.gpu { white-space: normal; min-width: 210px; }
table.t td.st { white-space: normal; min-width: 140px; }
.grey { color: var(--muted); }
tr.bold td { font-weight: 700; }

/* расходы на телефоне */
.srow { padding: 8px 0; border-bottom: 1px solid var(--line); }
.srow .s-top { display: flex; justify-content: space-between; font-weight: 600; }
.srow .sub { font-size: 13px; color: var(--muted); }

table.t td.hv { white-space: normal; min-width: 180px; }
body.wide-view main { max-width: 1500px; }

/* кнопки, окна, уведомления */
h3 { margin: 0 0 8px; font-size: 16px; }
.btn { font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--chip); color: var(--text);
  border-radius: 10px; padding: 8px 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.service { margin-top: 12px; }
.addrow { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.addrow input { flex: 1 1 140px; min-width: 0; }
.blrow { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.blrow .txt { flex: 1; min-width: 0; word-break: break-word; }
.modal { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.45); display: flex;
  align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.sheet { background: var(--card); color: var(--text); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 16px; } }
.sheet h3 { margin-bottom: 4px; }
.sheet .pre { white-space: pre-wrap; font-size: 13px; color: var(--muted); margin: 8px 0; }
.sheet label { display: block; font-size: 13px; color: var(--muted); margin-top: 8px; }
.sheet input { width: 100%; margin-top: 4px; }
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 20; display: flex;
  flex-direction: column; gap: 8px; width: min(92vw, 520px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); color: #fff; }
.ocard.mark, table.t tr.mark td { background: color-mix(in srgb, var(--accent) 12%, var(--card)); }
.ocard { cursor: pointer; }
table.t tbody tr { cursor: pointer; }
.gap-top { margin-top: 12px; }

/* ссылки: читаемые на любом фоне, без «посещённого» фиолетового */
a, a:visited { color: var(--accent); }
.attn a, .attn a:visited { color: var(--text); font-weight: 600; text-decoration: underline; white-space: nowrap; }
.badge.loc { color: var(--text); }

/* заказы на ПК: строки свободнее и с чередованием — легче читать (решение владельца) */
table.t { font-size: 14px; }
table.t th, table.t td { padding: 10px 12px; line-height: 1.35; }
table.t tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--chip) 55%, var(--card)); }
table.t tbody tr:hover td { background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
table.t td.loc { font-weight: 600; }

/* настройки */
.fgroup { margin-bottom: 12px; }
.frow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px;
  padding: 8px 0; border-bottom: 1px solid var(--line); }
.frow:last-child { border-bottom: 0; }
.frow .fl { flex: 1 1 220px; }
.frow .fv { display: flex; align-items: center; gap: 6px; flex: 0 1 auto; }
.frow input[type=number], .frow input[type=text] { width: 140px; }
.frow input[type=checkbox] { width: 20px; height: 20px; }
.frow .fh { flex-basis: 100%; font-size: 12px; color: var(--muted); }
.frow.changed { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 8px; padding-left: 6px; padding-right: 6px; }
.multi { display: flex; flex-wrap: wrap; gap: 10px; }
.multi label { display: flex; align-items: center; gap: 4px; }
table.models td input[type=number] { width: 100px; }
table.models td, table.models th { padding: 6px 8px; }
.savebar { position: sticky; bottom: 0; display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 10px;
  box-shadow: 0 -4px 16px rgba(0,0,0,.12); }
.savebar span { margin-right: auto; font-size: 14px; }
.coinrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* атрибут hidden сильнее display: flex у классов */
[hidden] { display: none !important; }
.stat .sub { margin-top: 2px; font-variant-numeric: tabular-nums; }

.frow.wide .fv { flex-basis: 100%; }
.frow textarea { width: 100%; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.frow select { max-width: 100%; }
#st-sections { margin-top: 2px; }
.frow .fv { max-width: 100%; min-width: 0; }
.frow .fv select { max-width: 100%; min-width: 0; text-overflow: ellipsis; }

/* локация — по содержимому, а не остаток ширины таблицы */
table.t td.loc { width: 1%; white-space: nowrap; }
.blrow { flex-wrap: wrap; }
.blrow .txt { flex: 1 1 180px; }
.bad-text { color: var(--bad); } .warn-text { color: var(--warn); }
