:root {
  color-scheme: light;
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-soft: #f7f8fa;
  --line: #d7dce2;
  --text: #171b20;
  --muted: #66717f;
  --green: #127e5e;
  --green-soft: #e8f5ef;
  --red: #b23a48;
  --red-soft: #fff0f2;
  --yellow: #a46a0a;
  --yellow-soft: #fff5db;
  --blue-soft: #f4f7fd;
  --focus: #1e6ac8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.brand-heading,
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  object-fit: cover;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  font-weight: 780;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  font-weight: 760;
  letter-spacing: 0;
}

.topbar p,
.detail-heading p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.status-line,
.controls,
.detail-heading,
.panel-heading,
.exchange-tabs {
  display: flex;
  align-items: center;
}

.status-line {
  gap: 10px;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid #c9d8ea;
  border-radius: 8px;
  background: var(--blue-soft);
  color: #27527e;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 760;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  white-space: nowrap;
}

.pill.good {
  border-color: #b7ddce;
  background: var(--green-soft);
  color: var(--green);
}

.pill.warn {
  border-color: #ead69b;
  background: var(--yellow-soft);
  color: var(--yellow);
}

.pill.bad {
  border-color: #efc4ca;
  background: var(--red-soft);
  color: var(--red);
}

#refresh-button,
#logout-button,
.view-tabs button,
.login-form button,
.password-form button,
.user-form button,
.user-item button,
.exchange-tabs button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 13px;
}

#refresh-button:hover,
#logout-button:hover,
.view-tabs button:hover,
.login-form button:hover,
.password-form button:hover,
.user-form button:hover,
.user-item button:hover:not(:disabled),
.exchange-tabs button:hover:not(:disabled),
.symbol-row:hover {
  border-color: #9ba7b4;
}

#refresh-button:disabled,
.login-form button:disabled,
.password-form button:disabled,
.user-form button:disabled,
.user-item button:disabled,
.exchange-tabs button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.controls {
  gap: 12px;
  margin-bottom: 14px;
}

.view-tabs {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 4px;
  margin-bottom: 14px;
}

.view-tabs button {
  min-width: 132px;
  border-color: transparent;
}

.view-tabs button.active {
  border-color: #9fd5c2;
  background: var(--green);
  color: white;
}

.view-panel[hidden] {
  display: none;
}

.search,
.select,
.toggle {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.search {
  width: min(420px, 100%);
}

.select {
  width: 180px;
}

.toggle {
  align-self: end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 0 12px;
  color: var(--text);
}

.toggle input {
  width: 16px;
  height: 16px;
  min-height: 0;
  padding: 0;
}

input,
select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(30, 106, 200, 0.16);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(420px, 100%);
}

.login-panel {
  display: grid;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
  box-shadow: 0 18px 60px rgba(23, 27, 32, 0.08);
}

.login-panel p {
  margin-top: 6px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form label,
.password-form label,
.user-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.login-form button {
  min-height: 42px;
  background: var(--green);
  color: white;
}

.password-form button {
  min-height: 40px;
  background: var(--green);
  color: white;
}

.login-error {
  min-height: 36px;
  border: 1px solid #efc4ca;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 720;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100vh - 150px);
}

.account-view {
  min-height: calc(100vh - 150px);
}

.account-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.account-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.account-summary {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
  margin-bottom: 12px;
}

.account-summary span,
#account-role {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.account-summary strong {
  font-size: 22px;
}

.password-form {
  display: grid;
  gap: 10px;
}

.form-message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 720;
}

.form-message.good {
  border-color: #b7ddce;
  background: var(--green-soft);
  color: var(--green);
}

.form-message.bad {
  border-color: #efc4ca;
  background: var(--red-soft);
  color: var(--red);
}

.form-message[hidden] {
  display: none;
}

.symbols-panel,
.detail-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.symbols-panel {
  overflow: hidden;
}

.panel-heading {
  justify-content: space-between;
  height: 52px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

#symbol-count {
  color: var(--muted);
  font-size: 13px;
}

.symbols-list {
  height: calc(100vh - 205px);
  min-height: 520px;
  overflow: auto;
  padding: 8px;
}

.symbol-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 62px;
  margin-bottom: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 7px 8px 7px 10px;
  text-align: left;
}

.symbol-row.active {
  border-color: #9fd5c2;
  background: var(--green-soft);
}

.symbol-row.pinned {
  border-color: #bfd1f1;
  background: var(--blue-soft);
}

.symbol-row.active.pinned {
  border-color: #8fb5e8;
  background: #edf5ff;
}

.symbol-select {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  text-align: left;
}

.symbol-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  padding: 0;
}

.icon-button:hover {
  border-color: #9ba7b4;
  color: var(--text);
}

.icon-button.favorite.active {
  border-color: #e2c978;
  background: var(--yellow-soft);
  color: var(--yellow);
}

.icon-button.pin.active {
  border-color: #9fd5c2;
  background: var(--green-soft);
  color: var(--green);
}

.symbol-main,
.symbol-ratio {
  display: grid;
  gap: 4px;
}

.symbol-main {
  min-width: 0;
}

