:root {
  --bg: #f7f5f8;
  --surface: #ffffff;
  --surface-soft: #fbf9fb;
  --surface-accent: #fff0f5;
  --text: #28232a;
  --muted: #716a72;
  --line: #e7dfe5;
  --line-strong: #d6c8d2;
  --accent: #b0476a;
  --accent-strong: #8e3454;
  --accent-soft: #f9dce6;
  --income: #377f6f;
  --income-strong: #286454;
  --income-soft: #eff8f5;
  --income-line: #cce2db;
  --expense: #ad4162;
  --expense-strong: #87304d;
  --expense-chart: #c96683;
  --expense-soft: #fff0f5;
  --expense-surface: #fff9fb;
  --expense-line: #ecc6d3;
  --danger: #a13939;
  --shadow: 0 16px 42px rgba(105, 75, 91, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI Variable Text", "PingFang SC", "Microsoft YaHei UI", "Noto Sans SC", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease, transform 0.1s ease;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.page {
  min-height: 100dvh;
}

.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card,
.panel,
.entry-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(105, 75, 91, 0.05);
}

.auth-card {
  width: min(440px, 100%);
  padding: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand.compact h1 {
  font-size: 1.15rem;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.3rem;
  line-height: 1.25;
  font-weight: 700;
}

h2 {
  font-size: 1.05rem;
  line-height: 1.35;
  font-weight: 700;
}

h1,
h2 {
  font-family: "Segoe UI Variable Display", "PingFang SC", "Microsoft YaHei UI", system-ui, sans-serif;
}

.brand p,
.security-note,
.panel-head span,
.entry-panel-head p {
  color: var(--muted);
  font-size: 0.86rem;
}

.mode-tabs,
.type-switch {
  display: grid;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3eef2;
}

.mode-tabs {
  grid-template-columns: 1fr 1fr;
  margin: 22px 0 16px;
}

.mode-tabs button,
.type-switch span {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  font-weight: 600;
}

.mode-tabs button.is-active,
.type-switch input:checked + span {
  background: #fff;
  color: var(--text);
  box-shadow: 0 5px 14px rgba(105, 75, 91, 0.1);
}

.auth-form,
.entry-form {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: #4a424b;
  font-weight: 600;
  font-size: 0.9rem;
}

input,
textarea,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  outline: none;
}

textarea {
  min-height: 66px;
  padding-top: 10px;
  padding-bottom: 10px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #82909a;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(176, 71, 106, 0.72);
  box-shadow: 0 0 0 3px rgba(176, 71, 106, 0.12);
}

button:focus-visible,
summary:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(176, 71, 106, 0.2);
  outline-offset: 2px;
}

.primary-button,
.ghost-button,
.danger-button,
.icon-button {
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  color: #fff;
  background: var(--accent-strong);
}

.primary-button:hover {
  background: #762a46;
}

.ghost-button,
.icon-button {
  color: #4a424b;
  background: #fff;
  border-color: var(--line);
}

.ghost-button:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.danger-button {
  color: var(--danger);
  background: #fff6f6;
  border-color: #efc9c9;
}

.security-note {
  margin-top: 14px;
  line-height: 1.65;
}

.auth-terms-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.55;
}

.auth-terms-row input {
  width: 17px;
  min-height: 17px;
  margin-top: 2px;
  accent-color: var(--accent);
}

.auth-terms-row a,
.auth-legal-links a,
.legal-page a {
  color: var(--accent-strong);
  text-decoration: none;
}

.auth-terms-row a:hover,
.auth-legal-links a:hover,
.legal-page a:hover {
  text-decoration: underline;
}

