:root { color-scheme: light dark; }
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, sans-serif;
  background: #f4f4f5;
  color: #18181b;
}
@media (prefers-color-scheme: dark) {
  body { background: #18181b; color: #f4f4f5; }
  input, textarea { background: #27272a; color: #f4f4f5; border-color: #3f3f46; }
  code { background: #27272a; }
}
main {
  max-width: 920px;
  margin: 2rem auto;
  padding: 1.5rem;
}
h1 { margin-top: 0; }

/* Fejléc: cím + mai dátum */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar h1 { margin: 0; }
.today { color: #52525b; font-variant-numeric: tabular-nums; }
@media (prefers-color-scheme: dark) {
  .today { color: #a1a1aa; }
}

/* Kétoszlopos elrendezés: balra szövegmező, jobbra a felismert adatok.
   A két oszlopfej azonos magasságú, ezért a szövegmező és a jobb doboz teteje
   egy vonalban kezdődik. */
.cols { display: flex; gap: 1.25rem; align-items: flex-start; }
.col { flex: 1 1 50%; min-width: 0; }
.col-head { font-weight: 600; line-height: 1.4; margin: 0 0 0.4rem; }
.col textarea { margin-top: 0; }
.box {
  margin-top: 0;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
}
.box .muted { color: #71717a; margin: 0; }
.box label:first-child { margin-top: 0; }
@media (prefers-color-scheme: dark) {
  .box { background: #27272a; border-color: #3f3f46; }
}
@media (max-width: 680px) {
  .cols { flex-direction: column; }
}

/* Fizetendő végösszeg */
.pending-total {
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid #e4e4e7;
  text-align: right;
}
@media (prefers-color-scheme: dark) {
  .pending-total { border-color: #3f3f46; }
}

/* Rögzített számlák táblázata – szélesebb, mint a beviteli rész (kitör a
   920px-es tartalomból), hogy a Megjegyzés is kiférjen görgetés nélkül. */
.transactions {
  margin-top: 2rem;
  width: min(1400px, 95vw);
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}
.transactions h2 { font-size: 1.05rem; margin: 0; }
.tx-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.tabs { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tab {
  padding: 0.25rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
  color: #52525b;
  background: transparent;
  border: 1px solid #e4e4e7;
  border-radius: 6px;
  cursor: pointer;
}
.tab:hover { background: #f4f4f5; }
.tab.active {
  color: #fff;
  background: #2563eb;
  border-color: #2563eb;
  font-weight: 600;
}
.tx-count { margin: 0 0 0.4rem; font-size: 0.8rem; }
@media (prefers-color-scheme: dark) {
  .tab { color: #a1a1aa; border-color: #3f3f46; }
  .tab:hover { background: #27272a; }
  .tab.active { color: #fff; background: #2563eb; }
}
.table-wrap {
  overflow-x: auto;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
}
table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th {
  position: sticky;
  top: 0;
  background: #f4f4f5;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #e4e4e7;
}
tbody td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid #f0f0f1;
  white-space: nowrap;
}
/* A Megjegyzés (utolsó oszlop) tördelhet, ne toljon vízszintes görgetést */
thead th:last-child, tbody td:last-child { white-space: normal; min-width: 14rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.paid { background: #eef7ea; }  /* rendezett (fizetett) sor */
/* Rendezett jelölő oszlop */
th.settled-th, td.settled-cell { text-align: center; }
.settled-box { width: auto; margin: 0; padding: 0; vertical-align: middle; cursor: pointer; }
/* Összeg oszlop (2.) jobbra igazítva */
thead th:nth-child(2), tbody td:nth-child(2) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
tbody td.neg { color: #b91c1c; font-weight: 600; }       /* negatív fizetendő (túlfizetés/jóváírás) */
@media (prefers-color-scheme: dark) {
  tbody td.neg { color: #f87171; }
}
@media (prefers-color-scheme: dark) {
  .table-wrap { border-color: #3f3f46; }
  thead th { background: #27272a; border-color: #3f3f46; }
  tbody td { border-color: #3f3f46; }
  tbody tr.paid { background: #1f2e22; }
}

/* Éves statisztika szolgáltatónként */
.stats {
  margin-top: 2rem;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
}
.stats h2 { margin: 0 0 0.6rem; font-size: 1.05rem; }
.stats .muted { color: #71717a; margin: 0.25rem 0 0; }
.stats-table { width: 100%; font-size: 14px; }
.stats-table td.num, .stats-table th.num { text-align: right; }
.stats-table th:last-child, .stats-table td:last-child {
  text-align: right; white-space: nowrap; min-width: 0;
  font-variant-numeric: tabular-nums;
}
.stats-table tfoot td { font-weight: 700; border-top: 2px solid #e4e4e7; }
.stats-avg { margin-top: 0.75rem; font-size: 1rem; }
.stats-avg strong { font-variant-numeric: tabular-nums; }
.stats-avg .muted { color: #71717a; font-size: 0.85rem; }
@media (prefers-color-scheme: dark) { .stats-avg .muted { color: #a1a1aa; } }
.stat-note {
  margin-left: 0.4rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #52525b;
  background: #f4f4f5;
  border-radius: 999px;
  cursor: help;
}
@media (prefers-color-scheme: dark) {
  .stat-note { color: #a1a1aa; background: #3f3f46; }
}
@media (prefers-color-scheme: dark) {
  .stats { background: #27272a; border-color: #3f3f46; }
  .stats-table tfoot td { border-color: #52525b; }
}

/* Lábléc: táblázat link */
.foot { margin-top: 2rem; text-align: center; }
.foot a { color: #2563eb; text-decoration: none; }
.foot a:hover { text-decoration: underline; }
label { display: block; margin: 0.75rem 0; font-weight: 600; }
textarea, input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem;
  font: inherit;
  font-weight: 400;
  border: 1px solid #d4d4d8;
  border-radius: 6px;
}
textarea { resize: vertical; }
.actions { margin-top: 1rem; display: flex; align-items: center; gap: 1rem; }
button {
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: #2563eb;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
button:hover { background: #1d4ed8; }
.msg { padding: 0.75rem 1rem; border-radius: 6px; margin: 1rem 0; }
.msg.ok { background: #dcfce7; color: #166534; }
.msg.error { background: #fee2e2; color: #991b1b; }
.msg.warn { background: #fef3c7; color: #92400e; }
code { padding: 0.1rem 0.3rem; background: #e4e4e7; border-radius: 4px; }

/* Befizetésre váró lista */
.pending {
  margin: 0 0 1.5rem;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
}
@media (prefers-color-scheme: dark) {
  .pending { background: #27272a; border-color: #3f3f46; }
}

/* Beérkezésre váró (előrejelzett) számlák */
.incoming {
  margin: 0 0 1.5rem;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
}
.incoming h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.incoming .muted { color: #71717a; margin: 0.25rem 0 0; }
.incoming-list { list-style: none; margin: 0; padding: 0; }
.incoming-list li {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.45rem 0.25rem;
}
.incoming-list .due { font-variant-numeric: tabular-nums; color: #52525b; min-width: 6.2rem; }
.incoming-list .prov { flex: 1; font-weight: 600; }
.incoming-list .freq {
  font-size: 0.72rem;
  color: #71717a;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.incoming-list .amt { font-variant-numeric: tabular-nums; white-space: nowrap; color: #52525b; }
.incoming-list .when { color: #52525b; white-space: nowrap; min-width: 6.5rem; text-align: right; }
.incoming-list li.overdue .due,
.incoming-list li.overdue .when { color: #b91c1c; font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .incoming { background: #27272a; border-color: #3f3f46; }
  .incoming .muted { color: #a1a1aa; }
  .incoming-list .freq, .incoming-list .amt, .incoming-list .when { color: #a1a1aa; }
}
.pending h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.pending .muted { color: #71717a; margin: 0.25rem 0 0; }
.pending-list { list-style: none; margin: 0; padding: 0; }
.pending-list li {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.45rem 0.25rem;
}
.pending-list .due { font-variant-numeric: tabular-nums; color: #52525b; min-width: 6.2rem; }
.pending-list .prov { flex: 1; font-weight: 600; }
.pending-list .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pending-list li.overdue { color: #991b1b; }
.pending-list li.overdue .due { color: #b91c1c; font-weight: 600; }
.badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: #fee2e2;
  color: #991b1b;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  white-space: nowrap;
}
.pay-btn {
  margin-left: auto;              /* jobbra tolja a sor végére */
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #166534;
  background: #dcfce7;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.pay-btn:hover { background: #bbf7d0; }
.pay-btn:disabled { opacity: 0.6; cursor: default; }

/* Belépés / passkey regisztráció */
main.auth { max-width: 420px; margin-top: 15vh; text-align: center; }
.logout { margin: 0; }
.logout button { padding: 0.25rem 0.75rem; font-size: 0.85rem; }

/* Beérkezett (emailben jött) számlák */
.inbox {
  margin: 0 0 1.5rem;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
}
.inbox h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.inbox .muted { color: #71717a; margin: 0.25rem 0 0; }
.inbox-table tbody tr { cursor: pointer; }
.inbox-table tbody tr:hover { background: #f4f4f5; }
.inbox-table tbody tr.selected { background: #dbeafe; }
@media (prefers-color-scheme: dark) {
  .inbox { background: #27272a; border-color: #3f3f46; }
  .inbox .muted { color: #a1a1aa; }
  .inbox-table tbody tr:hover { background: #3f3f46; }
  .inbox-table tbody tr.selected { background: #1e3a5f; }
}
/* Elvetés gomb (a levél sorában és a rögzítés mellett) */
.inbox-table td.discard-cell, .inbox-table thead th:last-child { min-width: 0; width: 1%; text-align: right; }
.inbox-table td:nth-last-child(2) { white-space: normal; min-width: 14rem; }
.discard-btn { padding: 0.25rem 0.7rem; font-size: 0.8rem; background: #71717a; }
.discard-btn:hover { background: #52525b; }
.actions .discard-btn { padding: 0.55rem 1.1rem; font-size: inherit; }
