:root {
    --green: #1f7a5a;
    --green-dark: #155c43;
    --red: #d23b3b;
    --red-bg: #fdecec;
    --amber: #c77700;
    --amber-bg: #fff4e0;
    --green-bg: #e7f5ef;
    --ink: #1c2127;
    --muted: #6b7280;
    --line: #e6e8eb;
    --bg: #f4f6f8;
    --card: #ffffff;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--green); text-decoration: none; }

/* ---------- Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--green);
    color: #fff;
    padding-top: env(safe-area-inset-top);
    box-shadow: var(--shadow);
}
.topbar-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 54px;
    padding: 0 8px;
    max-width: 720px;
    margin: 0 auto;
}
.brand { font-weight: 700; font-size: 18px; padding-left: 6px; }
.topbar-title {
    flex: 1;
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.iconbtn {
    color: #fff;
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 26px;
    border-radius: 10px;
    background: rgba(255,255,255,.12);
}
.iconbtn:active { background: rgba(255,255,255,.25); }

/* ---------- Layout ---------- */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 14px 14px 90px;
}

/* ---------- Flash ---------- */
.flash {
    padding: 11px 14px;
    border-radius: 10px;
    margin-bottom: 12px;
    font-weight: 500;
}
.flash-success { background: var(--green-bg); color: var(--green-dark); }
.flash-error   { background: var(--red-bg); color: var(--red); }

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    margin-bottom: 12px;
}
.card-link { display: block; color: inherit; }
.card-link:active { transform: scale(.997); }

.section-title {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin: 18px 4px 8px;
    font-weight: 700;
}

