:root {
  --ink: #172238;
  --muted: #677186;
  --paper: #f7f6f2;
  --panel: #ffffff;
  --line: #e2e4e8;
  --navy: #1d3156;
  --navy-deep: #13213b;
  --coral: #db6b58;
  --coral-dark: #b64d3d;
  --gold: #d7ad52;
  --green: #1f7a5d;
  --green-soft: #e8f5ef;
  --red: #b64040;
  --red-soft: #fbecec;
  --amber: #98670f;
  --amber-soft: #fff5dc;
  --shadow: 0 18px 45px rgba(28, 40, 64, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
[hidden] { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(235px, 1fr) auto minmax(210px, 1fr);
  align-items: center;
  gap: 28px;
  min-height: 78px;
  padding: 12px clamp(18px, 4vw, 64px);
  color: white;
  background: linear-gradient(120deg, var(--navy-deep), var(--navy));
  box-shadow: 0 8px 24px rgba(13, 27, 53, 0.16);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  width: fit-content;
}

.brand strong { display: block; font-size: 1.08rem; letter-spacing: 0.01em; }
.brand small { display: block; color: rgba(255,255,255,.68); font-size: .72rem; }

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  color: var(--navy-deep);
  background: linear-gradient(145deg, #f0ca79, var(--gold));
  font-weight: 800;
  letter-spacing: -0.04em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45);
}

.brand-mark-large { width: 64px; height: 64px; font-size: 1.25rem; }

.main-nav { display: flex; align-items: center; gap: 6px; }
.main-nav { scrollbar-width: none; }
.main-nav::-webkit-scrollbar { display: none; }
.main-nav a {
  padding: 9px 12px;
  border-radius: 10px;
  color: rgba(255,255,255,.76);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 650;
  transition: .15s ease;
}
.main-nav a:hover, .main-nav a.active { color: white; background: rgba(255,255,255,.1); }

.user-menu { display: flex; justify-content: flex-end; align-items: center; gap: 14px; color: rgba(255,255,255,.8); font-size: .82rem; }
.user-menu form { margin: 0; }
.text-button { padding: 0; border: 0; color: white; background: transparent; text-decoration: underline; text-underline-offset: 3px; }

.page { width: min(1240px, calc(100% - 36px)); min-height: calc(100vh - 150px); margin: 0 auto; padding: 48px 0 72px; }
.footer { display: flex; justify-content: space-between; gap: 24px; padding: 22px clamp(18px,4vw,64px); color: var(--muted); border-top: 1px solid var(--line); font-size: .78rem; }

.page-heading { margin-bottom: 28px; }
.page-heading h1 { margin: 3px 0 6px; font-size: clamp(2rem, 4vw, 3.1rem); line-height: 1.05; letter-spacing: -0.04em; }
.page-heading p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: 1.02rem; }
.split-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.heading-actions { display: flex; align-items: flex-end; gap: 12px; }
.report-export-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.report-export-note { margin-bottom: 22px; }
.eyebrow { margin: 0; color: var(--coral-dark); font-size: .73rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.back-link { display: inline-block; margin-bottom: 18px; color: var(--muted); text-decoration: none; font-weight: 650; }
.back-link:hover, .link:hover, .text-link:hover { color: var(--coral-dark); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 11px;
  text-decoration: none;
  font-weight: 750;
  font-size: .9rem;
  transition: transform .12s ease, background .12s ease, box-shadow .12s ease;
}
.button:hover { transform: translateY(-1px); }
.button-primary { color: white; background: var(--coral); box-shadow: 0 9px 20px rgba(219,107,88,.22); }
.button-primary:hover { background: var(--coral-dark); }
.button-secondary { color: var(--navy); background: #eef1f7; border-color: #dce2ed; }
.button-secondary:hover { background: #e5eaf3; }
.button-ghost { color: var(--muted); background: transparent; border-color: var(--line); }
.button-danger { color: white; background: var(--red); }
.button-wide { width: 100%; }
.link, .text-link, .row-action { color: var(--navy); font-weight: 700; text-decoration: none; }
.row-action { color: var(--coral-dark); white-space: nowrap; }

.notice { margin: 0 0 22px; padding: 13px 16px; border: 1px solid transparent; border-radius: 11px; font-size: .92rem; }
.notice-success { color: #145940; background: var(--green-soft); border-color: #bee4d3; }
.notice-error { color: #8e2929; background: var(--red-soft); border-color: #efc6c6; }
.notice-info { color: #345179; background: #edf3fb; border-color: #ccdbee; }
.review-explanation { display: grid; gap: 10px; }
.review-explanation > strong { color: var(--ink); }
.review-reasons { min-width: 340px; }
.review-reason { display: grid; gap: 5px; margin-bottom: 11px; }
.review-reason:last-child { margin-bottom: 0; }
.review-reason small { max-width: 440px; margin: 0; color: #5f6879; line-height: 1.45; }
.review-explanation .review-reason { grid-template-columns: max-content 1fr; align-items: start; margin: 0; }
.review-explanation .review-reason .badge { margin-top: 1px; }
.source-note-inline { margin-top: 8px; padding: 7px 9px; border-radius: 8px; color: #6d5628 !important; background: var(--amber-soft); }
.review-actions { min-width: 112px; }
.review-actions form { margin-top: 8px; }
.text-button-inline { padding: 0; border: 0; color: var(--coral-dark); background: transparent; font-size: .78rem; font-weight: 750; text-decoration: underline; text-underline-offset: 3px; }
.panel-note-block { margin: -8px 0 14px; }

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 22px; }
.metric-grid-report { grid-template-columns: repeat(3, minmax(0,1fr)); }
.metric-card {
  position: relative;
  overflow: hidden;
  min-height: 150px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.metric-card::after { content: ""; position: absolute; right: -34px; bottom: -52px; width: 130px; height: 130px; border-radius: 50%; background: #f4eee1; }
.metric-card > * { position: relative; z-index: 1; }
.metric-card span { display: block; color: var(--muted); font-size: .82rem; font-weight: 750; }
.metric-card strong { display: block; margin-top: 12px; font-size: clamp(1.75rem,3vw,2.4rem); line-height: 1; letter-spacing: -0.04em; }
.metric-card small { display: block; margin-top: 12px; color: var(--muted); }
.metric-card-featured { color: white; border-color: transparent; background: linear-gradient(135deg, var(--navy-deep), #284872); }
.metric-card-featured::after { background: rgba(215,173,82,.15); }
.metric-card-featured span, .metric-card-featured small { color: rgba(255,255,255,.68); }

.content-grid { display: grid; gap: 22px; margin-bottom: 22px; }
.content-grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.panel {
  margin-bottom: 22px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.content-grid > .panel { margin-bottom: 0; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.panel-heading h2, .panel h2 { margin: 3px 0 0; font-size: 1.35rem; letter-spacing: -0.02em; }
.panel-note { color: var(--muted); font-size: .82rem; }
.panel-attention { background: linear-gradient(145deg, #fff9ee, #fffdf8); border-color: #ecdcb4; }
.attention-number { margin: 14px 0 2px; color: var(--coral-dark); font-size: 3.8rem; font-weight: 820; line-height: 1; letter-spacing: -0.05em; }
.attention-number-muted { color: var(--navy); }
.panel-attention > p:not(.eyebrow) { color: #6d6047; }

.summary-list { margin: 0; }
.summary-list > div { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.summary-list dt, .summary-list dd { margin: 0; }
.summary-list dt { color: var(--muted); }
.summary-list dt small { display: block; margin-top: 3px; color: #9098a7; font-size: .72rem; }
.summary-list dd { font-weight: 780; }
.summary-list .summary-total { padding-top: 18px; border-bottom: 0; color: var(--ink); font-size: 1.06rem; }
.summary-list .summary-total dt { color: var(--ink); font-weight: 780; }

.amount-positive { color: var(--green) !important; }
.amount-negative { color: var(--red) !important; }
.align-right { text-align: right; font-variant-numeric: tabular-nums; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { padding: 11px 12px; color: var(--muted); border-bottom: 1px solid var(--line); text-align: left; font-size: .7rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; white-space: nowrap; }
td { padding: 14px 12px; border-bottom: 1px solid #edf0f3; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfbfc; }
td strong { display: block; font-size: .9rem; }
td small { display: block; max-width: 420px; margin-top: 3px; color: var(--muted); }
.row-warning { background: #fffaf0; }
.badge { display: inline-flex; align-items: center; width: fit-content; margin-top: 6px; padding: 3px 8px; border-radius: 999px; color: #41516e; background: #eaf0f8; font-size: .67rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.badge-warning { color: var(--amber); background: var(--amber-soft); }

.filter-panel {
  display: grid;
  grid-template-columns: .7fr .9fr 1fr 1.5fr auto;
  align-items: end;
  gap: 14px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}
.filter-panel label, .stack-form label, .entry-form label, .compact-select { display: grid; gap: 6px; }
.filter-panel label > span, .stack-form label > span, .entry-form label > span, .compact-select > span { color: #4f5c73; font-size: .76rem; font-weight: 750; }
.filter-panel input, .filter-panel select,
.stack-form input, .entry-form input, .entry-form select, .entry-form textarea, .compact-select select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  border: 1px solid #cfd5df;
  border-radius: 9px;
  background: white;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #6981a6 !important; box-shadow: 0 0 0 3px rgba(63,91,133,.12); }
.check-filter { grid-column: 1 / -2; display: flex !important; align-items: center; gap: 8px !important; color: var(--muted); font-size: .8rem; }
.check-filter input { width: auto; min-height: 0; }
.filter-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.panel-table { padding: 8px 14px; }
.pagination { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.pagination a { display: grid; place-items: center; min-width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px; background: white; text-decoration: none; font-weight: 700; }
.pagination a.active { color: white; border-color: var(--navy); background: var(--navy); }

.entry-form { max-width: 920px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.form-span-2 { grid-column: span 2; }
.entry-form textarea { resize: vertical; }
.entry-form label > span small { color: #969dab; font-weight: 500; }
.field-error { color: var(--red); font-size: .76rem; }
.input-money { position: relative; }
.input-money input { padding-right: 38px; }
.input-money span { position: absolute; right: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.static-field { display: flex; align-items: center; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #f5f6f8; }
.checkbox-field { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 10px !important; padding: 12px 14px; border-radius: 10px; background: var(--amber-soft); }
.checkbox-field input { width: auto; min-height: 0; }
.checkbox-field span { color: #6d5628 !important; }
.form-actions { display: flex; gap: 10px; margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line); }
.provenance-panel { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; max-width: 920px; }
.provenance-panel p { margin-bottom: 0; color: var(--muted); }
.source-note { padding: 10px 12px; border-radius: 9px; color: #6b5629 !important; background: var(--amber-soft); }
.hash-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .72rem; overflow-wrap: anywhere; }
.danger-zone { display: flex; justify-content: space-between; align-items: center; gap: 20px; max-width: 920px; margin-top: 32px; padding: 20px 22px; border: 1px solid #efcece; border-radius: 14px; background: #fffafa; }
.danger-zone h2 { margin: 0; font-size: 1rem; }
.danger-zone p { margin: 4px 0 0; color: var(--muted); font-size: .82rem; }
.error-panel { max-width: 680px; margin: 10vh auto; text-align: center; }
.empty-state { padding: 30px; color: var(--muted); text-align: center; }

.login-shell { min-height: 100vh; background: radial-gradient(circle at 15% 15%, rgba(215,173,82,.22), transparent 28%), linear-gradient(145deg, var(--navy-deep), #223c65 62%, #325174); }
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card { width: min(480px, 100%); padding: clamp(28px,6vw,46px); border: 1px solid rgba(255,255,255,.45); border-radius: 24px; background: rgba(255,255,255,.97); box-shadow: 0 30px 80px rgba(5,18,40,.28); }
.login-brand { display: flex; align-items: center; gap: 18px; margin-bottom: 28px; }
.login-brand h1 { margin: 3px 0 4px; font-size: 2rem; letter-spacing: -0.04em; }
.login-brand p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: .9rem; }
.stack-form { display: grid; gap: 18px; }

@media (max-width: 980px) {
  .topbar { position: static; grid-template-columns: 1fr auto; gap: 12px; }
  .main-nav { grid-column: 1 / -1; order: 3; overflow-x: auto; padding-top: 4px; border-top: 1px solid rgba(255,255,255,.1); }
  .user-menu > span { display: none; }
  .filter-panel { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .check-filter { grid-column: 1 / -1; }
  .filter-actions { justify-content: flex-start; }
}

@media (max-width: 740px) {
  .page { width: min(100% - 24px, 1240px); padding-top: 30px; }
  .split-heading, .heading-actions, .danger-zone, .footer { align-items: stretch; flex-direction: column; }
  .heading-actions { display: grid; }
  .report-export-actions { display: grid; grid-template-columns: 1fr; }
  .report-export-actions .button { width: 100%; }
  .metric-grid, .metric-grid-report, .content-grid-2 { grid-template-columns: 1fr; }
  .metric-card { min-height: 130px; }
  .form-grid, .filter-panel { grid-template-columns: 1fr; }
  .form-span-2, .check-filter { grid-column: span 1; }
  .filter-actions { flex-wrap: wrap; }
  .panel { padding: 20px; }
  .panel-table { padding: 5px; }
  .main-nav a { white-space: nowrap; }
  .brand small { display: none; }
  .user-menu { justify-self: end; }
  .login-brand { align-items: flex-start; }
}

@media print {
  body { background: white; }
  .topbar, .footer, .heading-actions, .button, .filter-panel, .danger-zone, .back-link { display: none !important; }
  .page { width: 100%; padding: 0; }
  .panel, .metric-card { box-shadow: none; break-inside: avoid; }
}
