:root {
  --bg: #050b2e;
  --panel: rgba(8, 16, 56, 0.72);
  --panel-solid: #0b1648;
  --panel-border: rgba(140, 170, 255, 0.22);
  --text: #eef2ff;
  --muted: #a5b1db;
  --accent: #3d7bff;
  --accent-2: #6fa0ff;
  --pos: #6ee7a8;
  --neg: #ff8a8a;
  --warn: #ffd166;
  --fixed: #7c8cff;
  --service: #36c5f0;
  --adhoc: #f7a440;
  --radius: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(4, 8, 40, 0.35) 0%, rgba(4, 8, 40, 0.65) 55%, rgba(3, 6, 30, 0.92) 100%),
    url('img/background.jpg') center 35% / cover no-repeat;
}

[hidden] {
  display: none !important;
}

body:not(.is-admin) .admin-only {
  display: none !important;
}

h2 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem;
  letter-spacing: 0.02em;
}

h3 {
  font-size: 0.8rem;
  margin: 1rem 0 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

h4 {
  margin: 1.2rem 0 0.5rem;
  font-size: 0.95rem;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.82rem;
}

.pos {
  color: var(--pos);
}

.neg {
  color: var(--neg);
}

/* ---------- controls ---------- */

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 0.5rem 0.95rem;
  transition: background 0.15s, border-color 0.15s;
}

button:hover {
  background: rgba(255, 255, 255, 0.12);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.primary:hover {
  background: var(--accent-2);
}

button.link {
  background: none;
  border: none;
  padding: 0.25rem 0.4rem;
  color: var(--accent-2);
}

button.link:hover {
  text-decoration: underline;
}

button.danger {
  color: var(--neg);
}

button.small {
  font-size: 0.82rem;
  padding: 0.25rem 0.6rem;
}

input,
select {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  padding: 0.55rem 0.7rem;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 1px;
}

label {
  display: block;
  margin-bottom: 0.7rem;
}

label > span:first-child {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

label.check input {
  width: auto;
}

label.check > span:first-child {
  display: inline;
}

.row {
  display: flex;
  gap: 0.75rem;
}

.row > label {
  flex: 1;
  min-width: 0;
}

.row > label.narrow {
  flex: 0 0 8.5rem;
}

.error {
  color: var(--neg);
  margin: 0.25rem 0 0.75rem;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: -0.3rem 0 0.8rem;
}

.hint.warn {
  color: var(--warn);
}

.row > button {
  align-self: flex-end;
  margin-bottom: 0.75rem;
}

.pdf-pick input[type='file'] {
  width: 100%;
  padding: 0.7rem;
  border: 1px dashed var(--panel-border);
  border-radius: 10px;
  cursor: pointer;
}

/* ---------- panels & layout ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 10px 40px rgba(0, 0, 20, 0.35);
}

#app-view {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 0 0.3rem;
  flex-wrap: wrap;
}

.brand .reg {
  font-weight: 800;
  font-size: 2.4rem;
  letter-spacing: 0.08em;
  line-height: 1;
}

.brand .callsign {
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.brand .type {
  color: var(--accent-2);
  font-weight: 600;
  margin-top: 0.2rem;
}

.brand.inline {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.brand.inline .reg {
  font-size: 1.9rem;
  text-shadow: 0 2px 18px rgba(60, 120, 255, 0.6);
}

.tools {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.tools .year {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0.5rem 0 0;
}

.tools .year > span:first-child {
  margin: 0;
}

.tools .year select {
  width: auto;
  padding: 0.3rem 0.5rem;
}

.who {
  color: var(--muted);
  padding: 0 0.3rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.section-head h2 {
  margin: 0;
}

.section-head input[type='month'],
.filters select {
  width: auto;
}

.filters {
  display: flex;
  gap: 0.5rem;
}

.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
}

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding-top: 0.5rem;
}

/* ---------- budget ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.8rem;
}

.tile {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  border-radius: 11px;
  padding: 0.7rem 0.85rem;
}

.tile-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tile-value {
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 0.15rem;
  font-variant-numeric: tabular-nums;
}

.tile.big .tile-value {
  font-size: 1.6rem;
}

.tile.pos .tile-value {
  color: var(--pos);
}

.tile.neg .tile-value {
  color: var(--neg);
}

.tile.warn .tile-value {
  color: var(--warn);
}

.tile-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.bars {
  margin-top: 1rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 11rem 1fr 8rem;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
}

.bar-label {
  color: var(--muted);
  font-size: 0.88rem;
}

.bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
  display: flex;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
}

.bar-fill.income {
  background: var(--pos);
}

.bar-fill.fixed,
.dot.fixed {
  background: var(--fixed);
}

.bar-fill.service,
.dot.service {
  background: var(--service);
}

.bar-fill.adhoc,
.dot.adhoc {
  background: var(--adhoc);
}

.bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: 1px;
}

/* ---------- three columns ---------- */

.columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.1rem;
}

.column {
  border-top: 4px solid var(--member);
}

.column header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.column header h2 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--member);
}