.symbol-title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 6px;
}

.note-badges {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.note-badge {
  width: 14px;
  height: 14px;
  border: 2px solid var(--panel-soft);
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(23, 27, 32, 0.08);
}

.note-badge + .note-badge {
  margin-left: -4px;
}

.note-badge-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 14px;
  margin-left: -3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 10px;
  font-weight: 820;
  line-height: 1;
}

.symbol-main strong,
.symbol-ratio strong {
  font-size: 15px;
}

.symbol-main small,
.symbol-ratio small {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.symbol-main .funding-line {
  font-weight: 720;
}

.symbol-ratio {
  text-align: right;
}

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

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

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

.detail-panel {
  padding: 16px;
}

.detail-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.funding-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.funding-card {
  display: grid;
  gap: 5px;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.funding-card.positive {
  border-color: #b7ddce;
  background: var(--green-soft);
}

.funding-card.negative {
  border-color: #efc4ca;
  background: var(--red-soft);
}

.funding-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.funding-card strong {
  font-size: 24px;
}

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

.exchange-tabs {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.exchange-tabs button {
  text-transform: capitalize;
}

.exchange-tabs button.active {
  border-color: #85cbb3;
  background: var(--green);
  color: white;
}

.chart-wrap {
  position: relative;
  height: min(56vh, 560px);
  min-height: 410px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
  overflow: hidden;
}

.chart-toolbar {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid rgba(215, 220, 226, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 4px;
  box-shadow: 0 8px 26px rgba(23, 27, 32, 0.08);
}

.chart-toolbar button {
  display: grid;
  place-items: center;
  min-width: 30px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0 8px;
  font-weight: 780;
}

.chart-toolbar button:hover {
  border-color: var(--line);
  background: var(--panel-soft);
}

#chart-range {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 28px;
  border-left: 1px solid var(--line);
  padding-left: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

#ratio-chart {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

#ratio-chart.dragging {
  cursor: grabbing;
}

.chart-tooltip {
  position: absolute;
  z-index: 4;
  display: grid;
  gap: 4px;
  max-width: 230px;
  border: 1px solid rgba(23, 27, 32, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 34px rgba(23, 27, 32, 0.16);
  color: var(--text);
  padding: 10px 11px;
  pointer-events: none;
}

.chart-tooltip[hidden] {
  display: none;
}

.chart-tooltip strong {
  font-size: 12px;
}

.chart-tooltip span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.chart-tooltip b {
  font-weight: 800;
}

.empty-chart {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 720;
}

.empty-chart[hidden] {
  display: none;
}

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

.exchange-cell {
  display: grid;
  gap: 5px;
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 12px;
  text-align: left;
}

.exchange-cell:not(:disabled):hover {
  border-color: #9ba7b4;
  background: #ffffff;
}

.exchange-cell.active {
  border-color: #85cbb3;
  background: var(--green-soft);
  box-shadow: inset 0 0 0 1px rgba(18, 126, 94, 0.12);
}

.exchange-cell:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.exchange-cell span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: capitalize;
}

.exchange-cell strong {
  font-size: 20px;
}

.exchange-cell b {
  font-weight: 780;
}

.exchange-cell small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.notes-panel,
.admin-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

.account-grid .admin-panel {
  margin-top: 0;
  background: var(--panel);
}

.notes-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

#notes-count,
#users-count {
  color: var(--muted);
  font-size: 13px;
}

.note-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.user-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(140px, 1fr) auto auto;
  align-items: end;
  gap: 10px;
}

.user-admin-toggle {
  min-width: 110px;
}

.note-form textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  line-height: 1.4;
}

.note-form textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(30, 106, 200, 0.16);
}

.note-form button,
.note-item button,
.user-form button,
.user-item button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 12px;
}

.note-form button:hover,
.note-item button:hover,
.user-form button:hover,
.user-item button:hover:not(:disabled) {
  border-color: #9ba7b4;
}

.note-form button:disabled,
.user-form button:disabled,
.user-item button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.notes-list,
.users-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.notes-empty {
  display: grid;
  min-height: 48px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 720;
}

.note-item,
.user-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 11px;
}

.note-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 5px;
}

.note-author {
  font-size: 12px;
  font-weight: 820;
  overflow-wrap: anywhere;
}

.note-item time {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.note-item p {
  color: var(--text);
  font-size: 14px;
  line-height: 1.42;
  overflow-wrap: anywhere;
  white-space: normal;
}

.user-item strong {
  display: block;
  margin-bottom: 4px;
}

.user-item small {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 980px) {
  .shell {
    width: min(100vw - 20px, 760px);
    padding: 14px 0;
  }

  .topbar,
  .detail-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .search,
  .select,
  .toggle {
    width: 100%;
  }

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

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

  .symbols-list {
    height: 360px;
    min-height: 360px;
  }

  .exchange-tabs {
    justify-content: flex-start;
  }

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

  .funding-strip {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 560px) {
  .status-line {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .view-tabs {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  #refresh-button,
  #logout-button,
  .user-pill,
  .pill {
    justify-content: center;
    width: 100%;
  }

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

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