:root {
  color-scheme: dark;
  --bg: #111;
  --panel: #181818;
  --panel-2: #202020;
  --text: #eee;
  --muted: #a6adba;
  --line: #444;
  --accent: #1eb854;
  --accent-2: #38bdf8;
  --warn: #f59e0b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 15px;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  color: var(--accent);
}

.shell {
  width: min(1840px, 100%);
  margin: 0 auto;
  padding: 30px 20px 48px;
}

.navbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 24px;
  width: 100vw;
  margin: -30px calc(50% - 50vw) 30px;
  padding: 10px 30px;
  background: rgba(17, 17, 17, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #333;
}

.hidden {
  display: none !important;
}

#navbar-refresh {
  margin-left: auto;
  padding: 4px 12px;
  background: #333;
  border: 1px solid #444;
  color: #aaa;
  cursor: pointer;
  font: inherit;
  font-size: 0.8em;
}

#navbar-refresh:hover {
  background: #444;
  color: #eee;
}

#navbar-refresh:not(.loading):hover .refresh-text {
  display: none;
}

#navbar-refresh:not(.loading):hover::after {
  content: "Refresh";
}

#navbar-refresh .refresh-spinner {
  display: none;
  width: 10px;
  height: 10px;
  border: 2px solid #555;
  border-top-color: #aaa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

#navbar-refresh.loading {
  cursor: default;
}

#navbar-refresh.loading .refresh-spinner {
  display: inline-block;
}

#navbar-refresh.loading .refresh-text {
  display: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#navbar-logout {
  padding: 4px 12px;
  background: #333;
  border: 1px solid #444;
  color: #eee;
  cursor: pointer;
  font: inherit;
  font-size: 0.8em;
}

#navbar-logout:hover {
  background: #444;
}

.masthead {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30px;
  text-align: center;
}

.navbar-brand {
  display: flex;
  align-items: flex-start;
  gap: 2px;
  color: #eee;
  text-decoration: none;
}

.navbar-logo {
  display: block;
  height: 2em;
}

.navbar-item {
  color: #888;
  text-decoration: none;
}

.navbar-item:hover {
  color: #eee;
}

.navbar-item[aria-current] {
  color: #eee;
  text-decoration: underline;
  text-underline-offset: 6px;
}

.view-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.view-btn {
  padding: 7px 18px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.view-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

.view-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.view-btn.offline {
  animation: flash-offline 1.5s ease-in-out infinite;
}

@keyframes flash-offline {
  0%, 100% { border-color: var(--line); color: var(--muted); }
  50% { border-color: #dc2626; color: #dc2626; }
}

.logo {
  display: block;
  height: 4em;
  margin: 0 auto 20px;
}

.masthead h1 {
  margin: 0 0 12px;
  font-size: 1.55em;
  text-align: center;
}

.section {
  padding: 0 0 30px;
}

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

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 17px;
}

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

.stat-grid,
.chart-grid {
  display: grid;
  gap: 12px;
}

.stat-grid {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  width: 100%;
  margin-inline: auto;
  margin-bottom: 12px;
}

.stat-grid:last-child {
  margin-bottom: 0;
}

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

.stat,
.empty {
  border: 1px solid var(--line);
  background: var(--panel);
}

.stat {
  min-height: 82px;
  padding: 14px;
}

.stat span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 21px;
  font-weight: 700;
}

.discount-slider {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  margin-top: 10px;
}

.chart-range {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
}

.range-btn {
  padding: 5px 14px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.range-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

.range-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chart-grid {
  width: 100%;
  margin: 0 auto;
  grid-template-columns: 1fr;
  gap: 28px;
}

.column {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  padding: 20px 30px;
}

.column-full {
  width: 100%;
  margin: 0 auto;
}

.chart-panel {
  padding: 0;
}

.column h2 {
  margin: 0 0 16px;
  font-size: 1.22em;
  text-align: left;
  color: var(--text);
}

.chart-panel h2 {
  margin: 0 0 8px;
  font-size: 1.22em;
  color: var(--muted);
}

.chart {
  width: 100%;
  height: 330px;
  background: transparent;
}

.empty {
  padding: 18px;
  color: var(--muted);
}

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

.node-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  margin-top: 10px;
}

.node-table th,
.node-table td {
  padding: 12px 16px;
  text-align: left;
  white-space: nowrap;
}

.node-table th {
  color: #888;
  font-weight: normal;
  border-bottom: 1px solid var(--line);
}

.node-table thead th {
  background: transparent;
  text-transform: none;
  font-size: inherit;
}

.node-table th[data-sort] {
  cursor: pointer;
  user-select: none;
}

.node-table th[data-sort]:hover {
  color: var(--text);
}

.node-table th[data-sort]::after {
  content: "";
  display: inline-block;
  width: 1em;
  margin-left: 4px;
  color: #ccc;
}

.node-table th[data-sort].sort-asc::after {
  content: "\25B2";
}

