:root {
  --bg: #f5f6f8; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --green: #15803d; --red: #b91c1c; --warn: #fef3c7;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 52px; background: #111827; color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar a { color: #d1d5db; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 16px; }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a, .topbar .user a { padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.topbar nav a.active, .topbar nav a:hover, .topbar .user a.active { background: #374151; color: #fff; text-decoration: none; }
.topbar .user { display: flex; gap: 8px; align-items: center; }
.topbar button.link { color: #d1d5db; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafafa; }
tr:hover td { background: #fafbff; }
tr.uncertain td { background: var(--warn); }
tr.total td { font-weight: 700; border-top: 2px solid var(--text); }
.table-wrap { overflow-x: auto; }
td.desc { max-width: 420px; }
td.desc .full { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.heat { position: relative; }

input, select, textarea, button { font: inherit; }
input[type=text], input[type=password], input[type=search], input[type=number], input[type=month], input[type=file], select, textarea {
  padding: 7px 9px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; max-width: 100%;
}
select.compact { padding: 3px 6px; font-size: 13px; max-width: 200px; }
label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.btn { display: inline-block; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; }
.btn:hover { filter: brightness(1.1); text-decoration: none; }
.btn-secondary { background: #fff; color: var(--accent); }
.btn-danger { background: #fff; border-color: var(--red); color: var(--red); }
.btn-sm { padding: 3px 9px; font-size: 12px; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
form.inline { display: inline; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash-ok { background: #ecfdf5; border-color: #a7f3d0; }
.flash-warn { background: var(--warn); border-color: #fcd34d; }
.flash-error { background: #fef2f2; border-color: #fecaca; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: #eef2ff; color: #3730a3; white-space: nowrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.bar { height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar > span { display: block; height: 100%; background: var(--red); }
.bar.over > span { background: #7f1d1d; }
.chart-box { position: relative; height: 300px; }
pre.raw { white-space: pre; overflow: auto; max-height: 600px; background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px; font-size: 12px; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 340px; }
.login-card input { width: 100%; }
.pager { display: flex; gap: 6px; margin-top: 12px; }
.pager a, .pager span { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pager span.cur { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (max-width: 700px) { .grid-2 { grid-template-columns: 1fr; } .container { padding: 12px; } }

/* --- Spórolás: főcsoport-sávok --- */
details.grp { border-bottom: 1px solid var(--line); }
details.grp:last-of-type { border-bottom: 0; }
details.grp summary { display: grid; grid-template-columns: minmax(120px, 190px) 1fr auto; gap: 12px; align-items: center; padding: 10px 2px; cursor: pointer; list-style: none; }
details.grp summary::-webkit-details-marker { display: none; }
details.grp summary::before { content: '▸'; position: absolute; margin-left: -14px; color: var(--muted); }
details.grp[open] summary::before { content: '▾'; }
details.grp > table { margin: 0 0 12px; }
.grp-name { font-weight: 600; padding-left: 14px; }
.grp-bar { display: flex; height: 12px; background: #f1f5f9; border-radius: 6px; overflow: hidden; }
.grp-bar .ess { background: #64748b; }
.grp-bar .disc { background: #f97316; }
.grp-bar .unk { background: #a8a29e; }
.grid-5 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grp-val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.insight table td { padding: 4px 6px; }

/* --- Mobil (böngészés) --- */
.show-sm { display: none; }
details.filters > summary { list-style: none; }
details.filters > summary::-webkit-details-marker { display: none; }
@media (max-width: 760px) {
  body { font-size: 15px; }
  .hide-sm, .desk { display: none !important; }
  .show-sm { display: inline-block; }
  button.show-sm { display: inline-block; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px 0; gap: 6px 12px; }
  .topbar .brand { flex: 1; }
  .topbar nav { order: 3; flex-basis: 100%; padding-bottom: 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .topbar nav::-webkit-scrollbar { display: none; }
  .topbar nav a { padding: 8px 12px; }
  .container { padding: 12px; }
  h1 { font-size: 19px; }
  .card { padding: 14px; border-radius: 12px; margin-bottom: 12px; }
  .grid { gap: 10px; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .kpi .value { font-size: 18px; }
  .kpi .label { font-size: 11px; }
  input, select, textarea { font-size: 16px !important; }    /* iOS ne zoomoljon */
  .row > form.row { width: 100%; }
  .row > form.row select { flex: 1 1 40%; min-width: 0; }
  details.filters > form.row > * { flex: 1 1 100%; }
  details.filters > form.row > .btn { flex: 0 0 auto; }
  details.filters summary { cursor: pointer; padding: 2px 0; }
  details.filters[open] summary { margin-bottom: 10px; }
  th, td { padding: 8px 6px; }
  .chart-box { height: 220px; }
  td.desc { max-width: 52vw; }
  td.desc .full { max-width: 52vw; }

  /* tranzakciók: dátum | kereskedő+kategória | összeg */
  table.tx-table th:nth-child(3) { display: none; }
  table.tx-table td:nth-child(3) { display: block; border: 0; padding: 0 6px 8px; margin-top: -6px; }
  table.tx-table tr { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; border-bottom: 1px solid var(--line); }
  table.tx-table td.desc { max-width: none; min-width: 0; }
  table.tx-table td.desc .full { max-width: 100%; }
  table.tx-table td:nth-child(4) { font-weight: 600; padding-left: 4px; }
  table.tx-table tr td { border-bottom: 0; }
  table.tx-table td:nth-child(1) { grid-row: span 2; }
  table.tx-table td:nth-child(3) { grid-column: 2; grid-row: 2; }
  table.tx-table td:nth-child(4) { grid-column: 3; grid-row: 1; }
  table.tx-table tr:first-child { display: none; }

  /* havi bontás: alapból csak összesen + átlag; gombbal a hónapok is (vízszintes görgetéssel) */
  table.pivot .mcol { display: none; }
  table.pivot.show-months .mcol { display: table-cell; }
  table.pivot.show-months td:first-child, table.pivot.show-months th:first-child { position: sticky; left: 0; background: #fff; z-index: 1; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; }

  /* kártyás táblázat */
  table.cards-sm tr:first-child { display: none; }
  table.cards-sm tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); }
  table.cards-sm td { display: flex; justify-content: space-between; gap: 10px; border: 0; padding: 3px 10px; }
  table.cards-sm td::before { content: attr(data-label); color: var(--muted); font-size: 12px; }

  details.grp summary { grid-template-columns: 1fr auto; }
  details.grp summary .grp-bar { grid-column: 1 / -1; grid-row: 2; }
  .flash { font-size: 14px; }
}
