/* ============================================================
   Material Design 3 · 深色主题
   ============================================================ */
:root {
  /* MD3 深色配色（baseline） */
  --md-primary: #D0BCFF;
  --md-on-primary: #381E72;
  --md-primary-container: #4F378B;
  --md-on-primary-container: #EADDFF;
  --md-secondary: #CCC2DC;
  --md-on-secondary: #332D41;
  --md-secondary-container: #4A4458;
  --md-on-secondary-container: #E8DEF8;
  --md-tertiary: #EFB8C8;
  --md-on-tertiary: #492532;
  --md-tertiary-container: #633B48;
  --md-on-tertiary-container: #FFD8E4;
  --md-error: #F2B8B5;
  --md-on-error: #601410;
  --md-error-container: #8C1D18;
  --md-on-error-container: #F9DEDC;

  --md-surface: #141218;
  --md-on-surface: #E6E0E9;
  --md-surface-variant: #49454F;
  --md-on-surface-variant: #CAC4D0;
  --md-outline: #938F99;
  --md-outline-variant: #49454F;

  --md-surface-lowest: #0F0D13;
  --md-surface-low: #1D1B20;
  --md-surface-container: #211F26;
  --md-surface-high: #2B2930;
  --md-surface-highest: #36343B;

  /* 语义色（收入/支出/结余） */
  --md-income: #8FD9A8;
  --md-expense: #FFB77C;
  --md-surplus: #8FD9A8;

  /* 形状 */
  --md-xs: 4px;
  --md-sm: 8px;
  --md-md: 12px;
  --md-lg: 16px;
  --md-xl: 28px;

  /* 字体 */
  --md-font: "Roboto", "Noto Sans SC", "Microsoft YaHei UI", system-ui, sans-serif;

  /* 高度（阴影） */
  --md-e1: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
  --md-e2: 0 1px 2px rgba(0,0,0,.3), 0 2px 6px 2px rgba(0,0,0,.15);
  --md-e3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--md-surface);
  color: var(--md-on-surface);
  font-family: var(--md-font);
  font-size: 14px;
  line-height: 20px;
  color-scheme: dark;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 10px 132px 10px 20px;
  background: var(--md-surface-container);
  border-bottom: 1px solid var(--md-outline-variant);
  user-select: none;
}
.brand h1 { margin: 0; font-size: 20px; line-height: 28px; font-weight: 500; letter-spacing: .1px; }
.tagline { margin: 2px 0 0; color: var(--md-on-surface-variant); font-size: 12px; }
.topbar-actions, .ledger-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ledger-bar { margin-left: auto; }
.ledger-bar label { color: var(--md-on-surface-variant); font-size: 12px; font-weight: 500; letter-spacing: .4px; }
.ledger-bar select { min-width: 170px; }
.save-state { color: var(--md-income); font-size: 12px; min-width: 44px; }
.save-state.err { color: var(--md-error); }

/* 窗口控制按钮：固定在窗口右上角，不随顶栏换行 */
.win-controls { position: fixed; top: 10px; right: 8px; z-index: 100; display: flex; align-items: center; gap: 2px; }
.win-btn {
  width: 40px; height: 40px; border: none; background: transparent;
  color: var(--md-on-surface-variant); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--md-sm); transition: background .12s ease, color .12s ease;
}
.win-btn:hover { background: color-mix(in srgb, var(--md-on-surface) 10%, transparent); color: var(--md-on-surface); }
.win-btn.win-close:hover { background: var(--md-error); color: var(--md-on-error); }

