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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f0f4f8;
  color: #1e293b;
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  color: white;
  padding: 1rem 1.5rem;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}

.header-inner {
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.admin-widget { position: relative; }

.admin-btn {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: white;
  border-radius: 8px;
  padding: .35rem .7rem;
  cursor: pointer;
  font-size: .95rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  transition: background .15s;
}
.admin-btn:hover { background: rgba(255,255,255,.25); }
.admin-btn.unlocked { background: rgba(255,255,255,.2); font-size: .8rem; }

.admin-panel {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + .5rem);
  background: white;
  border-radius: 10px;
  padding: .75rem;
  box-shadow: 0 8px 28px rgba(0,0,0,.18);
  z-index: 100;
  min-width: 210px;
}
.admin-panel.open { display: block; }
.admin-panel form { display: flex; gap: .4rem; }
.admin-panel input[type="password"] {
  flex: 1;
  padding: .5rem .7rem;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  font-size: .88rem;
  outline: none;
}
.admin-panel input:focus { border-color: #2563eb; }

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ── Flash ─────────────────────────────────────────────────────────────────── */
.flash {
  padding: .85rem 1.25rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-weight: 500;
  font-size: .92rem;
}
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Account cards ─────────────────────────────────────────────────────────── */
.accounts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 580px) {
  .accounts-grid { grid-template-columns: 1fr; }
}

.account-card {
  background: white;
  border-radius: 18px;
  padding: 1.5rem 1.6rem;
  box-shadow: 0 4px 24px rgba(0,0,0,.09);
  border-top: 5px solid #2563eb;
}

