:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --ink: #17212b;
  --ink-2: #4a5866;
  --muted: #7a8794;
  --line: #d9dfe5;
  --brand: #12324d;
  --brand-2: #1d4a70;
  --accent: #e08a12;
  --fuel-top: #f2a93b;
  --fuel-bottom: #c76d06;
  --ok: #1f8a4c;
  --ok-bg: #e3f4ea;
  --warn: #9a5b00;
  --warn-bg: #fff1d6;
  --err: #b42318;
  --err-bg: #fde7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 33, 48, .06), 0 2px 8px rgba(16, 33, 48, .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); min-height: 100vh; }
a { color: var(--brand-2); }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 28px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* Шапка */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--brand); color: #fff; padding: 0 28px; height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; white-space: nowrap; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: linear-gradient(to top, var(--accent) 0 55%, rgba(255,255,255,.18) 55% 100%);
  border: 2px solid rgba(255,255,255,.8);
}
.brand-mark.big { width: 40px; height: 40px; border-radius: 10px; border-color: var(--brand); background: linear-gradient(to top, var(--accent) 0 60%, #dfe7ee 60% 100%); }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { color: #cfdbe6; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.topnav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.who { color: #cfdbe6; font-size: 13.5px; white-space: nowrap; }
.logout .btn-ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.logout .btn-ghost:hover { background: rgba(255,255,255,.12); }

.main { max-width: 1840px; margin: 0 auto; padding: 18px 28px 40px; }

/* Кнопки и формы */
.btn {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 500;
  padding: 8px 16px; border-radius: 7px; border: 1px solid transparent; cursor: pointer;
  text-decoration: none; line-height: 1.2; white-space: nowrap;
}
.btn-primary { background: var(--brand-2); color: #fff; }
.btn-primary:hover { background: var(--brand); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { background: #f3f6f8; }
.btn-danger { background: transparent; border-color: #f0c4bf; color: var(--err); }
.btn-danger:hover { background: var(--err-bg); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .page-btn:focus-visible { outline: 3px solid #7fb3e0; outline-offset: 1px; }

.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.form input, .form select, .wh-switch select {
  font: inherit; color: var(--ink); padding: 8px 10px; border: 1px solid #c4ccd4; border-radius: 7px; background: #fff; min-width: 0;
}
.form label.check { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 9px; }
.form label.check input { width: 16px; height: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 18px; align-items: start; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.pw-row { display: flex; gap: 6px; }
.pw-row input { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.inline { display: inline; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.flash-ok { background: var(--ok-bg); border-color: #b7e2c7; color: #135c32; }
.flash-warn { background: var(--warn-bg); border-color: #f2d59b; color: var(--warn); }
.flash-err { background: var(--err-bg); border-color: #f3c0bb; color: var(--err); }

/* Вход */
.page-login .main { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card { width: 380px; background: var(--surface); border-radius: 14px; padding: 32px; box-shadow: 0 10px 40px rgba(16,33,48,.12); border: 1px solid var(--line); }
.login-head { text-align: center; margin-bottom: 22px; }
.login-head .brand-mark { margin: 0 auto 14px; display: block; }
.login-head h1 { font-size: 20px; }
.login-head p { margin: 4px 0 0; }
.login-card .form { display: flex; flex-direction: column; gap: 14px; }
.login-card .btn-primary { justify-content: center; padding: 10px; margin-top: 4px; }

/* Панель склада */
.dash-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 12px; }
.status-line { color: var(--muted); font-size: 13.5px; }
.wh-switch { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13.5px; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; font-size: 14px; }
.banner-err { background: var(--err-bg); border-color: #f3c0bb; color: var(--err); }
.banner-warn { background: var(--warn-bg); border-color: #f2d59b; color: var(--warn); }

.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1279px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 959px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.tank-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 8px;
  transition: opacity .2s;
}
.tank-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tank-name { font-size: 16px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tank-type { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.tank-vis { position: relative; display: flex; align-items: center; gap: 14px; }
.tank-svg { width: 56%; max-width: 172px; height: auto; flex: none; }
.tank-pct { font-size: 34px; font-weight: 650; letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; }
.tank-pct .unit { font-size: 18px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tank-volume { font-size: 15px; font-variant-numeric: tabular-nums; }
.tank-volume strong { font-size: 18px; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 2px 0 0; padding: 8px 0 0; border-top: 1px solid #edf0f3; }
.metric dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.metric dd { margin: 2px 0 0; font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.metric dd .unit { font-weight: 400; color: var(--ink-2); font-size: 12.5px; }
.metric dd.missing { color: var(--muted); font-weight: 400; font-size: 13px; }
.tank-foot { font-size: 12.5px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 11.5px; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-off { background: #eceff2; color: var(--ink-2); }

/* Цистерна */
.tank-inner { fill: #f4f7f9; }
.fuel-top { stop-color: var(--fuel-top); }
.fuel-bottom { stop-color: var(--fuel-bottom); }
.fuel-surface { stroke: #fff3d9; stroke-width: 1.5; opacity: .9; }
.tank-shell { fill: none; stroke: #5b6b79; stroke-width: 3; }
.tank-seam { stroke: #5b6b79; stroke-width: 1; opacity: .35; }
.tank-tick { stroke: #5b6b79; stroke-width: 1; opacity: .35; }
.tank-support { fill: #8796a3; }
.tank-nodata { font-size: 13px; fill: var(--muted); font-family: inherit; }

.state-stale .fuel-top, .state-stale .fuel-bottom, .offline .fuel-top, .offline .fuel-bottom { stop-color: #b9c2ca; }
.state-stale .tank-pct, .state-stale .tank-volume, .state-stale .metric dd { color: var(--muted); }
.state-stale { border-color: #f0d9ad; background: #fffdf8; }
.state-nodata .tank-pct { color: var(--muted); }
.offline { opacity: .65; }

.pager { display: flex; justify-content: center; gap: 6px; margin-top: 22px; }
.page-btn {
  min-width: 38px; height: 38px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); font: inherit; font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.page-btn:hover:not(:disabled) { background: #f3f6f8; }
.page-btn.current { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: default; }

.empty { background: var(--surface); border: 1px dashed #c4ccd4; border-radius: var(--radius); padding: 40px; text-align: center; color: var(--ink-2); grid-column: 1 / -1; }

/* Администрирование */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 16px 0 8px; flex-wrap: wrap; }
.tabs a { padding: 10px 16px; text-decoration: none; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--brand-2); border-bottom-color: var(--brand-2); }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid #edf0f3; vertical-align: middle; font-size: 14px; }
.table th { background: #f6f8fa; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * { margin-left: 4px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: var(--err-bg); color: var(--err); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: 12px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; margin: 16px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