.node-table th[data-sort].sort-desc::after {
  content: "\25BC";
}

.node-table td {
  border-bottom: 1px solid #333;
  vertical-align: middle;
}

.node-table td.node-down {
  color: var(--muted);
}

.node-table tbody th {
  color: var(--text);
  background: transparent;
  border-bottom: 1px solid #333;
  vertical-align: middle;
}

.node-table tbody tr:hover th,
.node-table tbody tr:hover td {
  background: #1a1a1a;
}

.node-table tbody tr:last-child th,
.node-table tbody tr:last-child td {
  border-bottom: 0;
}

.refinery {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.bid-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #888;
  font-size: 0.85em;
}

.bid-form label.full {
  grid-column: 1 / -1;
}

.bid-form input {
  background: #1a1a1a;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  min-width: 0;
}

.bid-form button {
  background: #333;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 16px;
  cursor: pointer;
  font: inherit;
}

.bid-form button:hover {
  background: #444;
}

.bid-form button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.bid-form .form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 12px;
  align-items: center;
}

.bid-form .form-actions button {
  padding: 10px 18px;
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #333;
  color: var(--muted);
}

.bid-form .form-actions button:hover {
  background: #444;
  color: var(--text);
}

.bid-form .form-actions button[type=submit] {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.bid-form .form-actions button[type=submit]:hover {
  filter: brightness(1.15);
}

.form-status {
  color: #888;
  font-size: 0.85em;
}

.form-status.error {
  color: #f44;
}

.form-status.success {
  color: #4f4;
}

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

.price-row input {
  flex: 1;
  -moz-appearance: textfield;
  appearance: textfield;
}

.price-row input::-webkit-inner-spin-button,
.price-row input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.price-adj {
  padding: 8px 10px;
  background: #333;
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.85em;
  white-space: nowrap;
}

.price-adj:hover {
  background: #444;
  color: var(--text);
}

.payouts-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.payouts-actions button {
  background: #333;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 16px;
  cursor: pointer;
  font: inherit;
}

.payouts-actions button:hover {
  background: #444;
}

.payouts-actions button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.table-pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

.table-pagination button {
  background: #333;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 4px 12px;
  cursor: pointer;
  font: inherit;
}

.table-pagination button:hover:not(:disabled) {
  background: #444;
}

.table-pagination button:disabled {
  cursor: default;
  opacity: 0.4;
}

.table-pagination span {
  color: var(--muted);
  font-size: 0.85em;
}

.cancel-bid {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #555;
  background: #2a1a1a;
  color: #f2b8b8;
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.cancel-bid:hover {
  background: #4a2222;
}

.cancel-bid.confirm {
  width: auto;
  padding: 0 8px;
  background: #7a2222;
  color: #fff;
}

.order-progress {
  position: relative;
  width: 120px;
  height: 18px;
  overflow: hidden;
  background: #111;
  border: 1px solid #444;
}

.order-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: #2d7a2d;
}

.order-progress-label {
  position: relative;
  z-index: 1;
  display: block;
  line-height: 18px;
  text-align: center;
  color: #eee;
  font-size: 0.9em;
}

.connected     { color: #4f4; }

.bid-active    { color: #4f4; }
.bid-placed    { color: #fa0; }
.bid-expired   { color: #f84; }
.bid-cancelled { color: #888; }
.bid-cancelling { color: #fa0; }
.bid-fulfilled { color: #6cf; }
.bid-pending   { color: #fa0; }
.bid-failed    { color: #f44; }
.bid-closed    { color: #888; }
.bid-unknown   { color: #888; }

@media (max-width: 720px) {
  .shell {
    padding: 20px 10px 36px;
  }

  .navbar {
    flex-wrap: wrap;
    gap: 10px 16px;
    margin: -20px calc(50% - 50vw) 24px;
    padding: 10px 16px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    justify-content: flex-start;
  }

  .chart {
    height: 290px;
  }

  .column {
    padding: 15px 20px;
  }

  .node-table {
    font-size: 0.75em;
  }


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

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

  .view-switcher {
    gap: 6px;
    margin-bottom: 18px;
  }

  .view-btn {
    padding: 6px 12px;
    font-size: 13px;
  }
}

#cancel-overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.82);
}

#cancel-modal {
  width: 340px;
  max-width: 90vw;
  padding: 26px;
  background: #1a1a1a;
  border: 1px solid #444;
  box-sizing: border-box;
}

#cancel-modal h2 {
  margin: 0 0 18px;
  color: #888;
  font-size: 1.15em;
  text-align: center;
}

#cancel-error {
  min-height: 1.4em;
  margin-bottom: 10px;
  color: #f55;
  font-size: 0.85em;
}

.cancel-actions {
  display: flex;
  gap: 10px;
}

.cancel-actions button {
  flex: 1;
  padding: 8px 16px;
  background: #333;
  border: 1px solid #444;
  color: #eee;
  cursor: pointer;
  font: inherit;
}

.cancel-actions button:hover {
  background: #444;
}
