:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --primary: #1f4e78;
  --primary-dark: #163a58;
  --primary-light: #e8f0f8;
  --border: #e2e5e9;
  --warn-bg: #fff7d6;
  --warn-border: #e8c95a;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --ok: #1e8449;
  --ok-bg: #e9f7ef;
  /* spojny jezyk kolorow dla mediow - uzywany wszedzie w aplikacji */
  --util-prad: #E67E22;
  --util-woda: #2E86C1;
  --util-gaz: #B7950B;
  --util-cieplo: #8E44AD;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  padding-bottom: 60px;
}
a { color: var(--primary); }

/* ---------------- nawigacja ---------------- */
.topnav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--primary);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topnav-scroll {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
.topnav-scroll::-webkit-scrollbar { display: none; }
.topnav a {
  color: white;
  text-decoration: none;
  padding: 14px 14px;
  font-weight: 600;
  white-space: nowrap;
  font-size: 0.95rem;
}
.topnav a.active { background: var(--primary-dark); }
.nav-sep { width: 1px; background: rgba(255,255,255,0.25); margin: 10px 4px; }
.topnav-account { display: flex; align-items: center; padding-right: 8px; flex-shrink: 0; }
.topnav-account a { padding: 14px 10px; font-size: 0.85rem; opacity: 0.9; }
.topnav a.logout { font-weight: 400; }

main { max-width: 980px; margin: 0 auto; padding: 16px; }
main.narrow { max-width: 720px; }

h1 { font-size: 1.4rem; margin: 8px 0 16px; color: var(--primary); }
h2 { font-size: 1.15rem; color: var(--primary); margin-top: 28px; margin-bottom: 10px; }
h3 { font-size: 1rem; color: var(--text); margin-top: 18px; margin-bottom: 8px; }

/* ---------------- pomoc kontekstowa (dymki) ---------------- */
.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  margin-left: 5px;
  position: relative;
  vertical-align: middle;
  user-select: none;
}
.help-tip:hover { background: var(--primary); color: white; }
.help-bubble {
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: white;
  font-weight: 400;
  font-size: 0.82rem;
  line-height: 1.4;
  padding: 10px 12px;
  border-radius: 8px;
  width: max-content;
  max-width: 260px;
  white-space: normal;
  z-index: 50;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.help-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1a1a1a;
}

/* ---------------- ogolne komponenty ---------------- */
.progress {
  background: var(--card);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  font-weight: 600;
}
.progress-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.progress-bar-fill { height: 100%; background: var(--ok); transition: width 0.3s; }

