:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --water: #0ea5e9;
  --electricity: #f59e0b;
  --ok-bg: #dcfce7; --ok-tx: #166534;
  --err-bg: #fee2e2; --err-tx: #991b1b;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --card: #111a2e; --text: #e5edff; --muted: #94a3b8;
    --border: #22304d; --ok-bg:#0f3323; --ok-tx:#86efac; --err-bg:#3a1414; --err-tx:#fca5a5;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Ekrany logowania --- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card {
  background: var(--card); width: 100%; max-width: 400px; border-radius: 16px;
  padding: 32px; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; justify-content: center; }
.brand h1 { font-size: 1.35rem; margin: 0; }
.logo { font-size: 1.5rem; }
.subtitle { text-align: center; color: var(--muted); margin: 6px 0 20px; }
form label { display: block; font-size: .85rem; font-weight: 600; margin: 14px 0 6px; }
form input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg); color: var(--text); font-size: 1rem;
}
form input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.btn-primary {
  width: 100%; margin-top: 20px; padding: 12px; border: 0; border-radius: 9px;
  background: var(--primary); color: #fff; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: var(--primary-dark); }
.auth-links { text-align: center; margin-top: 16px; font-size: .9rem; }
.alert { padding: 11px 14px; border-radius: 9px; font-size: .9rem; margin-bottom: 8px; }
.alert-ok { background: var(--ok-bg); color: var(--ok-tx); }
.alert-err { background: var(--err-bg); color: var(--err-tx); }

/* --- Topbar --- */
.topbar { background: var(--card); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand-sm { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-email { color: var(--muted); font-size: .9rem; }
.btn-ghost {
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: .88rem;
}
.btn-ghost:hover { background: var(--bg); text-decoration: none; }

/* --- Zawartość --- */
.container { width: 100%; max-width: 1600px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 40px) 60px; }
.topbar-inner { max-width: 1600px; }
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-head h2 { margin: 0; }
.controls-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 18px;
  margin-top: 14px; padding: 14px 16px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
}
.control-group { display: flex; align-items: center; gap: 8px; }
.control-title { font-weight: 600; font-size: .9rem; margin-right: 2px; }
.control-group label { font-size: .85rem; color: var(--muted); }
.controls-bar input[type="date"], .controls-bar select {
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: .9rem;
}
.btn-small {
  padding: 7px 14px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--primary); color: #fff; font-weight: 600; font-size: .85rem;
}
.btn-small:hover { background: var(--primary-dark); }
.updated { color: var(--muted); font-size: .82rem; margin-left: auto; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; margin: 12px 2px 0; }
.stat-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-top: 6px; }
.stat-label.period { margin-top: 12px; }
.period-value { font-size: 1.25rem; font-weight: 700; color: var(--primary); }
.period-value .unit { font-size: .8rem; font-weight: 500; color: var(--muted); margin-left: 4px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; border-bottom: 2px solid var(--border); }
.tab {
  padding: 10px 20px; border: 0; background: transparent; color: var(--muted);
  font-size: .95rem; font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent;
  margin-bottom: -2px; border-radius: 8px 8px 0 0;
}
.tab:hover { color: var(--text); background: var(--card); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.btn-small.ghost { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn-small.ghost:hover { background: var(--bg); }

.apartments { display: grid; gap: 20px; margin-top: 20px; }
.apt-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; box-shadow: var(--shadow);
}
.apt-card h3 { margin: 0 0 14px; font-size: 1.15rem; }
.meters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
@media (max-width: 640px) { .meters-grid { grid-template-columns: 1fr; } }

.meter-block { border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.meter-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.meter-icon { font-size: 1.25rem; }
.meter-name { font-weight: 600; }
.meter-value { font-size: 1.7rem; font-weight: 700; }
.meter-value .unit { font-size: .95rem; font-weight: 500; color: var(--muted); margin-left: 4px; }
.meter-ts { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.chart-wrap { margin-top: 12px; height: 210px; }
.badge-water { color: var(--water); }
.badge-electricity { color: var(--electricity); }

/* --- Panel administratora --- */
.link-box { margin-top: 18px; padding: 16px; border: 1px solid var(--primary); border-radius: 12px; background: color-mix(in srgb, var(--primary) 8%, var(--card)); }
.link-box-title { font-weight: 600; margin-bottom: 10px; }
.link-row { display: flex; gap: 8px; }
.link-row input { flex: 1; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); font-family: monospace; font-size: .85rem; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; }
.inline-form .field { display: flex; flex-direction: column; gap: 4px; }
.inline-form label { font-size: .82rem; font-weight: 600; }
.inline-form input[type="email"], .inline-form input[type="text"] { padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); min-width: 220px; }
.inline-form .check { display: flex; align-items: center; gap: 6px; font-size: .88rem; font-weight: 500; }
.btn-inline { width: auto; margin-top: 0; }
.table-scroll { overflow-x: auto; }
.user-table { width: 100%; border-collapse: collapse; }
.user-table th, .user-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: .9rem; }
.user-table th { color: var(--muted); font-weight: 600; }
.user-table .ok { color: #16a34a; font-weight: 600; }
.user-table .tag { font-size: .7rem; background: var(--primary); color: #fff; padding: 1px 6px; border-radius: 6px; vertical-align: middle; }
.actions { display: flex; gap: 6px; }
.actions form { margin: 0; }
.btn-mini { padding: 5px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--card); color: var(--text); cursor: pointer; font-size: .8rem; }
.btn-mini:hover { background: var(--bg); }
.btn-mini.danger { border-color: #ef4444; color: #ef4444; }
