:root {
  --bg-primary: #0b0d10;
  --bg-secondary: #14171c;
  --bg-tertiary: #1b1f26;
  --bg-card: #181c22;
  --border: #252a33;
  --border-strong: #343b47;
  --text: #e8ebf0;
  --text-muted: #8b92a0;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #22c55e;
  --green-dark: #166534;
  --red: #ef4444;
  --yellow: #eab308;
  --schwarz: #78716c;
  --bnc: #a855f7;
  --battery: #f97316;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button { font-family: inherit; cursor: pointer; }

/* ---------- Layout ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 0 24px 20px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--green);
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar nav { flex: 1; padding: 0 12px; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 2px;
  transition: all 0.15s;
}
.sidebar nav a:hover { background: var(--bg-tertiary); color: var(--text); }
.sidebar nav a.active { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.sidebar-user {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.sidebar-user .logout {
  background: none;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
}
.sidebar-user .logout:hover { border-color: var(--red); color: var(--red); }

.main {
  margin-left: 240px;
  padding: 32px 40px;
  min-height: 100vh;
}
@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .sidebar-logo { font-size: 14px; padding: 0 12px 20px; letter-spacing: 0; }
  .sidebar nav a span.lbl { display: none; }
  .sidebar-user { display: none; }
  .main { margin-left: 64px; padding: 20px; }
}

/* ---------- Typo & utilities ---------- */
h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
h2 { font-size: 18px; font-weight: 600; margin-bottom: 14px; }
h3 { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 12px; }
.muted { color: var(--text-muted); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1024px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 640px)  { .grid-2, .grid-4 { grid-template-columns: 1fr; } }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.card h3 { margin-bottom: 10px; }
.stat-card .v { font-size: 24px; font-weight: 700; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  background: var(--bg-tertiary);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover { background: var(--border-strong); }
.btn-primary { background: var(--green); border-color: var(--green); color: #000; font-weight: 600; }
.btn-primary:hover { background: #16a34a; }
.btn-danger  { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost   { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
input, select, textarea {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); outline: none; }
textarea { min-height: 70px; resize: vertical; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.table th { font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }
.table tr:hover td { background: var(--bg-tertiary); }
.table .right { text-align: right; }
.table .num { font-variant-numeric: tabular-nums; font-weight: 500; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-tertiary);
  color: var(--text-muted);
}
.badge-green { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); }
.badge-red { background: color-mix(in srgb, var(--red) 20%, transparent); color: var(--red); }
.badge-yellow { background: color-mix(in srgb, var(--yellow) 20%, transparent); color: var(--yellow); }
.badge-schwarz { background: color-mix(in srgb, var(--schwarz) 40%, transparent); color: #d6d3d1; }
.badge-bnc { background: color-mix(in srgb, var(--bnc) 22%, transparent); color: #d8b4fe; }
.badge-bat { background: color-mix(in srgb, var(--battery) 22%, transparent); color: #fdba74; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h2 { margin-bottom: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---------- Login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg-primary);
  background-image: radial-gradient(circle at 30% 20%, rgba(34,197,94,0.12), transparent 60%),
                    radial-gradient(circle at 70% 80%, rgba(34,197,94,0.08), transparent 60%);
}
.login-card { background: var(--bg-card); border: 1px solid var(--border); padding: 48px; border-radius: 16px; max-width: 420px; width: 100%; text-align: center; }
.login-logo { font-size: 32px; font-weight: 800; letter-spacing: 6px; color: var(--green); margin-bottom: 8px; }
.login-card h1 { font-size: 18px; font-weight: 500; margin-bottom: 4px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast-item {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--green);
  padding: 12px 18px;
  border-radius: 8px;
  max-width: 360px;
  font-size: 13px;
  animation: toast 0.25s ease-out;
}
.toast-error { border-left-color: var(--red); }
@keyframes toast { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Progress ---------- */
.progress { width: 100%; height: 8px; background: var(--bg-tertiary); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--green); transition: width 0.3s; }

/* ---------- Resource dots ---------- */
.res-icons { display: inline-flex; gap: 10px; align-items: center; }
.res { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; }
.res-bat { color: var(--battery); }
.res-schwarz { color: #d6d3d1; }
.res-bnc { color: var(--bnc); }
.res-gruen { color: var(--green); }

.house-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  cursor: pointer;
  transition: all 0.15s;
}
.house-card:hover { border-color: var(--green); transform: translateY(-1px); }
.house-card h3 { font-size: 18px; color: var(--text); text-transform: none; letter-spacing: 0; margin-bottom: 4px; }
.house-card .besitzer { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }

.empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* Chart */
.chart { display: flex; flex-direction: column; gap: 6px; }
.chart-row { display: grid; grid-template-columns: 60px 1fr 100px; gap: 12px; align-items: center; font-size: 12px; }
.chart-label { font-variant-numeric: tabular-nums; }
.chart-bars { display: flex; flex-direction: column; gap: 2px; }
.chart-bar { height: 6px; border-radius: 3px; transition: width 0.3s; min-width: 2px; }
.chart-bar-gruen { background: var(--green); }
.chart-bar-schwarz { background: #78716c; }
.chart-bar.neg { background: var(--red); }
.chart-val { font-variant-numeric: tabular-nums; text-align: right; font-size: 12px; font-weight: 600; }

.res-red { color: var(--red); }

/* Scrollbar unsichtbar (scrollt weiterhin) */
.no-scrollbar { scrollbar-width: none; -ms-overflow-style: none; }
.no-scrollbar::-webkit-scrollbar { display: none; width: 0; height: 0; }