.auth-legal-links {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.legal-page {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 64px;
}

.legal-header {
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.legal-header p,
.legal-section p,
.legal-section li {
  color: #475569;
  line-height: 1.8;
}

.legal-section {
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}

.legal-section h2 {
  margin-bottom: 9px;
}

.legal-section ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.legal-back {
  display: inline-flex;
  margin-top: 24px;
  font-weight: 700;
}

.install-app-button {
  width: 100%;
  min-height: 42px;
  margin-top: 12px;
  border: 1px solid rgba(176, 71, 106, 0.34);
  border-radius: 7px;
  color: var(--accent-strong);
  background: #fff5f8;
  font-weight: 700;
}

.top-actions .install-app-button {
  width: auto;
  margin-top: 0;
}

.install-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(31, 41, 55, 0.2);
}

.install-dialog::backdrop {
  background: rgba(23, 33, 47, 0.42);
}

.install-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.install-dialog-head > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.install-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.install-dialog-head .icon-button {
  width: 38px;
  padding: 0;
  font-size: 1.3rem;
}

.install-instructions {
  padding: 18px 20px 22px;
}

.install-instructions ol {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 22px;
  color: #334155;
}

.install-instructions li {
  padding-left: 4px;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 253, 0.96);
  backdrop-filter: blur(12px);
  box-shadow: 0 5px 20px rgba(105, 75, 91, 0.045);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.user-chip {
  padding: 8px 10px;
  border-radius: 7px;
  color: #594c55;
  background: #f7edf2;
  font-size: 0.86rem;
  font-weight: 600;
}

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.admin-banner {
  width: min(1360px, calc(100% - 36px));
  margin: 16px auto 0;
  border: 1px solid #facc15;
  border-radius: 8px;
  padding: 12px 14px;
  color: #713f12;
  background: #fef9c3;
  font-weight: 700;
}

.admin-panel {
  width: min(1360px, calc(100% - 36px));
  margin: 18px auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 16px;
}

.admin-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.admin-panel-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(360px, 1.2fr);
  gap: 14px;
}

.admin-access-panel,
.admin-audit-panel {
  grid-column: 1 / 3;
}

.admin-user-list,
.admin-record-list,
.admin-audit-list,
.admin-code-list {
  display: grid;
  gap: 8px;
}

.access-code-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: var(--line);
}

.access-code-stats span {
  display: grid;
  gap: 2px;
  padding: 11px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.access-code-stats strong {
  color: var(--text);
  font-size: 1.08rem;
}

.admin-code-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(150px, 0.7fr) minmax(210px, 0.9fr) auto;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 2px;
}

.admin-code-row > div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.admin-code-row strong {
  overflow-wrap: anywhere;
}

.admin-code-row span {
  color: var(--muted);
  font-size: 0.78rem;
}

.code-status {
  width: max-content;
  font-weight: 700;
}

.code-status-unused {
  color: #7c5b12 !important;
}

.code-status-active {
  color: var(--expense-strong) !important;
}

.code-status-revoked {
  color: var(--danger) !important;
}

.access-code-dialog {
  width: min(520px, calc(100vw - 28px));
}

.account-security-dialog {
  width: min(460px, calc(100vw - 28px));
}

.access-code-form,
.access-code-result,
.account-security-form {
  display: grid;
  gap: 13px;
  padding: 18px 20px 22px;
}

.account-security-note {
  color: var(--muted);
  font-size: 0.84rem;
}

.access-code-result p {
  color: var(--danger);
  font-size: 0.84rem;
  font-weight: 600;
}

.access-code-result textarea {
  min-height: 210px;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.65;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-user-row,
.admin-audit-row {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 10px;
  text-align: left;
}

.admin-user-row {
  display: grid;
  gap: 5px;
}

.admin-user-row.is-active {
  border-color: var(--accent);
  background: var(--surface-accent);
}

.admin-user-row strong,
.admin-audit-row strong {
  color: var(--text);
}

.admin-user-row span,
.admin-audit-row span,
.admin-detail-actions {
  color: var(--muted);
  font-size: 0.8rem;
}

.admin-detail-actions {
  margin-bottom: 10px;
}

.admin-record-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}

.entry-panel {
  position: sticky;
  top: 90px;
  padding: 18px;
}

.entry-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.entry-panel-head p {
  margin-top: 3px;
}

.entry-form small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 400;
}

.amount-field {
  position: relative;
  display: block;
}