.filter-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 0.9rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.meter-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.meter-card.done { border-left: 4px solid var(--ok); }
.meter-card.pending { border-left: 4px solid #d0d5dc; }
.meter-title { font-weight: 700; font-size: 1.05rem; }
.meter-meta { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.meter-last { margin-top: 10px; background: #f0f3f7; border-radius: 8px; padding: 8px 12px; font-size: 0.95rem; }
.meter-last b { color: var(--primary); }
.meter-audit { color: var(--muted); font-size: 0.78rem; margin-top: 4px; }

.entry-row { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.entry-row input[type=number] {
  flex: 1; font-size: 1.3rem; padding: 10px 12px; border: 2px solid var(--border); border-radius: 8px; min-width: 0;
}
.entry-row input[type=number]:focus { border-color: var(--primary); outline: none; }
.unit-tag { color: var(--muted); font-weight: 600; }

.btn {
  background: var(--primary); color: white; border: none; border-radius: 8px;
  padding: 11px 18px; font-size: 1rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  display: inline-block; text-decoration: none;
}
.btn:active { background: var(--primary-dark); }
.btn.secondary { background: #6b7280; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; }

.delta-hint { font-size: 0.85rem; color: var(--muted); margin-top: 6px; min-height: 1.1em; }
.delta-hint .pct-up { color: var(--danger); font-weight: 600; }
.delta-hint .pct-down { color: var(--primary); font-weight: 600; }
.delta-hint .pct-normal { color: var(--ok); font-weight: 600; }

.msg-box { margin-top: 10px; padding: 10px 12px; border-radius: 8px; font-size: 0.9rem; display: none; }
.msg-box.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); display: block; }
.msg-box.error { background: var(--danger-bg); border: 1px solid #f5b7ae; color: var(--danger); display: block; }
.msg-box.ok { background: var(--ok-bg); border: 1px solid #a6dfb9; color: var(--ok); display: block; }

.checkbox-row { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; margin-top: 8px; color: var(--muted); }

label.section-label {
  display: block; font-weight: 700; color: var(--primary); margin: 20px 0 8px;
  font-size: 1rem; text-transform: uppercase; letter-spacing: 0.03em;
}

/* ---------------- logowanie / formularze konta ---------------- */
.login-box, .form-box {
  max-width: 400px; margin: 40px auto; background: var(--card); border-radius: 12px;
  padding: 28px; border: 1px solid var(--border);
}
.login-box input, .form-box input, .form-box select, .form-box textarea {
  width: 100%; padding: 10px 12px; margin: 6px 0 14px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 1rem; font-family: inherit;
}
.form-box label { font-weight: 600; font-size: 0.9rem; }
.error-box { background: var(--danger-bg); color: var(--danger); padding: 10px; border-radius: 8px; margin-bottom: 12px; }
.ok-box { background: var(--ok-bg); color: var(--ok); padding: 10px; border-radius: 8px; margin-bottom: 12px; }

/* ---------------- tabele (rozliczenie, admin) ---------------- */
table.data-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; font-size: 0.9rem; }
table.data-table th, table.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: right; }
table.data-table th:first-child, table.data-table td:first-child { text-align: left; }
table.data-table thead { background: var(--primary); color: white; }
table.data-table tr.total-row { font-weight: 700; background: #f0f3f7; }
table.data-table tr.excluded { color: var(--muted); font-style: italic; }
table.data-table tr:hover td { background: #fafbfc; }
table.data-table a.row-link { color: var(--text); text-decoration: none; font-weight: 600; }
table.data-table a.row-link:hover { color: var(--primary); text-decoration: underline; }
.table-scroll { overflow-x: auto; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; padding: 3px 8px;
  font-size: 0.72rem; font-weight: 600; margin: 1px 2px 1px 0; cursor: default; position: relative;
}
.badge.badge-warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: #7a5c00; }
.badge.badge-info { background: var(--primary-light); border: 1px solid #c7dcef; color: var(--primary-dark); }
.badge.badge-error { background: var(--danger-bg); border: 1px solid #f5b7ae; color: var(--danger); }
.badge.badge-ok { background: var(--ok-bg); border: 1px solid #a6dfb9; color: var(--ok); }
.badge-bubble {
  position: absolute; top: 130%; left: 0; background: #1a1a1a; color: white; font-weight: 400;
  font-size: 0.8rem; line-height: 1.4; padding: 8px 10px; border-radius: 8px; width: max-content;
  max-width: 260px; white-space: normal; z-index: 50; box-shadow: 0 4px 14px rgba(0,0,0,0.25); display: none;
}
.badge:hover .badge-bubble { display: block; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.pill.active { background: var(--ok-bg); color: var(--ok); }
.pill.inactive { background: #eee; color: var(--muted); }

.period-select { padding: 8px; font-size: 1rem; margin-bottom: 16px; border-radius: 8px; border: 1px solid var(--border); }

/* ---------------- pulpit / alarmy ---------------- */
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li {
  background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--warn-border);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; font-size: 0.92rem;
}
.alert-list.danger li { border-left-color: var(--danger); }
.alert-list a { font-weight: 600; }
.empty-state { color: var(--muted); font-style: italic; padding: 8px 0; }
.primary-action { text-align: center; margin: 20px 0; }
.primary-action .btn { font-size: 1.1rem; padding: 14px 28px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-tile { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; text-align: center; }
.stat-tile .num { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-tile .lbl { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }

/* ---------------- admin: karty najemcy, formularze ---------------- */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 10px 0; }
.info-grid .box { background: #f0f3f7; border-radius: 8px; padding: 10px 12px; }
.info-grid .box .lbl { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; }
.info-grid .box .val { font-size: 1.1rem; font-weight: 700; color: var(--primary); }

.participation-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.participation-row:last-child { border-bottom: none; }
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0; background: #ccc; border-radius: 24px; transition: 0.2s;
}
.toggle-slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--ok); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

.lease-timeline { list-style: none; padding: 0; margin: 0; }
.lease-timeline li {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; font-size: 0.9rem;
}
.lease-timeline li.current { border-color: var(--ok); background: var(--ok-bg); }

/* ---------------- kolory mediow (spojne wszedzie) ---------------- */
.util-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; flex-shrink: 0;
}
.util-prad, .util-prad .util-dot { color: var(--util-prad); }
.util-woda, .util-woda .util-dot { color: var(--util-woda); }
.util-gaz, .util-gaz .util-dot { color: var(--util-gaz); }
.util-cieplo, .util-cieplo .util-dot { color: var(--util-cieplo); }
.util-prad .util-dot { background: var(--util-prad); }
.util-woda .util-dot { background: var(--util-woda); }
.util-gaz .util-dot { background: var(--util-gaz); }
.util-cieplo .util-dot { background: var(--util-cieplo); }
.util-label { font-weight: 700; }

/* ---------------- pasek filtrowania (odczyty, listy licznikow) ---------------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search], .toolbar select {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; font-family: inherit;
}
.toolbar input[type=search] { flex: 1; min-width: 160px; }
.date-nav { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.date-nav input[type=date] { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; }
.date-nav .btn.small { padding: 8px 12px; }

/* ---------------- wykres statystyk ---------------- */
.chart-box { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 16px; }

/* ---------------- druk / raporty ---------------- */
.report-page { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; margin-bottom: 24px; }
.report-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; border-bottom: 2px solid var(--primary); padding-bottom: 10px; }
.report-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.report-line.total { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--text); border-bottom: none; margin-top: 6px; padding-top: 10px; }
.no-print { }
@media print {
  .topnav, .no-print { display: none !important; }
  body { background: white; padding: 0; }
  main { max-width: 100%; padding: 0; }
  .report-page { border: none; box-shadow: none; page-break-after: always; }
  .report-page:last-child { page-break-after: auto; }
}
