:root {
  --ant-blue: #1677ff;
  --ant-blue-hover: #4096ff;
  --ant-green: #52c41a;
  --ant-orange: #faad14;
  --ant-red: #ff4d4f;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-subtle: #fafafa;
  --text: rgba(0, 0, 0, 0.88);
  --muted: rgba(0, 0, 0, 0.45);
  --line: #d9d9d9;
  --line-soft: #f0f0f0;
  --shadow: 0 6px 16px rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 14px;
}

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

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

.sider {
  background: #fff;
  border-right: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  min-height: 72px;
  display: flex;
  align-items: center;
  padding: 0 22px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 18px;
}

.menu {
  display: grid;
  padding: 10px 0;
}

.menu-item,
.menu-section,
.menu-subhead {
  width: 100%;
  border: 0;
  text-align: left;
  background: transparent;
  color: rgba(0, 0, 0, 0.68);
  min-height: 44px;
  padding: 0 22px;
  cursor: pointer;
  position: relative;
}

.menu-section,
.menu-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.menu-section.open {
  color: var(--text);
  font-weight: 600;
}

.menu-section.muted,
.menu-item.muted,
.menu-subhead {
  color: rgba(0, 0, 0, 0.45);
}

.menu-subhead {
  padding-left: 42px;
}

.menu-item {
  padding-left: 54px;
}

.menu-item:hover {
  background: #f5f5f5;
}

.menu-item.active {
  color: var(--ant-blue);
  background: #e6f0ff;
}

.menu-item.active::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--ant-blue);
}

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

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

.breadcrumb,
.panel-header p,
.section-header p,
.metric-card small,
.field-hint {
  color: var(--muted);
}

.panel-header p,
.section-header p,
.control-notes,
.detail-row {
  overflow-wrap: anywhere;
}

.breadcrumb {
  font-size: 13px;
  margin-bottom: 4px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
}

h2 {
  font-size: 18px;
  line-height: 26px;
  font-weight: 600;
}

h3 {
  font-size: 15px;
  line-height: 22px;
  font-weight: 600;
}

.activity-log-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(0, 0, 0, 0.62);
  cursor: pointer;
}

.activity-log-btn:hover {
  color: var(--ant-blue);
  background: rgba(0, 0, 0, 0.04);
}

.activity-log-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.page-panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  padding: 20px;
  min-width: 0;
}

.page-panel.active {
  display: block;
}

.panel-header,
.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-header > div,
.section-header > div,
.metric-card,
.inline-section {
  min-width: 0;
}

.panel-header p,
.section-header p {
  max-width: 100%;
  white-space: normal;
}

.section-header {
  margin-top: 24px;
}

.section-header.with-tabs {
  align-items: center;
}

.section-header.compact {
  margin-top: 0;
}

.header-actions,
.toolbar,
.drawer-footer,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar {
  margin-bottom: 12px;
}

.section-tabs {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  flex: 0 0 auto;
}

.section-tab {
  min-width: 118px;
  min-height: 32px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: rgba(0, 0, 0, 0.65);
  padding: 4px 12px;
  cursor: pointer;
}

.section-tab:last-child {
  border-right: 0;
}

.section-tab.active {
  color: #0958d9;
  background: #e6f4ff;
  font-weight: 500;
}

.section-tab:hover {
  color: var(--ant-blue);
}

.btn,
.icon-btn {
  min-height: 32px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 4px 15px;
  border-radius: 6px;
  cursor: pointer;
}

.btn:hover,
.icon-btn:hover {
  color: var(--ant-blue-hover);
  border-color: var(--ant-blue-hover);
}

.btn.primary {
  color: #fff;
  background: var(--ant-blue);
  border-color: var(--ant-blue);
}

.btn.primary:hover {
  color: #fff;
  background: var(--ant-blue-hover);
  border-color: var(--ant-blue-hover);
}

.btn.link {
  color: var(--ant-blue);
  border-color: transparent;
  background: transparent;
  padding-inline: 4px;
}

.btn.danger {
  color: var(--ant-red);
  border-color: #ffccc7;
}

.input,
.textarea {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 4px 11px;
  min-width: 220px;
}

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

.input.compact {
  min-width: 152px;
}

.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--ant-blue);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.12);
}

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

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

.metric-card {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-subtle);
  display: grid;
  gap: 6px;
}

.metric-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.metric-card span,
.inline-note {
  color: rgba(0, 0, 0, 0.64);
}

.inline-note {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #fafafa;
}

.latest-month {
  color: #0958d9;
  border-style: solid;
  border-color: #91caff;
  background: #e6f4ff;
  font-weight: 500;
}

.info-dot {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid #91caff;
  border-radius: 50%;
  background: #e6f4ff;
  color: #0958d9;
  font-size: 12px;
  line-height: 1;
  cursor: help;
  flex: 0 0 auto;
}

.info-dot::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 10;
  width: min(300px, 70vw);
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.86);
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.info-dot:hover::after,
.info-dot:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.metric-card strong {
  font-size: 22px;
  line-height: 30px;
}

.metric-card.warning strong {
  color: #ad6800;
}

.metric-card.danger strong {
  color: #cf1322;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 16px;
  align-items: start;
}

.details-table {
  width: 100%;
  table-layout: auto;
}

