:root {
  --bg: #f3f5f8; --card: #ffffff; --text: #18202b; --muted: #5d6877; --border: #dde2e9;
  --primary: #1d5fd1; --primary-text: #fff; --ok: #15803d; --ok-bg: #e7f6ec; --err: #b91c1c; --err-bg: #fdecec;
  --warn: #b45309; --oil: #c2830a; --oil-low: #dc2626; --input: #fff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151b; --card: #1a2029; --text: #e6eaf0; --muted: #9aa5b4; --border: #2d3542;
    --primary: #4b8bf5; --ok: #4ade80; --ok-bg: #14301f; --err: #f87171; --err-bg: #3a1a1c;
    --warn: #fbbf24; --oil: #e0a630; --input: #12171e; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11151b; --card: #1a2029; --text: #e6eaf0; --muted: #9aa5b4; --border: #2d3542;
  --primary: #4b8bf5; --ok: #4ade80; --ok-bg: #14301f; --err: #f87171; --err-bg: #3a1a1c;
  --warn: #fbbf24; --oil: #e0a630; --input: #12171e; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--primary); }
code, pre { font-family: ui-monospace, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--muted); }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--primary); color: var(--primary-text); }
.theme-btn { margin-left: auto; background: none; border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 1rem; }
.logo img { height: 48px; width: auto; display: block; }

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 20px; flex: 1; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 16px; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.card.highlight { border-color: var(--primary); }
.card.danger { border-color: var(--err); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--err-bg); color: var(--err); }

.btn { display: inline-block; padding: 8px 14px; border-radius: 7px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; font: inherit; text-decoration: none; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.small { padding: 4px 9px; font-size: 0.85em; }
.btn.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.disabled { opacity: .5; pointer-events: none; }
.btn-group { display: inline-flex; flex-wrap: wrap; gap: 4px; }

.form label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 500; }
.form label .small, .form label .muted { font-weight: 400; }
.form .check, label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input, select, textarea { font: inherit; padding: 7px 9px; border-radius: 6px; border: 1px solid var(--border); background: var(--input); color: var(--text); max-width: 100%; }
input[type=checkbox] { width: 18px; height: 18px; }
.w-sm { width: 70px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 4px; }
.form.inline { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.form.inline label { margin: 0; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .85em; color: var(--muted); font-weight: 600; }
.table input:not([type=checkbox]) { width: 100%; }
.card:has(> .table), .card:has(> form > .table) { overflow-x: auto; }
tr.lvl-alarm td { color: var(--err); }
tr.lvl-ok td { color: var(--ok); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0 16px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
pre.code { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 12px; overflow-x: auto; user-select: all; }

.badge { padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge.online { background: var(--ok-bg); color: var(--ok); }
.badge.offline { background: var(--err-bg); color: var(--err); }
.badge.off { background: var(--bg); color: var(--muted); }

/* Übersicht */
.device-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.device-head h2 { margin: 0; }
.device-foot { margin-top: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tile { border: 1px solid var(--border); border-radius: 9px; padding: 12px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.tile.tank { grid-column: span 2; }
.tile.stale { opacity: .65; border-style: dashed; }
.tile-title { font-weight: 600; color: var(--text); text-decoration: none; }
.tile-title:hover { text-decoration: underline; }
.tile-foot { font-size: .8rem; color: var(--muted); margin-top: auto; }
.big { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.alarm { color: var(--err); }
.blink { animation: blink 1.2s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .blink { animation: none; } }
.tank-body { display: flex; gap: 16px; align-items: stretch; }
.tank-gauge { position: relative; width: 70px; min-height: 140px; border: 2px solid var(--muted); border-radius: 8px 8px 12px 12px; overflow: hidden; background: var(--card); flex: none; }
.tank-fill { position: absolute; left: 0; right: 0; bottom: 0; background: var(--oil); transition: height .6s; }
.tank-fill.low { background: var(--oil-low); }
.tank-pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--text); text-shadow: 0 0 3px var(--card), 0 0 3px var(--card); }
.tank-info { display: flex; flex-direction: column; gap: 2px; }

/* Verlauf */
.history-controls { display: grid; grid-template-columns: 1fr auto; gap: 16px; }
.sensor-pick { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 24px; }
.pick-group { display: flex; flex-direction: column; gap: 2px; }
.range-pick { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.custom-range { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.custom-range label { display: flex; flex-direction: column; font-size: .85em; }
.chart-box { width: 100%; }
.chart-box canvas { display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
.stats { margin-top: 8px; font-size: .9em; }
.stat-row { margin: 2px 0; }

/* Objekte */
.object-tabs { margin-bottom: 14px; }
.object-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 16px; }
.object-card { display: block; text-decoration: none; color: var(--text); }
.object-card:hover { border-color: var(--primary); }
.object-card h2 { margin-bottom: 4px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.device-sub { font-size: 1rem; margin: 16px 0 8px; color: var(--muted); }
.device-head h2 a { color: var(--text); text-decoration: none; }
.device-head h2 a:hover { text-decoration: underline; }
.tile.planned { opacity: .55; border-style: dashed; }
.tile.unassigned { border-color: var(--warn); }
.tile.energy .big { font-size: 1.6rem; }
.refill-box { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--border); }
tr.planned td { color: var(--muted); }
.add-box { margin-top: 12px; }
.add-box summary { list-style: none; cursor: pointer; display: inline-block; }
.add-box summary::-webkit-details-marker { display: none; }
.add-box[open] summary { margin-bottom: 12px; }
.inline-form { display: inline-block; margin-top: 12px; }
.assign-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.assign-row:last-child { border-bottom: 0; }
.span2 { grid-column: 1 / -1; }
.w-md { width: 90px; }
.table input.w-sm { width: 70px; }
.refill-edit { gap: 6px; flex-wrap: nowrap; }
.table .refill-edit input[name] { padding: 4px 6px; width: 90px; }
.table .refill-edit input[name=note] { width: 170px; }
.assign-row label { flex-direction: row; align-items: center; gap: 8px; }
.export-pick { flex-direction: column; }
.indent { margin-left: 24px; }
.mt { margin-top: 14px; }
.steps { margin: 8px 0 0; padding-left: 22px; }
.steps li { margin: 4px 0; }
pre.code.yaml { max-height: 460px; overflow: auto; font-size: .85em; margin-top: 10px; }

.footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 14px 20px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border); background: var(--card); }

@media (max-width: 760px) {
  .container { padding: 12px; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .nav { order: 4; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .nav a { white-space: nowrap; }
  .logo img { height: 34px; }
  .grid2 { grid-template-columns: 1fr; }
  .history-controls { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile.tank { grid-column: 1 / -1; }
  .tank-body { flex-direction: row; }
  .big { font-size: 1.7rem; }
}
