:root {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #172033;
  background: #f5f7fb;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }

.app { max-width: 1280px; margin: 0 auto; padding: 24px; }
.hidden { display: none !important; }
.card { background: #fff; border: 1px solid #e7eaf0; border-radius: 18px; box-shadow: 0 8px 24px rgba(25, 35, 60, .06); }
.login-card { max-width: 420px; margin: 10vh auto; padding: 28px; }
.login-card form { display: grid; gap: 16px; margin-top: 20px; }
label { display: grid; gap: 6px; font-weight: 600; }
input, select { width: 100%; border: 1px solid #d8dde8; border-radius: 12px; padding: 11px 12px; background: #fff; }
button { border: 0; border-radius: 12px; padding: 11px 16px; background: #172033; color: #fff; cursor: pointer; }
button.ghost { background: #eef1f6; color: #172033; }
button:hover { opacity: .92; }
.error { color: #b42318; min-height: 20px; margin-top: 12px; }

.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 18px; }
h1 { margin: 0; font-size: 30px; }
p { margin: 6px 0 0; color: #667085; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filters { display: grid; grid-template-columns: minmax(220px, .8fr) minmax(260px, 1.2fr) 220px; gap: 12px; padding: 16px; margin-bottom: 16px; }
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.summary .card { padding: 16px; }
.summary span { color: #667085; display: block; margin-bottom: 4px; }
.summary strong { font-size: 28px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1100px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid #edf0f5; vertical-align: top; }
th { font-size: 13px; color: #667085; background: #fafbfe; position: sticky; top: 0; }
.badge { display: inline-flex; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 700; background: #eef1f6; }
.badge.ok { background: #ecfdf3; color: #027a48; }
.badge.warn { background: #fff6e6; color: #b54708; }
.sensors { color: #475467; font-size: 13px; line-height: 1.5; }
.empty { text-align: center; color: #667085; padding: 34px; }
.client-row td { background: #eef3ff; border-bottom: 1px solid #d9e3ff; padding-top: 14px; padding-bottom: 14px; }
.client-title { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.client-title strong { font-size: 16px; }
.client-title span { color: #667085; font-size: 13px; }

@media (max-width: 900px) {
  .app { padding: 14px; }
  .topbar { display: grid; }
  .filters, .summary { grid-template-columns: 1fr; }
}
button.secondary { background: #31405f; }
.account-cell small { color: #667085; }
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(12, 18, 32, .42); }
.modal-card { position: relative; width: min(1180px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: hidden; display: grid; grid-template-rows: auto auto auto 1fr; padding: 18px; }
.modal-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 14px; }
.modal-header h2 { margin: 0; font-size: 24px; }
.modal-controls { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; margin-bottom: 10px; }
.hint { color: #667085; font-size: 13px; margin-bottom: 10px; }
.catalog-wrap { overflow: auto; border: 1px solid #edf0f5; border-radius: 14px; }
.catalog-wrap table { min-width: 900px; }
.catalog-wrap input[type="checkbox"] { width: 18px; height: 18px; }
@media (max-width: 900px) {
  .modal-controls { grid-template-columns: 1fr; }
  .modal-header { display: grid; }
}

.progress-box { display: grid; gap: 10px; max-width: 520px; margin: 0 auto; text-align: left; }
.progress-bar { height: 12px; background: #e5eaf3; border-radius: 999px; overflow: hidden; }
.progress-bar > div { height: 100%; background: #13213b; border-radius: 999px; transition: width .25s ease; }
.inline { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.inline input { width: auto; }
.client-password { min-width: 180px; margin-bottom: 4px; }
.admin-only.hidden { display: none !important; }

/* v0.1.20: visual improvements */
html[data-theme="dark"] {
  color-scheme: dark;
  background: #0e1422;
}
html[data-theme="dark"] body { background: #0e1422; color: #e7ecf7; }
html[data-theme="dark"] :root { background: #0e1422; color: #e7ecf7; }
html[data-theme="dark"] .card { background: #141d2e; border-color: #26344d; box-shadow: 0 8px 24px rgba(0,0,0,.28); }
html[data-theme="dark"] input,
html[data-theme="dark"] select { background: #0f1726; color: #e7ecf7; border-color: #34435f; }
html[data-theme="dark"] input::placeholder { color: #8792a6; }
html[data-theme="dark"] p,
html[data-theme="dark"] .hint,
html[data-theme="dark"] .sensors,
html[data-theme="dark"] .client-title span,
html[data-theme="dark"] .muted { color: #a8b3c7; }
html[data-theme="dark"] th { background: #111a2a; color: #b9c4d8; }
html[data-theme="dark"] th,
html[data-theme="dark"] td { border-bottom-color: #26344d; }
html[data-theme="dark"] button.ghost { background: #202b3f; color: #e7ecf7; }
html[data-theme="dark"] button.secondary { background: #2d4167; }
html[data-theme="dark"] .client-row td { background: #17243a; border-bottom-color: #2b4168; }
html[data-theme="dark"] tr.data-row.row-even td { background: #141d2e; }
html[data-theme="dark"] tr.data-row.row-odd td { background: #172235; }
html[data-theme="dark"] tr.data-row:hover td { background: #1c2b45; }
html[data-theme="dark"] .progress-bar { background: #253149; }
html[data-theme="dark"] .progress-bar > div { background: #6ea8ff; }
html[data-theme="dark"] .badge.ok { background: rgba(2,122,72,.18); color: #7ee1aa; }
html[data-theme="dark"] .badge.warn { background: rgba(181,71,8,.18); color: #ffbc73; }

.icon-btn { min-width: 46px; padding-left: 12px; padding-right: 12px; background: #eef1f6; color: #172033; }
html[data-theme="dark"] .icon-btn { background: #202b3f; color: #e7ecf7; }
.tabs { display: inline-flex; gap: 8px; padding: 8px; margin-bottom: 12px; }
.tab { background: transparent; color: #667085; border-radius: 12px; padding: 10px 18px; }
.tab.active { background: #172033; color: #fff; }
html[data-theme="dark"] .tab { color: #a8b3c7; }
html[data-theme="dark"] .tab.active { background: #6ea8ff; color: #08111f; }
tr.data-row.row-even td { background: #ffffff; }
tr.data-row.row-odd td { background: #f8faff; }
tr.data-row:hover td { background: #eef5ff; }
.compact-sensors { line-height: 1.25; }
.sensor-line { margin: 0 0 8px; }
.sensor-line:last-child { margin-bottom: 0; }
.sensor-line small { line-height: 1.2; }
.sensor-current-value { font-weight: 400; }
.muted { color: #667085; }

.sensor-subline {
  margin-bottom: 2px;
}

.aggregate-fuel-line {
  margin-top: 2px;
}

.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: #172033; }
html[data-theme="dark"] .sortable:hover { color: #e7ecf7; }


/* v0.1.29: table sort headers */
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.sort-label {
  display: inline-block;
  vertical-align: middle;
}
.sort-arrow {
  display: inline-block;
  margin-left: 6px;
  min-width: 12px;
  color: #98a2b3;
  font-size: 13px;
  vertical-align: middle;
}
th.sort-active .sort-label,
th.sort-active .sort-arrow {
  color: #172033;
  font-weight: 700;
}
html[data-theme="dark"] th.sort-active .sort-label,
html[data-theme="dark"] th.sort-active .sort-arrow {
  color: #e7ecf7;
}


.app-version {
  position: fixed;
  right: 14px;
  bottom: 10px;
  font-size: 12px;
  color: #98a2b3;
  opacity: 0.75;
  z-index: 20;
  pointer-events: none;
}

html[data-theme="dark"] .app-version {
  color: #8b95a7;
}

/* v0.1.32: параметры справа от вкладок */
.tabs {
  display: flex;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}
.parameters-tab-btn {
  margin-left: auto;
}
.parameters-groups {
  display: grid;
  gap: 12px;
  max-height: 70vh;
  overflow: auto;
  padding-right: 4px;
}
.parameter-group {
  border: 1px solid #e4e7ec;
  border-radius: 14px;
  overflow: hidden;
}
.parameter-group summary {
  cursor: pointer;
  padding: 12px 14px;
  background: #f8faff;
  font-weight: 700;
}
.parameter-group-body {
  padding: 12px;
}
.parameter-table {
  width: 100%;
  border-collapse: collapse;
}
.parameter-table th,
.parameter-table td {
  font-size: 13px;
  vertical-align: top;
}
.parameter-used {
  white-space: nowrap;
}
html[data-theme="dark"] .parameter-group {
  border-color: #26344d;
}
html[data-theme="dark"] .parameter-group summary {
  background: #111a2a;
}


/* v0.1.33: окно параметров и список объектов */
#parametersModal .modal-card {
  height: min(85vh, calc(100vh - 48px));
}
.parameters-groups {
  min-height: 0;
  max-height: none;
}
.parameter-group-body {
  overflow: auto;
}
.parameter-table {
  min-width: 980px;
}
.link-btn {
  border: 0;
  background: transparent;
  color: #2458b8;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.link-btn:hover {
  color: #173b7a;
}
.modal-controls.one-column {
  grid-template-columns: 1fr;
}
.parameter-objects-card {
  width: min(760px, calc(100vw - 32px));
  height: min(80vh, calc(100vh - 48px));
}
.parameter-objects-wrap {
  min-height: 0;
  overflow: auto;
}
.parameter-objects-wrap table {
  min-width: 100%;
}
html[data-theme="dark"] .link-btn {
  color: #8ab4ff;
}
html[data-theme="dark"] .link-btn:hover {
  color: #b6cdfb;
}

/* v0.1.34: версия внизу и работа за nginx */

/* v0.1.35: параметры без пустых блоков и скролл только в окне */
body.modal-open {
  overflow: hidden;
}

#parametersModal .modal-card {
  overflow: hidden;
}

#parametersModal .parameters-groups {
  max-height: calc(85vh - 190px);
  overflow-y: auto;
  padding-right: 6px;
}

.parameter-group:not([open]) .parameter-group-body {
  display: none !important;
  height: 0;
  padding: 0;
  overflow: hidden;
}

.parameter-group:not([open]) {
  min-height: 0;
}

.parameter-group summary {
  user-select: none;
}



/* v0.1.37: полный список объектов в параметрах */
#parametersModal .modal-card {
  height: min(90vh, calc(100vh - 32px));
  max-height: min(90vh, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#parametersModal .modal-header,
#parametersModal .modal-controls,
#parametersModal #parametersInfo {
  flex: 0 0 auto;
}

#parametersModal .parameters-groups {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 6px;
}

.parameter-group {
  flex: 0 0 auto;
}

.parameter-group:not([open]) {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: hidden;
}

.parameter-group:not([open]) > :not(summary) {
  display: none !important;
  height: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
}

.parameter-group:not([open]) summary {
  border-radius: 14px;
}
