:root {
  --bg: #f4f6f9;
  --card: #fff;
  --text: #1a1d24;
  --muted: #5c6470;
  --accent: #1e5a8a;
  --accent-hover: #164a72;
  --danger: #a32020;
  --border: #d8dde5;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
}

.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.site-header .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.brand {
  font-size: 1.15rem;
}

.site-header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.site-header a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.site-header a:hover {
  text-decoration: underline;
}

.site-footer {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2rem;
}

h1 {
  font-size: 1.65rem;
  margin-top: 0;
}

h2 {
  font-size: 1.25rem;
  margin-top: 1.75rem;
}

.lead {
  color: var(--muted);
  max-width: 52rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}

.card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.card .big {
  font-size: 1.55rem;
  font-weight: 700;
  margin: 0;
}

.card .muted,
.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.big-total {
  font-size: 1.2rem;
  margin: 1rem 0;
}

.row-inline {
  margin: 0.75rem 0;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  max-width: 28rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  margin-top: 0.2rem;
}

.form-stack {
  max-width: 32rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  align-items: end;
  margin-bottom: 1.5rem;
}

.form-grid .span-2 {
  grid-column: span 2;
}

.section-title {
  font-size: 1.35rem;
  margin: 1.5rem 0 0.75rem;
  font-weight: 600;
}

.dashboard-main-accounts .section-title {
  margin-top: 0.5rem;
}

.label-text {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
}

.payee-field .payee-hint {
  margin: 0.25rem 0 0.35rem;
  max-width: 40rem;
}

.payee-control {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.35rem;
}

.payee-control select {
  flex: 0 0 auto;
  width: auto;
  min-width: 11rem;
  max-width: 16rem;
}

.payee-control input[type="text"] {
  flex: 1 1 14rem;
  min-width: 10rem;
  max-width: none;
}

.payee-control input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: #f0f2f5;
}

.contra-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 1rem;
}

.sub-account-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.card.sub-account-card h3 {
  font-size: 1.05rem;
  margin: 0 0 0.5rem;
}

@media (max-width: 640px) {
  .form-grid .span-2 {
    grid-column: span 1;
  }
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: -0.5rem 0 0;
}

.hint.danger-text {
  color: var(--danger);
  margin: 0 0 0.75rem;
}

.settings-extra,
.db-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.db-section h2 {
  margin-top: 0;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-weight: 500;
  cursor: pointer;
}

.checkbox-label input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

input[type="file"] {
  font: inherit;
  margin-top: 0.2rem;
}

.btn {
  display: inline-block;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn.small {
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
}

.btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.flash {
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

.flash-success {
  background: #e3f4e8;
  border: 1px solid #9cc9a8;
}

.flash-danger {
  background: #fce8e8;
  border: 1px solid #e0a0a0;
}

.flash-info {
  background: #e8f0fc;
  border: 1px solid #a8bde0;
}

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Transactions page ledger: fit table within container (no horizontal scroll) */
.table-wrap.fit {
  overflow-x: hidden;
}

.table-wrap.fit table.data {
  table-layout: fixed;
  width: 100%;
  font-size: 0.82rem;
}

.table-wrap.fit table.data th,
.table-wrap.fit table.data td {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.data th,
table.data td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

table.data th {
  background: #eef1f6;
  font-weight: 600;
}

table.data .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.inline-form {
  display: inline;
  margin: 0;
}

td.cell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

/* Print report */
.report-page {
  background: #fff;
}

.report {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
}

.report-header h1 {
  margin-bottom: 0.25rem;
}

.report-header h2 {
  margin-top: 0;
  font-weight: 600;
}

.report-header .meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.report-section {
  margin-top: 1.5rem;
  break-inside: avoid;
}

.report-section h3 {
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.report-table th,
.report-table td {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
}

.report-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.report-table .strong td {
  font-weight: 700;
}

.report-table.ledger th {
  background: #eee;
}

.report-sign {
  margin-top: 2rem;
}

@media print {
  @page {
    margin: 10mm;
  }

  .no-print {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .site-header,
  .site-footer {
    display: none !important;
  }

  .report-section {
    break-inside: avoid;
  }

  .report-page .report {
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .report-page .report-table {
    width: 100%;
    table-layout: fixed;
    font-size: 0.8rem;
  }

  .report-page .report-table.ledger {
    font-size: 0.72rem;
  }

  .report-page .report-table th,
  .report-page .report-table td {
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
    padding: 0.2rem 0.3rem;
  }

  .report-page .report-table.ledger th,
  .report-page .report-table.ledger td {
    padding: 0.14rem 0.2rem;
  }
}

/* Portrait printing: keep ALL fields, but shrink/wrap so nothing is cut. */
@media print and (orientation: portrait) {
  .report-page .report {
    width: calc(100% - 2mm);
    margin: 0 auto;
    padding: 0;
  }

  .report-page .report-table {
    width: 100%;
    max-width: 100%;
    margin: 0;
  }

  .report-page .report-table.ledger {
    table-layout: fixed;
    font-size: 0.62rem;
  }

  .report-page .report-table.ledger th,
  .report-page .report-table.ledger td {
    padding: 0.12rem 0.12rem;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}
