/* Стиль в духе Grafana. Все правила под .tm-root, чтобы встраивание в админку не задевало её стили. */
.tm-root {
  --tm-bg: #f4f5f5; --tm-panel: #ffffff; --tm-panel-h: #fafbfc; --tm-border: rgba(36, 41, 46, .13); --tm-ink: #24292e; --tm-mute: #6a737d;
  --tm-hover: rgba(61, 113, 217, .07);
  --tm-primary: #3871dc; --tm-green: #1a7f37; --tm-yellow: #b08800; --tm-orange: #d5701b; --tm-red: #d1242f; --tm-blue: #3871dc; --tm-purple: #8250df;
  --tm-code: #11131c; --tm-code-ink: #d7dbef;
  font: 13px/1.5 Inter, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--tm-ink);
  background: var(--tm-bg); padding: 16px; box-sizing: border-box; min-height: 100%; max-width: 100vw; overflow-x: hidden;
}
@media (prefers-color-scheme: dark) {
  .tm-root:not([data-theme="light"]) {
    --tm-bg: #111217; --tm-panel: #181b1f; --tm-panel-h: #181b1f; --tm-border: rgba(204, 204, 220, .12); --tm-ink: #ccccdc; --tm-mute: #8e8e9c;
    --tm-hover: rgba(204, 204, 220, .06);
    --tm-primary: #6e9fff; --tm-green: #73bf69; --tm-yellow: #f2cc0c; --tm-orange: #ff9830; --tm-red: #f2495c; --tm-blue: #5794f2; --tm-purple: #b877d9;
  }
}
.tm-root[data-theme="dark"] {
  --tm-bg: #111217; --tm-panel: #181b1f; --tm-panel-h: #181b1f; --tm-border: rgba(204, 204, 220, .12); --tm-ink: #ccccdc; --tm-mute: #8e8e9c;
  --tm-hover: rgba(204, 204, 220, .06);
  --tm-primary: #6e9fff; --tm-green: #73bf69; --tm-yellow: #f2cc0c; --tm-orange: #ff9830; --tm-red: #f2495c; --tm-blue: #5794f2; --tm-purple: #b877d9;
}
.tm-root *, .tm-root *::before, .tm-root *::after { box-sizing: border-box; }
.tm-root h1 { font-size: 18px; margin: 0; font-weight: 500; }
.tm-root h2 { font-size: 14px; margin: 0 0 8px; font-weight: 500; }
.tm-root button, .tm-root select, .tm-root input { font: inherit; color: inherit; }

/* Шапка */
.tm-head { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.tm-head-l { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tm-head-r { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tm-logo { width: 22px; height: 22px; flex: none; }
.tm-crumb { color: var(--tm-mute); font-size: 12px; }
.tm-live { display: inline-flex; align-items: center; gap: 6px; color: var(--tm-mute); font-size: 12px; }
.tm-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tm-mute); display: inline-block; flex: none; }
.tm-dot.ok { background: var(--tm-green); } .tm-dot.bad { background: var(--tm-red); } .tm-dot.warn { background: var(--tm-yellow); }
.tm-select, .tm-input { background: var(--tm-panel); border: 1px solid var(--tm-border); border-radius: 2px; padding: 0 8px; height: 32px; }
.tm-select:hover, .tm-input:hover, .tm-btn:hover { border-color: var(--tm-primary); }
.tm-select:focus, .tm-input:focus { outline: 1px solid var(--tm-primary); outline-offset: 0; }
.tm-input { min-width: 260px; }
.tm-btn { background: var(--tm-panel); border: 1px solid var(--tm-border); border-radius: 2px; padding: 0 12px; height: 32px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.tm-btn.primary { background: var(--tm-primary); border-color: var(--tm-primary); color: #fff; }
.tm-root a.tm-btn { color: inherit; text-decoration: none; }
.tm-pill { display: inline-flex; align-items: center; gap: 6px; background: var(--tm-panel); border: 1px solid var(--tm-border); border-radius: 2px; padding-left: 8px; height: 32px; color: var(--tm-mute); }
.tm-pill select { border: 0; background: transparent; height: 30px; padding: 0 8px 0 0; color: var(--tm-ink); cursor: pointer; }
.tm-pill:hover { border-color: var(--tm-primary); }
.tm-pill svg { width: 14px; height: 14px; }

.tm-banner { border-radius: 2px; padding: 8px 12px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; border: 1px solid var(--tm-border); border-left-width: 4px; background: var(--tm-panel); }
.tm-banner.crit { border-left-color: var(--tm-red); } .tm-banner.warn { border-left-color: var(--tm-yellow); } .tm-banner.ok { border-left-color: var(--tm-green); color: var(--tm-mute); }
.tm-banner a { color: var(--tm-primary); cursor: pointer; text-decoration: none; margin-left: auto; }
.tm-banner a:hover { text-decoration: underline; }

.tm-tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--tm-border); margin-bottom: 14px; }
.tm-tab { background: none; border: 0; padding: 8px 14px; cursor: pointer; color: var(--tm-mute); border-bottom: 2px solid transparent; white-space: nowrap; }
.tm-tab:hover { color: var(--tm-ink); }
.tm-tab[aria-selected="true"] { color: var(--tm-ink); border-bottom-color: var(--tm-orange); }
.tm-badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--tm-red); color: #fff; font-size: 11px; text-align: center; margin-left: 6px; }