.column .rate {
  font-size: 0.82rem;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
  margin: 0.9rem 0;
}

.stats div {
  min-width: 0;
}

.stats dt {
  font-size: 0.75rem;
  color: var(--muted);
}

.stats dd {
  margin: 0;
  font-weight: 650;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.col-actions {
  display: flex;
  gap: 0.5rem;
}

.col-actions button {
  flex: 1;
}

.mini {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mini li {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.88rem;
}

.mini li span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- calendar ---------- */

.cal-nav {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.cal-nav span {
  min-width: 10rem;
  text-align: center;
  font-weight: 600;
  text-transform: capitalize;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.cal-head {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 0.2rem 0;
}

.cal-day {
  min-height: 88px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 0.25rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.cal-day:hover {
  background: rgba(255, 255, 255, 0.09);
}

.cal-day.outside {
  opacity: 0.45;
}

.cal-day.today {
  border-color: var(--accent-2);
  box-shadow: inset 0 0 0 1px var(--accent-2);
}

.cal-num {
  font-size: 0.8rem;
  color: var(--muted);
  padding-left: 0.15rem;
}

.chip {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 0.74rem;
  padding: 0.15rem 0.35rem;
  border-radius: 5px;
  border: none;
  background: color-mix(in srgb, var(--member) 30%, transparent);
  border-left: 3px solid var(--member);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip.maint {
  --member: #9aa3b5;
  background: repeating-linear-gradient(45deg, rgba(154, 163, 181, 0.25) 0 6px, rgba(154, 163, 181, 0.1) 6px 12px);
}

/* ---------- commitment ---------- */

.progress {
  position: relative;
  height: 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  margin: 0.6rem 0 0.4rem;
}

.progress-fill {
  height: 100%;
  border-radius: 8px;
  background: var(--pos);
}

.progress-fill.behind {
  background: var(--warn);
}

.progress-mark {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  background: #fff;
}

.settle-total {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.4rem;
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--panel-border);
}

/* ---------- tables ---------- */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--panel-border);
  white-space: nowrap;
}

tfoot td {
  font-weight: 600;
  border-top: 1px solid var(--panel-border);
  border-bottom: none;
}

td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  vertical-align: top;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.row-actions {
  white-space: nowrap;
  text-align: right;
}

.badge {
  font-size: 0.7rem;
  padding: 0.05rem 0.4rem;
  border-radius: 6px;
  background: rgba(124, 140, 255, 0.25);
  margin-left: 0.3rem;
}

.cat {
  font-size: 0.78rem;
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
}

.cat.fixed {
  background: color-mix(in srgb, var(--fixed) 30%, transparent);
}

.cat.service {
  background: color-mix(in srgb, var(--service) 30%, transparent);
}

.cat.adhoc {
  background: color-mix(in srgb, var(--adhoc) 30%, transparent);
}

.status {
  font-size: 0.78rem;
  white-space: nowrap;
}

.status.statusPaid {
  color: var(--pos);
}

.status.statusUnpaid {
  color: var(--warn);
}

.status.statusOverdue {
  color: var(--neg);
  font-weight: 700;
}

/* ---------- auth ---------- */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem 1rem;
}

.auth-card {
  width: min(420px, 100%);
  text-align: left;
}

.auth-card .brand {
  text-align: center;
  margin-bottom: 1.3rem;
}

.auth-card .brand .reg {
  font-size: 3rem;
  text-shadow: 0 2px 24px rgba(60, 120, 255, 0.7);
}

.auth-card button.primary {
  width: 100%;
  padding: 0.7rem;
  margin-bottom: 0.4rem;
}

.auth-card .lang-toggle {
  display: block;
  margin: 0.4rem auto 0;
}

.label {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.4rem;
}

.user-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.user-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.code-input {
  font-size: 1.6rem;
  letter-spacing: 0.4em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.steps {
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.qr {
  display: flex;
  justify-content: center;
  margin: 0.5rem 0;
}

.qr svg {
  width: 220px;
  height: 220px;
  background: #fff;
  border-radius: 10px;
  padding: 6px;
}

#enroll-uri {
  display: block;
  text-align: center;
  color: var(--accent-2);
  margin-bottom: 0.4rem;
}

.secret {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.secret code {
  color: var(--text);
  word-break: break-all;
}

/* ---------- dialogs ---------- */

dialog {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel-solid);
  color: var(--text);
  padding: 0;
  width: min(520px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
}

dialog::backdrop {
  background: rgba(2, 5, 25, 0.65);
  backdrop-filter: blur(3px);
}

.dialog-form {
  padding: 1.2rem 1.3rem;
}

.dialog-form h3 {
  font-size: 1.15rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  margin: 0 0 1rem;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

#settings-dialog {
  width: min(680px, calc(100vw - 2rem));
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.user-row > span:first-child {
  flex: 1;
}

.pair-link {
  margin-top: 1rem;
  text-align: center;
}

.pair-link input {
  margin: 0.4rem 0;
  font-size: 0.8rem;
}

/* ---------- responsive ---------- */

@media (max-width: 1050px) {
  .tiles {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 860px) {
  .columns,
  .two {
    grid-template-columns: 1fr;
  }
  .tiles {
    grid-template-columns: 1fr 1fr;
  }
  .bar-row {
    grid-template-columns: 1fr auto;
  }
  .bar-row .bar {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .cal-day {
    min-height: 58px;
  }
  .chip b {
    display: none;
  }
}

@media (max-width: 520px) {
  #app-view {
    padding: 0 0.75rem 1.5rem;
  }
  .table-wrap table {
    min-width: 680px;
  }
  .tile.big .tile-value,
  .tile-value {
    font-size: 1.15rem;
  }
  .row {
    flex-direction: column;
    gap: 0;
  }
  .row > label.narrow {
    flex: 1;
  }
  .calendar {
    gap: 2px;
  }
  .chip {
    font-size: 0;
    height: 6px;
    padding: 0;
  }
  .cal-day {
    min-height: 46px;
  }
}

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

/* ---------- priority weeks (co-ownership agreement art. 5.2) ---------- */

.cal-day.prio {
  background: color-mix(in srgb, var(--prio) 9%, rgba(255, 255, 255, 0.03));
  border-top: 3px solid color-mix(in srgb, var(--prio) 70%, transparent);
}

.prio-name {
  font-size: 0.66rem;
  color: var(--prio);
  white-space: nowrap;
}

.chip.subject {
  outline: 1px dashed var(--member);
  outline-offset: -1px;
}

.cal-legend {
  margin-top: 0.6rem;
}

.legend-item {
  white-space: nowrap;
  margin-right: 0.5rem;
}

.badge.warn {
  background: color-mix(in srgb, var(--warn) 30%, transparent);
}

.mini li.bumped > span:first-child {
  text-decoration: line-through;
  text-decoration-color: var(--warn);
}

.mini li.bumped .badge,
.mini li.bumped button {
  text-decoration: none;
  display: inline-block;
}

/* ---------- quarterly clearing ---------- */

.clearing-table td:first-child {
  color: var(--muted);
}

.clearing-table .total-row td {
  font-weight: 700;
  color: var(--text);
  border-top: 1px solid var(--panel-border);
}

.transfer {
  margin: 0.8rem 0;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(124, 140, 255, 0.12);
}

.transfer .amount {
  font-size: 1.15rem;
  font-weight: 700;
}

.clearing-status .warn {
  color: var(--warn);
}

.invoice-row {
  align-items: flex-end;
}

.print-only {
  display: none;
}

@media print {
  body.print-clearing {
    background: #fff;
    color: #000;
  }
  body.print-clearing .backdrop,
  body.print-clearing #auth-view,
  body.print-clearing dialog,
  body.print-clearing #app-view > :not(#clearing-panel),
  body.print-clearing .no-print,
  body.print-clearing #clearing-panel .hint {
    display: none !important;
  }
  body.print-clearing #clearing-panel {
    background: #fff;
    color: #000;
    border: none;
    box-shadow: none;
  }
  body.print-clearing #clearing-panel * {
    color: #000 !important;
  }
  body.print-clearing .print-only {
    display: block;
  }
  body.print-clearing .table-wrap table {
    min-width: 0;
  }
}

.fund-table {
  max-width: 640px;
}

@media (max-width: 520px) {
  .table-wrap table.fund-table {
    min-width: 0;
  }
}