/* ---------- 移动端抽屉相关（桌面隐藏） ---------- */
.icon-btn {
  width: 44px; height: 44px; flex: none; border: none; background: transparent;
  color: var(--md-on-surface); border-radius: 50%; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s ease;
}
.icon-btn:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.drawer-toggle, .add-mobile { display: none; }
.add-mobile { margin-left: auto; }
.sidebar-head { display: none; }
.sidebar-slot { display: none; }
.drawer-scrim { display: none; }
.tt-short { display: none; }

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  height: 40px;
  padding: 0 20px;
  border-radius: 20px;
  background: transparent;
  color: var(--md-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: .1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  transition: background .15s ease, box-shadow .15s ease;
}
.btn:hover { background: color-mix(in srgb, var(--md-primary) 8%, transparent); }
.btn:active { background: color-mix(in srgb, var(--md-primary) 14%, transparent); }
.btn-primary { background: var(--md-primary); color: var(--md-on-primary); }
.btn-primary:hover { background: color-mix(in srgb, var(--md-primary) 90%, #fff); box-shadow: var(--md-e1); }
.btn-primary:active { background: color-mix(in srgb, var(--md-primary) 84%, #fff); }
.btn-ghost { color: var(--md-primary); }
.btn-close {
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  color: var(--md-on-surface-variant); font-size: 20px; line-height: 1;
}
.btn-close:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }

/* 分段按钮 */
.seg { display: inline-flex; border: 1px solid var(--md-outline); border-radius: 20px; overflow: hidden; }
.seg button {
  border: none; background: transparent; color: var(--md-on-surface);
  height: 40px; padding: 0 22px; font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .15s ease;
}
.seg button:hover { background: color-mix(in srgb, var(--md-on-surface) 6%, transparent); }
.seg button.active { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }

/* ---------- 布局 ---------- */
.layout { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 300px;
  min-width: 260px;
  padding: 12px;
  background: var(--md-surface-low);
  border-right: 1px solid var(--md-outline-variant);
  overflow-y: auto;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

.sidebar-title {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 4px 12px; font-size: 14px; font-weight: 500; color: var(--md-on-surface);
}
.count {
  background: var(--md-primary-container); color: var(--md-on-primary-container);
  border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 500;
}

/* ---------- 项目卡片 ---------- */
.item-list { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  background: var(--md-surface-container);
  border-radius: var(--md-md);
  padding: 12px 14px;
  transition: background .15s ease;
}
.item-row:hover { background: var(--md-surface-high); }
.item-row.disabled { opacity: .5; }
.item-row-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.item-name { flex: 1; font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.delta { font-weight: 500; font-size: 14px; }
.delta.in { color: var(--md-income); }
.delta.out { color: var(--md-expense); }

.kind-badge { font-size: 11px; font-weight: 500; padding: 2px 10px; border-radius: 8px; flex: none; }
.kind-income { background: color-mix(in srgb, var(--md-income) 22%, transparent); color: var(--md-income); }
.kind-expense { background: color-mix(in srgb, var(--md-expense) 22%, transparent); color: var(--md-expense); }
.kind-loan { background: var(--md-error-container); color: var(--md-on-error-container); }

.item-meta { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; }
.item-line { color: var(--md-on-surface-variant); font-size: 12px; line-height: 18px; }
.item-line b { color: var(--md-on-surface); font-weight: 500; }
.tag {
  display: inline-block; background: var(--md-surface-highest); color: var(--md-on-surface-variant);
  padding: 1px 8px; border-radius: 6px; font-size: 11px;
}
.item-actions { display: flex; align-items: center; gap: 8px; }
.item-actions .btn { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 16px; }

.muted { color: var(--md-on-surface-variant); }
.pad { padding: 10px 4px; }

/* ---------- 开关（MD3） ---------- */
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .slider {
  position: absolute; inset: 0; border-radius: 999px; pointer-events: none;
  background: var(--md-surface-highest);
  border: 2px solid var(--md-outline);
  transition: background .2s cubic-bezier(.2,0,0,1), border-color .2s cubic-bezier(.2,0,0,1);
}
.switch .slider::before {
  content: ""; position: absolute; top: 50%; left: 5px; transform: translateY(-50%);
  width: 16px; height: 16px; border-radius: 50%; background: var(--md-outline);
  transition: left .2s cubic-bezier(.2,0,0,1), width .2s cubic-bezier(.2,0,0,1),
              height .2s cubic-bezier(.2,0,0,1), background .2s ease;
}
.switch input:checked + .slider { background: var(--md-primary); border-color: var(--md-primary); }
.switch input:checked + .slider::before { width: 24px; height: 24px; left: 22px; background: var(--md-on-primary); }

/* ---------- 标签页（MD3 primary tabs） ---------- */
.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--md-surface); border-bottom: 1px solid var(--md-outline-variant); }
.tab {
  position: relative; background: none; border: none; cursor: pointer;
  color: var(--md-on-surface-variant); font-family: inherit; font-size: 14px; font-weight: 500;
  padding: 16px 22px 14px;
  transition: color .15s ease;
}
.tab:hover { color: var(--md-on-surface); }
.tab.active { color: var(--md-primary); }
.tab.active::after {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: 0; height: 3px;
  border-radius: 3px 3px 0 0; background: var(--md-primary);
}

.view { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 24px 32px; }

/* ---------- 指标卡 ---------- */
.metric-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.metric-card { background: var(--md-surface-high); border-radius: var(--md-md); padding: 16px; }
.metric-label { color: var(--md-on-surface-variant); font-size: 12px; letter-spacing: .4px; margin-bottom: 8px; }
.metric-value { font-size: 28px; line-height: 36px; font-weight: 500; }
.metric-value.green { color: var(--md-surplus); }
.metric-value.red { color: var(--md-error); }
.metric-value.blue { color: var(--md-primary); }
.metric-sub { color: var(--md-on-surface-variant); font-size: 12px; margin-top: 4px; }

/* ---------- 控件行 ---------- */
.control-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.field { display: flex; align-items: center; gap: 8px; }
.field label { color: var(--md-on-surface-variant); font-size: 12px; font-weight: 500; letter-spacing: .4px; }
.field .sep { color: var(--md-on-surface-variant); }

/* ---------- 输入（MD3 outlined） ---------- */
input, select {
  height: 44px;
  padding: 0 14px;
  background: transparent;
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline);
  border-radius: var(--md-xs);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus {
  border-color: var(--md-primary);
  box-shadow: inset 0 0 0 1px var(--md-primary);
}
input[type="date"], input[type="month"] { color-scheme: dark; }

select {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%23CAC4D0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
select option { background: var(--md-surface-high); color: var(--md-on-surface); }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator { filter: invert(.75); opacity: .9; cursor: pointer; }
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="month"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* ---------- MD3 下拉选单 ---------- */
.md-select { position: relative; display: inline-block; min-width: 170px; }
.md-select-trigger {
  width: 100%; height: 44px; padding: 0 40px 0 14px;
  display: flex; align-items: center;
  background: transparent; color: var(--md-on-surface);
  border: 1px solid var(--md-outline); border-radius: var(--md-xs);
  font-family: inherit; font-size: 14px; text-align: left; cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.md-select-trigger:hover { border-color: var(--md-on-surface); }
.md-select-trigger.open { border-color: var(--md-primary); box-shadow: inset 0 0 0 1px var(--md-primary); }
.md-select-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md-select-arrow {
  position: absolute; right: 14px; top: 50%; display: flex;
  color: var(--md-on-surface-variant); pointer-events: none;
  transform: translateY(-50%); transition: transform .2s ease;
}
.md-select-trigger.open .md-select-arrow { transform: translateY(-50%) rotate(180deg); }

.md-menu {
  position: fixed; z-index: 200; min-width: 120px; max-height: 300px; overflow-y: auto;
  padding: 8px 0;
  background: var(--md-surface-high); border-radius: var(--md-sm);
  box-shadow: var(--md-e2);
  opacity: 0; transform: scale(.92) translateY(-6px);
  transition: opacity .15s ease, transform .15s ease;
}
.md-menu.open { opacity: 1; transform: none; }
.md-menu-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 16px; border: none; background: transparent; cursor: pointer;
  color: var(--md-on-surface); font-family: inherit; font-size: 14px; white-space: nowrap;
  transition: background .12s ease;
}
.md-menu-item:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.md-menu-item.selected { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }

.modal-body .field .md-select { width: 100%; min-width: 0; }

/* ---------- MD3 日期 / 月份选择器 ---------- */
.md-datepicker { position: relative; display: inline-block; min-width: 150px; }
.md-dp-icon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--md-on-surface-variant); pointer-events: none; display: flex; }
.md-dp-popup {
  position: fixed; z-index: 200; padding: 12px;
  background: var(--md-surface-high); border-radius: var(--md-md); box-shadow: var(--md-e3);
  opacity: 0; transform: scale(.94) translateY(-6px);
  transition: opacity .15s ease, transform .15s ease;
}
.md-dp-popup.open { opacity: 1; transform: none; }
.md-dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.md-dp-title { font-size: 14px; font-weight: 500; }
.md-dp-nav { width: 36px; height: 36px; border: none; background: transparent; color: var(--md-on-surface-variant); border-radius: 50%; cursor: pointer; font-size: 20px; line-height: 1; }
.md-dp-nav:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.md-dp-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 4px; }
.md-dp-week span { text-align: center; font-size: 11px; color: var(--md-on-surface-variant); }
.md-dp-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.md-dp-day { height: 36px; border: none; background: transparent; color: var(--md-on-surface); border-radius: 50%; cursor: pointer; font-family: inherit; font-size: 13px; }
.md-dp-day:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.md-dp-day.today { box-shadow: inset 0 0 0 1px var(--md-primary); }
.md-dp-day.sel { background: var(--md-primary); color: var(--md-on-primary); }
.md-dp-day.empty { pointer-events: none; }
.md-dp-months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.md-dp-month { height: 46px; border: 1px solid var(--md-outline-variant); background: transparent; color: var(--md-on-surface); border-radius: var(--md-sm); cursor: pointer; font-family: inherit; font-size: 13px; }
.md-dp-month:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.md-dp-month.sel { background: var(--md-primary); color: var(--md-on-primary); border-color: var(--md-primary); }
.modal-body .field .md-datepicker { width: 100%; min-width: 0; }

/* ---------- 图表 ---------- */
.chart-title { color: var(--md-on-surface-variant); font-size: 13px; margin: 8px 0; }
.chart-wrap { position: relative; }
.chart {
  width: 100%; height: clamp(380px, 56vh, 620px);
  background: var(--md-surface-container);
  border-radius: var(--md-lg);
  position: relative; overflow: hidden;
}
@keyframes chartFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.sankey-svg { display: block; }
.sankey-svg.fade-in { animation: chartFadeIn .38s ease-out both; }
.sankey-svg .sk-link { opacity: .45; transition: opacity .15s; cursor: pointer; }
.sankey-svg .sk-node { transition: opacity .15s; cursor: pointer; }
.sankey-svg .sk-label { pointer-events: none; user-select: none; }
.sankey-svg.has-hover .sk-link { opacity: .1; }
.sankey-svg.has-hover .sk-node { opacity: .3; }
.sankey-svg.has-hover .sk-label { opacity: .4; }
.sankey-svg.has-hover .hi { opacity: 1 !important; }

.sankey-tip {
  position: absolute; z-index: 20; pointer-events: none;
  background: var(--md-surface-highest);
  border-radius: var(--md-sm);
  padding: 10px 12px;
  font-size: 12.5px; color: var(--md-on-surface); line-height: 1.6;
  box-shadow: var(--md-e2);
  max-width: 260px;
}

.chart-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: center;
  color: var(--md-on-surface-variant); font-size: 15px;
  background: var(--md-surface-container); border-radius: var(--md-lg);
}
.chart-empty span { font-size: 12.5px; color: var(--md-outline); }

