:root {
  --bg: #101214;
  --panel: #171a1d;
  --panel-2: #1d2227;
  --line: #3d444c;
  --text: #eef3f7;
  --muted: #8a96a3;
  --blue: #62a5ff;
  --green: #43ff42;
  --red: #ff4242;
  --amber: #ffd447;
}

* { box-sizing: border-box; }
html, body {
  max-width: 100%;
  overflow-x: hidden;
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Consolas, "SFMono-Regular", ui-monospace, monospace;
  font-size: 13px;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: #0d0f11;
}
.topbar > div {
  min-width: 0;
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.brand-logo {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}
.brand-logo:hover {
  text-decoration: none;
}
.brand-logo img {
  display: block;
  width: auto;
  height: 42px;
}
.brand-user {
  min-width: 0;
}
.topbar .muted {
  overflow-wrap: anywhere;
}
.topbar nav { display: flex; gap: 16px; }
.muted { color: var(--muted); }

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-shell {
  width: min(526px, 100%);
  display: grid;
  justify-items: center;
  gap: 26px;
}
.auth-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.auth-card {
  width: min(420px, 100%);
  padding: 28px;
}
.auth-brand {
  margin: -8px 0 18px;
}
.auth-brand img {
  display: block;
  width: min(260px, 100%);
  height: auto;
}
.auth-shell > .auth-brand {
  margin: 0;
}
.auth-brand-login img {
  width: min(330px, 82vw);
}
h1, h2 { margin: 0 0 12px; font-weight: 700; letter-spacing: 0; }
h1 { font-size: 22px; }
h2 { color: var(--blue); font-size: 14px; }
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--muted); }
input,
select {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #0d0f11;
  color: var(--text);
  font: inherit;
}
button, .button-link {
  border: 1px solid #5e91d9;
  border-radius: 3px;
  background: #173964;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  display: inline-block;
}
.small-button {
  padding: 6px 9px;
  font-size: 12px;
}
.danger-button {
  border-color: rgba(255,66,66,.55);
  background: rgba(255,66,66,.10);
  color: var(--red);
}
.table-action {
  display: inline;
}
.table-action + .table-action {
  margin-left: 6px;
}
.copy-key-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin: 12px 0;
}
.alert, .notice {
  padding: 10px 12px;
  border-radius: 3px;
  margin: 12px 0;
  border: 1px solid var(--line);
}
.alert { color: var(--red); background: rgba(255,66,66,.08); }
.notice { color: var(--green); background: rgba(67,255,66,.08); overflow-wrap: anywhere; }
.role-badge {
  display: inline-block;
  min-width: 46px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--muted);
  text-align: center;
}
.role-badge.admin {
  color: var(--green);
  border-color: rgba(67,255,66,.42);
  background: rgba(67,255,66,.07);
}
.role-badge.super-admin {
  min-width: 88px;
  color: var(--amber);
  border-color: rgba(255,212,71,.50);
  background: rgba(255,212,71,.08);
}
.status-badge {
  display: inline-block;
  min-width: 64px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 3px;
  text-align: center;
}
.status-badge.active {
  color: var(--green);
  border-color: rgba(67,255,66,.42);
  background: rgba(67,255,66,.07);
}
.status-badge.disabled {
  color: var(--red);
  border-color: rgba(255,66,66,.42);
  background: rgba(255,66,66,.07);
}
.admin-list {
  max-width: 100%;
  overflow: visible;
}
.admin-table {
  table-layout: fixed;
  min-width: 0;
}
.admin-table th,
.admin-table td {
  white-space: normal;
  overflow-wrap: anywhere;
  vertical-align: middle;
}
.admin-table th {
  white-space: nowrap;
  overflow-wrap: normal;
}
.admin-table th:nth-child(1),
.admin-table td:nth-child(1) {
  width: 29%;
}
.admin-table th:nth-child(2),
.admin-table td:nth-child(2) {
  width: 18%;
}
.admin-table th:nth-child(3),
.admin-table td:nth-child(3) {
  width: 8%;
}
.admin-table th:nth-child(4),
.admin-table td:nth-child(4) {
  width: 10%;
}
.admin-table th:nth-child(5),
.admin-table td:nth-child(5) {
  width: 10%;
}
.admin-table th:nth-child(6),
.admin-table td:nth-child(6) {
  width: 25%;
  text-align: center;
}
.user-cell {
  font-weight: 700;
}
.admin-actions {
  position: relative;
  text-align: center;
}
.admin-actions .table-action {
  display: block;
  margin: 0;
}
.action-dropdown {
  position: relative;
  display: inline-block;
}
.action-menu-toggle {
  min-width: 82px;
  padding: 6px 8px;
}
.action-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  display: none;
  min-width: 168px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #0d0f11;
  box-shadow: 0 14px 36px rgba(0,0,0,.42);
}
.action-dropdown.open .action-menu {
  display: grid;
  gap: 5px;
}
.action-modal .action-menu {
  position: static;
  display: grid;
  min-width: 0;
  margin-top: 14px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  gap: 8px;
}
.action-menu button {
  width: 100%;
  padding: 7px 9px;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.action-menu button:hover,
.action-menu button:focus {
  border-color: rgba(98,165,255,.45);
  background: rgba(98,165,255,.10);
}
.action-menu .danger-menu-item {
  color: var(--red);
}
.action-menu .danger-menu-item:hover,
.action-menu .danger-menu-item:focus {
  border-color: rgba(255,66,66,.45);
  background: rgba(255,66,66,.10);
}
.action-modal .action-menu button {
  padding: 10px 11px;
  border-color: var(--line);
  background: #0d0f11;
}
.action-label {
  color: var(--blue);
}
.audit-table th:nth-child(1),
.audit-table td:nth-child(1) {
  width: 18%;
}
.audit-table th:nth-child(2),
.audit-table td:nth-child(2),
.audit-table th:nth-child(4),
.audit-table td:nth-child(4) {
  width: 24%;
}
.audit-table th:nth-child(3),
.audit-table td:nth-child(3) {
  width: 16%;
}
.audit-table th:nth-child(5),
.audit-table td:nth-child(5) {
  width: 18%;
}

.page { padding: 20px; }
.narrow { max-width: 980px; margin: 0 auto 16px; padding: 18px; }
.admin-page .narrow { max-width: 1220px; }
.inline-form { grid-template-columns: 1fr 1fr auto; align-items: end; }
.backup-form {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 14px;
}
.backup-table-wrap {
  margin-top: 8px;
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}
.pagination-status {
  color: var(--muted);
}
.disabled-link {
  cursor: not-allowed;
  opacity: .45;
  pointer-events: none;
}
.settings-page .narrow { max-width: 1040px; }
.settings-grid {
  width: min(1040px, calc(100vw - 40px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.settings-card {
  display: grid;
  gap: 14px;
  align-content: start;
}
.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.settings-actions button {
  width: auto;
}
button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.dashboard {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: calc(100vh - 52px);
  max-width: 100vw;
}
.sidebar {
  border-right: 1px solid var(--line);
  background: #0d0f11;
  padding: 14px;
}
.section-title {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  margin-bottom: 10px;
}
.account-link {
  display: grid;
  gap: 4px;
  position: relative;
  padding: 10px;
  padding-right: 28px;
  border-radius: 3px;
  color: var(--text);
  border: 1px solid transparent;
}
.account-link.active {
  border-color: var(--blue);
  background: rgba(98,165,255,.10);
}
.account-link small { color: var(--muted); }
.account-status-dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255,255,255,.06);
}
.account-status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 2px rgba(67,255,66,.18), 0 0 8px rgba(67,255,66,.45);
}
.account-status-dot.offline {
  background: var(--red);
  box-shadow: 0 0 0 2px rgba(255,66,66,.18), 0 0 8px rgba(255,66,66,.45);
}
.workspace {
  min-width: 0;
  padding: 18px;
  display: grid;
  gap: 16px;
  align-content: start;
}
.dashboard-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}
.status-pill {
  min-width: 74px;
  text-align: center;
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 3px;
  color: var(--muted);
}
.status-pill.online { color: var(--green); border-color: rgba(67,255,66,.45); }
.status-pill.offline { color: var(--red); border-color: rgba(255,66,66,.45); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}
.metric {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px;
}
.metric span { display: block; color: var(--muted); margin-bottom: 8px; }
.metric strong { font-size: 18px; color: var(--text); }
.metric-with-action {
  display: grid;
  gap: 8px;
  align-items: start;
}
.metric-with-action span,
.metric-with-action strong {
  min-width: 0;
}
.metric-reset {
  justify-self: start;
  padding: 6px 9px;
  border-color: rgba(255,212,71,.55);
  background: rgba(255,212,71,.10);
  color: var(--amber);
  font-size: 11px;
}
.metric-reset:disabled {
  cursor: wait;
  opacity: .55;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5,7,9,.72);
  animation: fade-in .14s ease-out;
}
.modal-overlay.is-hiding {
  opacity: 0;
  transition: opacity .14s ease-out;
}
.modal {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 18px 60px rgba(0,0,0,.42);
  padding: 18px;
}
.modal-success {
  border-color: rgba(67,255,66,.42);
}
.modal-error {
  border-color: rgba(255,66,66,.42);
}
.modal-success h2 {
  color: var(--green);
}
.modal-error h2 {
  color: var(--red);
}
.modal h2 {
  margin-bottom: 10px;
}
.modal p {
  margin: 0;
  line-height: 1.5;
}
.modal-note {
  margin-top: 12px;
  padding: 10px 11px;
  border: 1px solid rgba(255,212,71,.35);
  border-radius: 3px;
  color: var(--amber);
  background: rgba(255,212,71,.08);
  line-height: 1.45;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
.modal-cancel {
  border-color: var(--line);
  background: #0d0f11;
  color: var(--muted);
}
.modal-confirm {
  border-color: rgba(255,212,71,.65);
  background: rgba(255,212,71,.14);
  color: var(--amber);
}
.modal-success .modal-confirm {
  border-color: rgba(67,255,66,.45);
  background: rgba(67,255,66,.10);
  color: var(--green);
}
.modal-error .modal-confirm {
  border-color: rgba(255,66,66,.45);
  background: rgba(255,66,66,.10);
  color: var(--red);
}
.modal-success .modal-cancel,
.modal-error .modal-cancel {
  display: none;
}
.server-message-hidden {
  display: none !important;
}
.toast-stack {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 60;
  display: grid;
  gap: 8px;
  width: min(320px, calc(100vw - 24px));
}
.toast {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(0,0,0,.34);
  animation: slide-in .16s ease-out;
}
.toast.success {
  color: var(--green);
  border-color: rgba(67,255,66,.42);
  background: rgba(67,255,66,.08);
}
.toast.error {
  color: var(--red);
  border-color: rgba(255,66,66,.42);
  background: rgba(255,66,66,.08);
}
.toast.is-hiding {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .14s ease-out, transform .14s ease-out;
}
.panel {
  min-width: 0;
  padding: 14px;
}
.trade-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 26px;
}
.terminal-lines {
  display: grid;
  gap: 7px;
}
.terminal-lines > div {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dotted rgba(138,150,163,.28);
  padding-bottom: 4px;
}
.terminal-lines span { color: var(--muted); }
.terminal-lines .summary-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}
.terminal-lines .summary-row span {
  color: var(--text);
  min-width: 0;
}
.terminal-lines .summary-row span:last-child {
  text-align: left;
}
.terminal-lines .summary-row b {
  color: var(--text);
  font-weight: 700;
}
.terminal-lines .summary-row strong {
  font-weight: 700;
}
.terminal-lines .summary-separator {
  display: none;
}
.pos { color: var(--green) !important; }
.neg { color: var(--red) !important; }
.status-text {
  font-weight: 700;
}
.status-text.verified {
  color: var(--green);
}
.status-text.pending {
  color: var(--amber);
}
.status-hint {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}
.table-wrap {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
.table-wrap table {
  min-width: 620px;
}
.mobile-positions {
  display: none;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 9px 8px;
  border-bottom: 1px solid rgba(138,150,163,.18);
  text-align: right;
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 400; }
.summary-total-row td {
  border-top: 1px solid var(--line);
  color: var(--amber);
  font-weight: 700;
}
.empty { margin: 32px auto; max-width: 640px; padding: 24px; }
.empty-row td { color: var(--muted); text-align: left; }

@media (max-width: 980px) {
  .dashboard { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .trade-board { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr; }
  .settings-grid {
    width: auto;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body { font-size: 12px; }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 10px 12px;
  }
  .brand-lockup {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }
  .brand-logo img {
    width: auto;
    height: 34px;
  }
  .topbar nav {
    width: 100%;
    justify-content: space-between;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .page { padding: 12px; }
  .dashboard {
    max-width: 100%;
    overflow-x: hidden;
  }
  .narrow {
    margin-bottom: 12px;
    padding: 12px;
  }
  .auth-page { padding: 14px; }
  .auth-card { padding: 18px; }
  .copy-key-box { grid-template-columns: 1fr; }
  .workspace {
    min-width: 0;
    max-width: 100vw;
    padding: 12px;
    gap: 12px;
    overflow-x: hidden;
  }
  .sidebar { padding: 10px 12px; }
  .dashboard-head {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }
  .status-pill {
    width: 100%;
  }
  .metric-grid {
    grid-template-columns: 1fr;
  }
  .metric {
    padding: 10px;
  }
  .metric strong {
    font-size: 16px;
  }
  .panel {
    max-width: 100%;
    padding: 12px;
    overflow: hidden;
  }
  .trade-board {
    gap: 14px;
  }
  .terminal-lines > div {
    gap: 10px;
  }
  .terminal-lines .summary-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  th, td {
    padding: 6px 3px;
    font-size: 10px;
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .table-wrap {
    margin: 0 -2px;
    padding-bottom: 4px;
    overflow-x: visible;
  }
  .panel:has(#positionsMobileList) .table-wrap {
    display: none;
  }
  .mobile-positions {
    display: grid;
  }
  .mobile-position {
    border-bottom: 1px solid rgba(138,150,163,.22);
    background: #0d0f11;
  }
  .mobile-position summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 10px 4px;
    list-style: none;
    cursor: pointer;
  }
  .mobile-position summary::-webkit-details-marker {
    display: none;
  }
  .mobile-position-main {
    display: grid;
    grid-template-columns: auto auto 1fr;
    column-gap: 5px;
    row-gap: 2px;
    min-width: 0;
  }
  .mobile-position-main b {
    color: var(--text);
  }
  .mobile-position-main small {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 12px;
  }
  .mobile-position summary > strong {
    font-size: 15px;
  }
  .mobile-position-details {
    display: grid;
    gap: 7px;
    padding: 0 4px 10px;
    color: var(--muted);
  }
  .mobile-position-details div {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    gap: 10px;
  }
  .mobile-position-details strong {
    color: var(--text);
    font-weight: 400;
    overflow-wrap: anywhere;
  }
  .mobile-position-empty {
    color: var(--muted);
    padding: 10px 4px;
  }
  .table-wrap table {
    min-width: 0;
    table-layout: fixed;
  }
  .table-action {
    display: inline-block;
    margin: 2px 0;
  }
  .table-action + .table-action {
    margin-left: 0;
  }
  .small-button {
    padding: 7px 8px;
  }
  .admin-page .narrow {
    padding: 10px;
  }
  .admin-table,
  .admin-table thead,
  .admin-table tbody,
  .admin-table tr,
  .admin-table th,
  .admin-table td {
    display: block;
    width: 100% !important;
  }
  .admin-table thead {
    display: none;
  }
  .admin-table tr {
    padding: 10px 0;
    border-bottom: 1px solid rgba(138,150,163,.18);
  }
  .admin-table td {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 10px;
    border-bottom: 0;
    text-align: left;
    font-size: 11px;
  }
  .admin-table td::before {
    color: var(--muted);
    content: attr(data-label);
  }
  .admin-actions {
    display: flex !important;
    justify-content: flex-start;
    grid-template-columns: none !important;
  }
  .admin-actions::before {
    width: 92px;
    flex: 0 0 92px;
  }
  .modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .toast-stack {
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
  }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
