:root {
  --ink: #14110f;
  --muted: #6f655c;
  --paper: #f7f1e8;
  --panel: #fffaf3;
  --line: #e5d8c6;
  --gold: #b8842d;
  --gold-deep: #8f6418;
  --green: #1f6b4a;
  --danger: #a33b2d;
  --shadow: 0 18px 50px rgba(40, 28, 12, 0.12);
  --display: "Noto Serif SC", "Songti SC", serif;
  --sans: "DM Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  background:
    linear-gradient(180deg, #efe6d8 0%, var(--paper) 38%, #f3ebe0 100%);
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 0%, rgba(184, 132, 45, 0.18), transparent 32%),
    radial-gradient(circle at 88% 8%, rgba(31, 107, 74, 0.10), transparent 28%),
    repeating-linear-gradient(
      -12deg,
      transparent 0 18px,
      rgba(255,255,255,0.18) 18px 19px
    );
  z-index: 0;
}

.hidden { display: none !important; }

.topbar, .page, .toast { position: relative; z-index: 1; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  border-bottom: 1px solid rgba(229, 216, 198, 0.9);
  background: rgba(255, 250, 243, 0.78);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #d7a84a, #8f6418);
  color: #fff8ea;
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(143, 100, 24, 0.28);
}
.brand strong {
  display: block;
  font-family: var(--display);
  font-size: 24px;
  letter-spacing: 0.04em;
}
.brand em {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}
.user-label {
  color: var(--muted);
  font-size: 14px;
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 18px 56px;
  display: grid;
  gap: 22px;
}

.hero {
  display: grid;
  grid-template-columns: 1.15fr 0.95fr;
  gap: 22px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.72), rgba(255,250,243,0.92)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23b8842d' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise .5s ease both;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold-deep);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
}
.hero h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(32px, 5vw, 46px);
  line-height: 1.15;
}
.hero-desc {
  margin: 10px 0 18px;
  color: var(--muted);
  max-width: 36ch;
}
.hero-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.month-nav {
  display: inline-flex;
  align-items: stretch;
  gap: 8px;
  height: 42px;
}
.month-nav .btn-month,
.month-select-wrap {
  height: 42px;
  box-sizing: border-box;
  margin: 0;
  flex-shrink: 0;
}
.month-select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-width: 132px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0 28px 0 14px;
}
.month-select-wrap::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--muted);
  transform: translateY(-40%);
  pointer-events: none;
}
.month-select-wrap select {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
  text-align: left;
}
.btn-month {
  min-width: 64px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 14px;
  line-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-month:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.hero-stats {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 8px 4px;
}
.metric {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(229, 216, 198, 0.9);
}
.metric.big {
  background: linear-gradient(160deg, #1d1712, #2d241c);
  color: #f8efe1;
  border: none;
}
.metric.big strong {
  color: #f0c56d;
  font-size: 36px;
}
.metric span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.metric.big span { color: rgba(248, 239, 225, 0.72); }
.metric strong {
  font-family: var(--display);
  font-size: 24px;
  font-weight: 700;
}
.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.progress-wrap { margin-top: 2px; }
.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(20, 17, 15, 0.08);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), #e0b35a 55%, var(--green));
  transition: width .45s ease;
}
.progress-text {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.ledger-panel, .chart-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 22px;
  animation: rise .55s ease both;
}
.chart-panel { animation-delay: .08s; }

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 24px;
}
.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fffdf8;
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.ledger-table .col-date { width: 22%; }
.ledger-table .col-week { width: 14%; }
.ledger-table .col-num { width: 21.333%; }
.ledger-table th,
.ledger-table td {
  padding: 12px 10px;
  border-bottom: 1px solid #efe4d4;
  text-align: center;
  font-size: 14px;
  vertical-align: middle;
}
.ledger-table thead th {
  position: sticky;
  top: 0;
  background: #f3e8d8;
  color: var(--muted);
  font-weight: 600;
  z-index: 1;
  text-align: center;
}
.ledger-table tbody tr {
  transition: background .18s ease, transform .18s ease;
}
.ledger-table tbody tr:hover {
  background: #fff4df;
}
.ledger-table tbody tr.is-today {
  background: linear-gradient(90deg, rgba(184,132,45,0.12), transparent 55%);
}
.ledger-table tbody tr.is-weekend .day-date {
  color: var(--gold-deep);
}
.ledger-table tfoot th {
  background: #1d1712;
  color: #f8efe1;
  border: none;
  font-family: var(--display);
  font-size: 16px;
  vertical-align: middle;
  text-align: center;
}
.ledger-table tfoot .foot-metric {
  text-align: center;
}
.ledger-table tfoot .foot-metric span {
  display: block;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  color: rgba(248, 239, 225, 0.65);
  margin-bottom: 4px;
}
.ledger-table tfoot .foot-metric strong {
  font-size: 20px;
  color: #f0c56d;
  font-weight: 700;
}

.day-date {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.day-week {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.cell-edit {
  width: 100%;
  margin: 0;
  display: block;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  color: var(--ink);
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-sizing: border-box;
  -moz-appearance: textfield;
  appearance: textfield;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.cell-edit::-webkit-outer-spin-button,
.cell-edit::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.ledger-table tbody tr:hover .cell-edit {
  background: rgba(255, 255, 255, 0.55);
}
.cell-edit:focus {
  background: #fff;
  border-color: #d8bf95;
  outline: none;
  box-shadow: 0 0 0 3px rgba(184, 132, 45, 0.15);
}
.cell-total {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease, color .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-gold {
  background: linear-gradient(145deg, #d7a84a, #8f6418);
  color: #fff8ea;
  box-shadow: 0 8px 18px rgba(143, 100, 24, 0.25);
}
.btn-outline {
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}
.file-btn { display: inline-flex; align-items: center; cursor: pointer; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #1d1712;
  color: #fff8ea;
  padding: 12px 16px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 50;
}
.toast.error { background: #7f1d1d; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(184,132,45,0.2), transparent 30%),
    linear-gradient(160deg, #1d1712, #3a2c1d 55%, #1f6b4a);
}
.login-card {
  width: min(420px, 100%);
  background: #fffaf3;
  border-radius: 28px;
  padding: 32px;
  box-shadow: var(--shadow);
  animation: rise .45s ease both;
}
.login-card h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 36px;
  color: var(--ink);
}
.login-sub {
  margin: 8px 0 22px;
  color: var(--muted);
}
.login-card form {
  display: grid;
  gap: 14px;
}
.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}
.login-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  font: inherit;
  background: #fff;
}
.login-card button { width: 100%; }
.error-text { color: var(--danger); font-size: 14px; margin: 0; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .metric-row { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .topbar { padding: 14px; }
  .brand em { display: none; }
  .page { padding: 16px 12px 40px; }
  .hero, .ledger-panel, .chart-panel { padding: 16px; border-radius: 20px; }
}