.amount-field input {
  padding-left: 36px;
  font-size: 1.08rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.currency-prefix {
  position: absolute;
  left: 13px;
  top: 50%;
  z-index: 1;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
}

.entry-form[data-entry-type="expense"] .amount-field input:focus {
  border-color: var(--expense);
  box-shadow: 0 0 0 3px rgba(173, 65, 98, 0.12);
}

.entry-form[data-entry-type="income"] .amount-field input:focus {
  border-color: var(--income);
  box-shadow: 0 0 0 3px rgba(55, 127, 111, 0.12);
}

.type-switch {
  grid-template-columns: 1fr 1fr;
}

.type-switch label {
  display: block;
}

.type-switch span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.type-switch span::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  content: "";
  opacity: 0.82;
}

.type-switch input[value="expense"] + span::before {
  background: var(--expense);
}

.type-switch input[value="income"] + span::before {
  background: var(--income);
}

.type-switch input[value="expense"]:checked + span {
  color: var(--expense-strong);
  background: var(--expense-soft);
  box-shadow: inset 0 0 0 1px var(--expense-line), 0 4px 10px rgba(173, 65, 98, 0.08);
}

.type-switch input[value="income"]:checked + span {
  color: var(--income-strong);
  background: var(--income-soft);
  box-shadow: inset 0 0 0 1px var(--income-line), 0 4px 10px rgba(55, 127, 111, 0.08);
}

.type-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  opacity: 0;
  pointer-events: none;
}

.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip-row button {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #4a424b;
  background: #fff;
  padding: 0 10px;
  font-weight: 600;
}

.chip-row button:hover,
.chip-row button.is-active {
  border-color: rgba(176, 71, 106, 0.42);
  color: var(--accent-strong);
  background: var(--surface-accent);
}

.entry-form[data-entry-type="expense"] .category-chips button.is-active {
  border-color: var(--expense-line);
  color: var(--expense-strong);
  background: var(--expense-soft);
}

.entry-form[data-entry-type="income"] .category-chips button.is-active {
  border-color: var(--income-line);
  color: var(--income-strong);
  background: var(--income-soft);
}

.category-more-button {
  justify-self: start;
  min-height: 28px;
  margin-top: -5px;
  border: 0;
  padding: 0 2px;
  color: var(--accent-strong);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 600;
}

.category-more-button:hover {
  color: var(--text);
}

.account-chips {
  margin-top: -5px;
  gap: 6px;
}

.account-chips button {
  min-height: 26px;
  padding: 0 8px;
  font-size: 0.78rem;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.entry-form[data-entry-type="expense"] #submitBtn {
  background: var(--expense);
}

.entry-form[data-entry-type="expense"] #submitBtn:hover {
  background: var(--expense-strong);
}

.entry-form[data-entry-type="income"] #submitBtn {
  background: var(--income);
}

.entry-form[data-entry-type="income"] #submitBtn:hover {
  background: var(--income-strong);
}

.dashboard {
  display: grid;
  gap: 18px;
  transition: opacity 0.16s ease;
}

.dashboard.is-loading {
  opacity: 0.58;
}

.month-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.month-bar h2 {
  min-width: 136px;
  text-align: center;
  font-size: 1.15rem;
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 1.35rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
}