/* ---------- Dashboard summary ---------- */
.summary {
    background: linear-gradient(135deg, var(--green), var(--green-dark));
    color: #fff;
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.summary .big { font-size: 30px; font-weight: 800; }
.summary .sub { opacity: .9; font-size: 14px; margin-top: 2px; }
.summary .pills { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.pill {
    background: rgba(255,255,255,.16);
    padding: 6px 11px; border-radius: 999px; font-size: 13px; font-weight: 600;
}

/* ---------- Unit card ---------- */
.unit-card { display: flex; align-items: center; gap: 12px; }
.unit-avatar {
    width: 46px; height: 46px; flex: 0 0 auto;
    border-radius: 12px;
    background: var(--green-bg); color: var(--green-dark);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 18px;
}
.unit-main { flex: 1; min-width: 0; }
.unit-name { font-weight: 700; font-size: 17px; }
.unit-addr { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit-debt { text-align: right; font-weight: 800; white-space: nowrap; }
.unit-debt.owed { color: var(--red); }
.unit-debt.clear { color: var(--green); }

/* ---------- Bill card ---------- */
.bill {
    border-left: 5px solid var(--muted);
}
.bill.paid    { border-left-color: var(--green); }
.bill.unpaid  { border-left-color: var(--red); }
.bill.overdue { border-left-color: var(--amber); background: var(--amber-bg); }

.bill-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.bill-period { font-weight: 700; font-size: 16px; }
.bill-cat {
    display: inline-block; font-size: 12px; font-weight: 700;
    padding: 2px 8px; border-radius: 999px;
    background: var(--green-bg); color: var(--green-dark); margin-top: 3px;
}
.bill-amount { font-weight: 800; font-size: 18px; white-space: nowrap; }
.bill-meta { color: var(--muted); font-size: 13px; margin-top: 6px; }
.bill-desc { margin-top: 6px; font-size: 14px; }

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
}
.badge.paid    { background: var(--green-bg); color: var(--green-dark); }
.badge.unpaid  { background: var(--red-bg); color: var(--red); }
.badge.overdue { background: var(--amber-bg); color: var(--amber); }

.thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.thumb {
    position: relative;
    width: 74px; height: 74px; border-radius: 10px; overflow: hidden;
    border: 1px solid var(--line); background: #fafafa;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.thumb .tlabel {
    position: absolute; left: 0; right: 0; bottom: 0;
    font-size: 10px; font-weight: 700; text-align: center;
    background: rgba(0,0,0,.55); color: #fff; padding: 1px 0;
}

.bill-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
    -webkit-appearance: none; appearance: none;
    border: 0; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font-size: 15px; font-weight: 600;
    padding: 11px 16px; border-radius: 11px;
    background: var(--green); color: #fff;
    text-decoration: none;
}
.btn:active { background: var(--green-dark); }
.btn.block { width: 100%; }
.btn.secondary { background: #eef1f4; color: var(--ink); }
.btn.danger { background: var(--red-bg); color: var(--red); }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.success { background: var(--green); }

.fabrow { display: flex; gap: 10px; margin: 14px 0; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
label.lbl { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=month], input[type=search], textarea, select {
    width: 100%;
    font-size: 16px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fff;
    color: var(--ink);
    font-family: inherit;
}
textarea { min-height: 70px; resize: vertical; }
.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; }

.check {
    display: flex; align-items: center; gap: 10px;
    padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: #fff;
}
.check input { width: 22px; height: 22px; }

/* filpor per chips */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
    font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 999px;
    background: #fff; border: 1px solid var(--line); color: var(--ink);
}
.chip.is-active { background: var(--green); color: #fff; border-color: var(--green); }

.searchbar { margin-bottom: 12px; }

/* upload preview */
.upload-box {
    border: 1px dashed var(--line); border-radius: 11px; padding: 12px; background: #fff;
}
.upload-preview { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.upload-preview img { width: 90px; height: 90px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

/* empty state */
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 40px; }

/* ---------- Bottom nav ---------- */
.bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex; justify-content: space-around;
    background: #fff; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
    max-width: 720px; margin: 0 auto;
}
.bottomnav a {
    flex: 1; text-align: center; padding: 8px 0 7px;
    color: var(--muted); font-size: 11px; font-weight: 600;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.bottomnav a.is-active { color: var(--green); }
.bn-ico { font-size: 20px; line-height: 1; }

/* ---------- Lightbox ---------- */
.lightbox {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(0,0,0,.92);
    display: flex; align-items: center; justify-content: center;
    padding: 12px;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-close {
    position: absolute; top: calc(env(safe-area-inset-top) + 8px); right: 14px;
    background: rgba(255,255,255,.18); color: #fff; border: 0;
    width: 44px; height: 44px; border-radius: 50%; font-size: 28px; cursor: pointer;
}

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
    background: linear-gradient(135deg, var(--green), var(--green-dark));
}
.login-card {
    background: #fff; border-radius: 18px; padding: 26px 22px;
    width: 100%; max-width: 360px; box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; text-align: center; }
.login-card p { margin: 0 0 18px; text-align: center; color: var(--muted); }

.group-head {
    display: flex; justify-content: space-between; align-items: center;
    margin: 18px 4px 8px;
}
.group-head .y { font-size: 18px; font-weight: 800; }
.group-head .t { font-size: 13px; color: var(--muted); font-weight: 600; }

/* ---------- Prikaz mjeseca u formi ---------- */
.month-preview {
    margin-top: 8px;
    font-weight: 800;
    font-size: 16px;
    color: var(--green-dark);
    background: var(--green-bg);
    border-radius: 9px;
    padding: 8px 12px;
    display: inline-block;
    min-height: 1px;
}
.month-preview:empty { display: none; }

/* ---------- Kalendar ---------- */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin: 6px 2px 12px; }
.cal-nav .ttl { font-weight: 800; font-size: 18px; }
.cal-nav a.navbtn {
    width: 40px; height: 40px; border-radius: 10px; background: #fff; border: 1px solid var(--line);
    display: inline-flex; align-items: center; justify-content: center; font-size: 22px; color: var(--ink);
}

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 4px 2px 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }
.sw-paid    { background: var(--green); }
.sw-unpaid  { background: var(--red); }
.sw-overdue { background: var(--amber); }
.sw-none    { background: #e9edf0; border: 1px solid var(--line); }

/* Godišnji pregled (12 mjeseci) */
.year-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.year-cell {
    border-radius: 10px; padding: 10px 6px; text-align: center; text-decoration: none;
    background: #fff; border: 1px solid var(--line); color: var(--ink);
}
.year-cell .mn { font-weight: 700; font-size: 14px; }
.year-cell .dot { display: block; width: 100%; height: 6px; border-radius: 4px; margin-top: 7px; background: #e9edf0; }
.year-cell.paid    .dot { background: var(--green); }
.year-cell.unpaid  .dot { background: var(--red); }
.year-cell.overdue .dot { background: var(--amber); }
.year-cell.is-active { outline: 2px solid var(--green); }

/* Mjesečni kalendar */
.cal-weekhead, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-weekhead { margin-bottom: 5px; }
.cal-weekhead div { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); }
.cal-cell {
    aspect-ratio: 1 / 1; border-radius: 9px; background: #fff; border: 1px solid var(--line);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    font-size: 14px; color: var(--ink); position: relative; padding: 0;
}
.cal-cell.empty { background: transparent; border: 0; }
.cal-cell.today { box-shadow: 0 0 0 2px var(--green) inset; }
.cal-cell.paid    { background: var(--green-bg);  border-color: #bfe3d3; }
.cal-cell.unpaid  { background: var(--red-bg);    border-color: #f5c9c9; }
.cal-cell.overdue { background: var(--amber-bg);  border-color: #f3d9a8; }
.cal-cell.has { cursor: pointer; font-weight: 700; }
.cal-cell .cnt {
    position: absolute; top: 3px; right: 4px; font-size: 9px; font-weight: 800;
    background: rgba(0,0,0,.12); border-radius: 8px; padding: 0 4px; line-height: 14px;
}
.cal-cell.unpaid .day-n, .cal-cell.overdue .day-n { color: var(--red); }
.cal-cell.paid .day-n { color: var(--green-dark); }

/* Panel za dan */
.day-panel { margin-top: 16px; }
.day-panel h3 { margin: 0 0 10px; font-size: 16px; }
.day-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #fff;
    border: 1px solid var(--line); border-left: 5px solid var(--muted); border-radius: 10px; margin-bottom: 8px;
    color: inherit;
}
.day-item.paid    { border-left-color: var(--green); }
.day-item.unpaid  { border-left-color: var(--red); }
.day-item.overdue { border-left-color: var(--amber); }
.day-item .di-main { flex: 1; min-width: 0; }
.day-item .di-unit { font-weight: 700; font-size: 14px; }
.day-item .di-sub { font-size: 12px; color: var(--muted); }
.day-item .di-amt { font-weight: 800; white-space: nowrap; }
