:root {
  --paper: #f3f2ee;
  --surface: #ffffff;
  --ink: #1a1d21;
  --ink-2: #3b4048;
  --muted: #5b6068;
  --line: #d9d7d0;
  --blue: #1f4e8c;
  --blue-dark: #163a69;
  --blue-soft: #e1eaf5;
  --blue-line: #b9c8dd;
  --orange: #c2410c;
  --orange-text: #9a3412;
  --orange-soft: #fce9dc;
  --orange-line: #e8b596;
  --red: #8f1d1d;
  --red-soft: #f6dada;
  --grey-soft: #eceae4;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "Noto Sans", "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.45 var(--sans); }
a { color: var(--blue); }
a:hover { color: var(--blue-dark); }
h1 { font-size: 28px; line-height: 1.15; margin: 0; font-weight: 600; }
h2 { font-size: 18px; margin: 0; font-weight: 600; }
h3 { font-size: 15px; margin: 0; font-weight: 600; }
p { margin: 0; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.pre { white-space: pre-line; }

/* шапка */
.top { background: var(--ink); color: #f3f2ee; padding: 10px 20px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; }
.brand { display: flex; align-items: baseline; gap: 10px; color: #fff; text-decoration: none; }
.brand b { font-family: var(--mono); font-size: 18px; letter-spacing: .04em; }
.brand span { font-size: 13px; color: #b9bcc2; }
.nav { display: flex; flex-wrap: wrap; gap: 2px 18px; font-size: 14px; }
.nav a { color: #c9ccd1; text-decoration: none; padding: 6px 0 2px; border-bottom: 2px solid transparent; }
.nav a:hover { color: #fff; }
.nav a.on { color: #fff; border-bottom-color: #f3f2ee; }
.top-right { margin-left: auto; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; font-size: 13px; }
.tariff { padding: 3px 10px; border-radius: 999px; font-weight: 500; background: #3b4048; color: #f3f2ee; }
.tariff.night { background: #2f6bb8; color: #fff; }
.top-right a, .linkbtn { color: #c9ccd1; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-decoration: underline; }
.top-right form { margin: 0; }

main { max-width: 1360px; margin: 0 auto; padding: 20px 20px 56px; display: flex; flex-direction: column; gap: 18px; }
.crumbs { font-size: 13px; color: var(--muted); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; }
.page-head .title { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions form { margin: 0; }

/* сообщения */
.flash { padding: 10px 14px; border-radius: 8px; background: var(--blue-soft); color: var(--blue-dark); }
.flash.error { background: var(--red-soft); color: var(--red); }
.flash.warn { background: var(--orange-soft); color: var(--orange-text); }
.errors { padding: 10px 14px; border-radius: 8px; background: var(--red-soft); color: var(--red); }
.errors ul { margin: 4px 0 0; padding-left: 18px; }
.note { padding: 10px 14px; border-radius: 8px; background: var(--blue-soft); color: var(--blue-dark); font-size: 14px; }

/* карточки */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; }
.cols { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.col-main { flex: 999 1 620px; min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.col-side { flex: 1 1 360px; min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-family: var(--mono); font-size: 26px; font-weight: 600; }
.kpi .sub { font-size: 13px; color: var(--muted); }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.cap { display: flex; flex-direction: column; gap: 6px; }
.cap .big { font-family: var(--mono); font-size: 22px; font-weight: 600; }
.cap .big small { font-size: 13px; font-weight: 400; }
.fit { padding: 10px 14px; background: var(--blue-soft); color: var(--blue-dark); border-radius: 8px; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 6px 12px; font-size: 14px; }
.kv > dt { color: var(--muted); }
.kv > dd { margin: 0; }

/* полосы загрузки */
.bar { display: block; height: 8px; background: #e7e5de; border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--blue); }
.bar.hot > span { background: var(--orange); }
.bar.thin { height: 6px; }

/* пилюли */
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; background: var(--grey-soft); color: var(--ink-2); }
.pill.ok { background: var(--blue-soft); color: var(--blue); }
.pill.warn { background: var(--orange-soft); color: var(--orange-text); }
.pill.down { background: var(--red); color: #fff; }

/* таблицы */
.scroll { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px 9px 0; border-bottom: 1px solid #eceae4; vertical-align: top; }
.tbl tr.closed td { color: var(--muted); }
.tbl tr.total td { font-weight: 600; border-bottom: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-family: var(--mono); }
.tbl tr.flagged td { background: #fdf3ec; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }

/* кнопки и формы */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 16px; border-radius: 8px; border: 1px solid #c7c4ba; background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--muted); color: var(--ink); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 500; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { color: var(--red); border-color: #e2b4b4; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; min-height: 48px; font-size: 16px; }
form.inline { display: inline; margin: 0; }
.form { display: flex; flex-direction: column; gap: 14px; max-width: 640px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
.field .help { color: var(--muted); font-size: 12px; }
.field.check { flex-direction: row; align-items: center; gap: 10px; font-size: 14px; color: var(--ink); }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=datetime-local], input[type=password], select, textarea {
  font: inherit; font-size: 15px; color: var(--ink); background: #fff; border: 1px solid #c7c4ba; border-radius: 8px; padding: 0 12px; height: 42px; width: 100%; }
textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
input[type=checkbox] { width: 20px; height: 20px; }
input[type=file] { font: inherit; font-size: 14px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline-form .field { min-width: 120px; flex: 1 1 140px; }
details.add { border-top: 1px dashed var(--line); padding-top: 10px; }
details.add > summary { cursor: pointer; color: var(--blue); font-size: 14px; list-style: none; }
details.add > summary::-webkit-details-marker { display: none; }
details.add[open] > summary { margin-bottom: 10px; }
.big-input { font-family: var(--mono); font-size: 24px !important; font-weight: 600; height: 52px !important; border: 2px solid var(--blue) !important; }
.seg { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 4px; background: #e7e5de; border-radius: 10px; }
.seg a { display: flex; align-items: center; justify-content: center; min-height: 40px; border-radius: 7px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
.seg a.on { background: #fff; color: var(--ink); font-weight: 600; }

/* дерево счётчиков */
.meter { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.meter .head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 8px; }
.meter-children { margin-left: 18px; display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.meter.removed { opacity: .65; }

/* журнал */
.log { display: flex; flex-direction: column; }
.log-item { display: grid; grid-template-columns: 100px 120px minmax(0, 1fr); gap: 4px 12px; padding: 9px 0; border-bottom: 1px solid #eceae4; font-size: 14px; }
.log-item:last-child { border-bottom: 0; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.photo-big { max-width: 100%; max-height: 260px; border-radius: 8px; border: 1px solid var(--line); }

/* схема площадки */
.plan-wrap { overflow-x: auto; }
.plan { position: relative; display: flex; flex-wrap: wrap; gap: 12px; padding: 12px; background: var(--paper); border: 1px dashed #c7c4ba; border-radius: 8px; }
.plan.js-plan { display: block; padding: 0; }
.tile { width: 320px; min-height: 150px; background: #fff; border: 2px solid var(--blue-line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; color: var(--ink); text-decoration: none; }
.tile.w20 { width: 200px; }
.js-plan .tile { position: absolute; }
.tile:hover { color: var(--ink); border-color: var(--blue); }
.tile .t-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 8px; }
.tile .t-name { font-family: var(--mono); font-weight: 600; font-size: 15px; }
.tile .t-line { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-2); }
.tile .t-line .mono { white-space: nowrap; }
.tile .t-meta { font-size: 11px; color: var(--muted); }
.tile .t-online { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.plan.editing .tile { cursor: grab; border-style: dashed; user-select: none; touch-action: none; }
.plan.editing .tile.dragging { cursor: grabbing; border-color: var(--orange); z-index: 2; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); }

/* мобильные экраны */
.narrow { max-width: 520px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.check-box { background: var(--blue-soft); color: var(--blue-dark); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.check-box .line { display: flex; justify-content: space-between; gap: 8px; }

/* вход */
.login { max-width: 380px; margin: 60px auto; }
.qr svg { display: block; }

@media (max-width: 720px) {
  .top { padding: 8px 12px; }
  main { padding: 14px 12px 48px; }
  h1 { font-size: 24px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv > dd { margin-bottom: 6px; }
  .log-item { grid-template-columns: 1fr; gap: 2px; }
  .card { padding: 14px; }
}