.overview-panel {
  display: grid;
  grid-template-columns: minmax(250px, 0.78fr) minmax(0, 1.6fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(105, 75, 91, 0.05);
}

.expense-summary {
  min-height: 132px;
  display: grid;
  gap: 4px;
  align-content: center;
  padding: 20px 22px;
  border-right: 1px solid var(--expense-line);
  background: var(--expense-surface);
  box-shadow: inset 4px 0 0 var(--expense-chart);
}

.expense-summary > span,
.metric-item > span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.expense-summary > strong {
  color: var(--expense-strong);
  font-family: "Segoe UI Variable Display", "PingFang SC", "Microsoft YaHei UI", system-ui, sans-serif;
  font-size: clamp(1.75rem, 2.8vw, 2.2rem);
  line-height: 1.15;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.expense-summary p {
  color: var(--muted);
  font-size: 0.78rem;
}

.metric-item {
  min-width: 0;
  min-height: 132px;
  display: grid;
  gap: 8px;
  align-content: center;
  padding: 18px;
  border-left: 1px solid var(--line);
}

.metric-item:first-child {
  border-left: 0;
}

.metric-item strong {
  overflow: hidden;
  color: var(--text);
  font-family: "Segoe UI Variable Display", "PingFang SC", "Microsoft YaHei UI", system-ui, sans-serif;
  font-size: 1.12rem;
  line-height: 1.25;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-item .income-value {
  color: var(--income);
}

.metric-item .expense-value {
  color: var(--expense-strong);
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.analysis-panel {
  min-width: 0;
  box-shadow: none;
}

.panel-head > div {
  min-width: 0;
}

.panel-head > div > span {
  display: block;
  margin-top: 3px;
}

.category-chart {
  display: grid;
  gap: 3px;
}

.category-chart-row {
  width: 100%;
  min-height: 48px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 0;
  border-radius: 6px;
  padding: 6px 7px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.category-chart-row:hover {
  background: var(--surface-soft);
}

.category-rank {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
  background: #f3edf1;
  font-size: 0.72rem;
  font-weight: 700;
}

.category-chart-main {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.category-chart-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.8rem;
}

.category-chart-label strong,
.category-amount {
  font-weight: 600;
}

.category-chart-label > span {
  color: var(--muted);
  font-size: 0.74rem;
}

.category-track {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #f1ebef;
}

.category-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--expense-chart);
}

.category-amount {
  color: var(--expense);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.category-fill.level-0 { width: 0; }
.category-fill.level-1 { width: 10%; }
.category-fill.level-2 { width: 20%; }
.category-fill.level-3 { width: 30%; }
.category-fill.level-4 { width: 40%; }
.category-fill.level-5 { width: 50%; }
.category-fill.level-6 { width: 60%; }
.category-fill.level-7 { width: 70%; }
.category-fill.level-8 { width: 80%; }
.category-fill.level-9 { width: 90%; }
.category-fill.level-10 { width: 100%; }

.insight-empty,
.ledger-empty {
  min-height: 190px;
  display: grid;
  place-content: center;
  gap: 5px;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.insight-empty strong,
.ledger-empty strong {
  color: #544b53;
  font-weight: 600;
}

.insight-empty span,
.ledger-empty span {
  font-size: 0.8rem;
}

.trend-chart {
  min-height: 118px;
  display: grid;
  grid-template-columns: repeat(31, minmax(14px, 1fr));
  gap: 3px;
  overflow-x: auto;
  padding: 4px 1px 8px;
  scrollbar-width: thin;
}

.trend-day {
  min-width: 8px;
  display: grid;
  grid-template-rows: 88px 18px;
  gap: 4px;
  place-items: center;
  border: 0;
  border-radius: 5px;
  padding: 0 1px;
  color: #817680;
  background: transparent;
  font-size: 0.62rem;
}

.trend-day:hover,
.trend-day.is-selected {
  color: var(--accent-strong);
  background: var(--surface-accent);
}

.trend-day.has-expense {
  color: var(--expense);
  font-weight: 600;
}

.trend-bar {
  width: 100%;
  height: 84px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  border-radius: 4px 4px 2px 2px;
  background: #f2edf0;
}

.trend-fill {
  width: 100%;
  display: block;
  border-radius: 3px 3px 1px 1px;
  background: var(--expense-chart);
}

.trend-fill.level-0 { height: 0; }
.trend-fill.level-1 { height: 10%; }
.trend-fill.level-2 { height: 20%; }
.trend-fill.level-3 { height: 30%; }
.trend-fill.level-4 { height: 40%; }
.trend-fill.level-5 { height: 50%; }
.trend-fill.level-6 { height: 60%; }
.trend-fill.level-7 { height: 70%; }
.trend-fill.level-8 { height: 80%; }
.trend-fill.level-9 { height: 90%; }
.trend-fill.level-10 { height: 100%; }

.trend-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
}

.trend-facts strong {
  margin-left: 4px;
  color: #514850;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.trend-facts strong.expense-value {
  color: var(--expense);
}

.panel {
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head input {
  max-width: 320px;
}

.weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.weekdays {
  margin-bottom: 6px;
  text-align: center;
  color: #5c515a;
  font-weight: 600;
}

.day-cell {
  min-height: 76px;
  border: 1px solid #e5dde3;
  border-radius: 7px;
  background: var(--surface-soft);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  color: var(--text);
}

.day-cell:hover:not(.is-empty) {
  border-color: var(--line-strong);
  background: #fdf7fa;
}

.day-cell.is-empty {
  visibility: hidden;
  pointer-events: none;
}

.day-cell.is-selected {
  border-color: var(--accent);
  background: var(--surface-accent);
  box-shadow: inset 0 0 0 1px rgba(176, 71, 106, 0.24);
}

.day-cell.is-income {
  border-color: var(--income-line);
  background: var(--income-soft);
}

.day-cell.is-expense {
  border-color: var(--expense-line);
  background: var(--expense-surface);
}

.day-cell strong {
  font-size: 1.05rem;
  font-weight: 700;
}

.day-cell span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.day-cell.is-income span {
  color: var(--income);
}

.day-cell.is-expense span {
  color: var(--expense);
}

.day-detail {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fffdfd;
}

.day-detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
}

.day-detail-title {
  display: grid;
  gap: 3px;
}

.day-detail-title span,
.day-total span,
.detail-meta,
.record-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.day-total {
  display: grid;
  gap: 3px;
  text-align: right;
}

.day-total strong {
  color: var(--expense);
  white-space: nowrap;
}

.day-detail-list,
.ledger-list {
  display: grid;
}

.day-detail-row,
.record-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.day-empty {
  min-height: 94px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px;
  color: var(--muted);
  font-size: 0.84rem;
}

.day-detail-row:last-child,
.record-row:last-child {
  border-bottom: 0;
}

.record-main,
.detail-main {
  min-width: 0;
}

.record-main strong,
.detail-main strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-meta,
.detail-meta {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.amount.income {
  color: var(--income);
}

.amount.expense {
  color: var(--expense);
}

.record-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 7px;
}

.record-actions button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #4a424b;
  padding: 0 9px;
  font-weight: 600;
}

.record-actions .delete-action {
  color: var(--danger);
}

.ledger-tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 148px auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.ledger-tools input,
.ledger-tools select {
  min-height: 40px;
}

.segment-control {
  min-height: 40px;
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f3eef2;
}

.segment-control button {
  min-width: 52px;
  border: 0;
  border-radius: 5px;
  padding: 0 9px;
  color: var(--muted);
  background: transparent;
  font-weight: 600;
}

.segment-control button.is-active {
  color: var(--text);
  background: #fff;
  box-shadow: 0 3px 10px rgba(105, 75, 91, 0.1);
}

.segment-control button[data-ledger-type="expense"].is-active {
  color: var(--expense-strong);
  background: var(--expense-soft);
}

.segment-control button[data-ledger-type="income"].is-active {
  color: var(--income-strong);
  background: var(--income-soft);
}

.ledger-expand-button {
  min-height: 40px;
  white-space: nowrap;
}

.ledger-list {
  margin-top: 8px;
}

.ledger-day-group {
  border-top: 1px solid var(--line);
}

.ledger-day-group:last-child {
  border-bottom: 1px solid var(--line);
}

.ledger-day-group > summary {
  min-height: 62px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 24px;
  gap: 12px;
  align-items: center;
  padding: 9px 5px 9px 8px;
  color: var(--text);
  cursor: pointer;
  list-style: none;
}

.ledger-day-group > summary::-webkit-details-marker {
  display: none;
}

.ledger-day-group > summary:hover,
.ledger-day-group[open] > summary {
  background: var(--surface-soft);
}

.ledger-date {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.ledger-date > strong {
  font-size: 0.9rem;
  font-weight: 600;
}

.ledger-date > span {
  color: var(--muted);
  font-size: 0.76rem;
}

.ledger-day-total {
  font-size: 0.84rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ledger-day-total.expense {
  color: var(--expense);
}

.ledger-day-total.income {
  color: var(--income);
}

.disclosure-icon {
  color: var(--muted);
  font-size: 1.05rem;
  text-align: center;
  transition: transform 0.16s ease;
}

.ledger-day-group[open] .disclosure-icon {
  transform: rotate(180deg);
}

.ledger-day-records {
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.ledger-day-records .record-row {
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 11px;
  min-height: 68px;
  padding: 10px 12px;
}

.category-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 700;
}

.category-mark.tone-0 { color: #8f3857; background: #f9dfe8; }
.category-mark.tone-1 { color: #2f6c5e; background: #dff1eb; }
.category-mark.tone-2 { color: #3d6282; background: #e4eef6; }
.category-mark.tone-3 { color: #67517d; background: #eee7f3; }
.category-mark.tone-4 { color: #7a6123; background: #f6efd8; }
.category-mark.tone-5 { color: #59616b; background: #e9edf0; }

.record-main strong {
  font-weight: 600;
}

.record-side {
  display: grid;
  gap: 5px;
  justify-items: end;
}

.record-side .record-actions {
  margin-top: 0;
}

.load-more-button {
  width: 100%;
  min-height: 42px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: #544b53;
  background: var(--surface-soft);
  font-weight: 600;
}

.load-more-button:hover {
  border-color: var(--line-strong);
  background: #f5eff3;
}

.top-entry-button,
.mobile-entry-button,
.close-entry-button,
.entry-backdrop {
  display: none;
}

.mobile-entry-button {
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: #fff;
  background: var(--accent-strong);
  box-shadow: 0 12px 28px rgba(142, 52, 84, 0.25);
  font-weight: 700;
}

.mobile-entry-button span,
.top-entry-button span {
  font-size: 1.15em;
}

.empty {
  padding: 22px 12px;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  min-width: 180px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  background: #382c35;
  text-align: center;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 30;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Soft rose product theme: decorative color stays restrained so financial data remains easy to scan. */
.auth-card {
  position: relative;
  overflow: hidden;
  border-color: #dfd1db;
  box-shadow: 0 24px 68px rgba(105, 75, 91, 0.12);
}

.auth-card::before {
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  content: "";
  background: var(--accent);
}

.brand-mark {
  box-shadow: 0 7px 18px rgba(142, 52, 84, 0.16);
}

input,
textarea,
select {
  background: #fffdfd;
}

.primary-button {
  box-shadow: 0 6px 16px rgba(142, 52, 84, 0.14);
}

.ghost-button:hover,
.icon-button:hover {
  background: #fdf7fa;
}

.panel,
.entry-panel,
.overview-panel {
  border-color: #e4d9e1;
}

.entry-panel {
  background: #fffdfd;
}

.month-bar h2,
.panel-head h2,
.entry-panel-head h2 {
  color: #3b3038;
}

.expense-summary {
  background: #fff7fa;
}

.metric-item {
  background: #fff;
}

.category-chart-row:hover,
.ledger-day-group > summary:hover,
.ledger-day-group[open] > summary {
  background: #fdf7fa;
}

.day-cell.is-selected:not(.is-empty) {
  border-color: var(--accent);
  background: var(--surface-accent);
  box-shadow: inset 0 0 0 1px rgba(176, 71, 106, 0.28), 0 5px 14px rgba(142, 52, 84, 0.08);
}

.ledger-day-records {
  background: #fcfafc;
}

.record-actions button:hover {
  border-color: var(--line-strong);
  background: #fff7fa;
}

.install-dialog {
  box-shadow: 0 24px 70px rgba(72, 48, 63, 0.2);
}

.install-dialog::backdrop {
  background: rgba(54, 39, 50, 0.42);
}

[hidden] {
  display: none !important;
}

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

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-access-panel,
  .admin-audit-panel {
    grid-column: auto;
  }

  .admin-code-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .admin-code-row > div:nth-child(3) {
    grid-column: 1 / -1;
  }

  .entry-panel {
    position: fixed;
    inset: auto 0 0;
    z-index: 50;
    width: min(560px, 100%);
    max-height: calc(100dvh - 30px);
    margin: 0 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 8px 8px 0 0;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
    transform: translateY(104%);
    visibility: hidden;
    transition: transform 0.22s cubic-bezier(0.2, 0.75, 0.25, 1), visibility 0.22s;
  }

  .entry-panel.is-open {
    transform: translateY(0);
    visibility: visible;
  }

  .entry-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: block;
    background: rgba(54, 39, 50, 0.46);
  }

  .close-entry-button {
    display: grid;
    place-items: center;
  }

  .top-entry-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
  }

  body.entry-open {
    overflow: hidden;
  }
}

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

  .overview-panel {
    grid-template-columns: 1fr;
  }

  .expense-summary {
    min-height: 112px;
    border-right: 0;
    border-bottom: 1px solid var(--expense-line);
  }

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

  .metric-item {
    min-height: 88px;
    padding: 14px 16px;
  }

  .metric-item:nth-child(odd) {
    border-left: 0;
  }

  .metric-item:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

  .top-entry-button {
    display: none;
  }

  .mobile-entry-button {
    position: fixed;
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    z-index: 20;
    display: inline-flex;
  }

  .toast {
    bottom: calc(76px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 620px) {
  .access-code-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-code-row {
    grid-template-columns: 1fr;
  }

  .admin-code-row > div:nth-child(3) {
    grid-column: auto;
  }

  .admin-code-row .danger-button {
    width: 100%;
  }

  .topbar {
    position: sticky;
    align-items: flex-start;
    flex-direction: column;
    padding: 10px 12px;
  }

  .top-actions {
    width: 100%;
    gap: 7px;
    flex-wrap: nowrap;
  }

  .top-actions > * {
    flex: 1 1 auto;
    text-align: center;
  }

  .top-actions .user-chip {
    display: none;
  }

  .top-actions .ghost-button,
  .top-actions .danger-button {
    min-height: 36px;
    padding: 0 10px;
    font-size: 0.82rem;
  }

  .top-actions .install-app-button {
    display: none;
  }

  .brand.compact .brand-mark {
    width: 38px;
    height: 38px;
  }

  .workspace {
    padding: 10px;
  }

  .dashboard {
    gap: 12px;
  }

  .month-bar {
    gap: 7px;
  }

  .month-bar h2 {
    min-width: 112px;
    font-size: 1.04rem;
  }

  .month-bar .ghost-button {
    padding: 0 10px;
  }

  .panel {
    padding: 12px;
  }

  .panel-head,
  .day-detail-head {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-head input {
    max-width: none;
  }

  .expense-summary {
    padding: 17px 18px;
  }

  .expense-summary > strong {
    font-size: 1.8rem;
  }

  .metric-item strong {
    font-size: 1rem;
  }

  .day-total {
    text-align: left;
  }

  .weekdays,
  .calendar-grid {
    gap: 4px;
  }

  .day-cell {
    min-height: 54px;
    padding: 4px 1px;
  }

  .day-cell strong {
    font-size: 0.9rem;
  }

  .day-cell span {
    font-size: 0.61rem;
  }

  .day-detail-row {
    grid-template-columns: 1fr;
  }

  .day-empty {
    align-items: stretch;
    flex-direction: column;
    text-align: center;
  }

  .ledger-tools {
    grid-template-columns: 1fr;
  }

  .segment-control {
    grid-template-columns: repeat(3, 1fr);
  }

  .ledger-day-group > summary {
    grid-template-columns: minmax(0, 1fr) auto 20px;
    gap: 8px;
  }

  .ledger-day-records .record-row {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px 6px;
  }

  .category-mark {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }

  .record-side {
    gap: 7px;
  }

  .record-actions {
    gap: 4px;
  }

  .record-actions button {
    min-height: 28px;
    padding: 0 7px;
    font-size: 0.74rem;
  }

  .record-main strong {
    max-width: 100%;
    font-size: 0.88rem;
  }

  .record-meta {
    font-size: 0.7rem;
  }

  .record-side .amount {
    font-size: 0.84rem;
  }

  .form-actions {
    grid-template-columns: 1fr;
  }

  .trend-chart {
    grid-template-columns: repeat(31, minmax(18px, 1fr));
  }
}

@media (max-width: 380px) {
  .workspace {
    padding: 8px;
  }

  .panel,
  .entry-panel {
    padding-left: 10px;
    padding-right: 10px;
  }

  .ledger-day-total {
    max-width: 102px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
