:root {
  --ink: #1d2633;
  --muted: #667085;
  --line: #e4e7ec;
  --paper: #f6f7f9;
  --panel: #ffffff;
  --gold: #b8932f;
  --gold-soft: #f5e9bd;
  --green: #2d7b57;
  --red: #e85d75;
  --red-soft: #ffd9df;
  --blue: #315d8a;
  --shadow: 0 18px 50px rgba(18, 31, 53, 0.08);
  font-family: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(184, 147, 47, 0.07), transparent 38%),
    linear-gradient(180deg, #fbfcfd, var(--paper));
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin-bottom: 6px;
}

.form-message {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.page-shell {
  width: min(1800px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 18px 0 36px;
}

.control-surface {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 22px;
  align-items: end;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.brand-block {
  min-width: 0;
}

.user-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--gold);
  font-family: "Consolas", "SFMono-Regular", monospace;
  font-size: 12px;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

h1,
h2 {
  margin: 0;
  font-weight: 740;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(170px, 1.1fr) minmax(190px, 1.2fr) repeat(3, minmax(150px, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

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

.field > span {
  color: #303846;
  font-size: 13px;
  font-weight: 700;
}

select,
input {
  width: 100%;
  min-height: 38px;
  border: 1px solid #d3b35d;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 7px 10px;
  outline: none;
}

select:focus,
input:focus,
button:focus-visible {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184, 147, 47, 0.18);
}

.multi-select {
  position: relative;
}

.multi-select > button {
  width: 100%;
  min-height: 38px;
  border: 1px solid #d3b35d;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 7px 34px 7px 10px;
  text-align: left;
  cursor: pointer;
}

.multi-select > button::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 17px;
  width: 7px;
  height: 7px;
  border-right: 1px solid #667085;
  border-bottom: 1px solid #667085;
  transform: rotate(45deg);
}

.multi-select.open > button {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184, 147, 47, 0.18);
}

.multi-menu {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: min(360px, 86vw);
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 18px 46px rgba(18, 31, 53, 0.16);
}

.multi-select.open .multi-menu {
  display: grid;
}

.multi-menu label {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 8px;
  color: #344054;
  font-size: 13px;
}

.multi-menu label:hover {
  background: #f6f7f9;
}

.multi-menu input {
  width: 15px;
  min-height: 15px;
  accent-color: var(--gold);
}

.primary-action,
.secondary-action,
.ghost-action {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 750;
}

.primary-action {
  min-width: 70px;
  color: #fff;
  background: var(--gold);
}

.button-row {
  display: flex;
  gap: 8px;
  align-items: end;
}

.secondary-action {
  min-width: 70px;
  color: var(--blue);
  border: 1px solid #c9d7e8;
  background: #f4f8fc;
}

.ghost-action {
  padding: 0 14px;
  color: var(--blue);
  background: #edf3fa;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(29, 38, 51, 0.32);
}

.admin-dialog {
  width: min(1220px, calc(100vw - 32px));
  max-height: min(820px, calc(100vh - 36px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(18, 31, 53, 0.24);
}

.user-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) repeat(3, auto) auto;
  gap: 10px;
  align-items: end;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.check-field {
  display: flex;
  gap: 7px;
  align-items: center;
  min-height: 38px;
  color: #303846;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

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

.user-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.user-table th,
.user-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-table th:last-child,
.user-table td:last-child {
  width: 190px;
}

.user-actions {
  display: flex;
  justify-content: flex-start;
  gap: 6px;
  white-space: nowrap;
}

.branch-permission {
  grid-column: 1 / -1;
}

.branch-permission textarea {
  width: 100%;
  resize: vertical;
  font: inherit;
}

.user-form .button-row {
  grid-column: auto;
}

.admin-subsection {
  border-top: 1px solid var(--line);
  padding-bottom: 12px;
}

.admin-subsection > .panel-title,
.org-form,
.org-message {
  padding-left: 16px;
  padding-right: 16px;
}

.org-form {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr 0.9fr 1.4fr auto;
  gap: 10px;
  align-items: end;
  padding-top: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.org-note {
  min-width: 0;
}

.org-table {
  min-width: 900px;
}

.org-table small {
  color: var(--muted);
  font-family: "Consolas", monospace;
}

.org-pending {
  color: var(--red);
  font-weight: 750;
}

.table-action {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #c9d7e8;
  border-radius: 7px;
  color: var(--blue);
  background: #f4f8fc;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.table-action:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.kpi-card {
  min-height: 90px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgba(18, 31, 53, 0.05);
}

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.kpi-card strong {
  display: block;
  margin-top: 10px;
  font-family: "Bahnschrift", "DIN Alternate", "Segoe UI", sans-serif;
  font-size: 31px;
  font-weight: 700;
  letter-spacing: 0;
}

.kpi-card.accent {
  color: #fff;
  border-color: #355f4b;
  background: linear-gradient(135deg, #234d3b, #2d7b57);
}

.kpi-card.accent span {
  color: rgba(255, 255, 255, 0.78);
}

.panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px 10px;
  border-bottom: 2px solid var(--gold);
}

.meta {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.meta-pill {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.fund-toolbar {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.pager {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pager-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  min-height: 34px;
  border: 1px solid #c9d7e8;
  border-radius: 8px;
  color: var(--blue);
  background: #f4f8fc;
  cursor: pointer;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

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

.page-info {
  min-width: 78px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1060px;
}

.data-table th,
.data-table td {
  padding: 10px 13px;
  border-bottom: 1px solid #edf0f4;
  text-align: right;
  white-space: nowrap;
  font-size: 13px;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--gold-soft);
  color: #161b22;
  font-weight: 750;
}

.sort-button {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  min-height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  font-weight: 780;
  text-align: right;
}

.sort-button::after {
  content: "↕";
  color: rgba(22, 27, 34, 0.45);
  font-size: 11px;
}

.sort-button[data-direction="desc"]::after {
  content: "↓";
  color: var(--blue);
}

.sort-button[data-direction="asc"]::after {
  content: "↑";
  color: var(--blue);
}

.sort-button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

.data-table th:first-child,
.data-table td:first-child,
.data-table th:nth-child(2),
.data-table td:nth-child(2),
.data-table th:nth-child(3),
.data-table td:nth-child(3) {
  text-align: left;
}

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

.data-table tbody tr:nth-child(even) {
  background: #f6f9fd;
}

.data-table tbody tr:nth-child(even):hover {
  background: #eef5fb;
}

.data-table .risk {
  color: var(--red);
  background: var(--red-soft);
}

.data-table .good {
  color: var(--green);
  font-weight: 720;
}

.data-table.compact {
  min-width: 1680px;
}

.data-table.compact th:nth-child(-n + 5),
.data-table.compact td:nth-child(-n + 5) {
  text-align: left;
}

.curve-toolbar {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.field.inline {
  display: flex;
  gap: 6px;
  align-items: center;
}

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

.field.inline select {
  width: auto;
  min-width: 118px;
  min-height: 34px;
  padding: 0 8px;
  font-size: 13px;
}

.field.inline input[type="date"] {
  width: auto;
  min-width: 142px;
  min-height: 34px;
  padding: 0 8px;
  font-size: 13px;
}

.curve-toolbar .ghost-action {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.curve-toolbar .ghost-action.active {
  color: #fff;
  background: var(--blue);
}

.curve-toolbar .ghost-action:disabled {
  color: var(--muted);
  background: #f2f4f7;
  cursor: default;
}

.curve-body {
  padding: 14px 16px 4px;
}

.curve-chart {
  position: relative;
  min-height: 240px;
}

.curve-chart svg {
  display: block;
  width: 100%;
}

.curve-empty {
  margin: 0;
  padding: 48px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.curve-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 10px;
}

.curve-legend button {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 3px 6px;
  border: 0;
  border-radius: 6px;
  color: #3d4655;
  font-size: 12.5px;
  font-weight: 700;
  background: none;
  cursor: pointer;
}

.curve-legend button:hover {
  background: #f1f4f8;
}

.curve-legend button.off {
  color: var(--muted);
  text-decoration: line-through;
  opacity: 0.55;
}

.curve-legend i {
  display: block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

.curve-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 150px;
  padding: 8px 10px;
  border-radius: 8px;
  color: #fff;
  font-size: 12px;
  line-height: 1.55;
  background: rgba(29, 38, 51, 0.94);
  box-shadow: 0 10px 26px rgba(18, 31, 53, 0.28);
  pointer-events: none;
  transform: translate(-50%, -100%);
}

.curve-tooltip .tip-date {
  margin-bottom: 4px;
  color: var(--gold-soft);
  font-weight: 750;
}

.curve-tooltip .tip-row {
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.curve-tooltip .tip-row span {
  color: #c9d3e2;
}

.tag-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  color: #8a6d1f;
  font-size: 11px;
  font-weight: 700;
  background: #fdf7e3;
  vertical-align: middle;
}

.curve-aum-ref {
  color: var(--muted);
}

.curve-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: middle;
}

.curve-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

.curve-table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--line);
}

.curve-table-wrap .data-table {
  min-width: 1020px;
}

.curve-table-wrap .data-table th:first-child,
.curve-table-wrap .data-table td:first-child {
  text-align: left;
}

@media (max-width: 760px) {
  .curve-toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .field.inline select {
    min-width: 96px;
  }

  .field.inline input[type="date"] {
    min-width: 128px;
  }

  .curve-body {
    padding: 12px 12px 2px;
  }

  .curve-table-wrap {
    display: none;
  }
}

.mobile-list {
  display: none;
  padding: 12px;
  gap: 10px;
}

.mobile-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: 10px;
  background: #fff;
  padding: 12px;
}

.mobile-card strong {
  display: block;
  font-size: 15px;
  margin-bottom: 8px;
}

.mobile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.mobile-grid span {
  color: var(--ink);
  font-weight: 720;
}

@media (max-width: 1380px) {
  .control-surface {
    grid-template-columns: 1fr;
  }

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

  .primary-action {
    width: 100%;
  }

  .button-row {
    grid-column: span 3;
  }

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

@media (max-width: 760px) {
  .page-shell {
    width: min(100vw - 18px, 640px);
    padding-top: 10px;
  }

  .control-surface {
    padding: 14px;
    border-radius: 12px;
  }

  h1 {
    font-size: 23px;
  }

  .filters,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .button-row {
    grid-column: auto;
  }

  .kpi-card {
    min-height: 76px;
  }

  .kpi-card strong {
    font-size: 26px;
  }

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

  .fund-toolbar {
    width: 100%;
    justify-content: space-between;
  }

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

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

  .admin-dialog {
    width: calc(100vw - 20px);
    overflow: auto;
  }

  .admin-dialog .table-wrap {
    display: block;
    overflow-x: auto;
  }

  .admin-dialog .user-table {
    min-width: 760px;
    table-layout: auto;
  }

  .table-wrap {
    display: none;
  }

  .mobile-list {
    display: grid;
  }
}