/* Панели */
.tm-card, .tm-panel { background: var(--tm-panel); border: 1px solid var(--tm-border); border-radius: 2px; margin-bottom: 12px; }
.tm-card { padding: 12px 14px; }
.tm-panel-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 8px 12px 0; font-weight: 500; }
.tm-panel-h small { color: var(--tm-mute); font-weight: 400; font-size: 11px; }
.tm-panel-b { padding: 4px 8px 8px; }
.tm-panel .tm-tablewrap { padding: 0 4px 6px; }
.tm-grid { display: grid; gap: 12px; }
.tm-panels { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.tm-panels > .tm-panel { margin: 0; }
.tm-cols { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; margin-bottom: 12px; align-items: start; }
.tm-cols.even { grid-template-columns: 1fr 1fr; }
.tm-cols > *, .tm-grid > *, .tm-panels > * { min-width: 0; }
.tm-cols > .tm-panel, .tm-cols > .tm-card { margin-bottom: 0; }
@media (max-width: 900px) { .tm-cols, .tm-cols.even { grid-template-columns: 1fr; } .tm-panels { grid-template-columns: 1fr; } }

/* Stat-плитки со спарклайном */
.tm-stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 12px; }
.tm-stat { position: relative; background: var(--tm-panel); border: 1px solid var(--tm-border); border-radius: 2px; padding: 10px 12px 28px; overflow: hidden; min-height: 96px; }
.tm-stat-t { color: var(--tm-mute); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tm-stat-v { font-size: 28px; font-weight: 500; line-height: 1.2; font-variant-numeric: tabular-nums; color: var(--tm-blue); }
.tm-stat-v small { font-size: 13px; color: var(--tm-mute); margin-left: 3px; font-weight: 400; }
.tm-stat-s { color: var(--tm-mute); font-size: 11px; }
.tm-stat.ok .tm-stat-v { color: var(--tm-green); } .tm-stat.warn .tm-stat-v { color: var(--tm-yellow); } .tm-stat.bad .tm-stat-v { color: var(--tm-red); } .tm-stat.neutral .tm-stat-v { color: var(--tm-ink); }
.tm-stat-spark { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 26px; display: block; }
.tm-gauge { position: absolute; left: 12px; right: 12px; bottom: 9px; height: 6px; background: var(--tm-border); border-radius: 3px; }
.tm-gauge > i { display: block; height: 100%; border-radius: 3px; background: var(--tm-green); }
.tm-stat.warn .tm-gauge > i { background: var(--tm-yellow); } .tm-stat.bad .tm-gauge > i { background: var(--tm-red); }
.tm-stat.dim { opacity: .5; }

/* Графики */
.tm-chart { width: 100%; display: block; }
.tm-chart text { fill: var(--tm-mute); font-size: 10px; }
.tm-chart .tm-grid-l { stroke: var(--tm-border); stroke-width: 1; }
.tm-chart .tm-thr { stroke-dasharray: 4 3; stroke-width: 1; opacity: .8; }
.tm-chart .tm-cross { stroke: var(--tm-mute); stroke-width: 1; stroke-dasharray: 3 3; }
.tm-chartwrap { position: relative; }
.tm-tip { position: absolute; top: 4px; pointer-events: none; background: var(--tm-panel); color: var(--tm-ink); border: 1px solid var(--tm-border); box-shadow: 0 4px 14px rgba(0, 0, 0, .35); border-radius: 2px; padding: 6px 9px; font-size: 12px; white-space: nowrap; z-index: 5; display: none; }
.tm-tip b { display: block; margin-bottom: 3px; color: var(--tm-mute); font-weight: 500; font-size: 11px; }
.tm-tip div { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tm-tip span.k { display: inline-flex; align-items: center; gap: 6px; }
.tm-tip i, .tm-lg i { width: 10px; height: 3px; border-radius: 1px; display: inline-block; flex: none; }
.tm-tip em { font-style: normal; margin-left: 14px; font-variant-numeric: tabular-nums; }
.tm-lg { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 2px; }
.tm-lg th { color: var(--tm-mute); font-weight: 400; text-align: right; padding: 1px 6px; font-size: 11px; }
.tm-lg th:first-child { text-align: left; }
.tm-lg td { padding: 1px 6px; text-align: right; font-variant-numeric: tabular-nums; }
.tm-lg td:first-child { text-align: left; cursor: pointer; white-space: nowrap; }
.tm-lg tr.off td { opacity: .35; text-decoration: line-through; }
.tm-lg tr:hover td { background: var(--tm-hover); }
.tm-lg i { margin-right: 6px; vertical-align: middle; }

/* Строки по серверам (как rows в Grafana) */
.tm-rowh { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; border-bottom: 1px solid var(--tm-border); padding: 8px 2px; margin: 4px 0 10px; cursor: pointer; text-align: left; font-weight: 500; font-size: 14px; }
.tm-rowh .chev { display: inline-block; transition: transform .15s; color: var(--tm-mute); }
.tm-rowh.closed .chev { transform: rotate(-90deg); }
.tm-rowh small { color: var(--tm-mute); font-weight: 400; font-size: 12px; margin-left: auto; }

/* Таблицы */
.tm-tablewrap { overflow-x: auto; }
.tm-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tm-table th, .tm-table td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--tm-border); white-space: nowrap; }
.tm-table td.wrap { white-space: normal; word-break: break-word; max-width: 420px; }
.tm-table th { color: var(--tm-mute); font-weight: 500; font-size: 11px; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--tm-panel); text-transform: uppercase; letter-spacing: .03em; }
.tm-table th.num, .tm-table td.num { text-align: right; }
.tm-table tbody tr:hover { background: var(--tm-hover); }
.tm-table tr.hot td { background: color-mix(in srgb, var(--tm-red) 9%, transparent); }
.tm-link { color: var(--tm-primary); cursor: pointer; text-decoration: none; }
.tm-link:hover { text-decoration: underline; }
.tm-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.tm-mute { color: var(--tm-mute); }
.tm-bar { height: 3px; background: var(--tm-border); border-radius: 2px; margin-top: 3px; min-width: 60px; }
.tm-bar > i { display: block; height: 100%; border-radius: 2px; background: var(--tm-blue); }
.tm-table .tm-btn { padding: 0 9px; height: 24px; font-size: 12px; }