.detail-comparison-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
  margin-top: 24px;
}

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

.borrow-snapshot-table {
  min-width: 1120px;
}

.lending-snapshot-table {
  min-width: 920px;
}

.fallback-snapshot-table {
  min-width: 1280px;
}

.config-settings-table {
  min-width: 820px;
}

.economics-table {
  min-width: 620px;
}

.vertical-detail-wrap {
  overflow-x: auto;
}

.vertical-detail-table {
  min-width: 0;
  table-layout: fixed;
}

.vertical-detail-table th,
.vertical-detail-table td {
  white-space: normal;
  overflow-wrap: anywhere;
}

.vertical-detail-table thead th:first-child,
.vertical-detail-table tbody th {
  width: 42%;
}

.vertical-detail-table tbody th {
  background: #fff;
  color: rgba(0, 0, 0, 0.64);
  font-weight: 500;
}

.detail-value-negative {
  color: #cf1322;
  font-weight: 600;
}

.detail-value-pending {
  color: #ad6800;
  font-weight: 600;
}

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

.details-table th,
.details-table td {
  padding: 9px 6px;
  font-size: 13px;
  white-space: normal;
}

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

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.table-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

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

.transaction-table td:nth-child(9),
.transaction-table td:nth-child(13) {
  min-width: 240px;
  white-space: normal;
}

.compact-table table {
  min-width: 920px;
}

th,
td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
  white-space: nowrap;
}

th {
  background: #fafafa;
  color: rgba(0, 0, 0, 0.72);
  font-weight: 600;
}

tr:last-child td {
  border-bottom: 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid transparent;
}

.tag.green {
  color: #389e0d;
  background: #f6ffed;
  border-color: #b7eb8f;
}

.tag.blue {
  color: #0958d9;
  background: #e6f4ff;
  border-color: #91caff;
}

.tag.orange {
  color: #ad6800;
  background: #fff7e6;
  border-color: #ffd591;
}

.tag.red {
  color: #cf1322;
  background: #fff1f0;
  border-color: #ffa39e;
}

.tag.gray {
  color: rgba(0, 0, 0, 0.65);
  background: #f5f5f5;
  border-color: #d9d9d9;
}

.control-notes {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #ffe58f;
  border-radius: 8px;
  background: #fffbe6;
}

.detail-list {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.detail-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.42fr) minmax(0, 0.58fr);
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
}

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

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

.detail-row strong {
  font-weight: 500;
  min-width: 0;
  overflow-wrap: anywhere;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.18);
  z-index: 20;
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(680px, 100vw);
  background: #fff;
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 0.18s ease;
  z-index: 30;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header,
.drawer-footer {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.drawer-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line-soft);
  border-bottom: 0;
}

.drawer-body {
  min-width: 0;
  overflow-y: auto;
  padding: 20px;
}

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

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

.field.full {
  grid-column: 1 / -1;
}

.field label {
  font-weight: 500;
}

.field .input,
.field .textarea {
  width: 100%;
  min-width: 0;
}

.segmented-control {
  display: inline-flex;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.segment {
  min-width: 92px;
  min-height: 32px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: rgba(0, 0, 0, 0.65);
  padding: 4px 12px;
  cursor: pointer;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  color: #0958d9;
  background: #e6f4ff;
  font-weight: 500;
}

.segment:hover {
  color: var(--ant-blue);
}

.drawer-section {
  margin-top: 20px;
}

.drawer-section:first-child {
  margin-top: 0;
}

.log-list {
  display: grid;
  gap: 16px;
}

.log-entry {
  border-left: 3px solid var(--ant-blue);
  padding-left: 12px;
}

.log-entry h3 {
  margin-bottom: 4px;
}

.diff-table {
  margin-top: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  overflow: hidden;
}

.diff-table table {
  min-width: 0;
}

.diff-table td,
.diff-table th {
  padding: 8px;
}

.diff-to {
  background: #e6f4ff;
  color: #0958d9;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.86);
  color: #fff;
  padding: 9px 14px;
  border-radius: 6px;
  transition: opacity 0.16s ease, transform 0.16s ease;
  z-index: 40;
}

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

.validation-error {
  color: var(--ant-red);
  font-size: 13px;
}

.support-result {
  display: grid;
  gap: 16px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .main {
    padding: 16px;
  }

  .metric-grid,
  .grid-2,
  .detail-comparison-grid {
    grid-template-columns: 1fr;
  }

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

  .panel-header,
  .section-header,
  .topbar {
    align-items: flex-start;
  }
}

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

  .sider {
    position: relative;
    height: auto;
    max-height: 46vh;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }

  .brand {
    min-height: 56px;
  }

  .main {
    padding: 12px;
  }

  .topbar,
  .panel-header,
  .section-header {
    flex-direction: column;
  }

  .dashboard-metrics {
    grid-template-columns: 1fr;
  }

  .header-actions,
  .toolbar,
  .section-tabs {
    width: 100%;
  }

  .section-tab {
    flex: 1 1 0;
    min-width: 0;
  }

  .input,
  .input.compact,
  .btn {
    width: 100%;
  }

  .page-panel {
    padding: 14px;
  }

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

  .drawer {
    width: 100vw;
  }
}
