/* MeterReadings – sachlich, kompakt, touch-tauglich */
:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #d9dde3;
  --line-soft: #eceef1;
  --accent: #1f3a5f;
  --accent-2: #2f5d8c;
  --accent-soft: #e6edf5;
  --ok: #2e7d4f;
  --ok-soft: #e7f3ec;
  --warn: #a15c00;
  --warn-soft: #fdf3e2;
  --err: #b42318;
  --err-soft: #fdecea;
  --ctl-h: 38px;          /* Höhe Bedienelemente (Maus) */
  --radius: 4px;
  --gap: 12px;
  font-size: 15px;
}
@media (pointer: coarse) {
  :root { --ctl-h: 44px; }   /* Finger */
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 var(--gap); font-weight: 600; }
h2 { font-size: 1.05rem; margin: 0 0 10px; font-weight: 600; }
h3 { font-size: .95rem; margin: 14px 0 6px; font-weight: 600; }
h2 small, h3 small { font-weight: 400; font-size: .85rem; }
p { margin: 0 0 10px; }
code { background: var(--line-soft); padding: 1px 4px; border-radius: 3px; }

/* ---------- Kopfleiste ---------- */
.topbar { background: var(--accent); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 0 12px; min-height: 48px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.prop-name { color: #cfdbe9; border-left: 1px solid rgba(255,255,255,.25); padding-left: 12px; }
.prop-switch select { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.3); min-width: 180px; max-width: 280px; }
.prop-switch select option { color: var(--text); background: #fff; }
.topbar nav { display: flex; margin-left: auto; align-self: stretch; }
.topbar nav a { color: #dbe5f0; padding: 0 12px; display: flex; align-items: center; border-bottom: 3px solid transparent; min-height: 48px; }
.topbar nav a:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,.06); }
.topbar nav a.active { color: #fff; border-bottom-color: #9cc0e6; }
.topbar nav a.user { border-left: 1px solid rgba(255,255,255,.2); margin-left: 4px; }
.nav-toggle { display: none; margin-left: auto; background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: var(--radius); min-height: var(--ctl-h); padding: 0 12px; font: inherit; }

@media (max-width: 900px) {
  .nav-toggle { display: block; }
  .topbar nav { display: none; width: 100%; flex-direction: column; margin: 0 -12px; width: calc(100% + 24px); }
  .topbar nav.open { display: flex; }
  .topbar nav a { min-height: 44px; border-bottom: 0; border-left: 3px solid transparent; border-top: 1px solid rgba(255,255,255,.1); }
  .topbar nav a.active { border-left-color: #9cc0e6; }
  .topbar nav a.user { margin: 0; border-left: 3px solid transparent; }
  .prop-switch select { min-width: 0; max-width: 200px; }
}

main { max-width: 1400px; margin: 0 auto; padding: 14px 12px 40px; }

/* ---------- Bausteine ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: var(--gap); }
.card.narrow { max-width: 380px; margin: 40px auto; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.page-head h1, .page-head h2 { margin: 0; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.crumbs { margin: 0 0 2px; font-size: .85rem; color: var(--muted); }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.hint { color: var(--muted); font-size: .85rem; margin: 0; }
.empty { color: var(--muted); padding: 14px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.card .empty { border: 0; padding: 8px 0; text-align: left; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.push-right { margin-left: auto; }
.link { color: var(--accent-2); }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--gap); }
.grid-cards > .card { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: var(--gap); align-items: start; }
.grid-2 > .card, .grid-2-1 > .card { margin: 0; }
@media (max-width: 900px) { .grid-2, .grid-2-1 { grid-template-columns: 1fr; } }

.flash { padding: 8px 12px; border-radius: var(--radius); margin-bottom: 10px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); border-color: #b9dcc7; color: #1d5236; }
.flash.err { background: var(--err-soft); border-color: #f3b8b2; color: #8a1c12; }
.flash.info { background: var(--accent-soft); border-color: #c4d4e6; color: var(--accent); }

.tag { display: inline-block; font-size: .75rem; padding: 1px 6px; border-radius: 3px; background: var(--line-soft); color: #374151; border: 1px solid var(--line); line-height: 1.4; vertical-align: 1px; }
.tag.admin { background: var(--accent-soft); color: var(--accent); border-color: #c4d4e6; }
.t-strom    { border-left: 3px solid #d4a017; }
.t-wasser   { border-left: 3px solid #2f80c0; }
.t-heizung, .t-fernwärme { border-left: 3px solid #c0392b; }
.t-gas      { border-left: 3px solid #e67e22; }
.t-kälte    { border-left: 3px solid #48b5c4; }
.t-solar    { border-left: 3px solid #f1c40f; }
.t-öl       { border-left: 3px solid #6d4c41; }
.warn-text { color: var(--warn); }
.ok-text { color: var(--ok); }
.note-text { color: var(--warn); }
.up { color: var(--err); }
.down { color: var(--ok); }
.neg { color: var(--err); font-weight: 600; }

/* ---------- Formulare ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; min-height: var(--ctl-h); padding: 6px 8px;
  border: 1px solid #c3c8d0; border-radius: var(--radius); background: #fff;
}
textarea { min-height: 60px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0e6; outline-offset: 0; border-color: var(--accent-2); }
input[type=checkbox] { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

.form label { display: flex; flex-direction: column; gap: 3px; font-size: .85rem; color: #4b5563; }
.form label small { color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-size: .95rem; color: var(--text); min-height: var(--ctl-h); align-self: end; }
.form { display: grid; gap: 10px 12px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (max-width: 760px) {
  .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr 1fr; }
  .span-3, .span-4, .span-5 { grid-column: 1 / -1; }
  .hide-sm { display: none; }
}
@media (max-width: 480px) {
  .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
  .span-2 { grid-column: 1 / -1; }
}
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
form.inline input:not([type=checkbox]) { width: auto; flex: 1; min-width: 0; }
.add-row { display: flex; margin-top: 8px; width: 100%; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: var(--ctl-h); padding: 0 12px; border-radius: var(--radius);
  border: 1px solid #c3c8d0; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: #f5f6f8; text-decoration: none; }
.btn:active { background: #eceef1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--err); border-color: #e5b4ae; }
.btn.danger:hover { background: var(--err-soft); }
.btn.small { min-height: 32px; padding: 0 9px; font-size: .9rem; }
.btn.icon { width: var(--ctl-h); padding: 0; }
.btn.block { width: 100%; }
@media (pointer: coarse) { .btn.small { min-height: 40px; padding: 0 12px; } }

.filterbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.filterbar select { width: auto; min-width: 160px; }
.filterbar select.wide { min-width: min(520px, 100%); }
.filterbar .check { display: flex; align-items: center; gap: 6px; min-height: var(--ctl-h); }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: var(--gap); }
.card .table-wrap { border: 0; margin: 0; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { padding: 6px 8px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; }
.table thead th { font-size: .8rem; font-weight: 600; color: #4b5563; background: #f8f9fa; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
.table tbody tr:hover { background: #fafbfc; }
.table tfoot th, .table tfoot td { border-top: 2px solid var(--line); font-weight: 600; }
.table .num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * + * { margin-left: 4px; }
.table.compact th, .table.compact td { padding: 4px 6px; }
.table.lookup td:first-child { width: 100%; }
tr.inactive td { color: var(--muted); }
tr.current td { background: var(--accent-soft); }
tr.group-row th { background: #f3f5f8; font-size: .85rem; padding: 4px 8px; }
tr.warn-row td { background: var(--warn-soft); }
.reg { font-size: .8rem; color: var(--muted); background: var(--line-soft); padding: 0 4px; border-radius: 3px; margin-left: 2px; }
.sub { font-size: .78rem; color: var(--muted); line-height: 1.3; }

.meter-chip { display: inline-block; border: 1px solid var(--line); border-radius: 3px; padding: 1px 6px; margin: 1px 2px 1px 0; color: var(--text); font-size: .9rem; }
.meter-chip small { color: var(--muted); }
.meter-chip.ended { color: var(--muted); text-decoration: line-through; }

.progress-cell { white-space: nowrap; }
.progress { display: inline-block; width: 80px; height: 6px; background: var(--line-soft); border-radius: 3px; vertical-align: middle; margin-right: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0 0 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.inline-kv { grid-template-columns: repeat(auto-fill, minmax(90px, max-content) minmax(140px, 1fr)); }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); margin-bottom: var(--gap); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; color: var(--muted); font-size: .85rem; }
.kpi span { display: block; color: var(--text); font-size: 1.25rem; font-weight: 600; }
@media (max-width: 760px) { .kpis { grid-template-columns: 1fr 1fr; } }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }
.warn-list { margin: 0; padding-left: 18px; color: var(--warn); }

.tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 10px; overflow-x: auto; }
.tabs a { padding: 0 14px; min-height: var(--ctl-h); display: flex; align-items: center; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* Kopfdaten zum Aufklappen */
details.collapsible > summary { list-style: none; display: flex; gap: 16px; flex-wrap: wrap; align-items: center; cursor: pointer; min-height: 28px; }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible[open] > summary { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line-soft); }

/* ---------- Erfassungsmaske ---------- */
.entry-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table.entry td { padding: 5px 8px; }
.table.entry td.place { width: 1%; white-space: nowrap; }
.table.entry td.place .tag { margin-left: 4px; }
.table.entry td.prev { white-space: nowrap; }
.table.entry td.value { width: 170px; white-space: nowrap; }
.table.entry td.value input { width: 130px; text-align: right; font-weight: 600; }
.table.entry td.value .unit { display: inline-block; width: 34px; font-size: .8rem; color: var(--muted); margin-left: 4px; text-align: left; }
.table.entry td.cons { width: 120px; white-space: nowrap; }
.table.entry td.date { width: 150px; }
.table.entry td.note { min-width: 160px; }
.table.entry tr.is-done td.place strong { color: var(--ok); }
.table.entry tr.is-dirty { background: #fffbea; }
.table.entry tr.has-warn td.value input { border-color: var(--warn); background: var(--warn-soft); }
.table.entry tr.has-err td.value input { border-color: var(--err); background: var(--err-soft); }
.savebar {
  position: sticky; bottom: 0; display: flex; gap: 12px; justify-content: flex-end; align-items: center;
  padding: 8px 12px; background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
}
.savebar .btn { min-width: 140px; }

/* Tablet hochkant / schmal: Zeilen als kompakte Karten */
@media (max-width: 860px) {
  .table.entry thead { display: none; }
  .table.entry, .table.entry tbody { display: block; }
  .table.entry tr {
    display: grid; grid-template-columns: 70px minmax(0, 1fr) 140px 150px; grid-template-areas:
      "place meter prev cons"
      "value value date note";
    gap: 4px 10px; padding: 6px 10px; border-bottom: 1px solid var(--line);
  }
  .table.entry td { display: block; border: 0; padding: 0 !important; width: auto !important; min-width: 0 !important; }
  .table.entry td.place { grid-area: place; text-align: left; }
  .table.entry td.place .tag { display: block; margin: 2px 0 0; width: max-content; }
  .table.entry td.meter { grid-area: meter; }
  .table.entry td.prev { grid-area: prev; }
  .table.entry td.prev .sub { display: inline; margin-left: 4px; }
  .table.entry td.value { grid-area: value; display: flex; align-items: center; }
  .table.entry td.value input { flex: 1; width: auto; font-size: 1.1rem; }
  .table.entry td.cons { grid-area: cons; }
  .table.entry td.date { grid-area: date; }
  .table.entry td.note { grid-area: note; }
  .table.entry td.note .sub { display: none; }
  .table.entry td.prev::before, .table.entry td.cons::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted); }
}
@media (max-width: 560px) {
  .table.entry tr {
    grid-template-columns: 48px minmax(0, 1fr) auto; grid-template-areas:
      "place meter prev"
      "value value cons"
      "date note note";
  }
  .table.entry td.prev .sub { display: block; margin: 0; }
}

/* ---------- Diagramme ---------- */
.chart-block { margin: 6px 0 14px; max-width: 900px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #e8eaee; stroke-width: 1; }
.chart .base { stroke: #9aa1ab; stroke-width: 1; }
.chart .axis { fill: #6b7280; font-size: 11px; font-family: inherit; }
.chart rect.s1, .legend i.s1 { fill: var(--accent-2); background: var(--accent-2); }
.chart rect.s2, .legend i.s2 { fill: #b8c4d2; background: #b8c4d2; }
.chart rect.neg { fill: var(--err); }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); margin-top: 2px; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; }
.report-card h2:not(:first-child) { margin-top: 18px; }
.table.report.dense th, .table.report.dense td { padding: 4px 6px; font-size: .88rem; }

@media print {
  .topbar, .toolbar, .filterbar, .tabs, .savebar { display: none !important; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}