.tm-tag { display: inline-block; padding: 0 7px; border-radius: 2px; font-size: 11px; line-height: 18px; margin: 0 4px 2px 0; background: color-mix(in srgb, var(--tm-yellow) 18%, transparent); color: var(--tm-yellow); }
.tm-tag.bad { background: color-mix(in srgb, var(--tm-red) 18%, transparent); color: var(--tm-red); }
.tm-tag.ok { background: color-mix(in srgb, var(--tm-green) 18%, transparent); color: var(--tm-green); }
.tm-tag.info { background: color-mix(in srgb, var(--tm-blue) 18%, transparent); color: var(--tm-blue); }
.tm-st { font-weight: 600; } .tm-st.s5 { color: var(--tm-red); } .tm-st.s4 { color: var(--tm-yellow); } .tm-st.s2 { color: var(--tm-green); }

/* Инциденты */
.tm-inc { border-left: 4px solid var(--tm-yellow); }
.tm-inc.critical { border-left-color: var(--tm-red); }
.tm-inc.resolved { border-left-color: var(--tm-border); opacity: .85; }
.tm-inc-h { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; justify-content: space-between; }
.tm-inc-h h3 { margin: 0; font-size: 14px; font-weight: 500; }
.tm-facts { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0; }
.tm-fact { font-size: 12px; color: var(--tm-mute); } .tm-fact b { color: var(--tm-ink); font-weight: 500; }
.tm-steps summary { cursor: pointer; font-weight: 500; margin: 6px 0; }
.tm-step { margin: 10px 0; }
.tm-step > b { display: block; margin-bottom: 4px; font-weight: 500; }
.tm-step small { color: var(--tm-mute); display: block; margin-top: 4px; }
.tm-cmd { position: relative; background: var(--tm-code); color: var(--tm-code-ink); border-radius: 2px; padding: 10px 70px 10px 12px; overflow-x: auto; margin: 0; border: 1px solid var(--tm-border); }
.tm-cmd code { white-space: pre; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.tm-copy { position: absolute; top: 6px; right: 6px; background: #2a2e40; color: #d7dbef; border: 0; border-radius: 2px; padding: 2px 9px; cursor: pointer; font-size: 12px; }
.tm-empty { color: var(--tm-mute); padding: 16px 4px; text-align: center; }
.tm-note { color: var(--tm-mute); font-size: 12px; margin: 0 0 10px; }
.tm-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }

.tm-probe { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--tm-border); flex-wrap: wrap; }
.tm-probe:last-child { border-bottom: 0; }
.tm-probe .u { flex: 1; min-width: 160px; word-break: break-all; }
.tm-spark { display: flex; gap: 1px; align-items: flex-end; height: 18px; }
.tm-spark i { width: 3px; background: var(--tm-green); border-radius: 1px; } .tm-spark i.bad { background: var(--tm-red); height: 100% !important; }

