:root {
  --bg: #0f1620;
  --surface: #1a2533;
  --surface2: #233044;
  --border: #2e3c52;
  --text: #e6edf3;
  --text-dim: #9fb0c3;
  --accent: #3a8bfd;
  --accent-msg: #31567d;
  --green: #34c38f;
  --red: #f46a6a;
  --orange: #f1b44c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.topbar h1 {
  font-size: 22px;
  margin: 0;
}

.topbar .nav a, .topbar .nav button {
  margin-left: 12px;
}

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { opacity: 0.9; text-decoration: none; }
.btn.secondary { background: var(--surface2); color: var(--text); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.secondary.active { background: var(--accent); color: #fff; }

.filter-bar {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}
.filter-bar .field { display: flex; flex-direction: column; }
.filter-bar label { margin: 0 0 4px; }
.filter-bar .presets { display: flex; gap: 6px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.obj-card h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 3px 10px;
  white-space: nowrap;
  border-radius: 999px;
  font-weight: 600;
}
.badge.online { background: rgba(52,195,143,0.15); color: var(--green); }
.badge.offline { background: rgba(244,106,106,0.15); color: var(--red); }
.badge::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.fuel-section { margin-top: 12px; }
.fuel-body { display: flex; align-items: center; gap: 14px; }

.tank-wrap {
  position: relative;
  width: 46px;
  height: 90px;
  border: 2px solid #3a5070;
  border-radius: 8px;
  overflow: hidden;
  background: #0c1520;
  flex-shrink: 0;
}
.tank-fill {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(to top, #1352a8, #3a8bfd);
  transition: height 0.6s ease;
}
.tank-mark {
  position: absolute;
  left: 0; right: 0;
  height: 1px;
  background: rgba(255,255,255,0.12);
  z-index: 1;
  pointer-events: none;
}
.tank-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  z-index: 2;
}

.muted { color: var(--text-dim); font-size: 13px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table th, table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}
table th { color: var(--text-dim); font-weight: 600; font-size: 13px; }

.kind-refuel { color: var(--green); font-weight: 600; }
.kind-drain { color: var(--orange); font-weight: 600; }

form.inline { display: inline; }

input, select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }
textarea { font-family: inherit; }

input[type=checkbox] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  cursor: pointer;
  vertical-align: middle;
  border-radius: 4px;
}

label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--text-dim); }

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  width: 320px;
}
.login-box h1 { text-align: center; font-size: 20px; }

.error { color: var(--red); font-size: 13px; margin-top: 8px; }

.link-box {
  display: flex;
  gap: 8px;
  align-items: center;
}
.link-box input {
  flex: 1;
}

.checkbox-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.checkbox-list .group-title {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  margin: 10px 0 4px;
}
.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  font-size: 14px;
  color: var(--text);
}
.checkbox-list input[type=checkbox] { width: auto; }

.back-link { margin-bottom: 16px; display: inline-block; }

/* ========== ADMIN HEADER / NAV ========== */
.adm-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 1px 0 var(--border);
}
.adm-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 0;
}
.adm-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  margin-right: 28px;
  white-space: nowrap;
}
.adm-logo:hover { text-decoration: none; opacity: .85; }
.adm-tabs {
  display: flex;
  height: 100%;
  gap: 0;
}
.adm-tab {
  display: flex;
  align-items: center;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color .12s, border-color .12s;
  white-space: nowrap;
}
.adm-tab:hover { color: var(--text); text-decoration: none; }
.adm-tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* Page content area below header */
.adm-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}
.adm-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.adm-page-header h1 { margin: 0; font-size: 20px; }

/* Icon action buttons */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, color .12s, border-color .12s;
  padding: 0;
  flex-shrink: 0;
  vertical-align: middle;
}
.icon-btn:hover { background: var(--surface2); border-color: var(--border); color: var(--text); text-decoration: none; }
.icon-btn.danger:hover { background: rgba(244,106,106,.12); color: var(--red); border-color: rgba(244,106,106,.3); }
.icon-btn svg { display: block; }
.icon-btns { display: flex; gap: 4px; justify-content: flex-end; }

/* ========== MODALS / DIALOGS ========== */

/* Браузерный UA-стиль dialog (белый фон, padding) перебиваем !important */
dialog {
  position: fixed !important;
  margin: auto !important;
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: 14px !important;
  padding: 0 !important;
  color: var(--text) !important;
  overflow: hidden !important;
  box-shadow: 0 32px 100px rgba(0,0,0,0.85) !important;
  outline: none;
}
dialog[open] {
  display: flex !important;
  flex-direction: column !important;
  animation: modalIn 0.18s cubic-bezier(0.16,1,0.3,1);
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}
dialog::backdrop {
  background: rgba(0,0,0,0.78) !important;
  backdrop-filter: blur(3px);
}

/* Modal header */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface2);
  border-radius: 14px 14px 0 0;
  gap: 12px;
}
.modal-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.modal-close {
  background: none !important;
  border: none !important;
  color: var(--text-dim) !important;
  font-size: 22px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  width: 32px;
  height: 32px;
  min-width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
}
.modal-close:hover { background: var(--border) !important; color: var(--text) !important; }

/* Modal body — scrollable */
.modal-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* ---- Settings dialog: wide, fixed height, two columns ---- */
#settingsDialog {
  width: min(980px, 96vw) !important;
  height: min(700px, 90vh) !important;
}

.settings-layout {
  display: grid;
  grid-template-columns: 1fr 290px;
  height: 100%;
  overflow: hidden;
}
.settings-main {
  padding: 20px 22px;
  overflow-y: auto;
}
.settings-sidebar {
  padding: 18px 16px;
  overflow-y: auto;
  background: var(--bg);
  border-left: 1px solid var(--border);
}

