:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* NAV */
nav {
  background: #1e293b;
  color: #fff;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  min-height: 56px;
}
.nav-brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  margin-right: auto;
}
.nav-links { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav-links a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  transition: background 0.15s, color 0.15s;
}
.nav-links a:hover { background: #334155; color: #fff; }

/* MAIN */
main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
}

h1 { font-size: 1.75rem; margin-bottom: 1.5rem; color: var(--text); }
h2 { font-size: 1.2rem; margin-bottom: 1rem; color: var(--text); }
h3 { font-size: 1rem; margin-bottom: 0.5rem; color: var(--text-muted); }

/* CARD */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

/* FORM */
.form-card h2 { margin-bottom: 1rem; }
.eingabe-form { display: flex; flex-direction: column; gap: 1rem; }
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}
label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}
input, select {
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s;
}
input:focus, select:focus {
  outline: none;
  border-color: #6366f1;
}

.btn-primary {
  align-self: flex-start;
  background: #6366f1;
  color: #fff;
  border: none;
  padding: 0.65rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: #4f46e5; }

.btn-secondary {
  display: inline-block;
  background: var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-secondary:hover { background: #cbd5e1; }

.btn-small {
  font-size: 0.8rem;
  color: #6366f1;
  text-decoration: none;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 5px;
  transition: background 0.15s;
}
.btn-small:hover { background: #ede9fe; }

.btn-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem 0.4rem;
  border-radius: 5px;
  transition: background 0.15s;
}
.btn-delete:hover { background: #fee2e2; }

/* DASHBOARD GRID */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.meter-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.meter-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.meter-icon { font-size: 1.75rem; }
.meter-name { font-weight: 700; font-size: 1rem; }
.meter-einheit { font-size: 0.8rem; color: var(--text-muted); }
.meter-header .btn-small { margin-left: auto; }

.meter-stand {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
}
.meter-stand span { font-size: 1rem; font-weight: 400; color: var(--text-muted); }

.meter-meta { font-size: 0.82rem; color: var(--text-muted); }

.meter-verbrauch {
  font-size: 0.9rem;
  font-weight: 600;
  color: #16a34a;
  background: #dcfce7;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
}
.meter-verbrauch.negativ { color: #dc2626; background: #fee2e2; }
.vb-label { font-weight: 400; color: inherit; opacity: 0.7; font-size: 0.78rem; }

.meter-leer {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
}

/* VERLAUF */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.page-header h1 { margin-bottom: 0; }

.verlauf-tabelle {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.verlauf-tabelle th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.verlauf-tabelle td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.verlauf-tabelle tr:last-child td { border-bottom: none; }
.verlauf-tabelle tr:hover td { background: #f8fafc; }
.stand-cell { font-weight: 700; font-family: monospace; font-size: 1rem; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
}
.badge-positiv { background: #dcfce7; color: #15803d; }
.badge-negativ { background: #fee2e2; color: #dc2626; }
.badge-neutral  { background: #f1f5f9; color: #64748b; }
.badge-wechsel  { background: #ede9fe; color: #7c3aed; margin-left: 0.3rem; padding: 0.1rem 0.35rem; }
.chart-hinweis  { font-size: 0.78rem; color: var(--text-muted); margin: 0 0 0.4rem 0; }
.modal-hinweis  { font-size: 0.8rem; color: var(--text-muted); margin: 0.3rem 0 0 0; }

/* Zählerwechsel-Button auf der Zählerkarte */
.btn-wechsel {
  margin-top: 0.6rem;
  align-self: flex-start;
  background: #ede9fe;
  color: #7c3aed;
  border: 1px solid #ddd6fe;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-wechsel:hover { background: #ddd6fe; }

/* Zählerwechsel-Checkbox im Formular */
.wechsel-check {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  cursor: pointer;
}
.wechsel-check input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: #7c3aed;
  cursor: pointer;
}

.leer-hinweis { color: var(--text-muted); }
.leer-hinweis a { color: #6366f1; }
.leer-text { color: var(--text-muted); font-style: italic; font-size: 0.9rem; }

/* AUSWERTUNG */
.auswertung-card { margin-bottom: 2rem; }
.auswertung-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.auswertung-header h2 { margin-bottom: 0; }
.auswertung-stats {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.stat-label { font-size: 0.75rem; color: var(--text-muted); }
.stat-wert { font-size: 1rem; font-weight: 700; }

.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
.chart-wrap { min-width: 0; }

@media (max-width: 700px) {
  .chart-row { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .auswertung-stats { gap: 1rem; }
}

/* VERLAUF LAYOUT */
.verlauf-layout {
  display: grid;
  grid-template-columns: 2fr 3fr;
  gap: 1.25rem;
  align-items: start;
}
.verlauf-col-rechts { display: flex; flex-direction: column; gap: 1.25rem; }

.verlauf-tabelle th { font-size: 0.75rem; padding: 0.5rem 0.5rem; }
.verlauf-tabelle td { padding: 0.55rem 0.5rem; font-size: 0.85rem; }
.stand-cell { font-size: 0.92rem !important; }
.notiz-cell { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stat-liste { display: flex; flex-direction: column; gap: 0; }
.stat-zeile {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  gap: 0.5rem;
}
.stat-zeile:last-child { border-bottom: none; }
.stat-zeile span { color: var(--text-muted); }
.stat-zeile strong { text-align: right; }

.jahres-schätzung {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 8px;
  text-align: center;
}
.js-label { font-size: 0.78rem; color: #15803d; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.25rem; }
.js-wert { font-size: 1.5rem; font-weight: 800; color: #15803d; }
.js-wert span { font-size: 0.9rem; font-weight: 400; }
.js-hinweis { font-size: 0.75rem; color: #4ade80; margin-top: 0.2rem; }

@media (max-width: 900px) {
  .verlauf-layout { grid-template-columns: 1fr; }
}

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  width: 100%; max-width: 420px;
  margin: 1rem;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem 0;
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-close {
  background: none; border: none; font-size: 1.2rem;
  cursor: pointer; color: var(--text-muted); padding: 0.25rem 0.5rem;
  border-radius: 5px;
}
.modal-close:hover { background: var(--border); }
.modal-body {
  padding: 1.25rem 1.5rem;
  display: flex; flex-direction: column; gap: 0.9rem;
}
.modal-footer {
  padding: 0 1.5rem 1.25rem;
  display: flex; justify-content: flex-end; gap: 0.75rem;
}

.aktionen-cell { white-space: nowrap; }
.btn-edit {
  background: none; border: none; cursor: pointer;
  font-size: 1rem; padding: 0.25rem 0.4rem;
  border-radius: 5px; transition: background 0.15s;
}
.btn-edit:hover { background: #ede9fe; }

/* SECTION TITLE */
.section-title {
  font-size: 1.3rem;
  margin: 2rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--border);
  color: var(--text);
}

/* FOOTER */
footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.watermark {
  font-weight: 600;
  color: #6366f1;
  letter-spacing: 0.5px;
}

/* ── Login / Setup ── */
.login-wrap {
  min-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 380px;
}
.login-card-wide {
  max-width: 460px;
}
.login-card h1 {
  margin-top: 0;
  text-align: center;
}
.login-fehler {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.qr-box {
  display: flex;
  justify-content: center;
  margin: 1rem 0;
}
.qr-box svg {
  width: 220px;
  height: 220px;
}
.qr-secret {
  text-align: center;
  font-size: 0.8rem;
  color: #64748b;
}
.qr-secret code {
  font-size: 0.95rem;
  color: #1e293b;
  word-break: break-all;
}
.nav-logout {
  margin-left: auto;
  color: #ef4444 !important;
}
