:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0eee7;
  --ink: #1f2933;
  --muted: #65717e;
  --line: #d9d5ca;
  --brand: #16324f;
  --brand-2: #2f6f73;
  --accent: #c27b36;
  --good: #27745f;
  --warn: #ad6a18;
  --bad: #a23b3b;
  --shadow: 0 10px 30px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 7px 12px;
  cursor: pointer;
}

.button-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 7px 12px;
  text-decoration: none;
}

.button-link:hover {
  border-color: var(--brand-2);
}

button:hover {
  border-color: var(--brand-2);
}

button.primary,
.nav-tabs button.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.app-header {
  min-height: 68px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

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

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

.header-actions,
.view-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.header-actions {
  display: none;
}

body[data-current-view="snapshots"] .header-actions {
  display: flex;
}

.layout-toggle {
  display: inline-flex;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.layout-toggle button {
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.layout-toggle button:last-child {
  border-right: 0;
}

.layout-toggle button.active {
  background: var(--brand);
  color: #fff;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: #ece8de;
  padding: 16px;
  position: sticky;
  top: 68px;
  align-self: start;
  height: calc(100vh - 68px);
  overflow: auto;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tabs button {
  width: 100%;
  text-align: left;
}

.side-panel {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.side-panel label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.side-panel select {
  width: 100%;
}

.autosave {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.content {
  min-width: 0;
  padding: 22px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.view-heading h2 {
  margin: 0;
  font-size: 24px;
}

.view-heading p {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.snapshot-card,
.panel,
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.snapshot-card {
  padding: 14px;
}

.snapshot-card h3,
.panel h3,
.metric-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.snapshot-card p,
.metric-card p {
  margin: 0;
  color: var(--muted);
}

.snapshot-card .actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

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

.metric-card {
  padding: 14px;
}

.metric-card strong {
  display: block;
  font-size: 22px;
  margin-top: 6px;
}

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

.report-print-header {
  margin-bottom: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.report-print-header h2 {
  margin: 0 0 6px;
  font-size: 24px;
}

.report-print-header p {
  margin: 0;
  color: var(--muted);
}

.report-header-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.report-header-metrics span {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
  background: #fbfaf7;
}

.panel {
  padding: 14px;
  min-width: 0;
}

.panel.wide {
  grid-column: 1 / -1;
}

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

.chart.tall {
  min-height: 340px;
}

.chart svg {
  width: 100%;
  height: auto;
  display: block;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.table-wrap.compact table {
  min-width: 760px;
}

table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  z-index: 1;
}

td input,
td select,
td textarea,
.side-panel select {
  width: 100%;
  min-width: 110px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  padding: 6px 7px;
}

td textarea {
  resize: vertical;
  min-height: 36px;
}

td .row-actions {
  display: flex;
  gap: 6px;
}

.mobile-card-track {
  display: none;
}

body[data-asset-layout="cards"] #view-assets .table-wrap,
body[data-liability-layout="cards"] #view-liabilities .table-wrap,
body[data-target-layout="cards"] #view-targets .table-wrap {
  display: none;
}

body[data-asset-layout="cards"] #assetCards,
body[data-liability-layout="cards"] #liabilityCards,
body[data-target-layout="cards"] #targetCards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}

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

.mobile-record-card h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}

.mobile-record-card .card-subtitle {
  margin: 4px 0 14px;
  color: var(--muted);
  font-size: 12px;
}

.mobile-field-grid {
  display: grid;
  gap: 11px;
}

.mobile-field {
  display: grid;
  gap: 5px;
}

.mobile-field label {
  color: var(--muted);
  font-size: 12px;
}

.mobile-field input,
.mobile-field select,
.mobile-field textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 7px 8px;
}

.mobile-field textarea {
  min-height: 72px;
  resize: vertical;
}

.mobile-card-actions {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mobile-empty {
  flex: 0 0 calc(100vw - 32px);
  padding: 18px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.danger {
  color: #fff;
  background: var(--bad);
  border-color: var(--bad);
}

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

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

.settings-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.settings-list h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.settings-list textarea {
  width: 100%;
  min-height: 140px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.settings-list input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
}

.settings-list-wide {
  grid-column: 1 / -1;
}

.change-list {
  display: grid;
  gap: 8px;
}

.change-item {
  border-left: 4px solid var(--brand-2);
  background: #f7f9f8;
  padding: 9px 10px;
}

.history-log-panel {
  margin-top: 14px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 860px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .layout-toggle {
    display: none;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    position: static;
    height: auto;
    overflow: visible;
  }

  .nav-tabs {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-tabs button {
    width: auto;
    white-space: nowrap;
  }

  .content {
    padding: 16px;
  }

  .view-heading {
    display: block;
  }

  .view-heading .view-actions,
  .view-heading > button {
    margin-top: 12px;
  }

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

  #view-assets .table-wrap,
  #view-liabilities .table-wrap,
  #view-targets .table-wrap {
    display: none;
  }

  .mobile-card-track {
    display: flex;
    grid-template-columns: none;
    gap: 12px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding: 2px 2px 14px;
    margin: 0 -2px;
    -webkit-overflow-scrolling: touch;
  }

  body[data-asset-layout="cards"] #assetCards,
  body[data-liability-layout="cards"] #liabilityCards,
  body[data-target-layout="cards"] #targetCards {
    display: flex;
    grid-template-columns: none;
    gap: 12px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding: 2px 2px 14px;
    margin: 0 -2px;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-record-card {
    flex: 0 0 calc(100vw - 32px);
    scroll-snap-align: start;
  }

  .mobile-empty {
    flex: 0 0 calc(100vw - 32px);
    scroll-snap-align: start;
  }

  .mobile-card-actions button {
    flex: 1;
  }
}

@page {
  size: A3;
  margin: 12mm;
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .sidebar,
  .view-heading,
  .toast {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .content {
    padding: 0;
  }

  .view {
    display: none !important;
  }

  #view-report {
    display: block !important;
  }

  .panel,
  .metric-card,
  .report-print-header {
    box-shadow: none;
    break-inside: avoid;
  }

  .panel,
  .metric-card,
  .report-print-header {
    border-color: #999;
  }

  .report-grid {
    gap: 10mm;
  }

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