:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #6b7686;
  --line: #e3e6ea;
  --accent: #1f4e79;
  --accent-soft: #e8f0f8;
  --green: #1e7e46;
  --green-soft: #e2f3e9;
  --red: #b3261e;
  --red-soft: #fbe9e7;
  --orange: #b05a00;
  --orange-soft: #fdf0dd;
  --gray-soft: #eef0f3;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 45, .08);
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px;
}

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 24px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 0 20px; position: sticky; top: 0; z-index: 50;
}
.brand h1 { font-size: 17px; letter-spacing: .5px; color: var(--red); white-space: nowrap; }
.brand h1 span { font-weight: 400; color: var(--red); opacity: .75; }
nav { display: flex; gap: 2px; flex: 1; }
.tab {
  border: none; background: none; padding: 16px 14px; font-size: 14px;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.header-actions { display: flex; gap: 8px; }

button.ghost {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; color: var(--muted); cursor: pointer; font-size: 13px;
}
button.ghost:hover { border-color: var(--accent); color: var(--accent); }
button.primary {
  background: var(--accent); color: #fff; border: none; border-radius: 6px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
}
button.primary:hover { filter: brightness(1.15); }
button.danger-link { background: none; border: none; color: var(--red); cursor: pointer; font-size: 13px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }

/* ---------- dashboard ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px;
}
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.dash-col { display: flex; flex-direction: column; gap: 20px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h3 { font-size: 14px; margin-bottom: 12px; color: var(--ink); }
.loc-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.loc-row:last-child { border-bottom: none; }
.loc-row .name { flex: 0 0 150px; font-weight: 600; }
.loc-row .bar-wrap { flex: 1; background: var(--gray-soft); border-radius: 4px; height: 10px; overflow: hidden; }
.loc-row .bar { background: var(--accent); height: 100%; }
.loc-row .amt { flex: 0 0 100px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input[type="search"], .toolbar select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); font-size: 13px; color: var(--ink);
}
.toolbar input[type="search"] { min-width: 220px; }
.toolbar .spacer { flex: 1; }
.count-note { color: var(--muted); font-size: 13px; }

/* ---------- tables ---------- */
.table-wrap { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted);
  background: #fafbfc; cursor: pointer; user-select: none; white-space: nowrap;
  position: sticky; top: 0;
}
th .arrow { font-size: 10px; }
tbody tr:hover { background: #f7f9fb; }
tbody tr { cursor: pointer; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }
.small { color: var(--muted); font-size: 12px; display: block; margin-top: 2px; max-width: 340px; font-weight: 400; }
tfoot td { font-weight: 700; background: #fafbfc; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.gray { background: var(--gray-soft); color: var(--muted); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }

/* category palette — used for property-category badges and settings chips */
.cat-0 { background: #e3edf9; color: #1d5ba6; }   /* магацински — сино */
.cat-1 { background: #ddf2ee; color: #0d6e5f; }   /* деловен — тиркизно */
.cat-2 { background: #e6e6fa; color: #4a3fae; }   /* маг./деловен — индиго */
.cat-3 { background: #fdf3d7; color: #8a6400; }   /* станбен — жолто */
.cat-4 { background: #fbe4f0; color: #a52270; }   /* туристичко — розово */
.cat-5 { background: #e8f0dc; color: #4b6e14; }   /* земјиште — маслинесто */
.cat-6 { background: #dff2f9; color: #0b6784; }   /* канцеларија — светло сино */
.cat-7 { background: #f9e5dc; color: #a03d12; }   /* за рушење — теракота */
.cat-8 { background: #eceff3; color: #4e5d6e; }   /* гаража / помошна — сиво */
.cat-9 { background: #efe3f6; color: #6f2d9e; }   /* скривница — виолетово */

/* ---------- modal ---------- */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 22, 32, .45);
  display: flex; align-items: flex-start; justify-content: center; z-index: 100;
  padding: 40px 16px; overflow-y: auto;
}
#modal-backdrop.hidden { display: none; }
#modal { background: var(--panel); border-radius: var(--radius); width: 640px; max-width: 100%; }
#modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
#modal-head h2 { font-size: 16px; }
#modal-close { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); }
#modal-form { padding: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
#modal-form .full { grid-column: 1 / -1; }
#modal-form label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
#modal-form input, #modal-form select, #modal-form textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px;
  font-family: inherit; color: var(--ink); background: #fff;
}
#modal-form textarea { resize: vertical; min-height: 56px; }
.modal-actions { grid-column: 1 / -1; display: flex; justify-content: space-between; margin-top: 8px; }
.modal-actions .right { display: flex; gap: 10px; }

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

.unit-code { color: var(--accent); font-weight: 700; }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .settings-grid { grid-template-columns: 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--gray-soft); border-radius: 20px; padding: 4px 6px 4px 12px; font-size: 13px;
}
.chip button { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 12px; padding: 0 4px; }
.chip button:hover { color: var(--red); }
.chip-add { display: flex; gap: 8px; }
.chip-add input { flex: 1; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.settings-note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.danger-zone { border: 1px solid var(--red-soft); }
.danger-zone h3 { color: var(--red); }

/* ---------- auth ---------- */
#auth {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
#auth.hidden { display: none; }
.auth-card {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 36px 40px; width: 360px; max-width: calc(100% - 32px);
}
.auth-brand { color: var(--red); font-size: 26px; letter-spacing: .5px; text-align: center; }
.auth-sub { color: var(--muted); text-align: center; margin: 2px 0 24px; }
.auth-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.auth-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 14px; color: var(--ink);
}
.auth-card button.primary { width: 100%; margin-top: 18px; padding: 11px; font-size: 14px; }
#auth-error { color: var(--red); font-size: 13px; text-align: center; margin-top: 14px; min-height: 18px; }
#forgot { display: block; text-align: center; font-size: 13px; color: var(--muted); margin-top: 8px; }
#forgot:hover { color: var(--accent); }
#user-chip { align-self: center; margin-right: 4px; }
.hidden { display: none !important; }
