/* ============================================================
   Статусная модель техники — полный стилевой каркас
   (палитра slate/blue; чат и комментарии — см. нижние секции)
   ============================================================ */
:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --accent: #2563eb;
  --accent-dark: #1e40af;
  --danger: #dc2626;
  --ok-bg: #ecfdf5;
  --ok-line: #a7f3d0;
  --err-bg: #fef2f2;
  --err-line: #fecaca;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.15rem; margin: .2rem 0 .7rem; }
h3 { font-size: 1rem; margin: .2rem 0 .5rem; }
p { margin: .45rem 0; }
code { background: #eef2ff; padding: .05rem .35rem; border-radius: 5px; font-size: .85em; }
.muted { color: var(--muted); font-size: .9rem; }

/* ---------- шапка ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap;
  padding: .65rem 1.2rem; background: #0b1220; color: #e2e8f0;
  position: sticky; top: 0; z-index: 20; box-shadow: 0 1px 6px rgba(2, 6, 23, .35);
}
.topbar a { color: #cbd5e1; }
.topbar a:hover { color: #fff; text-decoration: none; }
.brand { font-weight: 700; color: #fff !important; font-size: 1.02rem; white-space: nowrap; }
.topbar nav { display: flex; gap: .95rem; flex-wrap: wrap; }
.topbar nav a.active { color: #fff; font-weight: 600; border-bottom: 2px solid var(--accent); padding-bottom: .1rem; }
.topbar .who { margin-left: auto; font-size: .85rem; color: #94a3b8; }
.topbar .logout { font-size: .85rem; color: #fca5a5; }

/* ---------- каркас страниц ---------- */
main { max-width: 74rem; margin: 1.1rem auto 3rem; padding: 0 1rem; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem 1.15rem; margin: 0 0 1.1rem; box-shadow: 0 1px 4px rgba(15, 23, 42, .05);
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.page-head > * { min-width: 0; }
.cols { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.cols > * { min-width: 0; }
.grow2 { flex: 2 1 26rem; min-width: 0; }
.grid2 {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .7rem .9rem; align-items: start;
}
.grid2 > * { min-width: 0; }
.span2 { grid-column: 1 / -1; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* форма учётных параметров карточки: сетка сверху, текст — снизу во всю ширину */
.attrs { display: grid; gap: .7rem; }
.form-sub {
  margin: .5rem 0 0; font-size: .95rem; color: var(--ink-2);
  border-bottom: 1px dashed var(--line); padding-bottom: .3rem;
}
.field-wide { display: grid; gap: .3rem; }
.field-wide input, .field-wide textarea { width: 100%; box-sizing: border-box; }
.field-wide textarea { min-height: 4.5rem; }

/* ---------- формы ---------- */
label { display: block; font-size: .85rem; color: var(--ink-2); }
form label { margin: 0; }
input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="submit"]):not([type="button"]),
select, textarea {
  display: block; width: 100%; min-width: 0; max-width: 100%;
  margin-top: .2rem; padding: .45rem .6rem;
  border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--ink);
  font: inherit;
}
select[multiple] { min-height: 7.5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 1rem; height: 1rem; }
textarea { resize: vertical; }
form p.muted { margin: .1rem 0; }
.inline-form { display: flex; gap: .5rem; align-items: end; flex-wrap: wrap; margin: 0; }
.auth { max-width: 26rem; margin: 3rem auto; }
.auth form { display: grid; gap: .7rem; }
.error-text { color: var(--danger); font-size: .9rem; }
.mini { display: inline-flex; flex-direction: column; font-size: .8rem; }
.mini input { min-width: 9.5rem; }

/* ---------- кнопки / чипы ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .3rem; cursor: pointer;
  padding: .45rem .9rem; border: 1px solid #cbd5e1; border-radius: 8px;
  background: #fff; color: var(--ink); font: inherit; font-weight: 600; font-size: .9rem;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f1f5f9; border-color: #94a3b8; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { background: #fff; border-color: #fca5a5; color: var(--danger); }
.btn.danger:hover { background: var(--err-bg); border-color: var(--danger); }
.btn.subtle { background: transparent; border-color: transparent; color: var(--accent); font-weight: 500; }
.btn.subtle:hover { background: #eff6ff; }
.btn.small { padding: .25rem .6rem; font-size: .8rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.chip {
  display: inline-block; padding: .12rem .6rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, var(--c, #64748b) 14%, #fff);
  color: color-mix(in srgb, var(--c, #64748b) 78%, #0f172a);
  border: 1px solid color-mix(in srgb, var(--c, #64748b) 38%, #fff);
}
.sla_bad { background: #fef3c7; border-color: #f59e0b; }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-right: .3rem; vertical-align: baseline; }
.chip-link {
  display: inline-block; padding: .18rem .65rem; border-radius: 999px; font-size: .82rem;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
}
.chip-link:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.chip-link.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- уведомления ---------- */
.flash { padding: .6rem .9rem; border-radius: 10px; margin: 0 0 .9rem; border: 1px solid; font-size: .92rem; }
.flash.ok { background: var(--ok-bg); border-color: var(--ok-line); color: #065f46; }
.flash.error { background: var(--err-bg); border-color: var(--err-line); color: #991b1b; }

/* ---------- таблицы ---------- */
table { border-collapse: collapse; width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.table th, .table td { padding: .5rem .65rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; font-size: .9rem; }
.table th { background: #f8fafc; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tbody tr:hover td { background: #f8fafc; }
.table tr:last-child td { border-bottom: none; }
.table.right th, .table.right td { text-align: right; }
.table.compact th, .table.compact td { padding: .35rem .55rem; }
.table.wide { min-width: 60rem; }
.table .wrap { word-break: break-word; white-space: normal; }
.table .empty td { text-align: center; color: var(--muted); padding: 1.2rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.wrap-any { word-break: break-word; overflow-wrap: anywhere; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .8rem; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .7rem .85rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .05); min-width: 0;
}
.card b { display: block; }
.card .muted { word-break: break-word; }
/* ---------- источник смены статуса ---------- */
.src { display: inline-block; padding: .08rem .5rem; border-radius: 6px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.src-manual { background: #eff6ff; color: #1d4ed8; }
.src-onec { background: #fef3c7; color: #92400e; }
.src-api { background: #f5f3ff; color: #6d28d9; }
.src-system, .src-seed { background: #f1f5f9; color: #475569; }

/* ---------- фильтры ---------- */
.toolbar { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; margin-bottom: .9rem; }
.filters-bar { width: 100%; }
.filter-details { border: 1px solid var(--line); border-radius: 10px; padding: .3rem .6rem; background: #fff; width: 100%; }
.filter-details summary { cursor: pointer; font-size: .85rem; color: var(--ink-2); font-weight: 600; }
.filter-grid { display: flex; gap: 1rem; align-items: start; flex-wrap: wrap; margin-top: .6rem; }
.filter-item { display: grid; gap: .3rem; min-width: 0; }
.filter-label { font-size: .8rem; color: var(--muted); }
.checklist { display: flex; gap: .35rem .8rem; flex-wrap: wrap; align-items: center; max-width: 46rem; }
.checklist label { display: inline-flex; align-items: center; gap: .35rem; font-size: .88rem; color: var(--ink); }
.check { display: inline-flex; align-items: center; gap: .35rem; font-size: .88rem; }

/* ---------- форма смены статуса ---------- */
.change-form { display: flex; flex-direction: column; gap: .6rem; max-width: 42rem; }
.change-form select, .change-form textarea { width: 100%; }
.change-form .checklist { margin: 0; padding: .35rem .5rem; background: #f8fafc; border: 1px dashed var(--line); border-radius: 8px; }
.change-form textarea { min-height: 5.5rem; }

/* ---------- периоды ---------- */
.period-form { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; margin-bottom: .7rem; }
.preset-row { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }

/* ---------- лента истории ---------- */
.timeline { display: grid; gap: .15rem; }
.tl-item { display: flex; gap: .8rem; align-items: baseline; padding: .5rem 0; border-bottom: 1px dashed var(--line); flex-wrap: wrap; }
.tl-item time { color: var(--muted); font-size: .85rem; min-width: 11.5rem; }
.tl-legend { display: flex; gap: .8rem; flex-wrap: wrap; margin-top: .7rem; font-size: .82rem; color: var(--ink-2); }
.tl-legend span { display: inline-flex; align-items: center; gap: .3rem; }
.tl-seg { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; }

/* ---------- отчёты ---------- */
.chart-panel { overflow-x: auto; }
.chart-title { font-weight: 700; margin-bottom: .6rem; }
.stack-bar { display: flex; height: 1.15rem; border-radius: 7px; overflow: hidden; border: 1px solid var(--line); margin-bottom: .8rem; background: #f8fafc; }
.stack-seg { min-width: 2px; }
.bars { display: grid; gap: .45rem; }
.bar-row { display: grid; grid-template-columns: minmax(9rem, 18rem) 5rem 1fr; gap: .6rem; align-items: center; }
.bar-label { font-size: .85rem; color: var(--ink-2); word-break: break-word; }
.bar-val { font-size: .82rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.bar-track { background: #f1f5f9; border-radius: 6px; height: .8rem; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; min-width: 2px; }

/* ---------- реестр сервис-сессий ---------- */
.sess-card { margin-bottom: .9rem; }
.sess-head { display: flex; gap: .8rem; align-items: baseline; flex-wrap: wrap; margin-bottom: .55rem; }
.sess-title { font-weight: 700; font-size: 1rem; }
.sess-meta { color: var(--muted); font-size: .85rem; }
.sess-open-label { font-size: .85rem; color: var(--ink-2); }
.sess-chain { display: flex; gap: .25rem; align-items: center; flex-wrap: wrap; }
.sess-chip { display: inline-flex; flex-direction: column; padding: .3rem .6rem; border-radius: 8px; font-size: .8rem; background: #f1f5f9; border: 1px solid var(--line); gap: .2rem; }
.sess-chip time, .sess-chip .muted { font-size: .72rem; }
.sess-chip.start { background: #f8fafc; }
.sess-chip.open { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.sess-chip.done { background: var(--ok-bg); border-color: var(--ok-line); }
.sess-arrow { color: var(--muted); }
.sess-card > .muted { margin-top: .5rem; }

/* --- комментарии в реестре сессий --- */
.sess-chat-link { white-space: nowrap; }
.sess-cmts { margin-top: .6rem; border-top: 1px dashed #e2e8f0; padding-top: .5rem; display: grid; gap: .25rem; }
.sess-cmt { font-size: .85rem; color: #334155; overflow-wrap: anywhere; }
.sess-cmt.prev { color: #64748b; }
.sess-cmt b { color: #0f172a; font-weight: 600; }

/* ---------- чат сервис-сессии ---------- */
.chat-list { display: grid; gap: .6rem; margin: .8rem 0 1rem; }
.chat-msg { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: .6rem .9rem; box-shadow: 0 1px 3px rgba(15,23,42,.05); }
.chat-head { display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; margin-bottom: .25rem; }
.chat-head b { color: #0f172a; }
.chat-edited { font-style: italic; }
.chat-main { display: flex; align-items: flex-start; gap: .7rem; }
.chat-body { flex: 1 1 auto; min-width: 0; white-space: pre-wrap; word-break: break-word; }
.chat-del { flex: 0 0 auto; margin-left: auto; }
.chat-admin { display: flex; gap: .8rem; align-items: center; margin-top: .45rem; }
.chat-edit { margin-top: .45rem; }
.chat-edit summary { cursor: pointer; color: #2563eb; font-size: .85rem; }
.chat-edit form { margin-top: .4rem; display: grid; gap: .4rem; max-width: 46rem; }
.chat-form { display: grid; gap: .55rem; max-width: 60rem; }
.chat-form textarea { width: 100%; box-sizing: border-box; padding: .6rem .8rem; border: 1px solid #cbd5e1; border-radius: 8px; font: inherit; resize: vertical; min-height: 8rem; font-size: .95rem; }

/* ---------- редактирование статусов ---------- */
.status-edit { display: flex; gap: .8rem; align-items: end; flex-wrap: wrap; padding: .55rem 0; border-bottom: 1px dashed #e2e8f0; }
.status-edit label { display: grid; gap: .15rem; font-size: .8rem; color: #475569; }
.status-edit label.check { display: flex; align-items: center; gap: .3rem; }
.status-edit input[type="text"], .status-edit input[type="number"] { padding: .35rem .5rem; border: 1px solid #cbd5e1; border-radius: 6px; }
.status-edit input[type="color"] { width: 2.6rem; height: 2rem; padding: 0; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; }
.status-code { align-self: center; min-width: 6.5rem; color: #334155; }
.status-edit .btn { align-self: center; }

/* ---------- печать ---------- */
@media print {
  .topbar, .btn, form, .toolbar, .preset-row, .chat-del, .chat-edit { display: none !important; }
  body { background: #fff; }
  .panel { box-shadow: none; border-color: #cbd5e1; }
}