/* ---- Add / sensor dialogs: narrower ---- */
#addDialog  { width: min(540px, 96vw) !important; max-height: 90vh !important; }
#sensorDialog { width: min(580px, 96vw) !important; max-height: 90vh !important; }
#addDialog .modal-body,
#sensorDialog .modal-body { padding: 20px 22px; }

/* ---- Warehouse dialogs ---- */
.wh-dialog { width: min(600px, 96vw) !important; max-height: 90vh !important; }
.wh-dialog-wide { width: min(820px, 96vw) !important; }
.wh-dialog .modal-body { padding: 20px 22px; }

/* Custom typeahead dropdown (replaces native <datalist>, which browsers can clip
   inside overflow:hidden dialogs — that clipping was why suggestions never appeared). */
.wh-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.wh-suggestions .wh-suggestion-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}
.wh-suggestions .wh-suggestion-item:hover {
  background: var(--surface2);
}

/* Search / filter bar above objects table */
.obj-search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.obj-search-bar input[type=search] { flex: 1; min-width: 180px; }
.obj-search-bar select { min-width: 160px; }

/* Sensor item row in settings modal */
.sensor-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.sensor-item:last-child { border-bottom: none; }
.sensor-info { flex: 1; min-width: 0; }
.sensor-info .s-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sensor-info .s-meta { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

/* Param chip — click to insert param name */
.param-chip {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  font-family: monospace;
  font-size: 12px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.param-chip:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Params table in sidebar */
.params-tbl { width: 100%; font-size: 13px; border-collapse: collapse; }
.params-tbl td { padding: 5px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.params-tbl tr:last-child td { border-bottom: none; }
.params-tbl .pval { text-align: right; color: var(--text-dim); padding-left: 10px; font-variant-numeric: tabular-nums; }

/* Retranslation hint box */
.retrans-hint {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.retrans-hint code {
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 13px;
}

/* Danger zone in settings modal */
.danger-zone {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.danger-zone .muted { font-size: 12px; flex: 1; min-width: 180px; }

/* Sensors section header */
.sensors-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* Empty state */
.empty-hint {
  color: var(--text-dim);
  font-size: 13px;
  padding: 14px 0;
}

/* Object meta rows */
.obj-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 14px;
}
.obj-meta-row .label { color: var(--text-dim); min-width: 80px; font-size: 13px; }

/* ---- Raw data page ---- */
.raw-date-bar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.raw-date-bar .field { display: flex; flex-direction: column; gap: 4px; }
.raw-date-bar label { font-size: 12px; color: var(--text-dim); margin: 0; }
.raw-presets { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.raw-presets span { color: var(--text-dim); font-size: 13px; }

.raw-wrap {
  display: grid;
  grid-template-columns: 1fr 210px;
  height: 460px;          /* фиксированная высота всего блока */
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  margin-bottom: 14px;
}
.raw-main {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.raw-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}
.raw-tab-btn {
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color .12s, border-color .12s;
}
.raw-tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.raw-chart-wrap {
  flex: 1;
  min-height: 0;          /* критично для flex + canvas */
  position: relative;
  padding: 14px;
  overflow: hidden;
}
.raw-chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 14px;
  pointer-events: none;
}
.raw-table-wrap { flex: 1; min-height: 0; overflow: auto; display: none; }
.raw-sidebar {
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.raw-sidebar-head {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.raw-sidebar-head strong { font-size: 13px; display: block; margin-bottom: 8px; }
.raw-sidebar-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 10px; }
.raw-param-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 2px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  font-size: 13px;
}
.raw-param-row:last-child { border-bottom: none; }
.raw-param-row input[type=checkbox] { cursor: pointer; accent-color: var(--accent); flex-shrink: 0; }
.raw-param-row .pdot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.raw-param-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Report table ===== */
.report-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-tbl th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.report-tbl td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.report-tbl tbody tr:last-child td { border-bottom: none; }
.report-tbl tbody tr:hover { background: rgba(255,255,255,0.03); }
.report-tbl tr.row-bypass { background: rgba(244,106,106,0.06); }
.report-tbl tr.row-bypass:hover { background: rgba(244,106,106,0.1); }
.td-ts { white-space: nowrap; color: var(--text-dim); font-size: 12px; }

.badge-bypass {
  display: inline-block;
  background: rgba(244,106,106,0.18);
  color: #f46a6a;
  border: 1px solid rgba(244,106,106,0.4);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
}

.print-split {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}
.print-split-main {
  border-radius: 8px 0 0 8px !important;
}
.print-split-toggle {
  border-radius: 0 8px 8px 0 !important;
  border-left: 1px solid rgba(255,255,255,0.25);
  padding: 5px 10px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}
.print-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  min-width: 240px;
  padding: 6px;
}
.print-menu-label {
  display: block;
  padding: 4px 10px 2px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-dim);
}
.print-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}
.print-menu-item {
  display: block;
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--text);
  text-decoration: none;
  border-radius: 5px;
  white-space: nowrap;
  cursor: pointer;
}
.print-menu-item:hover {
  background: var(--surface2);
}

input[type=checkbox].wh-row-check, input[type=checkbox]#whSelectAll {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  min-width: 14px;
  max-width: 14px;
  padding: 0;
  margin: 0;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--surface2);
  cursor: pointer;
  position: relative;
  vertical-align: middle;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}
input[type=checkbox].wh-row-check:hover, input[type=checkbox]#whSelectAll:hover {
  border-color: var(--accent);
}
input[type=checkbox].wh-row-check:checked, input[type=checkbox]#whSelectAll:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type=checkbox].wh-row-check:checked::after, input[type=checkbox]#whSelectAll:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0px;
  width: 4px;
  height: 7px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
