:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-alt: #eef2ec;
  --ink: #18211d;
  --muted: #66736b;
  --line: #d7ded6;
  --line-strong: #bac6bd;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #d9f2ed;
  --gold: #b67812;
  --gold-soft: #fff1d6;
  --red: #b42318;
  --red-soft: #ffe5e1;
  --green: #16794f;
  --green-soft: #dff5e9;
  --blue: #2f66a3;
  --blue-soft: #e3edf8;
  --shadow: 0 16px 40px rgba(24, 33, 29, 0.08);
  --radius: 8px;
  --radius-sm: 6px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  min-width: 320px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(16, 24, 20, 0.86), rgba(16, 24, 20, 0.9)),
    url("https://images.unsplash.com/photo-1639762681485-074b7f938ba0?auto=format&fit=crop&w=1800&q=80") center / cover;
}

.login-panel {
  width: min(430px, 100%);
  display: grid;
  gap: 24px;
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

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

.login-brand > div:last-child,
.login-heading,
.login-note {
  display: grid;
}

.login-brand > div:last-child {
  gap: 2px;
}

.login-brand strong {
  font-size: 18px;
}

.login-brand span,
.login-heading p,
.login-note span {
  color: var(--muted);
  font-size: 13px;
}

.login-heading {
  gap: 7px;
}

.login-heading h1,
.login-heading p {
  margin: 0;
}

.login-heading h1 {
  font-size: 25px;
}

.login-note {
  gap: 4px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.form-error {
  border: 1px solid #efb7b0;
  border-radius: var(--radius-sm);
  background: var(--red-soft);
  color: var(--red);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
}

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

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
}

.primary-bar {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  padding: 9px 24px;
  background: #101814;
  color: #eef6ef;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #33c4ae;
  color: #09231f;
  font-weight: 900;
}

.brand-copy strong {
  display: block;
  letter-spacing: 0;
  font-size: 16px;
}

.brand-copy span {
  display: block;
  color: #aab8b0;
  font-size: 12px;
  margin-top: 1px;
}

.nav {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

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

.nav button {
  min-width: max-content;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #d9e7dd;
  cursor: pointer;
  padding: 7px 9px;
  white-space: nowrap;
}

.nav button:hover,
.nav button.active {
  background: #1e2c25;
  color: #ffffff;
}

.nav .ico,
.tool-button .ico,
.icon-only .ico {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  font-weight: 800;
  color: inherit;
}

.top-account {
  min-width: 180px;
  display: grid;
  justify-items: end;
  gap: 2px;
  padding-left: 16px;
  border-left: 1px solid rgba(255, 255, 255, 0.15);
  text-align: right;
}

.top-account strong {
  font-size: 13px;
}

.top-account span {
  max-width: 240px;
  overflow: hidden;
  color: #9dafb6;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 246, 243, 0.94);
  backdrop-filter: blur(10px);
}

.page-title {
  display: grid;
  gap: 3px;
}

.page-title h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

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

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.content {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 18px 24px 34px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid > *,
.content,
.panel,
.table-shell {
  min-width: 0;
}

.grid.two {
  grid-template-columns: minmax(280px, 0.85fr) minmax(420px, 1.45fr);
  align-items: start;
}

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

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

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

.panel {
  padding: 18px;
}

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

.panel-title {
  display: grid;
  gap: 3px;
}

.panel-title h2,
.section-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: 0;
}

.panel-title span,
.section-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.metric {
  min-height: 122px;
  padding: 16px;
  display: grid;
  gap: 10px;
  align-content: space-between;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric strong {
  font-size: 23px;
  line-height: 1.1;
}

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

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

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

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

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.admin {
  color: #5f3b00;
  background: var(--gold-soft);
}

.badge.manager {
  color: #0a514a;
  background: var(--accent-soft);
}

.badge.consultant,
.badge.operator {
  color: #234f7e;
  background: var(--blue-soft);
}

.badge.viewer,
.badge.inactive {
  color: #59645d;
  background: #edf0ec;
}

.badge.buy,
.badge.deposit,
.badge.transfer_in {
  color: var(--green);
  background: var(--green-soft);
}

.badge.sell,
.badge.withdraw,
.badge.transfer_out,
.badge.fee {
  color: var(--red);
  background: var(--red-soft);
}

.badge.rebalance-ok {
  color: var(--green);
  background: var(--green-soft);
}

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

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

.token-position-panel {
  padding: 16px 18px;
}

.token-position-panel .panel-header {
  align-items: center;
  margin-bottom: 12px;
}

.token-position-form {
  gap: 0;
}

.token-position-grid {
  grid-template-columns:
    minmax(190px, 1.35fr)
    minmax(125px, 0.85fr)
    minmax(150px, 1fr)
    minmax(165px, 1.05fr)
    minmax(115px, 0.7fr)
    minmax(120px, 0.75fr)
    auto;
  align-items: end;
}

.token-form-action {
  display: flex;
  align-items: flex-end;
}

.token-form-action .button {
  min-width: max-content;
  white-space: nowrap;
}

.token-positions-table {
  margin-top: 16px;
}

.rebalance-panel {
  margin-top: 16px;
}

.rebalance-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.rebalance-strip div {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.rebalance-strip div:last-child {
  border-right: 0;
}

.rebalance-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.rebalance-strip strong {
  font-size: 18px;
  line-height: 1.2;
}

.rebalance-strip small {
  color: var(--muted);
}

.link-button {
  min-height: 0;
  margin-top: 5px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

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

.field label {
  color: #3b463f;
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

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

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.field input[disabled],
.field select[disabled],
.field textarea[disabled] {
  color: #7f8a83;
  background: #f2f4f1;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.toolbar.between {
  justify-content: space-between;
}

.button,
.tool-button,
.ghost-button,
.danger-button,
.icon-only {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 800;
  color: #ffffff;
  background: var(--accent);
}

.button:hover,
.tool-button:hover {
  background: var(--accent-strong);
}

.ghost-button,
.icon-only {
  color: var(--ink);
  border-color: var(--line-strong);
  background: #ffffff;
}

.ghost-button:hover,
.icon-only:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.danger-button {
  color: #ffffff;
  background: var(--red);
}

.danger-button:hover {
  background: #8f1f17;
}

.icon-only {
  width: 40px;
  padding: 0;
}

.table-shell {
  overflow: hidden;
}

.table-scroll {
  overflow: auto;
}

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

.positions-table {
  min-width: 1460px;
}

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

th {
  color: #4d5a52;
  background: #f7f9f6;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td {
  font-size: 14px;
}

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

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.row-actions button {
  min-height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  padding: 6px 9px;
}

.row-actions button:hover {
  color: var(--accent-strong);
  border-color: var(--accent);
}

.row-actions button.danger {
  color: var(--red);
}

.split-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.token-identity {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  vertical-align: middle;
}

.token-identity.compact {
  gap: 8px;
}

.token-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.token-copy strong,
.token-copy span {
  overflow-wrap: anywhere;
}

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

.token-avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #f1f5f1;
  color: #324139;
  font-size: 11px;
  font-weight: 900;
}

.token-avatar.sm {
  width: 26px;
  height: 26px;
  font-size: 9px;
}

.token-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.token-avatar-fallback[hidden] {
  display: none;
}

.small {
  font-size: 12px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 170px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.58);
  text-align: center;
  padding: 20px;
}

.allocation-list {
  display: grid;
  gap: 12px;
}

.allocation-row {
  display: grid;
  gap: 7px;
}

.allocation-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ebe4;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e, #6aa43f);
}

.tabs {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.tabs button {
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.tabs button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(24, 33, 29, 0.08);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 28px));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #10231f;
  color: #f4fff9;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-weight: 700;
}

.toast.error {
  background: #431611;
}

.import-input {
  display: none;
}

.permission-grid {
  display: grid;
  grid-template-columns: 1.2fr repeat(5, minmax(84px, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.permission-grid div {
  padding: 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
}

.permission-grid div:nth-child(6n) {
  border-right: 0;
}

.permission-grid div:nth-last-child(-n + 6) {
  border-bottom: 0;
}

.permission-grid .head {
  background: #f7f9f6;
  color: #4d5a52;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.permission-grid .ok {
  color: var(--green);
  font-weight: 900;
}

.permission-grid .no {
  color: #9aa59e;
}

@media (max-width: 1180px) {
  .primary-bar {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px 18px;
  }

  .nav {
    grid-column: 1 / -1;
    grid-row: 2;
  }

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

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

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

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

  .rebalance-strip div:nth-child(2n) {
    border-right: 0;
  }
}

@media (max-width: 860px) {
  .app-header {
    position: static;
  }

  .primary-bar {
    padding: 10px 14px;
  }

  .nav {
    padding-bottom: 2px;
  }

  .topbar {
    grid-template-columns: 1fr;
    min-width: 0;
    padding: 14px;
  }

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

  .content {
    padding: 16px 14px 28px;
  }

  .grid.three,
  .grid.four,
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .token-form-action .button {
    width: 100%;
  }

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

  .rebalance-strip div,
  .rebalance-strip div:nth-child(2n) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rebalance-strip div:last-child {
    border-bottom: 0;
  }

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

  .permission-grid div,
  .permission-grid div:nth-child(6n),
  .permission-grid div:nth-last-child(-n + 6) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 560px) {
  .primary-bar {
    grid-template-columns: minmax(0, 1fr);
  }

  .top-account {
    display: none;
  }

  .nav {
    grid-row: auto;
  }

  .brand-copy span {
    display: none;
  }

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