:root {
    --paper: #f4c7b7;
    --card: #fffaf4;
    --card-soft: #fff3e9;
    --line: #e7b8a7;
    --ink: #241b17;
    --muted: #7f665d;
    --gold: #f6c85f;
    --green: #2f6f68;
    --red: #a6534b;
    --shadow: 0 10px 28px rgba(91, 54, 39, 0.08);
  }

  * { box-sizing: border-box; }

  html {
    min-height: 100%;
    background: var(--paper);
  }

  body {
    margin: 0;
    min-width: 320px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 12px;
    color: var(--ink);
    background: var(--paper);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
  }

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

  .app {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
  }

  aside {
    background: rgba(255, 250, 244, 0.72);
    border-right: 1px solid var(--line);
    padding: 20px 16px;
  }

  main {
    min-width: 0;
    padding: 24px;
  }

  h1 {
    margin: 0 0 6px;
    font-size: 20px;
    line-height: 1.18;
  }

  h2 {
    margin: 0 0 12px;
    font-size: 14px;
    line-height: 1.25;
  }

  p {
    color: var(--muted);
    margin: 0;
    line-height: 1.5;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 13px;
    margin-bottom: 24px;
    line-height: 1.25;
  }

  .brand-copy,
  .m-brand-name {
    font-family: "STXingkai", "Xingkai SC", "HanziPen SC", "Kaiti SC", "KaiTi", "STKaiti", cursive;
    font-weight: 600;
    letter-spacing: 0.03em;
  }

  .brand-copy {
    font-size: 22px;
    line-height: 1;
  }

  .brand-copy small {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
  }

  .brand-icon {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: inline-grid;
    place-items: center;
    border-radius: 8px;
    color: var(--green);
    background: linear-gradient(145deg, #ffe4ad, #fff7e8);
    border: 1px solid rgba(231, 184, 167, 0.9);
    box-shadow: 0 8px 18px rgba(91, 54, 39, 0.08);
  }

  .brand-icon svg {
    width: 22px;
    height: 22px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .brand small {
    color: var(--muted);
    font-weight: 700;
    font-size: 12px;
  }

  .nav {
    display: grid;
    gap: 6px;
  }

  .nav button {
    width: 100%;
    min-height: 44px;
    border: 0;
    text-align: left;
    background: transparent;
    padding: 12px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    color: var(--ink);
  }

  .nav button.active {
    background: #ffe8cf;
    box-shadow: inset 0 0 0 1px rgba(231, 184, 167, 0.8);
  }

  .topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
  }

  .topbar > div:last-child {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .chip,
  button.primary,
  button.secondary {
    border: 1px solid var(--line);
    background: var(--card);
    border-radius: 8px;
    padding: 9px 12px;
    font-weight: 800;
    min-height: 40px;
  }

  button.primary {
    background: var(--gold);
    border-color: #e7b84f;
    cursor: pointer;
    color: var(--ink);
  }

  button.secondary {
    background: var(--card-soft);
    cursor: pointer;
    color: var(--ink);
  }

  button.small {
    border: 1px solid var(--line);
    background: #fffdf9;
    border-radius: 7px;
    padding: 7px 9px;
    cursor: pointer;
    font-weight: 700;
    min-height: 36px;
    color: var(--ink);
  }

  button.danger {
    border-color: #d89a93;
    background: #fff1ef;
    color: var(--red);
  }

  .link-button {
    border: 0;
    background: transparent;
    padding: 0;
    color: var(--green);
    font: inherit;
    font-weight: 900;
    cursor: pointer;
    text-align: left;
  }

  .link-button:hover {
    text-decoration: underline;
  }

  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
  }

  .trading-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 24px;
    color: #fefaf2;
    background: linear-gradient(135deg, #214f49, #2f6f68);
    border-radius: 10px;
    border: 1px solid #285d56;
  }

  #trading.active {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(300px, .85fr) minmax(300px, .85fr);
    gap: 12px;
    align-items: start;
  }
  #trading .trading-hero, #trading .trading-metrics { grid-column: 1 / -1; }
  #trading .invest-panel { min-width: 0; height: min(55vh, 560px); overflow: auto; }

  .trading-hero h2 { margin: 7px 0 6px; font-size: 22px; }
  .trading-hero p { color: #d7e8e4; }
  .trading-kicker { color: #f6c85f; font-size: 10px; font-weight: 900; letter-spacing: .14em; }
  .risk-rule { max-width: 280px; padding: 14px; color: var(--ink); background: #f6c85f; border-radius: 8px; }
  .risk-rule strong, .risk-rule span { display: block; }
  .risk-rule span { margin-top: 4px; font-size: 11px; line-height: 1.5; }
  .trading-metrics { margin-top: 0; }
  .trading-plan-form, .trading-holding-form, .trading-journal-form { margin-top: 14px; }
  .trading-plan-form textarea { min-height: 82px; }
  .trading-plan-form { grid-template-columns: 1fr 1fr; }
  .global-news { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fffdf9; }
  .news-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
  .news-head span { color: var(--muted); font-size: 10px; }
  .news-grid { display: grid; grid-template-columns: 120px minmax(150px, .8fr) minmax(170px, .9fr) minmax(220px, 1.3fr); gap: 6px; }
  .news-grid input, .news-grid select { min-height: 34px; padding: 6px 8px; }
  .news-grid-head { color: var(--muted); font-size: 10px; font-weight: 900; }
  .trading-table-wrap { overflow-x: auto; margin-bottom: 16px; }
  .trading-table-wrap table { min-width: 1280px; }
  .trade-action { display: inline-block; white-space: nowrap; padding: 5px 7px; border-radius: 6px; color: var(--green); background: #e5f4ef; font-weight: 900; }
  .trade-action.danger { color: var(--red); background: #fff0ed; }
  .check-field { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card-soft); }
  .check-field input { width: auto; min-height: 0; }
  .plan-history, .journal-list { display: grid; gap: 8px; margin-top: 16px; }
  .plan-entry { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fffdf9; }
  .plan-entry > div { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
  .plan-entry span { color: var(--muted); font-size: 10px; }
  .plan-entry p { margin-top: 5px; }
  .saved-news { display: grid; gap: 5px; margin-top: 10px; }
  .news-item { display: grid; grid-template-columns: 82px 1fr; gap: 4px 8px; padding: 8px; color: var(--ink); text-decoration: none; border: 1px solid var(--line); border-radius: 7px; background: var(--card); }
  .news-item span { color: var(--green); font-weight: 900; }
  .news-item small { grid-column: 2; color: var(--muted); }
  details { margin-top: 12px; }
  summary { cursor: pointer; color: var(--green); font-weight: 900; }
  .journal-row { display: grid; grid-template-columns: 90px minmax(0,1fr) auto; gap: 14px; align-items: start; padding: 13px 0; border-top: 1px solid var(--line); }
  .journal-row time, .journal-row small { color: var(--muted); }
  .journal-row p { margin: 5px 0; }

  .card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    box-shadow: var(--shadow);
  }

  .capture-hero {
    padding: 22px;
    color: #fefaf2;
    background: linear-gradient(135deg, #2f6f68, #214f49);
    border-radius: 12px;
    border: 1px solid #285d56;
    box-shadow: var(--shadow);
  }

  .capture-hero h2 { margin: 6px 0; font-size: 22px; }
  .capture-hero p { color: #d7e8e4; }
  .capture-kicker { color: var(--gold); font-size: 10px; font-weight: 900; letter-spacing: .14em; }
  .capture-form { grid-template-columns: 1fr 1fr; }
  .manual-entry-hero { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
  .manual-entry-hero .hero-note { display: grid; gap: 4px; min-width: 150px; padding: 12px; border-radius: 8px; color: var(--ink); background: var(--gold); }
  .manual-entry-hero .hero-note span { color: #6f4e19; font-size: 11px; }
  .manual-entry-form { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 14px; }
  .manual-entry-form label, .category-form label { display: grid; gap: 6px; color: var(--muted); font-weight: 800; }
  .manual-entry-form label span, .category-form label span { font-size: 11px; }
  .assistant-note-card { border-color: #bfd9d0; background: #f7fffb; }
  .compact-steps { display: grid; gap: 8px; margin: 0; padding-left: 20px; color: var(--muted); line-height: 1.55; }
  .category-form { grid-template-columns: 1fr 1.2fr 1.2fr .7fr auto auto; align-items: end; margin-top: 14px; }
  .category-settings-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
  .category-setting-group { border: 1px solid var(--line); border-radius: 8px; background: #fffdf9; overflow: hidden; }
  .category-setting-head { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--card-soft); }
  .category-setting-head span { color: var(--muted); font-size: 11px; }
  .category-setting-items { display: grid; gap: 0; }
  .category-setting-item { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 8px 12px; border-top: 1px solid #f1ddd3; }
  .category-setting-item span { overflow-wrap: anywhere; }
  .capture-file {
    min-height: 118px;
    display: grid;
    gap: 8px;
    place-items: center;
    text-align: center;
    padding: 18px;
    border: 2px dashed #d79b84;
    border-radius: 12px;
    background: #fff7ee;
    cursor: pointer;
  }
  .capture-file strong { font-size: 16px; color: var(--green); }
  .capture-file span { color: var(--muted); line-height: 1.45; }
  .capture-file input { border: 0; background: transparent; padding: 0; min-height: auto; }
  .import-inbox { display: grid; gap: 10px; }
  .import-card, .candidate-card, .candidate-mini {
    padding: 12px;
    border: 1px solid #efd1c5;
    border-radius: 10px;
    background: #fffdf9;
  }
  .import-card { display: grid; gap: 9px; }
  .import-card-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
  .import-card-head strong { line-height: 1.25; }
  .import-card-head span, .candidate-mini span, .candidate-card span { color: var(--muted); font-size: 12px; line-height: 1.35; }
  .import-badges { display: flex; flex-wrap: wrap; gap: 6px; }
  .import-badges span, .import-badges a {
    padding: 5px 7px;
    border-radius: 999px;
    background: #fff2e2;
    color: var(--green);
    font-weight: 800;
    text-decoration: none;
  }
  .candidate-mini { display: grid; gap: 4px; }
  .candidate-card { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
  .candidate-card > div:first-child { display: grid; gap: 4px; min-width: 0; }
  .candidate-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
  .review-card { border-color: #d79b84; background: #fff7ee; }
  .review-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .review-form label { display: grid; gap: 6px; color: var(--muted); font-weight: 800; }
  .review-form label span { font-size: 11px; }
  .review-form textarea { min-height: 140px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
  .field-source-list { display: grid; gap: 8px; margin-top: 12px; }
  .field-source-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: 8px; align-items: start; padding: 9px; border: 1px solid #efd1c5; border-radius: 8px; background: #fffdf9; }
  .field-source-row b { color: var(--ink); }
  .field-source-row span { color: var(--muted); line-height: 1.35; overflow-wrap: anywhere; }
  .field-source-row em { font-style: normal; font-weight: 900; white-space: nowrap; }

  .metric {
    font-size: 18px;
    font-weight: 900;
    line-height: 1.12;
    margin-top: 10px;
    overflow-wrap: anywhere;
  }
  .dual-metric-card { min-width: 0; }
  .currency-pair { display: grid; gap: 8px; margin-top: 11px; }
  .currency-pair > div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
  .currency-pair span { color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .08em; }
  .currency-pair strong { font-size: 16px; overflow-wrap: anywhere; }

  .positive { color: var(--green); }
  .negative { color: var(--red); }

  .section-title {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
  }

  .section-title h2 {
    margin-bottom: 4px;
  }

  .trend-card {
    margin-top: 14px;
  }

  .trend-chart {
    padding: 0 0 8px;
  }

  .trend-kpi-row {
    display: flex;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
  }

  .trend-kpi {
    flex: 1;
    min-width: 120px;
    background: var(--card);
    border-radius: 10px;
    padding: 12px 14px;
    text-align: center;
    border: 1px solid #f0d8c8;
  }

  .trend-kpi-label {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 3px;
    font-weight: 600;
  }

  .trend-kpi-value {
    font-size: 18px;
    font-weight: 800;
  }

  .trend-kpi-value.income { color: var(--green); }
  .trend-kpi-value.expense { color: var(--red); }
  .trend-kpi-value.repayment { color: #b3833d; }
  .trend-kpi-value.net { color: #2f4f6f; }

  .trend-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .trend-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  .legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
  }

  .legend-dot.income { background: var(--green); }
  .legend-dot.expense { background: var(--red); }
  .legend-dot.repayment { background: #b3833d; }
  .legend-dot.net { background: #2f4f6f; }

  .dashboard-feed {
    margin-top: 14px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .insight-card {
    min-width: 0;
  }

  .insight-list {
    display: grid;
    gap: 9px;
  }

  .insight-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-top: 1px solid #efd1c5;
  }

  .insight-row:first-child {
    border-top: 0;
    padding-top: 0;
  }

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

  .insight-row strong {
    font-size: 12px;
    line-height: 1.25;
  }

  .insight-row span,
  .empty-note {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
  }

  .insight-row b {
    flex: 0 0 auto;
    max-width: 44%;
    text-align: right;
    font-size: 12px;
    overflow-wrap: anywhere;
  }

  .tag-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    white-space: normal;
  }

  .tag-chip {
    font-style: normal;
    padding: 3px 9px;
    border-radius: 999px;
    background: #ffe8cf;
    color: var(--ink);
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
  }

  .treemap {
    position: relative;
    width: 100%;
    height: 220px;
    margin-top: 10px;
    border-radius: 8px;
    overflow: hidden;
    background: #fff7ee;
    border: 1px solid var(--line);
  }

  .treemap-cell {
    position: absolute;
    box-sizing: border-box;
    border: 1px solid;
    border-radius: 6px;
    padding: 6px 8px;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    display: grid;
    gap: 2px;
    align-content: start;
  }

  .treemap-cell strong {
    font-size: 12px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .treemap-cell span {
    font-size: 11px;
    font-weight: 800;
    color: var(--muted);
    white-space: nowrap;
  }

  .treemap-cell small {
    font-size: 10px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

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

  .ai-settings-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-weight: 800;
  }

  .ai-settings-form label span {
    font-size: 11px;
  }

  .llm-extra-fields {
    display: grid;
    gap: 8px;
  }

  .extra-fields-head {
    display: grid;
    gap: 3px;
    padding: 10px 12px;
    border: 1px solid #e7b84f;
    border-radius: 8px;
    background: #fff8e6;
  }

  .extra-fields-head strong {
    font-size: 12px;
  }

  .extra-fields-head span {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.4;
  }

  .extra-fields-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .extra-fields-grid label {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-weight: 800;
  }

  .extra-fields-grid label span {
    font-size: 11px;
  }

  .muted-row b {
    color: var(--muted);
  }

  .pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .pager button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
  }

  .account-type-guide {
    background: #fff7ee;
  }

  .table-intro {
    box-shadow: none;
  }

  .account-detail-card .section-title {
    align-items: flex-start;
  }

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

  .account-summary div {
    min-width: 0;
    padding: 12px;
    border: 1px solid #efd1c5;
    border-radius: 8px;
    background: #fffdf9;
    display: grid;
    gap: 6px;
  }

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

  .account-summary strong {
    font-size: 13px;
    overflow-wrap: anywhere;
  }

  .account-group-row td {
    background: #fff2e2;
    color: var(--ink);
    font-weight: 900;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .account-group-row span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    margin-left: 6px;
  }

  .guide-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .guide-grid div {
    padding: 10px 0;
    border-top: 1px solid #efd1c5;
  }

  .guide-grid strong {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
  }

  .guide-grid p {
    font-size: 12px;
    line-height: 1.45;
  }

  .calendar-title {
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
  }

  .calendar-title h2 {
    margin-bottom: 4px;
  }

  .calendar-controls {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .calendar-controls input[type="month"] {
    width: auto;
    min-width: 135px;
    min-height: 36px;
    padding: 7px 9px;
  }

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

  .calendar-head {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-align: center;
  }

  .calendar-day {
    min-height: 48px;
    border: 1px solid #efd1c5;
    border-radius: 8px;
    background: #fffdf9;
    color: var(--ink);
    display: grid;
    place-items: center;
    gap: 3px;
    cursor: pointer;
    padding: 6px 2px;
  }

  .calendar-day strong {
    font-size: 12px;
    line-height: 1;
  }

  .calendar-day span {
    min-height: 7px;
    display: flex;
    justify-content: center;
    gap: 3px;
    flex-wrap: wrap;
    max-width: 100%;
  }

  .calendar-day.active {
    background: #ffe8cf;
    border-color: #d79b84;
    box-shadow: inset 0 0 0 1px #d79b84;
  }

  .calendar-day.empty {
    background: rgba(255, 250, 244, 0.35);
    cursor: default;
  }

  .calendar-dot {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    display: inline-block;
  }

  .calendar-dot.income { background: var(--green); }
  .calendar-dot.expense { background: var(--red); }
  .calendar-dot.repayment { background: #b3833d; }
  .calendar-dot.fixed { background: #7d6097; }
  .calendar-dot.planned-income { background: #4f8d9a; }
  .calendar-dot.planned-expense { background: #c78657; }
  .calendar-dot.paid { background: #2f9d62; }
  .calendar-dot.unpaid { background: #f0a33a; }
  .calendar-dot.overdue { background: #d3483e; }

  .repayment-schedule-review {
    margin-top: 12px;
    display: grid;
    gap: 10px;
  }

  .schedule-review-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border: 1px solid #efd1c5;
    border-radius: 8px;
    background: #fff7ee;
  }

  .schedule-review-head strong,
  .schedule-review-head span {
    display: block;
  }

  .schedule-review-head span {
    margin-top: 4px;
    color: var(--muted);
    line-height: 1.45;
  }

  .schedule-review-head b {
    white-space: nowrap;
  }

  .schedule-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .schedule-table {
    min-width: 720px;
    box-shadow: none;
    border: 1px solid #efd1c5;
  }

  table {
    width: 100%;
    min-width: 620px;
    border-collapse: collapse;
    background: var(--card);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
  }

  th,
  td {
    border-bottom: 1px solid #efd1c5;
    padding: 11px;
    text-align: left;
    white-space: nowrap;
  }

  th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

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

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

  textarea {
    min-height: 92px;
    resize: vertical;
  }

  .full { grid-column: 1 / -1; }
  .status { margin-top: 10px; font-weight: 700; color: var(--muted); }
  .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .clickable { cursor: pointer; }
  .clickable:hover { background: #fff2e2; }

  .view,
  .view.stack {
    display: none;
  }

  .view.active { display: block; }

  .view.stack.active {
    display: grid;
  }

  .stack {
    gap: 14px;
  }

  .stack > table {
    display: table;
    overflow: hidden;
  }

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

    aside {
      position: sticky;
      top: 0;
      z-index: 10;
      padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
      border-right: 0;
      border-bottom: 1px solid var(--line);
      background: rgba(244, 199, 183, 0.96);
      backdrop-filter: blur(18px);
    }

    .brand {
      margin-bottom: 10px;
      font-size: 13px;
    }

    .brand-icon {
      width: 30px;
      height: 30px;
      flex-basis: 30px;
    }

    .brand-icon svg {
      width: 19px;
      height: 19px;
    }

    .brand small {
      font-size: 12px;
    }

    .nav {
      display: flex;
      gap: 8px;
      overflow-x: auto;
      padding-bottom: 2px;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: none;
    }

    .nav::-webkit-scrollbar {
      display: none;
    }

    .nav button {
      width: auto;
      min-width: max-content;
      min-height: 40px;
      padding: 9px 12px;
      background: rgba(255, 250, 244, 0.55);
      white-space: nowrap;
    }

    main {
      padding: 16px;
      padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }

    .topbar {
      display: grid;
      gap: 12px;
      margin-bottom: 16px;
    }

    .topbar > div:last-child {
      justify-content: flex-start;
    }

    h1 {
      font-size: 18px;
    }

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

    #trendChart {
      max-height: 260px;
    }

    .dashboard-feed {
      grid-template-columns: 1fr;
      gap: 10px;
    }

    .card {
      padding: 14px;
    }

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

    .metric {
      font-size: 16px;
    }

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

    .stack > table {
      display: block;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }
  }

  @media (max-width: 1180px) {
    #trading.active { grid-template-columns: 1fr 1fr; }
    #trading .trading-plan-card { grid-column: 1 / -1; }
    #trading .invest-panel { height: auto; max-height: 620px; }
    .news-grid { grid-template-columns: 105px 1fr 1fr; }
    .news-grid > :last-child { grid-column: 2 / -1; }
  }

  @media (max-width: 760px) {
    #trading.active { grid-template-columns: 1fr; }
    #trading .trading-plan-card { grid-column: auto; }
    #trading .invest-panel { max-height: none; }
    .news-grid { grid-template-columns: 1fr; padding-top: 8px; border-top: 1px solid var(--line); }
    .news-grid > :last-child { grid-column: auto; }
    .news-grid-head { display: none; }
  }

  @media (max-width: 520px) {
    main {
      padding: 12px;
      padding-bottom: calc(22px + env(safe-area-inset-bottom));
    }

    h1 {
      font-size: 17px;
    }

    h2 {
      font-size: 13px;
    }

    .chip,
    button.primary,
    button.secondary,
    button.small,
    input,
    select,
    textarea {
      border-radius: 8px;
    }

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

    .grid .card {
      min-height: 112px;
    }

    .metric {
      font-size: 14px;
    }

    .trend-card {
      margin-top: 10px;
    }

    .trend-kpi-row {
      gap: 8px;
    }

    .trend-kpi {
      min-width: 70px;
      padding: 10px 8px;
    }

    .trend-kpi-value {
      font-size: 15px;
    }

    #trendChart {
      max-height: 240px;
    }

    .insight-row {
      align-items: flex-start;
    }

    .insight-row b {
      max-width: 42%;
    }

    .treemap {
      height: 180px;
    }

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

    .extra-fields-grid {
      grid-template-columns: 1fr;
    }

    .pager {
      justify-content: space-between;
      gap: 6px;
      font-size: 12px;
    }

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

    .calendar-title,
    .calendar-controls {
      display: grid;
      grid-template-columns: 1fr;
      justify-content: stretch;
    }

    .calendar-controls {
      grid-template-columns: 1fr 1fr;
    }

    .calendar-controls input[type="month"] {
      width: 100%;
      grid-column: 1 / -1;
    }

    .calendar-day {
      min-height: 42px;
      border-radius: 7px;
    }

    .schedule-review-head {
      display: grid;
    }

    .guide-grid {
      grid-template-columns: 1fr;
      gap: 4px;
    }

    .account-detail-card .section-title {
      display: grid;
    }

    form,
    .capture-form,
    .review-form,
    .manual-entry-form,
    .category-form {
      grid-template-columns: 1fr;
    }

    .manual-entry-hero { display: grid; }
    .category-settings-list { grid-template-columns: 1fr; }

    .full {
      grid-column: auto;
    }

    .field-source-row {
      grid-template-columns: 1fr;
    }

    .field-source-row em {
      white-space: normal;
    }

    .confirm-import-btn {
      margin-top: 14px;
      min-height: 52px;
      font-size: 15px;
      font-weight: 900;
      border-radius: 10px;
      box-shadow: 0 8px 20px rgba(91, 54, 39, 0.14);
    }

    .topbar p {
      font-size: 12px;
    }

    .version-badge {
      display: inline-block;
      font-style: normal;
      font-size: 10px;
      font-weight: 800;
      color: #5b3627;
      background: #ffe4ad;
      border: 1px solid #e7b84f;
      border-radius: 999px;
      padding: 1px 7px;
      vertical-align: middle;
      margin-left: 2px;
    }

    .topbar > div:last-child {
      display: grid;
      grid-template-columns: 1fr auto;
      width: 100%;
    }

    .chip {
      min-width: 0;
      overflow-wrap: anywhere;
    }

    table {
      min-width: 560px;
      font-size: 12px;
    }

    th,
    td {
      padding: 10px;
    }

    .trading-hero { display: grid; padding: 18px; }
    .risk-rule { max-width: none; }
    .journal-row { grid-template-columns: 70px 1fr; }
    .journal-row > b { grid-column: 2; }
  }

  /* ================= Mobile shell (true mobile layout) ================= */
  .mobile-shell {
    display: none;
    min-height: 100vh;
    background: var(--paper);
    color: var(--ink);
  }

  .m-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
    background: rgba(244, 199, 183, 0.96);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--line);
  }

  .m-brand {
    display: grid;
    gap: 2px;
  }

  .m-brand strong {
    font-size: 16px;
  }

  .m-brand .m-brand-name {
    font-size: 22px;
    line-height: 1;
  }

  .m-brand span {
    color: var(--muted);
    font-size: 12px;
  }

  .m-header-actions {
    display: flex;
    gap: 8px;
  }

  .m-icon-btn {
    min-width: 40px;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
    color: var(--ink);
    font-size: 16px;
    font-weight: 800;
  }

  .m-content {
    padding: 14px 14px calc(90px + env(safe-area-inset-bottom));
    max-width: 640px;
    margin: 0 auto;
  }

  .m-page {
    display: none;
  }

  .m-page.active {
    display: grid;
    gap: 14px;
  }

  .m-page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 2px;
  }

  .m-page-head h2 {
    margin: 0;
    font-size: 18px;
  }

  .m-page-head > span {
    color: var(--muted);
    font-size: 13px;
  }

  .m-calendar-controls {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .m-calendar-controls span {
    font-weight: 800;
    font-size: 14px;
    min-width: 86px;
    text-align: center;
  }

  .m-networth-card {
    display: grid;
    gap: 6px;
    padding: 22px 20px;
    border-radius: 16px;
    color: #fefaf2;
    background: linear-gradient(135deg, #214f49, #2f6f68);
    border: 1px solid #285d56;
    box-shadow: var(--shadow);
  }

  .m-networth-label {
    font-size: 12px;
    font-weight: 800;
    color: #d7e8e4;
    letter-spacing: 0.05em;
  }

  .m-networth-value {
    font-size: 30px;
    line-height: 1.1;
  }

  .m-networth-sub {
    font-size: 11px;
    color: #d7e8e4;
    line-height: 1.4;
  }

  .m-section {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
    box-shadow: var(--shadow);
  }

  .m-section-title {
    margin: 0 0 10px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .m-section-badge {
    background: var(--gold);
    border-radius: 999px;
    padding: 2px 9px;
    font-size: 11px;
    font-weight: 800;
  }

  .m-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .m-metric {
    display: grid;
    gap: 3px;
    padding: 10px;
    border-radius: 10px;
    background: #fff7ee;
    border: 1px solid #f0d8c8;
  }

  .m-metric span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
  }

  .m-metric strong {
    font-size: 16px;
  }

  .m-capture-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .m-capture-btn {
    display: grid;
    gap: 4px;
    justify-items: start;
    text-align: left;
    padding: 16px 14px;
    border-radius: 12px;
    border: 1px solid;
    min-height: 118px;
    cursor: pointer;
  }

  .m-capture-photo {
    background: linear-gradient(145deg, #ffe4ad, #fff7e8);
    border-color: #e7b84f;
    color: var(--ink);
  }

  .m-capture-paste {
    background: #e5f4ef;
    border-color: #b5dccd;
    color: var(--ink);
  }

  .m-capture-icon {
    font-size: 26px;
  }

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

  .m-capture-btn small {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
  }

  .m-paste-panel {
    display: grid;
    gap: 10px;
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fffdf9;
  }

  .m-btn {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card-soft);
    color: var(--ink);
    font-weight: 800;
    padding: 10px 16px;
    cursor: pointer;
  }

  .m-btn-primary {
    background: var(--gold);
    border-color: #e7b84f;
  }

  .m-btn-lg {
    width: 100%;
    min-height: 50px;
    font-size: 16px;
  }

  .m-status {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    line-height: 1.4;
  }

  .m-list {
    display: grid;
    gap: 0;
  }

  .m-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 2px;
    border-top: 1px solid #f0d8c8;
  }

  .m-row:first-child {
    border-top: 0;
  }

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

  .m-row strong {
    font-size: 13px;
    line-height: 1.25;
  }

  .m-row span {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.3;
  }

  .m-row b {
    flex: 0 0 auto;
    font-size: 13px;
    white-space: nowrap;
  }

  .m-row .pos,
  .pos {
    color: var(--green);
  }

  .m-row .neg,
  .neg {
    color: var(--red);
  }

  .m-empty {
    padding: 14px 2px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
  }

  .m-row-actions {
    display: flex;
    gap: 8px;
    padding: 2px 0 10px;
  }

  .m-loan-row {
    padding-bottom: 4px;
  }

  .m-loan-detail {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    padding: 0 2px 10px;
    border-bottom: 1px solid #f0d8c8;
    color: var(--muted);
    font-size: 11px;
  }

  .m-repay-row.paid b,
  .m-repay-row.paid strong {
    color: var(--green);
  }

  .m-repay-row.paid span {
    color: var(--green);
    font-weight: 800;
  }

  .paid-meta {
    color: var(--green);
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
  }

  .m-calendar-head,
  .m-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
  }

  .m-calendar-head span {
    text-align: center;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    padding: 4px 0;
  }

  .m-cal-day {
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--card);
    color: var(--ink);
    min-height: 44px;
    font-weight: 800;
  }

  .m-cal-day.today {
    background: var(--gold);
    border-color: #e7b84f;
  }

  .m-cal-day.empty {
    border: 0;
    background: transparent;
  }

  .m-cal-day span {
    display: flex;
    gap: 2px;
  }

  .m-calendar-dot,
  .calendar-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    display: inline-block;
  }

  .m-field {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-weight: 800;
    font-size: 11px;
    margin-bottom: 10px;
  }

  .m-field input,
  .m-field select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fffdf9;
    padding: 10px 12px;
    color: var(--ink);
    font-size: 14px;
  }

  .m-help {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
    margin: 0 0 8px;
  }

  .m-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    background: #fff7ee;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
    margin: 0 0 10px;
  }

  .m-review-card {
    display: grid;
    gap: 2px;
  }

  .m-confirm-sticky {
    position: sticky;
    bottom: calc(76px + env(safe-area-inset-bottom));
    z-index: 5;
    margin-top: 14px;
    font-size: 16px;
  }

  .m-review-source {
    padding: 10px 12px;
    border-radius: 10px;
    background: #fff8e6;
    border: 1px solid #e7b84f;
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 10px;
  }

  .m-review-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 10px;
  }

  .m-extra-fields {
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #e7b84f;
    border-radius: 10px;
    background: #fff8e6;
  }

  .m-extra-fields > strong {
    display: block;
    font-size: 12px;
    margin-bottom: 8px;
  }

  .m-review-schedule {
    padding: 10px 12px;
    border-radius: 10px;
    background: #e5f4ef;
    border: 1px solid #b5dccd;
    font-size: 12px;
    font-weight: 800;
    margin: 10px 0;
    display: grid;
    gap: 3px;
  }

  .m-advice-row.danger strong {
    color: var(--red);
  }

  .m-advice-row.warning strong {
    color: #b07a2e;
  }

  .m-tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    display: flex;
    background: rgba(255, 250, 244, 0.97);
    backdrop-filter: blur(18px);
    border-top: 1px solid var(--line);
    padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
  }

  .m-tab {
    flex: 1;
    display: grid;
    gap: 2px;
    place-items: center;
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 6px 0;
    border-radius: 10px;
  }

  .m-tab span {
    font-size: 20px;
  }

  .m-tab small {
    font-size: 10px;
    font-weight: 800;
  }

  .m-tab.active {
    color: var(--green);
    background: #e5f4ef;
  }

  @media (min-width: 821px) {
    .mobile-shell {
      display: none !important;
    }
  }
