:root {
  color-scheme: light;
  --bg: #f3efe7;
  --paper: #fffdf8;
  --ink: #1f2933;
  --muted: #687076;
  --line: #d7ccbb;
  --green: #2f7d57;
  --green-soft: #dfeee5;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --orange: #d97706;
  --orange-soft: #fbe7c6;
  --red: #b91c1c;
  --red-soft: #f6d5d5;
  --shadow: 0 10px 30px rgba(47, 42, 35, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 12px calc(env(safe-area-inset-bottom) + 28px);
}

.sheet-head {
  display: grid;
  grid-template-columns: 1fr 118px;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: clamp(27px, 8vw, 42px); line-height: 1.04; }
h2 { font-size: 19px; }

.sync-status {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.year-box {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
}

.month-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(74px, 1fr);
  gap: 7px;
  overflow-x: auto;
  padding: 3px 1px 10px;
  scrollbar-width: none;
}

.month-btn {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  display: grid;
  align-content: center;
  gap: 3px;
  box-shadow: var(--shadow);
}

.month-btn span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.month-btn strong {
  font-size: 15px;
}

.month-btn.active {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.month-btn.active span { color: #e9fff1; }

.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 4px 0 12px;
}

.summary article {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  min-width: 0;
  box-shadow: var(--shadow);
}

.summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(15px, 4vw, 21px);
  white-space: nowrap;
}

.tabs {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px;
  margin: 0 -2px 12px;
  background: rgba(243, 239, 231, 0.94);
  backdrop-filter: blur(10px);
}

.tab, .primary, .secondary, .add-line, .delete-btn {
  border: 0;
  border-radius: 7px;
  min-height: 44px;
  font-weight: 750;
}

.tab { background: #e5dccd; color: var(--ink); }
.tab.active { background: var(--green); color: #fff; }
.primary { width: 100%; background: var(--green); color: #fff; padding: 0 14px; }
.primary:disabled { background: #a8b8ae; }
.secondary { background: #e5dccd; color: var(--ink); padding: 0 12px; }
.secondary.danger { background: var(--red-soft); color: var(--red); }

.view { display: none; gap: 12px; }
.view.active { display: grid; }

.template-page {
  display: grid;
  gap: 12px;
  background: #fff;
  border: 1px solid #c8d0d8;
  border-radius: 4px;
  padding: 10px;
  box-shadow: var(--shadow);
}

.template-title {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 6px;
  align-items: center;
  border-bottom: 2px solid #2f5f87;
  padding-bottom: 6px;
}

.template-title span,
.template-title strong {
  background: #3f73a6;
  color: #fff;
  padding: 5px 8px;
  font-size: 13px;
  font-weight: 850;
}

.template-title strong {
  background: #dbe7f4;
  color: #1f3f5f;
  border: 1px solid #8aa8c7;
}

.template-note {
  max-width: 680px;
  color: #38434f;
  font-size: 12px;
  line-height: 1.35;
}

.template-note p {
  margin: 5px 0 0;
}

.template-grid {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 12px;
  align-items: start;
}

.template-block {
  border-top: 2px solid #2f5f87;
  padding-top: 6px;
}

.template-block h2 {
  font-size: 14px;
  margin-bottom: 7px;
}

.mini-table,
.realization,
.percent-table {
  display: grid;
  gap: 4px;
}

.mini-table div,
.realization div,
.percent-table div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid #8aa8c7;
  min-height: 28px;
  padding: 4px 7px;
  background: #edf4fb;
  font-size: 12px;
}

.realization div {
  background: #e8f0fb;
}

.mini-table strong,
.realization strong {
  font-size: 12px;
}

.progress-row {
  display: grid;
  grid-template-columns: 1fr minmax(110px, 180px) 44px;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
  color: #23384f;
  font-size: 12px;
  font-weight: 750;
}

.progress {
  height: 18px;
  border: 1px solid #2f5f87;
  background: #fff;
}

.progress i {
  display: block;
  height: 100%;
  background: #3f73a6;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  min-height: 190px;
  align-items: end;
  border-left: 1px solid #d0d7df;
  border-bottom: 1px solid #d0d7df;
  padding: 10px 6px 0;
}

.bar-item {
  display: grid;
  gap: 4px;
  align-items: end;
  text-align: center;
  font-size: 10px;
}

.bar-track {
  height: 116px;
  display: grid;
  align-items: end;
}

.bar-track i {
  display: block;
  width: 100%;
  min-height: 3px;
}

.bar-track .blue { background: #5b8cc0; }
.bar-track .orange { background: #f59e0b; }
.bar-track .green { background: #76b947; }
.bar-track .red { background: #ef4444; }

.bar-item strong {
  font-size: 10px;
}

.percent-table div {
  grid-template-columns: 1fr auto 42px;
  background: #fff;
}

.percent-table em {
  font-style: normal;
  font-weight: 850;
}

.pie-block {
  display: grid;
  justify-items: center;
}

.pie-chart {
  width: 180px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid #cad3dc;
  background: #edf2f7;
}

.pie-legend {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin-top: 8px;
  font-size: 11px;
}

.pie-legend span {
  display: flex;
  gap: 5px;
  align-items: center;
}

.pie-legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: 0 0 auto;
}

.section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sheet-panel, .panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel { padding: 14px; }

.table-title {
  padding: 10px 12px;
  font-weight: 850;
  border-bottom: 1px solid var(--line);
}

.income-title { background: var(--green-soft); color: #1f5f3f; }
.expense-title { background: var(--orange-soft); color: #8a4b05; }
.year-title { background: var(--blue-soft); color: #1d4ed8; }
.detail-title { background: #e8eef6; color: #2f5f87; }
.loan-title { background: #f6d5d5; color: #8f1d1d; }

.sheet-grid {
  display: grid;
  grid-template-columns: minmax(148px, 1.4fr) minmax(92px, .8fr) minmax(102px, .8fr) minmax(102px, .8fr) 42px;
  gap: 6px;
  align-items: center;
  padding: 8px;
}

.sheet-grid.head {
  background: #f7f0e6;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  border-bottom: 1px solid var(--line);
}

.sheet-grid.line {
  border-bottom: 1px solid #eadfce;
}

.sheet-grid.line input {
  min-height: 40px;
}

.loan-grid {
  display: grid;
  grid-template-columns: minmax(148px, 1.3fr) minmax(132px, .9fr) minmax(98px, .7fr) minmax(104px, .7fr) 42px;
  gap: 6px;
  align-items: center;
  padding: 8px;
}

.loan-grid.head {
  background: #f7e8e8;
  color: #8f1d1d;
  font-size: 12px;
  font-weight: 850;
  border-bottom: 1px solid var(--line);
}

.loan-grid.line {
  border-bottom: 1px solid #ead6d6;
}

.loan-grid input {
  min-height: 40px;
}

.paid-box {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border-radius: 6px;
  background: #fff8f8;
  color: #8f1d1d;
  font-weight: 750;
}

.paid-box input {
  width: auto;
  min-height: auto;
}

.loan-empty {
  padding: 12px;
  color: var(--muted);
}

.installment-form {
  display: grid;
  gap: 10px;
  padding: 12px 8px 8px;
  border-top: 1px solid #ead6d6;
  background: #fffafa;
}

.installment-title {
  color: #8f1d1d;
  font-weight: 850;
}

.installment-grid {
  display: grid;
  grid-template-columns: minmax(170px, 1.4fr) minmax(105px, .75fr) minmax(140px, .9fr) minmax(95px, .65fr);
  gap: 8px;
}

.installment-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.installment-grid input {
  min-height: 42px;
}

.installment-add {
  margin-top: 0;
}

.money-cell {
  min-height: 40px;
  display: grid;
  align-items: center;
  justify-content: end;
  padding: 0 8px;
  border-radius: 6px;
  background: #f6f0e7;
  font-weight: 750;
}

.positive { color: #16803f; }
.negative { color: var(--red); }

.delete-btn {
  width: 42px;
  min-height: 40px;
  background: var(--red-soft);
  color: var(--red);
}

.add-line {
  width: calc(100% - 16px);
  margin: 8px;
  background: #efe7da;
  color: var(--ink);
}

.year-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
}

.daily-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 10px;
}

.daily-grid div {
  min-height: 46px;
  border: 1px solid #b8cadb;
  background: #f8fbff;
  padding: 5px;
  display: grid;
  align-content: space-between;
  font-size: 11px;
}

.daily-grid div.has-value {
  background: #fff6db;
  border-color: #e4b949;
}

.daily-grid span {
  color: var(--muted);
  font-weight: 800;
}

.daily-grid strong {
  font-size: 10px;
}

.daily-grid em {
  display: block;
  color: #8f1d1d;
  font-size: 9px;
  font-style: normal;
  overflow: hidden;
  text-overflow: ellipsis;
}

.year-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #fff;
}

.year-card.active {
  border-color: var(--blue);
  background: #eff6ff;
}

.year-card span, .year-card small {
  display: block;
  color: var(--muted);
}

.year-card strong {
  display: block;
  margin: 5px 0;
}

.camera-box {
  display: grid;
  gap: 8px;
  place-items: center;
  min-height: 142px;
  margin: 12px 0;
  padding: 18px;
  border: 2px dashed #c8bca9;
  border-radius: 8px;
  background: #fff;
  text-align: center;
}

.camera-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.camera-box span {
  color: var(--green);
  font-size: 20px;
  font-weight: 850;
}

.camera-box small, .status, label {
  color: var(--muted);
  font-size: 13px;
}

.receipt-preview {
  display: none;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 8px;
  background: #efe7da;
  margin-bottom: 10px;
}

textarea {
  margin-top: 10px;
  resize: vertical;
  line-height: 1.35;
}

.ocr-candidates {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.ocr-candidates h3 {
  margin: 0;
  font-size: 15px;
}

.compact-add-all {
  min-height: 42px;
  font-size: 14px;
}

.ocr-candidate {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 7px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  background: #fff;
}

.ocr-candidate strong,
.ocr-candidate span {
  display: block;
}

.ocr-candidate span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.ocr-candidate button {
  border: 0;
  border-radius: 7px;
  min-height: 38px;
  padding: 0 9px;
  background: #e5dccd;
  color: var(--ink);
  font-weight: 800;
}

.field-grid {
  display: grid;
  gap: 11px;
  margin: 12px 0;
}

#loanPaymentForm {
  border-color: #ead6d6;
}

#loanPaymentTarget {
  min-height: 44px;
}

#loanPaymentHint {
  margin: 2px 0 10px;
}

label {
  display: grid;
  gap: 5px;
}

.transactions {
  display: grid;
  gap: 8px;
  padding-top: 10px;
}

.backup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 12px;
}

.import-label {
  min-height: 46px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  font-weight: 850;
}

.import-label input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.transaction-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.transaction-main strong, .transaction-main span { display: block; }
.transaction-main span { color: var(--muted); font-size: 13px; margin-top: 3px; }
.transaction-amount { text-align: right; font-weight: 850; margin-bottom: 6px; }

@media (min-width: 760px) {
  .app { padding-inline: 22px; }
  #scanView.active { grid-template-columns: 1fr 1fr; align-items: start; }
  .field-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .template-grid { grid-template-columns: 1fr; }
  .template-title { grid-template-columns: 1fr; }
  .sheet-panel { overflow-x: auto; }
  .sheet-grid { min-width: 610px; }
  .loan-grid { min-width: 640px; }
  .installment-form { min-width: 640px; }
  .year-grid { grid-template-columns: repeat(2, 1fr); }
  .daily-grid { grid-template-columns: repeat(4, 1fr); }
  .bar-chart { min-height: 165px; }
}

@media (max-width: 420px) {
  .sheet-head { grid-template-columns: 1fr 104px; }
  .summary { grid-template-columns: 1fr; }
}

/* Modern UI refresh */
:root {
  --bg: #eef2f4;
  --paper: #ffffff;
  --ink: #17202a;
  --muted: #637083;
  --line: #d8e0e7;
  --green: #247a52;
  --green-soft: #e7f4ee;
  --blue: #2f6fa3;
  --blue-soft: #e6f0f8;
  --orange: #c87918;
  --orange-soft: #fff0dc;
  --red: #b42318;
  --red-soft: #fde7e5;
  --shadow: 0 10px 24px rgba(17, 24, 39, 0.08);
  --shadow-soft: 0 1px 2px rgba(17, 24, 39, 0.08);
  --radius: 12px;
}

body {
  background: #eef2f4;
}

.app {
  padding-inline: 14px;
}

.sheet-head {
  grid-template-columns: 1fr 112px;
  gap: 14px;
  align-items: center;
  margin: 4px 0 14px;
  padding: 16px;
  border: 1px solid rgba(36, 122, 82, 0.16);
  border-radius: 18px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin-bottom: 7px;
  color: #4f6477;
  font-size: 11px;
  font-weight: 850;
}

h1 {
  font-size: clamp(30px, 7.5vw, 46px);
  line-height: .98;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin-top: 10px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #edf4fb;
  color: #35536e;
  font-size: 11px;
}

.year-box {
  padding: 8px;
  border-radius: 13px;
  background: #f7fafc;
  font-weight: 850;
}

input, select, textarea {
  border-color: #cfd9e2;
  border-radius: 10px;
  background: #fbfdff;
  box-shadow: var(--shadow-soft);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(47, 111, 163, 0.22);
  border-color: #2f6fa3;
}

.month-strip {
  grid-auto-columns: minmax(82px, 1fr);
  gap: 9px;
  padding-bottom: 12px;
}

.month-btn {
  min-height: 66px;
  border-color: transparent;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.month-btn.active {
  background: #247a52;
  box-shadow: 0 10px 22px rgba(36, 122, 82, 0.22);
}

.summary {
  gap: 10px;
  margin-bottom: 14px;
}

.summary article {
  border: 0;
  border-radius: 15px;
  padding: 13px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.summary span {
  font-weight: 750;
}

.summary strong {
  margin-top: 6px;
  font-size: clamp(17px, 4vw, 23px);
}

.tabs {
  gap: 8px;
  padding: 7px;
  border: 1px solid rgba(216, 224, 231, 0.9);
  border-radius: 16px;
  background: rgba(238, 242, 244, 0.92);
}

.tab, .primary, .secondary, .add-line, .delete-btn {
  border-radius: 12px;
  min-height: 48px;
}

.tab {
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.tab.active, .primary {
  background: #247a52;
  box-shadow: 0 9px 18px rgba(36, 122, 82, 0.18);
}

.secondary, .add-line {
  background: #eef1f4;
}

.secondary.danger {
  background: #fde7e5;
}

.template-page {
  gap: 14px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.template-title {
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 14px;
  border: 0;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.template-title span,
.template-title strong {
  border: 0;
  border-radius: 11px;
  background: #edf4fb;
  color: #294966;
}

.template-title span {
  background: #2f6fa3;
  color: #ffffff;
}

.template-note {
  max-width: none;
  padding: 14px;
  border-radius: 16px;
  background: #ffffff;
  color: #384757;
  box-shadow: var(--shadow-soft);
}

.template-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.template-block,
.sheet-panel,
.panel {
  border: 0;
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.template-block {
  padding: 14px;
  border-top: 0;
}

.template-block h2,
.panel h2 {
  margin-bottom: 10px;
  font-size: 16px;
}

.mini-table div,
.realization div,
.percent-table div {
  min-height: 36px;
  border: 0;
  border-radius: 10px;
  background: #f4f8fb;
  font-size: 13px;
}

.mini-table strong,
.realization strong {
  font-size: 13px;
}

.progress-row {
  grid-template-columns: 1fr minmax(96px, 180px) 44px;
  margin-top: 10px;
}

.progress {
  height: 12px;
  border: 0;
  border-radius: 999px;
  background: #dfe7ee;
  overflow: hidden;
}

.progress i {
  border-radius: inherit;
}

.bar-chart {
  min-height: 210px;
  border-color: #e1e7ed;
  align-items: stretch;
}

.bar-item {
  grid-template-rows: 130px 42px 18px;
  align-items: stretch;
}

.bar-track {
  height: 130px;
  border-radius: 10px 10px 4px 4px;
  background: #eef3f7;
  overflow: hidden;
  align-self: end;
}

.bar-track i {
  border-radius: inherit;
}

.bar-item span {
  min-height: 38px;
  display: grid;
  align-items: start;
  line-height: 1.15;
}

.bar-item strong {
  min-height: 18px;
  display: grid;
  align-items: end;
}

.pie-chart {
  border: 8px solid #f3f6f9;
  box-shadow: inset 0 0 0 1px #d7e0e8;
}

.table-title {
  padding: 12px 14px;
  border-bottom: 1px solid #edf1f5;
  font-size: 14px;
}

.income-title,
.expense-title,
.year-title,
.detail-title,
.loan-title {
  background: #f7fafc;
}

.income-title { color: #247a52; }
.expense-title { color: #a15c0c; }
.year-title, .detail-title { color: #2f6fa3; }
.loan-title { color: #b42318; }

.sheet-grid.head,
.loan-grid.head {
  background: #ffffff;
  color: #536273;
  border-top: 2px solid #2f6fa3;
  border-bottom: 1px solid #cbd7e1;
}

.sheet-grid.line,
.loan-grid.line {
  border-bottom: 1px solid #dfe7ee;
}

.money-cell {
  font-weight: 850;
}

.paid-box {
  border-radius: 10px;
  background: #fff4f3;
}

.installment-form {
  background: #fff8f6;
}

.daily-grid div,
.year-card,
.transaction-row,
.ocr-candidate {
  border-color: #e0e7ee;
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
}

.camera-box {
  border-color: #b9c8d6;
  border-radius: 16px;
  background: #f8fbfd;
}

.receipt-preview {
  border-radius: 14px;
  background: #e9eef3;
}

.backup-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.sheet-panel {
  border-radius: 0;
  box-shadow: none;
  border: 0;
  border-top: 1px solid #cbd7e1;
  background: #ffffff;
}

.sheet-panel + .sheet-panel {
  margin-top: 4px;
}

.table-title {
  padding: 12px 0 9px;
  border-bottom: 0;
  background: #ffffff !important;
  color: #17202a;
  font-size: 15px;
}

.income-title,
.expense-title,
.year-title,
.detail-title,
.loan-title {
  color: #17202a;
}

.sheet-grid,
.loan-grid {
  padding: 8px 0;
}

.sheet-grid.head,
.loan-grid.head {
  padding: 8px 0;
}

.sheet-grid.line input,
.loan-grid.line input {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  padding-left: 0;
}

.money-cell {
  justify-content: end;
}

.add-line {
  margin-top: 8px;
}

.daily-grid,
.year-grid {
  border-top: 2px solid #2f6fa3;
  padding-top: 8px;
}

.daily-grid div,
.year-card {
  box-shadow: none;
}

@media (min-width: 760px) {
  .template-title {
    grid-template-columns: auto 1fr auto;
  }
}

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

  .template-title {
    position: relative;
  }
}

@media (max-width: 420px) {
  .app {
    padding-inline: 10px;
  }

  .sheet-head {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .year-box {
    max-width: 150px;
  }

  .summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .tabs {
    margin-inline: 0;
  }
}

/* Money Pro inspired dark finance theme */
:root {
  --bg: #10252b;
  --paper: #19333a;
  --ink: #edf7f8;
  --muted: #9fb6bb;
  --line: rgba(159, 182, 187, 0.18);
  --green: #22c7a7;
  --green-soft: rgba(34, 199, 167, 0.14);
  --blue: #28b7d8;
  --blue-soft: rgba(40, 183, 216, 0.16);
  --orange: #f0b429;
  --orange-soft: rgba(240, 180, 41, 0.16);
  --red: #ff5b5f;
  --red-soft: rgba(255, 91, 95, 0.16);
  --shadow: 0 16px 30px rgba(0, 0, 0, 0.22);
  --shadow-soft: 0 1px 0 rgba(255, 255, 255, 0.06);
}

body {
  background:
    radial-gradient(circle at 50% -120px, rgba(44, 218, 218, .22), transparent 330px),
    linear-gradient(180deg, #10252b 0%, #122b32 48%, #0f2026 100%);
}

.app {
  color: var(--ink);
}

.sheet-head,
.summary article,
.template-title,
.template-note,
.template-block,
.panel,
.tabs {
  background: rgba(25, 51, 58, 0.92);
  border: 1px solid rgba(118, 229, 231, 0.12);
  box-shadow: var(--shadow);
}

.sheet-head {
  border-radius: 22px;
}

.eyebrow,
.sync-status,
.year-box,
.summary span,
.month-btn span,
.template-note,
.camera-box small,
.status,
label {
  color: var(--muted);
}

h1, h2,
.summary strong,
.template-block h2,
.panel h2,
.transaction-main strong {
  color: #f7ffff;
}

.sync-status {
  background: rgba(34, 199, 167, 0.12);
  color: #9cf4df;
}

.year-box,
input,
select,
textarea {
  background: rgba(9, 25, 30, 0.55);
  border-color: rgba(159, 182, 187, 0.2);
  color: #f5ffff;
}

input::placeholder,
textarea::placeholder {
  color: #789198;
}

.month-btn {
  background: rgba(25, 51, 58, 0.88);
  border: 1px solid rgba(159, 182, 187, 0.14);
  color: #f5ffff;
}

.month-btn.active,
.tab.active,
.primary {
  background: linear-gradient(180deg, #2dd4bf 0%, #159a82 100%);
  color: #06231f;
  box-shadow: 0 12px 24px rgba(34, 199, 167, 0.22);
}

.month-btn.active span,
.tab.active {
  color: #06231f;
}

.tab,
.secondary,
.add-line {
  background: rgba(255, 255, 255, 0.08);
  color: #e7f7f7;
}

.template-title span {
  background: rgba(40, 183, 216, 0.18);
  color: #95efff;
}

.template-title strong {
  background: rgba(34, 199, 167, 0.16);
  color: #a8ffe9;
}

.mini-table div,
.realization div,
.percent-table div {
  background: rgba(255, 255, 255, 0.06);
  color: #e9f8f8;
}

.mini-table span,
.realization span,
.percent-table span,
.transaction-main span,
.ocr-candidate span {
  color: var(--muted);
}

.positive {
  color: #45e3ad !important;
}

.negative {
  color: #ff7175 !important;
}

.progress {
  background: rgba(255, 255, 255, 0.12);
}

.progress i {
  background: linear-gradient(90deg, #25d0f2, #28d5a7);
}

.bar-chart {
  border-left-color: rgba(159, 182, 187, 0.22);
  border-bottom-color: rgba(159, 182, 187, 0.22);
}

.bar-track {
  background: rgba(255, 255, 255, 0.08);
}

.bar-track .blue { background: linear-gradient(180deg, #35c7f2, #2479b7); }
.bar-track .orange { background: linear-gradient(180deg, #ffd166, #f59e0b); }
.bar-track .green { background: linear-gradient(180deg, #6ee7b7, #35a852); }
.bar-track .red { background: linear-gradient(180deg, #ff7a7d, #ef4444); }

.pie-chart {
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(159, 182, 187, 0.16);
}

.percent-table div {
  grid-template-columns: 1fr auto 42px;
  position: relative;
  min-height: 52px;
  padding-left: 54px;
  border-radius: 16px;
}

.percent-table div::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 30px;
  height: 30px;
  border: 2px solid #c6d63f;
  border-radius: 50%;
  transform: translateY(-50%);
  background:
    radial-gradient(circle at 50% 50%, rgba(198, 214, 63, .24), transparent 48%),
    rgba(255, 255, 255, 0.04);
}

.sheet-panel {
  background: rgba(25, 51, 58, 0.86);
  border-top-color: rgba(40, 183, 216, 0.4);
}

.table-title {
  background: transparent !important;
  color: #dffbff;
}

.sheet-grid.head,
.loan-grid.head {
  background: transparent;
  border-top-color: rgba(40, 183, 216, 0.55);
  border-bottom-color: rgba(159, 182, 187, 0.18);
  color: #9fb6bb;
}

.sheet-grid.line,
.loan-grid.line {
  border-bottom-color: rgba(159, 182, 187, 0.16);
}

.money-cell,
.sheet-grid.line input,
.loan-grid.line input {
  color: #f5ffff;
}

.paid-box {
  background: rgba(255, 91, 95, 0.1);
  color: #ffb3b6;
}

.installment-form,
.camera-box,
.receipt-preview,
.transaction-row,
.ocr-candidate,
.daily-grid div,
.year-card {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(159, 182, 187, 0.16);
}

.camera-box {
  border-style: solid;
}

.camera-box span {
  color: #8ff4df;
}

.ocr-candidate button {
  background: rgba(255, 255, 255, 0.1);
  color: #f5ffff;
}

.delete-btn {
  background: rgba(255, 91, 95, 0.14);
  color: #ffb3b6;
}

@media (max-width: 420px) {
  .sheet-head {
    border-radius: 18px;
  }

  .summary article {
    min-height: 86px;
  }
}

/* Money Pro dashboard refinement */
.template-grid {
  align-items: stretch;
}

.chart-block {
  order: -3;
}

.category-block {
  order: -2;
}

.pie-block {
  order: -1;
}

.plan-block,
.realization-block {
  order: 1;
}

.chart-block,
.category-block,
.pie-block {
  background: linear-gradient(180deg, rgba(24, 55, 63, 0.96), rgba(15, 36, 42, 0.96));
}

.chart-block h2,
.category-block h2,
.pie-block h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(159, 182, 187, 0.18);
  color: #dffbff;
  text-transform: uppercase;
  font-size: 12px;
}

.chart-block h2::after {
  content: "plan / wykonanie";
  color: #f4c542;
  font-size: 11px;
  font-weight: 850;
  text-transform: none;
}

.bar-chart {
  min-height: 174px;
  padding: 12px 2px 0;
  border: 0;
  gap: 10px;
}

.bar-item {
  grid-template-rows: 104px 36px 18px;
}

.bar-track {
  height: 104px;
  border-radius: 4px;
  background:
    linear-gradient(rgba(255,255,255,.08) 1px, transparent 1px),
    rgba(255, 255, 255, 0.07);
  background-size: 100% 25%;
}

.bar-track i {
  border-radius: 4px 4px 0 0;
}

.bar-item span {
  min-height: 34px;
  color: #d5e8eb;
  font-size: 10px;
  font-weight: 750;
}

.bar-item strong {
  color: #ffffff;
  font-size: 10px;
}

.category-block {
  grid-column: 1 / -1;
}

.percent-table {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.percent-table div {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  align-content: start;
  gap: 4px;
  min-height: 124px;
  padding: 8px 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: center;
}

.percent-table div::before {
  display: none;
}

.cat-ring {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 2px solid #c8d23c;
  border-radius: 50%;
  color: #dffbff;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0;
  background:
    radial-gradient(circle at 50% 50%, rgba(40, 183, 216, .18), transparent 48%),
    rgba(255, 255, 255, 0.04);
  box-shadow:
    0 0 0 3px rgba(200, 210, 60, 0.08),
    inset 0 0 18px rgba(40, 183, 216, 0.12);
}

.progress-row,
.progress-row span,
.progress-row strong {
  color: #e8f7f9;
}

.progress-row span {
  opacity: .96;
}

.installment-title {
  color: #dffbff !important;
  font-size: 18px;
}

.installment-form {
  border-top: 1px solid rgba(40, 183, 216, 0.28);
}

.daily-grid div {
  background: rgba(255, 255, 255, 0.06);
  color: #e8f7f9;
}

.daily-grid div.has-value {
  background: rgba(244, 197, 66, 0.18);
  border-color: rgba(244, 197, 66, 0.55);
}

.daily-grid div.has-value span,
.daily-grid div.has-value strong,
.daily-grid div.has-value em {
  color: #fff5c2;
}

.daily-grid span,
.daily-grid strong,
.daily-grid em {
  color: #d8ecef;
}

.sheet-grid.head,
.loan-grid.head {
  color: #cfe1e5;
}

.sheet-grid.line input,
.loan-grid.line input,
.money-cell {
  color: #ffffff;
}

.loan-grid.line,
.sheet-grid.line {
  color: #f5ffff;
}

/* Readability fixes for bright cells inside dark theme */
.sheet-grid.line .money-cell,
.loan-grid.line .money-cell {
  background: #f4efe6;
  color: #13242a !important;
  border: 1px solid rgba(255, 255, 255, 0.22);
  font-weight: 900;
}

.sheet-grid.line .money-cell.positive,
.loan-grid.line .money-cell.positive {
  color: #159a74 !important;
}

.sheet-grid.line .money-cell.negative,
.loan-grid.line .money-cell.negative {
  color: #d9384a !important;
}

.sheet-grid.line input,
.loan-grid.line input {
  background: rgba(255, 255, 255, 0.08);
  color: #f7ffff !important;
  border: 1px solid rgba(159, 182, 187, 0.18);
  border-radius: 10px;
  padding-left: 10px;
}

.daily-grid div.has-value {
  background: #fff4bf;
  border-color: #d7bd3f;
}

.daily-grid div.has-value span {
  color: #6a5a12 !important;
}

.daily-grid div.has-value strong,
.daily-grid div.has-value em {
  color: #4a230f !important;
  font-weight: 900;
}

.daily-grid div:not(.has-value) span,
.daily-grid div:not(.has-value) strong,
.daily-grid div:not(.has-value) em {
  color: #d8ecef !important;
}

/*
.percent-table div::before {
  width: 48px;
  height: 48px;
  transform: none;
  border: 2px solid #c8d23c;
  box-shadow:
    0 0 0 3px rgba(200, 210, 60, 0.08),
    inset 0 0 18px rgba(40, 183, 216, 0.12);
}
*/

.percent-table span {
  max-width: 100%;
  min-height: 28px;
  display: grid;
  align-items: end;
  color: #eefbfc;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.percent-table strong {
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(244, 197, 66, 0.92);
  color: #182a2f;
  font-size: 12px;
}

.percent-table em {
  color: #8addec;
  font-size: 10px;
  font-style: normal;
  font-weight: 750;
}

.pie-block {
  grid-column: 1 / -1;
}

.pie-block .pie-chart {
  width: min(210px, 62vw);
  border-width: 0;
  box-shadow:
    inset 0 0 0 18px rgba(11, 28, 34, 0.68),
    0 0 0 1px rgba(159, 182, 187, 0.16);
}

.pie-legend {
  grid-template-columns: 1fr;
  gap: 6px;
  color: #dffbff;
}

.pie-legend span {
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid rgba(159, 182, 187, 0.12);
}

.plan-block,
.realization-block {
  background: rgba(25, 51, 58, 0.82);
}

.template-note {
  display: none;
}

.summary article {
  position: relative;
  overflow: hidden;
}

.summary article::after {
  content: "";
  position: absolute;
  inset: auto 12px 9px 12px;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, #25d0f2, #28d5a7);
  opacity: .72;
}

.summary article:nth-child(2)::after {
  background: linear-gradient(90deg, #ffd166, #f59e0b);
}

.summary article:nth-child(3)::after,
.summary article:nth-child(4)::after {
  background: linear-gradient(90deg, #45e3ad, #25d0f2);
}

@media (min-width: 760px) {
  .chart-block {
    grid-column: span 1;
  }

  .pie-block {
    grid-column: span 1;
  }
}

@media (max-width: 720px) {
  .percent-table {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .percent-table {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .percent-table div {
    min-height: 116px;
  }

  .cat-ring {
    width: 47px;
    height: 47px;
    font-size: 21px;
  }
}
