* { box-sizing: border-box; margin: 0; padding: 0; }

/* Muss vor allen display-Regeln stehen: eine Klasse wie .login-overlay mit
   display:flex wuerde das hidden-Attribut sonst aushebeln. */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f6f9;
  color: #2d3142;
  padding: 24px 16px calc(48px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 960px; margin: 0 auto; }

/* ------------------------------------------------------------------ Kopf */

.app-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

h1 { font-size: 1.5rem; font-weight: 700; }
.subtitle { font-size: 0.88rem; color: #8a8fa8; margin-top: 2px; }

.head-right { display: flex; align-items: center; gap: 10px; }

.sync-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 20px;
  background: #e8f5ec;
  color: #1a7f43;
  white-space: nowrap;
}

.sync-pill.busy    { background: #eceaff; color: #5850e6; }
.sync-pill.offline { background: #fdf0e3; color: #b45309; }
.sync-pill.error   { background: #fdeaea; color: #c0392b; }

/* --------------------------------------------------------------- Bausteine */

.card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.07);
  margin-bottom: 22px;
  overflow: hidden;
}

.card-pad { padding: 20px 22px; }

.card-title {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8a8fa8;
  margin-bottom: 15px;
}

.btn {
  font-family: inherit;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: #6c63ff;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.btn:hover { background: #5850e6; }
.btn:disabled { background: #c8cfe8; cursor: default; }
.btn-wide { width: 100%; }

.btn-ghost {
  background: #fff;
  border: 1.5px solid #e0e3ec;
  color: #555d7a;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: border-color 0.2s, color 0.2s;
}

.btn-ghost:hover { border-color: #6c63ff; color: #6c63ff; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.field label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #8a8fa8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input, select {
  font-family: inherit;
  padding: 9px 11px;
  border: 1.5px solid #e0e3ec;
  border-radius: 8px;
  font-size: 16px;          /* verhindert das Zoomen beim Fokus unter iOS */
  color: #2d3142;
  background: #f7f8fb;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  width: 100%;
  -moz-appearance: textfield;
}

@media (min-width: 700px) { input, select { font-size: 0.9rem; } }

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

input:focus, select:focus { border-color: #6c63ff; background: #fff; }
input.amount { text-align: right; font-weight: 600; }

.v-pat { color: #3b82f6; }
.v-jas { color: #ec4899; }

/* -------------------------------------------------------------- Monatswahl */

.month-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.month-bar .nav {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 1.5px solid #e0e3ec;
  background: #fff;
  color: #555d7a;
  font-size: 1.1rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.month-bar .nav:hover { border-color: #6c63ff; color: #6c63ff; }

.month-label { font-size: 1.05rem; font-weight: 700; min-width: 180px; text-align: center; }
.month-bar input[type="month"] { width: auto; }

/* --------------------------------------------------------------------- KPI */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.07);
  padding: 16px 18px;
}

.kpi .kpi-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #8a8fa8;
  font-weight: 600;
  margin-bottom: 6px;
}

.kpi .kpi-value { font-size: 1.3rem; font-weight: 700; }
.kpi .kpi-sub { font-size: 0.74rem; color: #8a8fa8; margin-top: 4px; }

.kpi.total { background: #2d3142; }
.kpi.total .kpi-label { color: #c8cfe8; }
.kpi.total .kpi-value { color: #a5f3b4; }
.kpi.total .kpi-sub { color: #8a90ad; }

/* --------------------------------------------------------------- Formular */

.form-grid {
  display: grid;
  grid-template-columns: 130px 1fr 190px 115px 125px auto;
  gap: 12px;
  align-items: end;
}

@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .f-desc, .form-grid .f-submit { grid-column: 1 / -1; }
}

/* --------------------------------------------------------------- Tabelle */

.table-head-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 14px;
  flex-wrap: wrap;
}

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

table { width: 100%; border-collapse: collapse; }

thead tr { background: #2d3142; color: #fff; }

thead th {
  padding: 12px 18px;
  text-align: left;
  font-weight: 600;
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.col-date   { width: 78px; }
.col-who    { width: 120px; }
.col-amount { width: 118px; }

thead th.num, td.num { text-align: right; }
thead th.act, td.act { text-align: center; width: 44px; }

.day-header td {
  background: #f0f2f7;
  padding: 7px 18px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8a8fa8;
  border-top: 1px solid #e8eaf0;
}

.day-header .day-sum { float: right; color: #555d7a; letter-spacing: 0; }

tbody tr.entry { border-bottom: 1px solid #f0f2f7; transition: background 0.15s; }
tbody tr.entry:hover { background: #fafbff; }
tbody tr.entry.pending { background: #fffdf5; }

td { padding: 10px 18px; font-size: 0.9rem; vertical-align: middle; }

td.cell-date { color: #8a8fa8; font-size: 0.82rem; white-space: nowrap; }

.desc { font-weight: 600; }
.posten { font-size: 0.76rem; color: #8a8fa8; margin-top: 2px; }
.emoji { margin-right: 6px; }

.who-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.who-badge.pat { background: #e5efff; color: #2563eb; }
.who-badge.jas { background: #ffe5f2; color: #db2777; }

td.num { font-weight: 600; white-space: nowrap; }

.del {
  border: none;
  background: none;
  color: #c8cfe8;
  font-size: 1.05rem;
  cursor: pointer;
  line-height: 1;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.del:hover { color: #e05555; background: #fdeaea; }

tfoot tr { background: #2d3142; color: #fff; }
tfoot td { padding: 14px 18px; font-weight: 700; font-size: 0.96rem; }
tfoot td:first-child {
  color: #c8cfe8; font-size: 0.78rem;
  letter-spacing: 0.05em; text-transform: uppercase;
}

/* Auf schmalen Bildschirmen wird aus der Tabelle eine gestapelte Liste –
   sonst schiebt sich ausgerechnet der Betrag aus dem sichtbaren Bereich. */
@media (max-width: 640px) {
  .table-scroll { overflow-x: visible; }

  #journal, #journal tbody, #journal tfoot, #journal tr { display: block; }
  #journal thead { display: none; }

  .day-header td { display: block; width: auto; }

  tr.entry {
    display: grid;
    grid-template-columns: 1fr auto 34px;
    grid-template-areas:
      "desc amount del"
      "who  amount del";
    align-items: center;
    padding: 8px 14px 10px;
  }

  tr.entry td { padding: 0; border: none; }
  tr.entry td.cell-date { display: none; }          /* Datum steht im Tagesbalken */
  tr.entry td:nth-child(2) { grid-area: desc; }
  tr.entry td:nth-child(3) { grid-area: who; padding-top: 5px; }
  tr.entry td.num { grid-area: amount; padding-left: 12px; font-size: 0.98rem; }
  tr.entry td.act { grid-area: del; text-align: right; }

  #journal tfoot tr { display: flex; justify-content: space-between; align-items: center; }
  #journal tfoot td.act { display: none; }
}

.empty { padding: 42px 22px; text-align: center; color: #8a8fa8; font-size: 0.88rem; }
.empty.compact { padding: 18px 0; }
.empty .big { font-size: 2rem; display: block; margin-bottom: 10px; }

/* ------------------------------------------------------------- Kategorien */

.cat-row {
  display: grid;
  grid-template-columns: 190px 1fr 110px 54px;
  gap: 14px;
  align-items: center;
  padding: 9px 0;
}

@media (max-width: 640px) {
  .cat-row { grid-template-columns: 1fr 100px; row-gap: 6px; }
  .cat-row .bar-wrap { grid-column: 1 / -1; order: 3; }
  .cat-row .cat-pct { display: none; }
}

.cat-name { font-size: 0.86rem; font-weight: 600; }
.bar-wrap { background: #f0f2f7; border-radius: 20px; height: 9px; overflow: hidden; }
.bar { height: 100%; border-radius: 20px; background: #6c63ff; transition: width 0.3s; }
.cat-amount { text-align: right; font-weight: 700; font-size: 0.88rem; white-space: nowrap; }
.cat-pct { text-align: right; font-size: 0.78rem; color: #8a8fa8; }

/* ------------------------------------------------------------- Aufteilung */

.ratio-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 14px;
  margin-bottom: 6px;
  border-bottom: 1px solid #f0f2f7;
  flex-wrap: wrap;
}

.ratio-row label {
  font-size: 0.72rem; font-weight: 600; color: #8a8fa8;
  text-transform: uppercase; letter-spacing: 0.04em;
}

.ratio-row input[type="range"] { flex: 1; min-width: 150px; width: auto; accent-color: #6c63ff; padding: 0; }
.ratio-value { font-weight: 700; font-size: 0.9rem; min-width: 70px; text-align: right; }

.split-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid #f0f2f7;
  font-size: 0.88rem;
}

.split-label { color: #555d7a; }
.split-value { font-weight: 700; text-align: right; }

/* ------------------------------------------------------------ Wechselkurs */

.fx-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.fx-row .field { width: 150px; }

.fx-result-item {
  display: flex; flex-direction: column; gap: 2px;
  align-items: flex-end; min-width: 120px; margin-left: auto;
}

.fx-result-item .fx-label {
  font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: #8a8fa8; font-weight: 600;
}

.fx-result-item .fx-value { font-size: 1.02rem; font-weight: 700; }

.fx-status {
  font-size: 0.72rem; color: #8a8fa8; margin-top: 12px;
  display: flex; align-items: center; gap: 6px;
}

.fx-status.error { color: #e05555; }

.spinner {
  width: 11px; height: 11px;
  border: 2px solid #c8cfe8;
  border-top-color: #6c63ff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- Legende */

.legend {
  display: flex; gap: 24px; justify-content: center;
  font-size: 0.8rem; color: #8a8fa8; margin-top: 4px;
}

.legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-pat { background: #3b82f6; }
.dot-jas { background: #ec4899; }

/* --------------------------------------------------------------- Anmeldung */

.login-overlay {
  position: fixed;
  inset: 0;
  background: #f4f6f9;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.login-box {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.10);
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-icon { font-size: 2.2rem; text-align: center; }
.login-box h2 { font-size: 1.2rem; text-align: center; font-weight: 700; }
.login-hint { text-align: center; font-size: 0.85rem; color: #8a8fa8; margin-top: -8px; margin-bottom: 4px; }

.login-error {
  background: #fdeaea;
  color: #c0392b;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.82rem;
}

/* ------------------------------------------------------------------ Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #2d3142;
  color: #fff;
  padding: 11px 20px;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,0.2);
  z-index: 60;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.warn { background: #b45309; }
.toast.err  { background: #c0392b; }
