:root {
  --ink: #1b2430;
  --muted: #5c6a7a;
  --paper: #f5f7fa;
  --card: #ffffff;
  --line: #d8dee8;
  --accent: #1d3557;
  --accent-2: #4a6fa5;
  --warn: #9a4a1f;
  --ok: #1d3557;
  --sidebar: #1d3557;
  --sidebar-text: #f4f7fb;
  --wash: #eef2f7;
  --ok-bg: #e4ebf4;
  --shadow: 0 10px 30px rgba(27, 36, 48, 0.08);
  --radius: 3px;
  --heading: Corbel, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Calibri", sans-serif;
  background:
    radial-gradient(circle at top right, #dce6f0 0, transparent 32%),
    linear-gradient(180deg, #eef2f7 0%, var(--paper) 100%);
  color: var(--ink);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 28px 18px;
}
.brand {
  font-family: var(--heading);
  font-size: 22px;
  line-height: 1.25;
  margin: 0 0 8px;
}
.brand small {
  display: block;
  font-family: "Segoe UI", sans-serif;
  font-size: 12px;
  opacity: 0.7;
  margin-top: 6px;
  font-weight: 400;
}
nav { margin-top: 28px; display: flex; flex-direction: column; gap: 4px; }
nav a {
  color: var(--sidebar-text);
  padding: 9px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  opacity: 0.86;
}
nav a:hover, nav a.active {
  background: rgba(255,255,255,0.1);
  opacity: 1;
  text-decoration: none;
}
.sidebar-user {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 13px;
  opacity: 0.86;
}
.sidebar-user form { margin-top: 8px; }
.sidebar-logout {
  background: transparent;
  color: var(--sidebar-text);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 6px 10px;
  font-size: 13px;
}
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
}
.login-card h1 { margin-bottom: 4px; }

.main { padding: 28px 32px 48px; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
}
h1, h2, h3 { font-family: var(--heading); margin: 0 0 8px; }
.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  width: 100%;
  margin: 0 0 8px;
}
.page-head h1 { margin: 0; }
.page-head-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.page-head > .card-help-toggle { margin-left: auto; }
.card-help-panel {
  background: var(--wash);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}