/* ---------- 日历 ---------- */
.calendar-wrap { background: var(--md-surface-container); border-radius: var(--md-lg); padding: 12px; margin-bottom: 16px; }
.cal-week-header { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.cal-wd { text-align: center; color: var(--md-on-surface-variant); font-size: 12px; padding: 4px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; grid-auto-rows: 104px; }
.cal-cell {
  height: 104px; overflow: hidden;
  background: var(--md-surface-low);
  border: 1px solid transparent;
  border-radius: var(--md-md);
  padding: 6px; cursor: pointer; position: relative;
  transition: background .15s ease, border-color .15s ease;
}
.cal-cell:hover { background: var(--md-surface-high); }
.cal-cell.today { border-color: var(--md-primary); }
.cal-cell.selected { background: var(--md-secondary-container); }
.cal-cell.empty { background: transparent; border: none; cursor: default; }
.cal-num { font-size: 12px; color: var(--md-on-surface); margin-bottom: 4px; }
.cal-cell.today .cal-num { color: var(--md-primary); font-weight: 700; }
.cal-chips { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.chip {
  display: flex; align-items: center; gap: 5px; min-width: 0;
  font-size: 11px; color: var(--md-on-surface-variant);
  background: var(--md-surface-highest); border-radius: 8px; padding: 2px 6px;
}
.chip-type { width: 3px; align-self: stretch; border-radius: 2px; flex: none; }
.chip-cat { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.chip-txt {
  flex: 1; min-width: 0; white-space: normal; word-break: break-word; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.chip.more { color: var(--md-outline); justify-content: center; }

/* ---------- 当天详情 ---------- */
.day-detail { background: var(--md-surface-container); border-radius: var(--md-lg); padding: 16px; }
.day-title { font-size: 15px; font-weight: 500; margin-bottom: 12px; }
.day-detail .item-row { background: var(--md-surface-low); margin-bottom: 8px; }
.btn-ghost.on { color: var(--md-primary); }

/* ---------- 弹窗（MD3 dialog） ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100; padding: 20px;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  background: var(--md-surface-high);
  border-radius: var(--md-xl);
  box-shadow: var(--md-e3);
}
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 24px 24px 0; }
.modal-header h2 { margin: 0; font-size: 22px; line-height: 28px; font-weight: 400; }
.modal-body { padding: 16px 24px 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.modal-body .field { flex-direction: column; align-items: stretch; gap: 6px; margin-bottom: 16px; }
.modal-body .field label { font-size: 12px; color: var(--md-on-surface-variant); }
.checkbox { display: flex; align-items: center; gap: 10px; color: var(--md-on-surface); margin: 6px 0 20px; cursor: pointer; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.period-hint {
  background: var(--md-surface-highest); color: var(--md-on-surface);
  font-size: 13px; padding: 12px 14px; border-radius: var(--md-sm); margin-bottom: 16px;
}
.period-hint b { color: var(--md-income); font-weight: 500; }

/* ---------- MD3 对话框（alert / confirm / prompt） ---------- */
#mdDialogHost { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 24px; }
.md-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); opacity: 0; transition: opacity .16s ease; }
#mdDialogHost.open .md-scrim { opacity: 1; }
.md-dialog {
  position: relative; width: min(420px, calc(100vw - 48px));
  background: var(--md-surface-high); border-radius: var(--md-xl); box-shadow: var(--md-e3);
  padding: 24px; opacity: 0; transform: scale(.92);
  transition: opacity .16s ease, transform .16s ease;
}
#mdDialogHost.open .md-dialog { opacity: 1; transform: none; }
.md-dialog-title { margin: 0 0 16px; font-size: 22px; line-height: 28px; font-weight: 400; }
.md-dialog-body { color: var(--md-on-surface-variant); font-size: 14px; line-height: 20px; margin-bottom: 20px; word-break: break-word; }
.md-dialog-input { width: 100%; margin-bottom: 20px; }
.md-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.md-dialog-ok.danger { background: var(--md-error); color: var(--md-on-error); }
.md-dialog-ok.danger:hover { background: color-mix(in srgb, var(--md-error) 90%, #fff); }

/* ---------- 滚动条 ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--md-surface-highest) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--md-surface-highest); border-radius: 8px; border: 2px solid var(--md-surface); }
::-webkit-scrollbar-thumb:hover { background: var(--md-outline-variant); }
::selection { background: color-mix(in srgb, var(--md-primary) 35%, transparent); color: #fff; }

/* ---------- 桌面版（WinUI 3）：使用 MD3 不透明表面色 ---------- */
html.native, html.native body { background: var(--md-surface); }

/* ---------- 表格视图（直接编辑数据行） ---------- */
.table-wrap { overflow-x: auto; }
.md-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.md-table th {
  text-align: left; font-weight: 500; color: var(--md-on-surface-variant);
  padding: 10px 8px; border-bottom: 1px solid var(--md-outline-variant); white-space: nowrap;
}
.md-table td { padding: 4px 6px; border-bottom: 1px solid var(--md-outline-variant); vertical-align: middle; }
.md-table .t-input { height: 36px; width: 100%; min-width: 96px; padding: 0 8px; font-size: 13px; border-radius: var(--md-xs); }
.md-table td.center { text-align: center; }
.md-table input[type="checkbox"] { width: 18px; height: 18px; padding: 0; accent-color: var(--md-primary); }
.t-add { margin-top: 16px; }
.t-del { height: 32px; padding: 0 12px; font-size: 12px; color: var(--md-error); }
.t-del:hover { background: color-mix(in srgb, var(--md-error) 10%, transparent); }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .sidebar { width: 260px; min-width: 220px; }
  .metric-row { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- 移动端（竖屏）：菜单 / 账单 / 操作收进侧滑抽屉 ---------- */
@media (max-width: 820px) {
  .drawer-toggle { display: inline-flex; }
  .add-mobile { display: inline-flex; }
  .brand .tagline { display: none; }
  .brand h1 { font-size: 16px; line-height: 22px; }
  .tt-full { display: none; }
  .tt-short { display: inline; }

  .layout { display: block; }
  .main { height: 100%; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 290px; max-width: 86vw; min-width: 0; max-height: none;
    z-index: 60;
    transform: translateX(-102%);
    transition: transform .24s cubic-bezier(.2, 0, 0, 1);
    border-right: 1px solid var(--md-outline-variant);
    box-shadow: 0 0 28px rgba(0, 0, 0, .45);
  }
  .sidebar.open { transform: none; }
  .sidebar-head {
    display: flex; align-items: center; justify-content: space-between;
    margin: 2px 0 12px; font-size: 15px; font-weight: 500; color: var(--md-on-surface);
  }
  .sidebar-slot {
    display: flex; flex-direction: column; gap: 10px;
    padding-bottom: 14px; margin-bottom: 14px;
    border-bottom: 1px solid var(--md-outline-variant);
  }
  .sidebar-slot .ledger-bar { margin-left: 0; flex-direction: column; align-items: stretch; gap: 8px; }
  .sidebar-slot .ledger-bar .md-select { width: 100%; min-width: 0; }
  .sidebar-slot .ledger-bar > .btn { justify-content: flex-start; }
  .sidebar-slot .topbar-actions { flex-direction: column; align-items: stretch; }
  .sidebar-slot .topbar-actions .btn { justify-content: flex-start; }

  .drawer-scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(0, 0, 0, .6); opacity: 0; transition: opacity .2s ease;
  }
  .drawer-scrim.open { opacity: 1; }

  .tabs { padding: 0 6px; }
  .tab { flex: 1; padding: 14px 6px 12px; text-align: center; }
  .view { padding: 14px 12px 28px; }
  .metric-row { gap: 8px; }
  .metric-card { padding: 12px; }
  .metric-value { font-size: 22px; line-height: 28px; }
  .control-row { gap: 8px; }
  .chart { height: clamp(280px, 42vh, 380px); }
  .calendar-wrap { padding: 8px; }
  .cal-grid { grid-auto-rows: 74px; gap: 4px; }
  .cal-cell { height: 74px; padding: 4px; }
  .cal-num { font-size: 11px; }
  .chip { font-size: 10px; padding: 1px 4px; }
  .modal { padding: 12px; }
  .modal-box { max-width: 100%; }
  .grid-2 { grid-template-columns: 1fr; gap: 12px; }
}