.account-card.account-martin { border-top-color: #f97316; background: linear-gradient(160deg, #fff8f1 0%, #fff 60%); }
.account-card.account-lucas  { border-top-color: #3b82f6; background: linear-gradient(160deg, #f0f6ff 0%, #fff 60%); }

.account-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .6rem;
}

.account-name {
  font-size: 1.2rem;
  font-weight: 800;
  color: #1e293b;
  letter-spacing: -.01em;
}

.account-emoji { font-size: 2.2rem; line-height: 1; }

.account-balance {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -.04em;
  margin-bottom: .7rem;
  line-height: 1;
}
.account-balance.positive { color: #16a34a; }
.account-balance.negative { color: #dc2626; }
.account-balance.zero     { color: #94a3b8; }

.account-lcl-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .4rem .5rem;
  background: #f8fafc;
  border-radius: 8px;
  margin-bottom: .4rem;
  font-size: .85rem;
}
.lcl-label { color: #64748b; font-weight: 600; }
.lcl-amount { color: #334155; font-weight: 700; }

.account-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .4rem .5rem;
  border-top: 2px solid #f1f5f9;
  margin-bottom: .6rem;
  font-size: .92rem;
}
.total-label { color: #64748b; font-weight: 700; text-transform: uppercase; font-size: .75rem; letter-spacing: .05em; }
.total-amount { font-weight: 800; font-size: 1rem; }

.lcl-form { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.lcl-field { display: flex; flex-direction: column; gap: .3rem; }
.lcl-field label { font-size: .82rem; font-weight: 600; color: #64748b; }
.lcl-field input {
  padding: .6rem .85rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: .9rem;
  width: 150px;
  outline: none;
}
.lcl-field input:focus { border-color: #2563eb; }

.account-month {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .8rem;
  margin-bottom: .5rem;
  flex-wrap: wrap;
}
.month-label { color: #94a3b8; font-style: italic; }
.month-in  { color: #16a34a; font-weight: 700; }
.month-out { color: #dc2626; font-weight: 700; }

.account-last {
  font-size: .76rem;
  color: #94a3b8;
}

/* ── Section card ──────────────────────────────────────────────────────────── */
.section {
  background: white;
  border-radius: 14px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 2px 14px rgba(0,0,0,.06);
  margin-bottom: 1.25rem;
}

.section h3 {
  font-size: .95rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 1rem;
  padding-bottom: .6rem;
  border-bottom: 1px solid #f1f5f9;
}

/* ── Form ──────────────────────────────────────────────────────────────────── */
.tx-form .form-row {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: stretch;
}

.tx-form select,
.tx-form input[type="number"],
.tx-form input[type="text"] {
  padding: .6rem .85rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: .88rem;
  background: #f8fafc;
  color: #1e293b;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  height: 38px;
}

.tx-form select:focus,
.tx-form input:focus {
  border-color: #2563eb;
  background: white;
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.tx-form select          { min-width: 105px; }
.tx-form .input-amount   { width: 105px; }
.tx-form .input-desc     { flex: 1; min-width: 160px; }

.btn {
  padding: .6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  height: 38px;
  white-space: nowrap;
}
.btn:hover  { opacity: .88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: #2563eb; color: white; }

/* ── Transaction table ─────────────────────────────────────────────────────── */
.tx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.tx-table th {
  text-align: left;
  padding: .45rem .75rem;
  color: #94a3b8;
  font-weight: 600;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 2px solid #f1f5f9;
}
.tx-table th:last-child,
.tx-table td:last-child { width: 1%; white-space: nowrap; }

.tx-table td {
  padding: .65rem .75rem;
  border-bottom: 1px solid #f8fafc;
  vertical-align: middle;
}

.tx-table tbody tr:last-child td { border-bottom: none; }

.tx-table tbody tr:hover { background: #fafbfc; }

.tx-table tr.deleted td {
  opacity: .35;
  text-decoration: line-through;
}

.tx-date { color: #64748b; white-space: nowrap; font-size: .8rem; }

.tx-desc { color: #334155; }
.tx-desc .tx-rate,
.tx-desc .tx-meta {
  display: block;
  color: #94a3b8;
  font-size: .73rem;
  font-style: italic;
}

.tx-amount {
  font-weight: 700;
  white-space: nowrap;
  text-align: right;
  font-size: .92rem;
}
.tx-amount.positive { color: #16a34a; }
.tx-amount.negative { color: #dc2626; }

.badge {
  display: inline-block;
  padding: .22rem .65rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-martin { background: #ffedd5; color: #c2410c; }
.badge-lucas  { background: #dbeafe; color: #1d4ed8; }

.btn-delete {
  background: none;
  border: 1px solid #e2e8f0;
  color: #cbd5e1;
  border-radius: 6px;
  padding: .22rem .55rem;
  cursor: pointer;
  font-size: .78rem;
  line-height: 1;
  transition: all .15s;
}
.admin-actions { display: flex; gap: .3rem; align-items: center; white-space: nowrap; }

.btn-action {
  border: none;
  border-radius: 6px;
  padding: .3rem .6rem;
  cursor: pointer;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1;
  transition: opacity .15s;
}
.btn-action:hover { opacity: .8; }
.btn-soft { background: #fff7ed; color: #c2410c; }
.btn-undo { background: #f0fdf4; color: #16a34a; }
.btn-edit { background: #eff6ff; color: #2563eb; }
.btn-hard { background: #fee2e2; color: #dc2626; }

/* keep old .btn-delete for compat */
.btn-delete {
  background: none;
  border: 1px solid #e2e8f0;
  color: #94a3b8;
  border-radius: 6px;
  padding: .22rem .55rem;
  cursor: pointer;
  font-size: .78rem;
  line-height: 1;
  transition: all .15s;
}
.btn-delete:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #dc2626;
}

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: white;
  border-radius: 16px;
  padding: 1.75rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .82rem; font-weight: 600; color: #64748b; margin-bottom: .35rem; }
.form-group input[type="number"],
.form-group input[type="text"] {
  width: 100%;
  padding: .6rem .85rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: .9rem;
  outline: none;
  transition: border-color .15s;
}
.form-group input:focus { border-color: #2563eb; }

.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

/* ── Credit/Debit toggle ───────────────────────────────────────────────────── */
.type-toggle {
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #e2e8f0;
  height: 38px;
}
.type-toggle input[type="radio"] { display: none; }
.type-btn {
  padding: 0 1rem;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 700;
  background: #f8fafc;
  color: #94a3b8;
  transition: all .15s;
  user-select: none;
}
.type-btn.type-credit { border-right: 1px solid #e2e8f0; }
#type-credit:checked ~ .type-credit { background: #dcfce7; color: #16a34a; border-color: #86efac; }
#type-debit:checked  ~ .type-debit  { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }

.input-amount { transition: border-color .15s, background .15s, color .15s; }
.type-credit-active { border-color: #86efac !important; background: #f0fdf4 !important; color: #16a34a !important; }
.type-debit-active  { border-color: #fca5a5 !important; background: #fff5f5 !important; color: #dc2626 !important; }

/* ── Account toggle ────────────────────────────────────────────────────────── */
.account-toggle {
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  height: 38px;
}
.account-toggle input[type="radio"] { display: none; }
.acc-btn {
  padding: 0 1.1rem;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 700;
  background: #f8fafc;
  color: #94a3b8;
  transition: all .15s;
  user-select: none;
}
.acc-btn-martin { border-right: 1px solid #e2e8f0; }
#acc-martin:checked ~ .acc-btn-martin { background: #ffedd5; color: #c2410c; }
#acc-lucas:checked  ~ .acc-btn-lucas  { background: #dbeafe; color: #1d4ed8; }

/* ── Transaction row colors ────────────────────────────────────────────────── */
.tx-row-martin:not(.deleted) { background: rgba(249,115,22,.04); }
.tx-row-lucas:not(.deleted)  { background: rgba(59,130,246,.04); }
.tx-row-martin:not(.deleted):hover { background: rgba(249,115,22,.08); }
.tx-row-lucas:not(.deleted):hover  { background: rgba(59,130,246,.08); }

.muted { color: #94a3b8; }
.text-center { text-align: center; }

/* ── Theme popup ───────────────────────────────────────────────────────────── */
.theme-widget { position: relative; }
.theme-trigger {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,.5);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: .3rem .5rem;
  display: flex;
  align-items: center;
  gap: .3rem;
  transition: color .15s;
}
.theme-trigger:hover { color: rgba(255,255,255,.9); }
.theme-trigger-arrow { font-size: .6rem; opacity: .6; }

.theme-popup {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + .5rem);
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: .4rem;
  box-shadow: 0 8px 28px rgba(0,0,0,.15);
  z-index: 150;
  min-width: 130px;
}
.theme-popup.open { display: block; }
.theme-option {
  display: block;
  padding: .5rem .85rem;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-decoration: none;
  color: #64748b;
  border-radius: 7px;
  transition: all .12s;
  white-space: nowrap;
}
.theme-option:hover { background: #f1f5f9; color: #1e293b; }
.theme-option.active { color: #2563eb; }

footer {
  text-align: center;
  padding: 1.5rem;
  color: #cbd5e1;
  font-size: .72rem;
}

.empty-state {
  padding: 2.5rem;
  text-align: center;
  color: #94a3b8;
  font-size: .9rem;
}

@media (max-width: 580px) {
  .tx-table th:nth-child(1),
  .tx-table td:nth-child(1) { display: none; }
}