.card-help-panel ul {
  margin: 0;
  padding-left: 1.2em;
}
.card-help-panel li { margin: 0 0 6px; }
.card-help-panel li:last-child { margin: 0; }
.muted { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.stat { font-size: 28px; font-weight: 700; }
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--ok-bg);
  color: var(--accent);
}
.badge.warn { background: #f6e4d6; color: var(--warn); }
.badge.expired { background: #f4d4ce; color: #8b2e24; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.owner { background: #eee8dc; color: #6a5430; }

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th.num, td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
input.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
th { font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.lease-predpis-history-wrap { overflow-x: auto; }
.lease-predpis-history { width: auto; min-width: 100%; }
.lease-predpis-history th, .lease-predpis-history td { white-space: nowrap; }
tfoot td { border-bottom: none; border-top: 2px solid var(--line); }

.meter-table { table-layout: fixed; }
.meter-table .col-unit { width: 13%; }
.meter-table .col-place { width: 14%; }
.meter-table .col-meter { width: 18%; }
.meter-table .col-ean { width: 16%; }
.meter-table .col-breaker { width: 10%; }
.meter-table .col-rate { width: 12%; }
.meter-table .col-eic { width: 16%; }
.meter-table .col-reading { width: 22%; }
.meter-table .col-actions { width: 210px; }
.meter-table td:last-child { white-space: nowrap; }
.meter-table tr.main-meter td { background: var(--wash); }
.meter-table tr.after-main td { border-top: 3px solid var(--line); }
.meter-table tr.same-unit td { border-top-style: dotted; border-top-color: var(--line); }
.meter-table tr.same-unit td:first-child {
  border-top-color: transparent;
  border-top-style: solid;
}
.meter-table tr:has(+ tr.same-unit) td:first-child,
.meter-table tr:has(+ tr.reading-form-row + tr.same-unit) td:first-child {
  border-bottom-color: transparent;
}
.meter-table .reading-form-row td { background: var(--wash); }
.inspection-edit-row td { background: var(--wash); }
.inspection-table { table-layout: fixed; width: 100%; }
.inspection-table .col-unit { width: 14%; }
.inspection-table .col-date { width: 11%; }
.inspection-table .col-who { width: 16%; }
.inspection-table .col-result { width: 16%; }
.inspection-table .col-notes { width: 16%; }
.inspection-table .col-status { width: 10%; }
.inspection-table .col-actions { width: 6%; }
.inspection-table td:last-child { white-space: nowrap; }
tr.vendor-row:target { background: var(--ok-bg); }
.vendor-edit-row td { background: var(--wash); }
.add-meter-form, .add-inline-form {
  margin-top: 16px;
  padding: 14px;
  background: var(--wash);
  border-radius: var(--radius);
}
.add-meter-form h3, .add-inline-form h3 { margin-top: 0; }
.place-link {
  font-weight: 700;
  color: var(--accent);
  text-decoration: underline;
}
.place-link:hover { text-decoration: none; }
.history-block { margin-top: 0; }
.history-block h2 { margin-top: 0; margin-bottom: 10px; }
.history-block td.num { text-align: right; font-variant-numeric: tabular-nums; }
.history-latest td { font-weight: 600; }
.history-reading-form {
  display: none;
  margin-top: 12px;
  padding: 12px;
  background: var(--wash);
  border-radius: var(--radius);
}
.history-reading-form.is-open {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn, button, input[type="submit"] {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: var(--radius);
  padding: 9px 14px;
  cursor: pointer;
  font: inherit;
}
a.btn {
  display: inline-block;
  text-decoration: none;
}
a.btn:not(.secondary) { color: white; }
a.btn:not(.secondary):hover { color: white; text-decoration: none; }
.btn.secondary, .secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn.danger, button.danger { background: var(--accent-2); }
.btn.secondary { font-size: 13px; padding: 6px 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.acc-rules-table td form { margin: 0; }
.acc-rules-table input,
.acc-rules-table select { width: 100%; min-width: 8rem; }
.dep-table-wrap { overflow-x: auto; }
.dep-table {
  width: max-content;
  min-width: 100%;
}
.dep-col-name { width: 28rem; min-width: 28rem; }
.dep-col-cost { width: 10rem; min-width: 10rem; }
.dep-col-reduce { width: 11rem; min-width: 11rem; }
.dep-card-name {
  display: block;
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  line-height: 1.35;
}
.dep-table td.dep-card { white-space: normal; }
.dep-table th:nth-child(2),
.dep-table td:nth-child(2),
.dep-table th:nth-child(3),
.dep-table td:nth-child(3) {
  white-space: nowrap;
}
.dep-year { min-width: 7.5rem; white-space: nowrap; }
.dep-owner-card h2 { margin-bottom: 4px; }
.dap-card h2 { margin-bottom: 4px; }
.dap-table { width: 100%; }
.dap-table td:first-child { width: 4rem; white-space: nowrap; }
.dap-table input { width: 8rem; text-align: right; }
.dap-banner {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #fff4d6;
  border: 1px solid #e6d18a;
}
.dap-model {
  display: grid;
  gap: 10px 24px;
  margin: 12px 0 4px;
}
.dap-model-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}
.dap-model-row label { margin: 0; }
.dap-model-row .num, .dap-model-row input[type="text"], .dap-model-row input[inputmode="decimal"] {
  width: 9rem;
  text-align: right;
  justify-self: end;
}
.dap-model-row input[type="number"] {
  width: 4.5rem;
  text-align: right;
}
.dap-model-check {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-self: end;
}
.dap-model-check input[name="transport_month_kc"] {
  width: 6rem;
  text-align: right;
}
.dap-model-check input[readonly] {
  background: #f4f4f4;
}
.dap-choice {
  display: flex;
  gap: 16px;
  justify-self: end;
  align-items: center;
}
.dap-dep-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}
.dap-dep-list li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.dap-total { font-weight: 700; }
.dap-block {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.dap-card > .dap-block:first-of-type {
  margin-top: 12px;
  padding-top: 0;
  border-top: none;
}
.dap-block h3 { margin-bottom: 4px; }
.dap-block.dap-inset {
  margin-left: 2.5rem;
}
.dap-block.dap-inset-end {
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 4px;
}
.dap-block.dap-after-inset {
  border-top: none;
  padding-top: 12px;
}
.acc-dep { margin-top: 12px; }
.acc-dep .muted { margin-top: 8px; }

.acc-rules-table .actions .btn,
.acc-rules-table .actions button {
  font-size: 13px;
  line-height: 1.2;
  padding: 6px 10px;
  min-height: 32px;
  min-width: 64px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
.actions.right { justify-content: flex-end; }
.share-input {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 280px;
}
.share-input input { width: 100%; }
.share-slash { font-size: 22px; color: var(--muted); }
.readonly-value { margin: 8px 0 0; font-weight: 600; }
.checks { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 8px; width: max-content; color: var(--ink); font-size: 15px; }
.check input { width: auto; margin: 0; }
.person-checks {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-top: 8px;
  max-height: 240px;
  overflow: auto;
  padding: 10px 12px;
  background: var(--wash);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.lease-flags {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  margin-top: 4px;
  padding: 12px 14px;
  background: var(--wash);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.lease-flags .check { font-size: 16px; }
.lease-flags .check input { width: 18px; height: 18px; }
.unit-pick {
  margin-top: 4px;
  padding: 12px;
  background: var(--wash);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.unit-pick-all {
  font-weight: 600;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.unit-pick-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px 14px;
}

form.stack, .stack { display: flex; flex-direction: column; gap: 10px; }
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  background: white;
}
textarea { min-height: 90px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.flash {
  background: var(--ok-bg);
  border: 1px solid #c7d8cc;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.alert {
  background: #f6e4d6;
  border: 1px solid #e8c8ae;
  padding: 12px 14px;
  border-radius: var(--radius);
}
.hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}
.year-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.year-tabs a {
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}
.year-tabs a.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.year-tabs a:hover { text-decoration: none; }
.owner-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -6px 0 18px;
}
.owner-tab {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 12rem;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}
.owner-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.owner-tab.active .muted { color: rgba(255, 255, 255, 0.85); }
.owner-tab:hover { text-decoration: none; }
.lock-year {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.lock-year .check { flex: 0 0 auto; }
.acc-year-sums {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px 24px;
  margin: 0 0 16px;
  max-width: 1280px;
}
.acc-year-sums .stat {
  font-size: 22px;
  margin-top: 2px;
}
.acc-year-sums-label {
  font-weight: 700;
}

.drop-csv {
  display: block;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  background: var(--wash);
  cursor: pointer;
}
.drop-csv input { display: block; margin: 12px auto 0; }
.acc-wrap { overflow-x: auto; }
.acc-journal-card {
  padding: 0;
  overflow: hidden;
  max-width: 100%;
}
.acc-journal-wrap {
  overflow: auto;
  max-height: calc(100vh - 280px);
  max-width: 100%;
}
.acc-import-card {
  padding: 0;
  overflow: hidden;
  max-width: 100%;
}
.acc-import-wrap {
  overflow: auto;
  max-height: calc(100vh - 220px);
  max-width: 100%;
}
.acc-table {
  min-width: 1480px;
  font-size: 13px;
  border: 1px solid var(--line);
}
.acc-table th, .acc-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  vertical-align: top;
}
.acc-table thead th {
  background: var(--accent);
  color: var(--sidebar-text);
  font-weight: 600;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 5;
}
.acc-table thead tr:first-child th {
  background: var(--sidebar);
  top: 0;
  z-index: 6;
}
.acc-table thead tr:nth-child(2) th {
  top: var(--acc-head1, 2.15em);
  z-index: 5;
  box-shadow: 0 1px 0 var(--accent);
}
.acc-table tbody td {
  position: relative;
  z-index: 0;
}
.acc-table tfoot td {
  font-weight: 700;
  background: var(--wash);
}
.acc-table td.num, .acc-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.acc-table td.acc-cash, .acc-table tfoot td.acc-cash { background: #fff6d8; }
.acc-table td.acc-bank, .acc-table tfoot td.acc-bank { background: #dcebff; }
.acc-table td.acc-bal, .acc-table tfoot td.acc-bal { font-weight: 700; }
.acc-table td.acc-rent, .acc-table tfoot td.acc-rent { background: #d8f0e4; }
.acc-table td.acc-tax, .acc-table tfoot td.acc-tax { background: #fde4d8; }
.acc-table td.acc-nontax, .acc-table tfoot td.acc-nontax { background: #eee4f5; }
.acc-table td.acc-svc, .acc-table tfoot td.acc-svc { background: #fdebd0; }
.acc-table tr.acc-xfer td { font-style: italic; background: var(--wash); }
.acc-table tr.acc-row-focus td { outline: 2px solid var(--accent); outline-offset: -2px; }
.acc-ratio { display: flex; flex-direction: column; gap: 6px; }
.acc-ratio-custom { max-width: 90px; }
.acc-table .acc-ratio label { display: none; }
.acc-reduce { display: flex; flex-direction: column; gap: 8px; justify-content: flex-end; }
.acc-reduce-opts { display: flex; flex-direction: column; gap: 8px; }
.acc-table .acc-reduce { min-width: 220px; }
.acc-import-table {
  width: max-content;
  min-width: 2600px;
  table-layout: auto;
}
.acc-import-table th,
.acc-import-table td {
  white-space: nowrap;
}
.acc-import-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 1px 0 var(--sidebar);
}
.acc-import-table tbody td {
  position: relative;
  z-index: 0;
}
.acc-import-table th.acc-split-col {
  white-space: normal;
  min-width: 4.5em;
  max-width: 5.5em;
  line-height: 1.2;
  padding-left: 6px;
  padding-right: 6px;
}
.acc-import-table td.acc-split-cell {
  text-align: center;
  padding-left: 4px;
  padding-right: 4px;
}
.acc-import-table td.acc-import-text {
  min-width: 240px;
}
.acc-import-table input:not([type="checkbox"]),
.acc-import-table select.acc-import-kind,
.acc-import-table select.acc-import-kind2 {
  min-width: 200px;
  width: 100%;
}
.acc-import-table .acc-split-toggle {
  min-width: 0;
  width: auto;
  margin: 0;
}
.acc-import-table .acc-split-amount {
  min-width: 120px;
}
.th-sort {
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.service-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.service-row {
  display: grid;
  grid-template-columns: minmax(140px, 200px) minmax(160px, 1fr);
  gap: 12px;
  align-items: end;
}
.totals-box {
  margin: 10px 0 0;
  padding: 10px 12px;
  background: var(--wash);
  border-radius: var(--radius);
  font-size: 14px;
}
.lease-block {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.lease-block h3 { margin: 0 0 6px; font-size: 16px; }
details { margin-top: 10px; }
details summary { cursor: pointer; font-weight: 600; }
.print-only { display: none; }
.protocol-kind { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.protocol-kind legend { font-weight: 600; }
.protocol-person { margin-bottom: 8px; }
.protocol-meters {
  width: max-content;
  max-width: 100%;
  table-layout: auto;
}
.protocol-meters th, .protocol-meters td {
  width: auto;
  white-space: nowrap;
  padding: 6px 12px 6px 0;
}
.protocol-meters .protocol-meter-value { white-space: nowrap; width: 1%; }
.protocol-meters .protocol-meter-value input {
  width: 6.5rem;
  min-width: 0;
  max-width: 7rem;
  display: inline-block;
  margin-right: 6px;
}
.protocol-keys { display: flex; flex-direction: column; gap: 8px; }
.protocol-key-row {
  display: grid;
  grid-template-columns: minmax(16rem, 22rem) 6.2rem 1fr;
  align-items: center;
  column-gap: 12px;
  row-gap: 6px;
}
.protocol-key-qty { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.protocol-chip-serials { grid-column: 1 / -1; padding-left: 1.6rem; }
.protocol-key-qty input {
  width: 3.4rem;
  min-width: 0;
  display: inline-block;
  padding: 6px 8px;
}
.protocol-form textarea[name="keys_extra"] { min-height: 52px; }
.protocol-form textarea[name="notes"] { min-height: 70px; }
.protocol-form textarea[name="warning_text"] { min-height: 70px; }
.protocol-form textarea[name="unit_description"] { min-height: 64px; }
.protocol-form h2 { margin: 16px 0 6px; font-size: 18px; }
.lease-doc-types { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 8px; }
.lease-doc-types .btn { text-align: left; }
@media print {
  .sidebar, .no-print { display: none !important; }
  .app { display: block; }
  .print-only { display: block; }
  body { background: white; }
  .card { box-shadow: none; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { padding: 16px; }
  nav { flex-direction: row; flex-wrap: wrap; }
}