/* Вход */
.tm-login { margin: 0; background: #111217; min-height: 100vh; display: flex; align-items: center; justify-content: center; font: 14px/1.4 Inter, -apple-system, "Segoe UI", Roboto, sans-serif; }
.tm-login-card { background: #181b1f; color: #ccccdc; padding: 28px; border-radius: 2px; border: 1px solid rgba(204, 204, 220, .12); width: min(360px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 14px; }
.tm-login-card h1 { font-size: 18px; font-weight: 500; margin: 0; }
.tm-login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: #8e8e9c; }
.tm-login-card input { background: #111217; border: 1px solid rgba(204, 204, 220, .12); border-radius: 2px; padding: 9px 12px; color: #ccccdc; font-size: 14px; }
.tm-login-card button { background: #6e9fff; color: #111217; border: 0; border-radius: 2px; padding: 10px; font-size: 14px; font-weight: 500; cursor: pointer; }
.tm-login-err { color: #f2495c; margin: 0; }

@media (max-width: 600px) {
  .tm-root { padding: 10px; }
  .tm-input, .tm-select { min-width: 0; flex: 1 1 140px; }
  .tm-head-r { width: 100%; }
  .tm-stat-v { font-size: 22px; }
}

/* ---------- доработка внешнего вида ---------- */
.tm-root { color-scheme: light; }
@media (prefers-color-scheme: dark) { .tm-root:not([data-theme="light"]) { color-scheme: dark; } }
.tm-root[data-theme="dark"] { color-scheme: dark; }

/* Отдельная страница: фон на всю высоту и шапка, которая не уезжает при прокрутке */
.tm-root.tm-standalone { min-height: 100vh; padding-top: 0; }
.tm-standalone .tm-top { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--tm-bg) 92%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); margin: 0 -16px 16px; padding: 12px 16px 0; border-bottom: 1px solid var(--tm-border); }
.tm-standalone .tm-top .tm-tabs { border-bottom: 0; margin-bottom: 0; }
.tm-standalone .tm-top .tm-banner { margin-bottom: 8px; }
.tm-top .tm-head { margin-bottom: 10px; }

/* Скругления и глубина */
.tm-card, .tm-panel, .tm-stat, .tm-banner, .tm-srv { border-radius: 6px; }
.tm-select, .tm-input, .tm-btn, .tm-pill, .tm-cmd, .tm-tip { border-radius: 4px; }
.tm-panel, .tm-stat, .tm-card, .tm-srv { background: linear-gradient(180deg, color-mix(in srgb, var(--tm-panel) 100%, #fff 2%) 0%, var(--tm-panel) 60%); }
.tm-panel:hover, .tm-stat:hover, .tm-srv:hover { border-color: color-mix(in srgb, var(--tm-border) 60%, var(--tm-primary) 40%); }

/* Вкладки с иконками */
.tm-tab { display: inline-flex; align-items: center; gap: 7px; }
.tm-ico { width: 15px; height: 15px; flex: none; vertical-align: -3px; }
.tm-tab .tm-ico { opacity: .75; }
.tm-tab[aria-selected="true"] .tm-ico { opacity: 1; color: var(--tm-orange); }
.tm-table td .tm-ico { margin-right: 6px; color: var(--tm-mute); }

/* Пустые состояния и загрузка */
.tm-emptybox { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; padding: 44px 20px; color: var(--tm-mute); }
.tm-emptybox .tm-ico-xl { width: 44px; height: 44px; opacity: .55; margin-bottom: 6px; stroke-width: 1.1; }
.tm-emptybox b { color: var(--tm-ink); font-weight: 500; font-size: 15px; }
.tm-emptybox p { margin: 0; max-width: 620px; line-height: 1.6; }
.tm-hero .tm-emptybox { padding: 56px 20px; }
.tm-hero .tm-ico-xl { color: var(--tm-orange); opacity: .9; }
.tm-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--tm-mute); }
.tm-spin { width: 16px; height: 16px; border: 2px solid var(--tm-border); border-top-color: var(--tm-primary); border-radius: 50%; animation: tm-spin .8s linear infinite; }
@keyframes tm-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .tm-spin { animation: none; } }
.tm-tag.neutral { background: color-mix(in srgb, var(--tm-mute) 18%, transparent); color: var(--tm-mute); }

/* Карточки серверов */
.tm-srv-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.tm-srv { border: 1px solid var(--tm-border); padding: 14px 16px; border-top: 3px solid var(--tm-mute); }
.tm-srv.ok { border-top-color: var(--tm-green); } .tm-srv.silent { border-top-color: var(--tm-red); } .tm-srv.never { opacity: .75; }
.tm-srv-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tm-srv-h b { font-size: 15px; font-weight: 500; display: inline-flex; align-items: center; gap: 8px; }
.tm-srv-h b .tm-ico { color: var(--tm-mute); width: 16px; height: 16px; }
.tm-srv-meta { color: var(--tm-mute); font-size: 12px; margin: 8px 0 14px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.tm-mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 12px; }
.tm-mini small { display: block; color: var(--tm-mute); font-size: 11px; margin-bottom: 2px; }
.tm-mini span { font-size: 18px; font-variant-numeric: tabular-nums; }
.tm-mini .ok span { color: var(--tm-green); } .tm-mini .warn span { color: var(--tm-yellow); } .tm-mini .bad span { color: var(--tm-red); }
.tm-mini .bar { height: 4px; background: var(--tm-border); border-radius: 2px; margin-top: 5px; }
.tm-mini .bar i { display: block; height: 100%; border-radius: 2px; background: var(--tm-green); }
.tm-mini .warn .bar i { background: var(--tm-yellow); } .tm-mini .bad .bar i { background: var(--tm-red); }

/* Полосы прокрутки в тон */
.tm-root * { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--tm-mute) 45%, transparent) transparent; }
.tm-root ::-webkit-scrollbar { width: 10px; height: 10px; }
.tm-root ::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--tm-mute) 40%, transparent); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
.tm-root ::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 600px) {
  .tm-standalone .tm-top { margin: 0 -10px 12px; padding: 10px 10px 0; position: static; }
  .tm-mini { grid-template-columns: repeat(2, 1fr); }
  .tm-srv-grid { grid-template-columns: 1fr; }
}
.tm-srv-hint { color: var(--tm-mute); font-size: 12px; line-height: 1.6; margin: 12px 0 2px; }
