:root {
  color-scheme: light;
  --canvas: #f3f5f1;
  --panel: #ffffff;
  --ink: #18211e;
  --muted: #68736e;
  --muted-strong: #4b5752;
  --border: #dde3dd;
  --border-strong: #c8d1ca;
  --accent: #0b6559;
  --accent-hover: #084e45;
  --accent-soft: #e8f3f0;
  --positive: #bc2f2a;
  --positive-soft: #fff1ef;
  --negative: #087552;
  --negative-soft: #e9f7f0;
  --warning: #9a5b00;
  --warning-soft: #fff5df;
  --info-soft: #eef2f7;
  --shadow: 0 8px 24px rgba(19, 38, 31, 0.06);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-family:
    "Segoe UI",
    "Microsoft YaHei UI",
    "PingFang SC",
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.brand-block,
.topbar-actions,
.section-heading,
.heading-actions,
.toolbar,
.toolbar-title,
.summary-strip,
.modal-actions,
.inline-add-form,
.check-line {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border-radius: 6px;
  font-size: 18px;
  font-weight: 700;
}

.brand-block h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand-block p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  gap: 12px;
  flex-wrap: wrap;
}

.sync-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted-strong);
  font-size: 12px;
  white-space: nowrap;
}

.sync-dot {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sync-state.is-busy .sync-dot {
  animation: pulse 1s infinite ease-in-out;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

main {
  display: grid;
  width: 100%;
  min-width: 0;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr);
  padding: 24px 28px 32px;
}

.notice-stack {
  display: grid;
  gap: 8px;
  padding: 12px 28px 0;
}

.notice {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 13px;
  color: var(--warning);
  background: var(--warning-soft);
  border: 1px solid #f0d7a8;
  border-radius: 6px;
  font-size: 13px;
}

.notice button {
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
}

.summary-strip {
  align-items: stretch;
  gap: 14px;
  min-width: 0;
}

.summary-card {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 138px;
  padding: 22px 24px;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: var(--shadow);
}

.summary-card-action {
  cursor: pointer;
  transition:
    border-color 120ms ease,
    transform 120ms ease,
    box-shadow 120ms ease;
}

.summary-card-action:hover {
  border-color: #aabbb2;
  box-shadow: 0 10px 28px rgba(19, 38, 31, 0.09);
  transform: translateY(-1px);
}

.summary-card-action:focus-visible {
  outline: 3px solid rgba(11, 101, 89, 0.2);
  outline-offset: 2px;
}

.summary-link-icon {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.summary-card::after {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 46px;
  height: 3px;
  background: var(--accent);
  content: "";
}

.summary-card:nth-child(2)::after {
  background: var(--positive);
}

.summary-card:nth-child(3)::after {
  background: #c5861b;
}

.summary-card-primary {
  color: #fff;
  background: #173f38;
  border-color: #173f38;
}

.summary-card-primary::after {
  background: #8ed1c1;
}

.summary-label {
  color: var(--muted);
  font-size: 13px;
}

.summary-card-primary .summary-label {
  color: #c6ddd7;
}

.summary-value {
  display: block;
  margin: 8px 0;
  font-size: 30px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.summary-meta {
  color: var(--muted);
  font-size: 12px;
}

.summary-card-primary .summary-meta {
  color: #b7d2cb;
}

.numeric {
  font-variant-numeric: tabular-nums;
}

.is-positive {
  color: var(--positive) !important;
}

.is-negative {
  color: var(--negative) !important;
}

.is-muted {
  color: var(--muted) !important;
}

.toolbar {
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
  min-height: 62px;
  padding: 10px 14px 10px 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.toolbar-title {
  gap: 12px;
  min-width: 170px;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.toolbar-title strong {
  padding-left: 12px;
  border-left: 1px solid var(--border-strong);
  font-size: 16px;
}

.period-options {
  display: flex;
  gap: 3px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 3px;
  overflow-x: auto;
  background: #f1f3ef;
  border-radius: 5px;
  scrollbar-width: thin;
}

.period-button {
  flex: 1;
  min-width: max-content;
  padding: 8px 13px;
  color: var(--muted-strong);
  background: transparent;
  border: 0;
  border-radius: 4px;
  font-size: 12px;
}

.period-button:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.65);
}

.period-button.is-active {
  color: var(--accent);
  background: #fff;
  box-shadow: 0 1px 4px rgba(20, 42, 34, 0.11);
  font-weight: 700;
}

.panel {
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: 0 3px 12px rgba(25, 43, 35, 0.03);
}

.trend-body {
  padding: 18px 20px 14px;
}

.trend-chart {
  width: 100%;
  min-height: 260px;
  overflow: hidden;
}

.trend-chart svg {
  display: block;
  width: 100%;
  overflow: visible;
}

.trend-grid-line {
  stroke: #e5ebe6;
  stroke-width: 1;
}

.trend-axis-label {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.trend-axis-title {
  fill: var(--muted-strong);
  font-size: 11px;
  font-weight: 600;
}

.trend-snapshot-line {
  fill: none;
  stroke: #32413c;
  stroke-width: 1.8;
}

.trend-live-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-dasharray: 6 6;
}

.trend-snapshot-dot {
  fill: #17211e;
  stroke: #fff;
  stroke-width: 2;
}

.trend-live-dot {
  fill: var(--panel);
  stroke: var(--accent);
  stroke-width: 2;
}

.trend-direct-label {
  fill: var(--ink);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.trend-empty {
  display: flex;
  min-height: 240px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  text-align: center;
}

.trend-empty strong {
  color: var(--ink);
  font-size: 14px;
}

.trend-empty span {
  font-size: 12px;
}

.trend-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  min-height: 26px;
  color: var(--muted);
  font-size: 11px;
}

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

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #17211e;
  border-radius: 50%;
}

.legend-dash {
  display: inline-block;
  width: 20px;
  border-top: 2px dashed var(--accent);
}

.market-trends-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
}

.market-trend-item {
  min-width: 0;
  padding: 14px 14px 10px;
  background: #fff;
}

.market-trend-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.market-trend-name {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 700;
}

.market-trend-value {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.market-trend-change {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.market-chart {
  width: 100%;
  min-height: 128px;
  margin-top: 8px;
}

.market-chart svg {
  display: block;
  width: 100%;
  overflow: visible;
}

.market-chart-line {
  fill: none;
  stroke-width: 1.8;
}

.market-chart-grid {
  stroke: #e8ece8;
  stroke-width: 1;
}

.market-chart-label {
  fill: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.market-chart-current {
  stroke: #fff;
  stroke-width: 1.5;
}

.market-trend-source {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.market-trend-error {
  display: flex;
  min-height: 128px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.market-trend-loading {
  grid-column: 1 / -1;
  display: flex;
  min-height: 170px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
}

.section-heading {
  justify-content: space-between;
  gap: 20px;
  min-height: 70px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
}

.section-heading h2 {
  margin: 3px 0 0;
  font-size: 17px;
  line-height: 1.25;
}

.section-heading-wrap {
  flex-wrap: wrap;
}

.heading-actions {
  gap: 10px;
  flex-wrap: wrap;
}

.section-note {
  color: var(--muted);
  font-size: 12px;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 5px;
  transition:
    background-color 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}

.button {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.button svg,
.icon-button svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  stroke-width: 1.8;
}

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

.button-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.button-secondary {
  color: var(--ink);
  background: #fff;
  border-color: var(--border-strong);
}

.button-secondary:hover {
  border-color: #9daaa1;
  background: #f8f9f7;
}

.button-quiet {
  color: var(--muted-strong);
  background: transparent;
  border-color: transparent;
}

.button-quiet:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.button-danger-quiet {
  color: var(--danger, var(--positive));
  background: transparent;
  border-color: transparent;
}

.button-danger-quiet:hover {
  background: var(--positive-soft);
}

.icon-button {
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--muted-strong);
  background: transparent;
  border-color: transparent;
}

.icon-button:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.icon-button.danger:hover {
  color: var(--positive);
  background: var(--positive-soft);
}

.compact-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.compact-field > span {
  white-space: nowrap;
}

.compact-field select {
  height: 36px;
  min-width: 130px;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.asset-table {
  min-width: 1080px;
}

.platform-table {
  min-width: 740px;
}

.plan-table {
  min-width: 1210px;
}

.income-plan-table,
.expense-plan-table {
  min-width: 1060px;
}

.transaction-table {
  min-width: 1020px;
}

.data-table th,
.data-table td {
  padding: 11px 14px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid #edf0ec;
}

.data-table th {
  color: var(--muted);
  background: #f8f9f7;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover td {
  background: #fbfcfa;
}

.data-table tfoot td {
  padding: 13px 14px;
  background: #f6f8f5;
  border-top: 1px solid var(--border-strong);
  font-weight: 700;
}

.data-table .align-right,
.align-right {
  text-align: right !important;
}

.cell-main {
  color: var(--ink);
  font-weight: 600;
}

.cell-sub {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.rate {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.asset-name-cell {
  min-width: 190px;
}

.asset-title-line {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.asset-code {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.platform-badge,
.source-badge,
.status-badge,
.category-badge {
  display: inline-flex;
  align-items: center;
  width: max-content;
  max-width: 100%;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}

.platform-badge {
  color: #3f514a;
  background: #edf1ed;
}

.category-badge {
  color: #3e574f;
  background: #edf4f1;
}

.source-badge {
  margin-top: 3px;
  color: var(--muted-strong);
  background: #f0f2ef;
  font-weight: 600;
}

.source-badge.source-live {
  color: #075f49;
  background: var(--negative-soft);
}

.source-badge.source-estimate {
  color: var(--warning);
  background: var(--warning-soft);
}

.source-badge.source-stale,
.source-badge.source-manual {
  color: #5c6470;
  background: var(--info-soft);
}

.status-badge {
  color: #166247;
  background: #e8f6ef;
}

.status-badge.is-paused,
.status-badge.is-failed {
  color: #8a4b00;
  background: #fff3df;
}

.status-badge.is-insufficient {
  color: #9b2e29;
  background: #fff0ee;
}

.status-badge.is-success {
  color: #166247;
  background: #e8f6ef;
}

.allocation {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 105px;
}

.allocation-track {
  width: 58px;
  height: 4px;
  overflow: hidden;
  background: #e6eae6;
  border-radius: 4px;
}

.allocation-track span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.empty-state-row td {
  padding: 0 !important;
}

.empty-state {
  display: flex;
  min-height: 150px;
  align-items: center;
  justify-content: center;
  padding: 28px;
  flex-direction: column;
  gap: 8px;
  text-align: center;
}

.empty-state-icon {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 50%;
}

.empty-state-icon svg {
  width: 18px;
  height: 18px;
}

.empty-state strong {
  font-size: 14px;
}

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

.inline-quantity {
  width: 112px;
  height: 32px;
  padding: 4px 8px;
  text-align: right;
}

.inline-total {
  width: 120px;
  height: 32px;
  padding: 4px 8px;
  text-align: right;
}

.row-actions {
  display: inline-flex;
  gap: 2px;
  justify-content: flex-end;
}

.plan-asset-name {
  display: block;
  min-width: 170px;
}

.plan-next {
  display: block;
  min-width: 108px;
  font-variant-numeric: tabular-nums;
}

.history-details summary {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  cursor: pointer;
  list-style: none;
}

.history-details summary::-webkit-details-marker {
  display: none;
}

.history-details summary strong {
  display: block;
  margin-top: 2px;
  font-size: 17px;
}

.history-count {
  color: var(--muted);
  font-size: 12px;
}

.history-table-wrap {
  border-top: 1px solid var(--border);
}

.income-history-details {
  border-top: 1px solid var(--border);
}

.income-transaction-table {
  min-width: 820px;
}

.income-account {
  display: block;
  min-width: 150px;
}

.snapshot-search {
  position: relative;
  display: flex;
  width: min(280px, 100%);
  align-items: center;
}

.snapshot-search svg {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}

.snapshot-search input {
  width: 100%;
  height: 36px;
  padding: 6px 10px 6px 32px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  outline: none;
}

.snapshot-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 101, 89, 0.1);
}

.snapshot-month-control {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: #f3f5f2;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.snapshot-month-picker {
  position: relative;
  display: flex;
  align-items: center;
}

.snapshot-month-picker svg {
  position: absolute;
  left: 7px;
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
}

.snapshot-month-picker input {
  width: 134px;
  height: 30px;
  padding: 3px 5px 3px 26px;
  color: var(--ink);
  background: #fff;
  border: 0;
  border-radius: 3px;
  outline: none;
}

.snapshot-month-picker input:focus {
  box-shadow: 0 0 0 2px rgba(11, 101, 89, 0.15);
}

.snapshot-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.snapshot-table {
  min-width: 980px;
}

.snapshot-manual-row td {
  color: var(--ink);
  background: #f7faf8;
  font-weight: 700;
}

.snapshot-average-row td {
  color: var(--muted-strong);
  background: #eef4f1;
  border-top: 1px solid var(--border-strong);
}

.snapshot-average-row .cell-main {
  color: var(--accent);
}

.snapshot-platform-list {
  display: block;
  max-width: 340px;
  color: var(--muted-strong);
  font-size: 12px;
}

.snapshot-source {
  color: var(--muted-strong);
  font-size: 11px;
}

.snapshot-detail-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.snapshot-detail-stat {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  background: #f8faf7;
}

.snapshot-detail-stat span {
  color: var(--muted);
  font-size: 10px;
}

.snapshot-detail-stat strong {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.snapshot-detail-section {
  display: grid;
  gap: 8px;
}

.snapshot-detail-note {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 11px;
}

#snapshot-detail-dialog {
  width: min(920px, calc(100vw - 28px));
}

.snapshot-detail-section h3 {
  margin: 0;
  font-size: 14px;
}

.snapshot-category-detail-table {
  min-width: 760px;
}

.snapshot-platform-detail-table {
  min-width: 360px;
}

.snapshot-category-row td {
  background: #f3f6f3;
  border-top: 1px solid var(--border-strong);
  font-weight: 700;
}

.snapshot-category-row:first-child td {
  border-top: 0;
}

.snapshot-detail-toggle-row {
  cursor: pointer;
}

.snapshot-detail-toggle-row:hover td {
  background: #f1f7f4;
}

.snapshot-expand-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.snapshot-expand-label svg {
  width: 14px;
  height: 14px;
  color: var(--muted);
  flex: 0 0 auto;
}

.snapshot-category-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.snapshot-category-label i {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
}

.snapshot-category-count {
  margin-left: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
}

.snapshot-asset-detail-row td:first-child {
  color: var(--muted);
}

.snapshot-asset-platform-row td {
  color: var(--muted-strong);
  background: #fbfcfa;
  font-size: 12px;
}

.snapshot-asset-platform-row td:nth-child(2) {
  padding-left: 34px;
}

.snapshot-platform-child-row td {
  background: #fbfcfa;
}

.snapshot-platform-child-row .category-badge {
  margin-right: 7px;
}

.snapshot-asset-detail-row .asset-code {
  margin-left: 4px;
}

.snapshot-detail-table-wrap {
  border: 1px solid var(--border);
  border-radius: 5px;
}

.ranking-period-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

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

.ranking-section {
  min-width: 0;
}

.ranking-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.ranking-table {
  min-width: 540px;
  border: 1px solid var(--border);
}

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

.formula-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.formula-metrics > div {
  display: grid;
  gap: 4px;
  padding: 12px;
  background: #f8faf7;
}

.formula-metrics span {
  color: var(--muted);
  font-size: 10px;
}

.formula-metrics strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.formula-block {
  display: grid;
  gap: 7px;
}

.formula-block h3 {
  margin: 0;
  font-size: 13px;
}

.formula-block code {
  display: block;
  padding: 11px 12px;
  overflow-wrap: anywhere;
  color: var(--ink);
  background: #f3f6f3;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px 28px;
  color: var(--muted);
  font-size: 11px;
}

.footer code {
  padding: 1px 4px;
  background: #e9ede8;
  border-radius: 3px;
}

.modal {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 36px);
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(13, 30, 23, 0.22);
}

.modal-wide {
  width: min(690px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(20, 28, 24, 0.52);
  backdrop-filter: blur(2px);
}

.modal-frame {
  display: flex;
  max-height: calc(100vh - 38px);
  margin: 0;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px 15px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 3px 0 0;
  font-size: 19px;
}

.modal-body {
  display: grid;
  gap: 16px;
  padding: 20px;
  overflow-y: auto;
}

.modal-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 9px;
  padding: 13px 20px;
  border-top: 1px solid var(--border);
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field > span,
.field legend {
  padding: 0;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 600;
}

.field input,
.field select,
.compact-field select,
.inline-add-form input {
  width: 100%;
  height: 39px;
  padding: 7px 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  outline: none;
}

.field input:focus,
.field select:focus,
.compact-field select:focus,
.inline-add-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 101, 89, 0.1);
}

.input-with-icon {
  position: relative;
  display: block;
}

.input-with-icon svg {
  position: absolute;
  top: 50%;
  left: 11px;
  width: 15px;
  height: 15px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.input-with-icon input {
  padding-left: 34px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

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

.category-field {
  gap: 8px;
}

.asset-flow {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  color: var(--muted);
  background: #f6f8f5;
  border-radius: 5px;
  font-size: 11px;
}

.asset-flow span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.asset-flow b {
  display: inline-grid;
  width: 18px;
  height: 18px;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 50%;
  font-size: 10px;
}

.asset-flow svg {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
}

.search-result > svg {
  width: 15px;
  height: 15px;
}

.search-confirm {
  display: inline-flex !important;
  min-width: 42px;
  align-items: center;
  justify-content: center;
  padding: 4px 7px;
  color: var(--accent) !important;
  background: var(--accent-soft);
  border-radius: 4px;
  font-size: 10px !important;
  font-weight: 700;
}

.selected-asset .quote-preview-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid #c5ddd7;
}

.selected-asset .quote-preview-line strong {
  margin: 0;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.quote-preview-status {
  color: var(--muted);
  font-size: 10px;
}

.quote-preview-status.is-error {
  color: var(--positive);
}

.market-preview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.market-preview > div {
  display: grid;
  gap: 3px;
  padding: 10px 11px;
  background: #f8faf7;
}

.market-preview span {
  color: var(--muted);
  font-size: 10px;
}

.market-preview strong {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 3px;
  background: #f0f3ef;
  border-radius: 5px;
}

.segmented-control label {
  position: relative;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  color: var(--muted-strong);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.segmented-control input:checked + span {
  color: var(--accent);
  background: #fff;
  box-shadow: 0 1px 5px rgba(15, 39, 29, 0.1);
  font-weight: 700;
}

.lookup-status {
  min-height: 18px;
  margin-top: -8px;
  color: var(--muted);
  font-size: 11px;
}

.search-results {
  display: grid;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.search-results:empty {
  display: none;
}

.search-result {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 11px;
  text-align: left;
  background: #fff;
  border: 0;
  border-bottom: 1px solid var(--border);
}

.search-result:last-child {
  border-bottom: 0;
}

.search-result:hover {
  background: var(--accent-soft);
}

.search-result strong {
  display: block;
  font-size: 13px;
}

.search-result span {
  color: var(--muted);
  font-size: 11px;
}

.selected-asset {
  padding: 11px 12px;
  background: var(--accent-soft);
  border: 1px solid #c5ddd7;
  border-radius: 5px;
}

.selected-asset strong {
  display: block;
  margin-top: 3px;
}

.check-line {
  gap: 8px;
  min-height: 25px;
  color: var(--muted-strong);
  font-size: 12px;
}

.check-line input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.plan-active-line {
  padding-top: 4px;
}

.field-help {
  margin: -5px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.form-error {
  display: none;
  padding: 9px 11px;
  color: #9c2722;
  background: var(--positive-soft);
  border: 1px solid #f1c7c3;
  border-radius: 5px;
  font-size: 12px;
}

.form-error.is-visible {
  display: block;
}

.asset-context {
  padding: 12px;
  background: #f5f7f4;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.asset-context strong {
  display: block;
  margin-top: 3px;
}

.platform-manager {
  display: grid;
  gap: 1px;
  overflow: hidden;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.platform-manager-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 7px;
  padding: 8px;
  background: #fff;
}

.platform-manager-row input {
  width: 100%;
  height: 34px;
  padding: 4px 8px;
  color: var(--ink);
  background: #fff;
  border: 1px solid transparent;
  border-radius: 4px;
}

.platform-manager-row input:focus {
  border-color: var(--accent);
  outline: none;
}

.inline-add-form {
  gap: 8px;
}

.inline-add-form input {
  flex: 1;
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  display: grid;
  width: min(360px, calc(100vw - 40px));
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 11px 13px;
  color: #fff;
  background: #1d2f29;
  border-radius: 5px;
  box-shadow: 0 10px 32px rgba(20, 34, 28, 0.2);
  font-size: 12px;
  animation: toast-in 160ms ease-out;
}

.toast.is-error {
  background: #8d2823;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (max-width: 960px) {
  .topbar {
    padding: 12px 18px;
  }

  main {
    padding: 18px 18px 28px;
  }

  .notice-stack {
    padding: 10px 18px 0;
  }

  .summary-value {
    font-size: 25px;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .period-options {
    overflow-x: auto;
  }

  .period-button {
    flex: 0 0 auto;
  }

  .footer {
    padding: 0 18px 24px;
  }

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

@media (max-width: 700px) {
  body {
    font-size: 13px;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

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

  .summary-card:first-child {
    grid-column: 1 / -1;
  }

  .summary-card {
    min-height: 116px;
    padding: 17px;
  }

  .summary-value {
    font-size: 22px;
    overflow-wrap: anywhere;
  }

  .section-heading {
    align-items: flex-start;
    padding: 14px 15px;
    flex-direction: column;
  }

  .trend-body {
    padding: 12px 12px 8px;
  }

  .trend-chart {
    min-height: 220px;
  }

  .trend-empty {
    min-height: 200px;
  }

  .trend-legend {
    justify-content: flex-start;
  }

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

  .ranking-grid,
  .formula-metrics {
    grid-template-columns: 1fr;
  }

  .heading-actions {
    width: 100%;
    justify-content: space-between;
  }

  .compact-field {
    flex: 1;
  }

  .compact-field select {
    flex: 1;
    min-width: 0;
  }

  .toolbar {
    padding: 12px;
  }

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

  .asset-flow {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .market-preview,
  .snapshot-detail-summary {
    grid-template-columns: 1fr;
  }

  .snapshot-search {
    width: 100%;
  }

  .snapshot-month-control {
    width: 100%;
  }

  .snapshot-month-picker {
    flex: 1;
  }

  .snapshot-month-picker input {
    width: 100%;
  }

  .asset-table.is-empty,
  .plan-table.is-empty,
  .snapshot-table.is-empty,
  .income-plan-table.is-empty,
  .expense-plan-table.is-empty {
    min-width: 0;
    table-layout: fixed;
  }

  .asset-table.is-empty thead,
  .plan-table.is-empty thead,
  .snapshot-table.is-empty thead,
  .income-plan-table.is-empty thead,
  .expense-plan-table.is-empty thead {
    display: none;
  }

  .asset-table.is-empty tbody,
  .plan-table.is-empty tbody,
  .snapshot-table.is-empty tbody,
  .income-plan-table.is-empty tbody,
  .expense-plan-table.is-empty tbody,
  .asset-table.is-empty tbody tr,
  .plan-table.is-empty tbody tr,
  .snapshot-table.is-empty tbody tr,
  .income-plan-table.is-empty tbody tr,
  .expense-plan-table.is-empty tbody tr,
  .asset-table.is-empty tbody td,
  .plan-table.is-empty tbody td,
  .snapshot-table.is-empty tbody td,
  .income-plan-table.is-empty tbody td,
  .expense-plan-table.is-empty tbody td {
    display: block;
    width: 100%;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-header,
  .modal-actions {
    padding-right: 16px;
    padding-left: 16px;
  }

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

  .footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .toast-region {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }
}

@media (max-width: 520px) {
  .market-trends-grid {
    grid-template-columns: 1fr;
  }
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(11, 101, 89, 0.08), transparent 42%),
    var(--canvas);
}

.auth-panel {
  width: min(430px, 100%);
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.auth-brand h1 {
  margin: 2px 0 0;
  font-size: 23px;
  line-height: 1.25;
}

.auth-intro {
  margin: 18px 0;
  color: var(--muted-strong);
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
  padding: 3px;
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: 7px;
}

.auth-tab {
  min-height: 36px;
  color: var(--muted-strong);
  background: transparent;
  border: 0;
  border-radius: 5px;
}

.auth-tab.is-active {
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 1px 4px rgba(19, 38, 31, 0.08);
  font-weight: 600;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 600;
}

.auth-form input {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  outline: none;
}

.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-submit {
  width: 100%;
  min-height: 42px;
  margin-top: 2px;
  justify-content: center;
}

.auth-footnote {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.account-chip {
  display: inline-flex;
  max-width: 180px;
  min-height: 30px;
  padding: 4px 9px;
  overflow: hidden;
  align-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(11, 101, 89, 0.14);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .auth-screen {
    padding: 14px;
  }

  .auth-panel {
    padding: 22px 18px;
  }

  .account-chip {
    max-width: 120px;
  }
}
