html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}

/* Header: blocks with the same structure (label / value / detail), aligned and separated */
header {
  display: flex; align-items: stretch; flex-wrap: wrap; row-gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand-box { display: flex; flex-direction: column; justify-content: center; padding-right: 14px; }
.pair { color: var(--muted); font-size: 12px; }
.node-btn {
  display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; padding: 0;
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
}
.node-btn:hover { color: var(--text); }
.node-btn img { width: 16px; height: 16px; border-radius: 50%; }
.node-btn .i {
  border: 1px solid currentColor; border-radius: 50%; width: 13px; height: 13px; font-size: 9px;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
}
.stat {
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  padding: 0 11px; border-left: 1px solid var(--line); min-width: 0;
}
.stat .label { color: var(--muted); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
.stat .value { font-size: 16px; font-weight: 600; white-space: nowrap; }
.stat .sub { color: var(--muted); font-size: 11px; white-space: nowrap; }
.stat .unit { color: var(--muted); font-size: 11px; font-weight: 400; margin-left: 4px; }
.stat.big .value { font-size: 24px; font-weight: 700; color: var(--avg); line-height: 1.15; }
/* Blink when the Tasa K changes: a moment in green or red and back to blue */
.stat.big .value.tick-up { animation: tick-up 1.6s ease-out; }
.stat.big .value.tick-down { animation: tick-down 1.6s ease-out; }
@keyframes tick-up { 0%, 35% { color: var(--up); background: var(--up-bg); } 100% { color: var(--avg); background: transparent; } }
@keyframes tick-down { 0%, 35% { color: var(--down); background: var(--down-bg); } 100% { color: var(--avg); background: transparent; } }
.stat.big .value { border-radius: 4px; margin: 0 -4px; padding: 0 4px; }
@media (prefers-reduced-motion: reduce) { .stat.big .value.tick-up, .stat.big .value.tick-down { animation: none; } }
.value-row { display: flex; align-items: baseline; gap: 10px; }
.chg {
  font-size: 12px; font-weight: 600; padding: 1px 6px; border-radius: 4px; white-space: nowrap;
}
.chg.up { background: var(--up-bg); }
.chg.down { background: var(--down-bg); }
.head-end { margin-left: auto; align-self: center; display: flex; align-items: center; padding-left: 10px; }
.status {
  align-self: center; font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 6px; white-space: nowrap; cursor: default;
}
.status .ok { color: var(--up); }
.status .warn { color: var(--accent); }
/* The signed Tasa K doesn't match this browser's; an order without signature (the node's database) */
.stat .warn, .faq .warn { color: var(--accent); }
.unsigned { color: var(--muted); cursor: help; }
.status.error { color: var(--down); white-space: normal; max-width: 320px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--up); box-shadow: 0 0 6px var(--up); }

.filters {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding: 8px 16px; border-bottom: 1px solid var(--line);
}
.filters .label { color: var(--muted); font-size: 12px; margin-right: 4px; }
select {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 4px; padding: 3px 6px; font: inherit; font-size: 13px;
}
.chip {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 3px 10px; font: inherit; font-size: 12px; cursor: pointer;
}
.chip.on { border-color: var(--accent); color: var(--text); background: var(--accent-bg); }
.chip .c { opacity: .6; margin-left: 4px; }
.sep { width: 1px; height: 18px; background: var(--line); margin: 0 8px; }
[hidden] { display: none !important; }

main {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 1fr 440px; gap: 1px; background: var(--line);
}
.col { display: grid; gap: 1px; min-height: 0; min-width: 0; }
.col.left { grid-template-rows: 1fr; }
.col.right { grid-template-rows: var(--book, 1fr) 5px var(--trades, 1fr); gap: 0; }
/* Draggable splitter between order book and executed orders, like the volume one */
.splitter { background: var(--line); cursor: row-resize; touch-action: none; }
.splitter:hover, .splitter.drag, .splitter:focus-visible { background: var(--avg-soft); outline: none; }
.panel { background: var(--bg); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel-head {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 6px 12px; border-bottom: 1px solid var(--line); min-height: 37px;
}
.panel-head h2 { font-size: 13px; font-weight: 600; margin: 0 auto 0 0; }
.panel-head .hint { color: var(--muted); font-size: 11px; }
.tabs button {
  background: none; border: 0; color: var(--muted); padding: 3px 9px; border-radius: 4px;
  font: inherit; font-size: 12px; cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); background: var(--line); }
.chart { flex: 1; min-height: 240px; position: relative; }
.icon-btn {
  background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 4px;
  font: inherit; font-size: 14px; line-height: 1; padding: 4px 7px; cursor: pointer; margin-left: 4px;
}
.icon-btn:hover { color: var(--text); }

/* Dropdown menu of the payment method filter */
.menu { position: relative; margin-left: auto; }
.menu > summary {
  list-style: none; cursor: pointer; color: var(--muted); font-size: 12px;
  border: 1px solid var(--line); border-radius: 4px; padding: 3px 9px;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary:hover, .menu[open] > summary { color: var(--text); }
.menu > summary.filtered { border-color: var(--accent); color: var(--text); }
.menu .pop {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; width: 280px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px;
  box-shadow: 0 8px 24px var(--shadow);
}
.menu .pop p { margin: 0 0 8px; color: var(--muted); font-size: 11px; }
.menu .pop .chips { display: flex; flex-wrap: wrap; gap: 6px; }
/* Timeframe dropdown, like TradingView's */
.menu.tf { margin-left: 0; }
.menu.tf > summary { color: var(--text); min-width: 52px; text-align: center; }
.menu.tf .pop { left: 0; right: auto; width: 190px; padding: 6px 0; max-height: 60vh; overflow-y: auto; }
.tf-group {
  color: var(--muted); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; padding: 8px 14px 4px;
}
.tf-group:not(:first-child) { border-top: 1px solid var(--line); margin-top: 4px; }
.tf-pop button {
  display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text);
  font: inherit; font-size: 13px; padding: 6px 14px; cursor: pointer;
}
.tf-pop button:hover { background: var(--row); }
.tf-pop button.on { background: var(--line); }

/* Full screen: native API or, if missing (iPhone), a fixed panel */
.panel:fullscreen { width: 100vw; height: 100vh; }
.panel.max { position: fixed; inset: 0; z-index: 50; }
.panel.max .chart, .panel:fullscreen .chart { min-height: 0; }
/* Tag of the volume pane, with the eye to show or hide it */
.vol-tag {
  position: absolute; left: 10px; z-index: 5; display: flex; align-items: center; gap: 4px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px 1px 7px;
  font-size: 11px; color: var(--muted);
}
.vol-tag button {
  background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px; display: flex;
}
.vol-tag button:hover { color: var(--text); }
/* Legend over the chart (TradingView style): values under the cursor or of the last point */
.legend {
  position: absolute; top: 6px; left: 10px; z-index: 4; pointer-events: none;
  font-size: 12px; line-height: 1.5; text-shadow: 0 0 4px var(--bg), 0 0 4px var(--bg);
}
.legend .row { display: flex; gap: 10px; flex-wrap: wrap; }
.legend .k { color: var(--muted); margin-right: 3px; }
.legend .when { color: var(--muted); }
.empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); pointer-events: none; z-index: 3; text-align: center; padding: 16px;
}

.scroll { overflow: auto; flex: 1; min-height: 0; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th {
  color: var(--muted); font-weight: 400; text-align: right; padding: 5px 8px;
  position: sticky; top: 0; background: var(--bg); z-index: 1;
}
td { text-align: right; padding: 3px 8px; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
.trades td { border-bottom: 1px solid var(--row); }
.trades tr[data-key], .book tr[data-key] { cursor: pointer; }
.trades tr[data-key]:hover td, .book tr[data-key]:hover td { background: var(--row); }
.faq-body .ev-note { margin: 8px 0 0; }
.ev-meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 8px 0 12px; font-size: 13px; }
.ev-meta dt { color: var(--muted); }
.ev-meta dd { margin: 0; overflow-wrap: anywhere; }
.ev-json {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin: 0;
  font-size: 11px; line-height: 1.45; max-height: 45vh; overflow: auto; white-space: pre-wrap; word-break: break-all;
}
.ev-actions { display: flex; gap: 8px; margin-top: 12px; align-items: center; flex-wrap: wrap; }
.ev-actions a { color: var(--avg); font-size: 13px; }
.trades tr.out td { opacity: .45; }
tr.new td { animation: flash 1.5s; }
@keyframes flash { from { background: var(--accent-flash); } to { background: transparent; } }
.pm { color: var(--muted); font-size: 11px; max-width: 96px; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: bottom; }

/* Order book: depth bar behind each row */
.book tr.ask, .book tr.bid { position: relative; }
.book tr.ask td:first-child { color: var(--down); }
.book tr.bid td:first-child { color: var(--up); }
.book tr.ask { background: linear-gradient(to left, var(--down-bg) var(--d), transparent var(--d)); }
.book tr.bid { background: linear-gradient(to left, var(--up-bg) var(--d), transparent var(--d)); }
.book tr.mid td {
  padding: 8px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: 13px; text-align: left; white-space: normal;
}
.book tr.mid strong { font-size: 16px; }
.book .none td, .trades .none td { color: var(--muted); text-align: center; padding: 10px; }

.head-btn { margin-left: 8px; font-size: 12px; padding: 5px 10px; white-space: nowrap; }
.node-filter { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
/* «Your selection»: the rate with the visitor's methods and nodes, apart from the official one */
.selection {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 2px 3px 2px 10px; border: 1px solid var(--accent-line); border-radius: 999px; background: var(--accent-bg);
  cursor: help;
}
.selection[hidden] { display: none; }
.selection .label { margin-right: 0; }
.selection strong { font-size: 13px; }
.selection .unit { color: var(--muted); font-size: 11px; font-weight: 400; margin-left: 4px; }
.selection .muted { font-size: 12px; }
.selection .icon-btn { padding: 1px 7px; font-size: 11px; cursor: pointer; }
/* Narrow screens: the whole width, and the text wraps instead of hiding ✕ */
@media (max-width: 900px) {
  .selection { margin-left: 0; width: 100%; flex-wrap: wrap; white-space: normal; border-radius: 12px; padding: 4px 4px 4px 10px; }
  .selection .icon-btn { margin-left: auto; }
}
.info-nav { margin-left: 10px; display: flex; align-items: center; gap: 6px; }
.info-nav .head-btn { margin-left: 0; }
/* Links to the node information and the FAQ, in the accent colour so they stand out */
.info-nav .head-btn { color: var(--accent); border-color: var(--accent-line); background: var(--accent-bg); }
.info-nav .head-btn:hover { color: var(--bg); background: var(--accent); border-color: var(--accent); }
a.head-btn, a.node-btn { text-decoration: none; }
dialog.faq {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 0; width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog.faq::backdrop { background: var(--backdrop); }
.faq-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel);
}
.faq-head h2 { margin: 0; font-size: 16px; }
.faq-body { padding: 8px 16px 16px; }
.faq details { border-bottom: 1px solid var(--line); padding: 10px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details p, .faq details ul { margin: 8px 0 0; color: var(--muted); line-height: 1.55; }
.faq details li { margin: 2px 0; }
.faq code { color: var(--text); background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.faq strong { color: var(--text); }

@media (max-width: 900px) {
  body { height: auto; }
  main { grid-template-columns: 1fr; }
  .col.left, .col.right { grid-template-rows: auto; }
  .col.right { gap: 1px; }
  .stat { border-left: 0; padding: 0 20px 0 0; }
  .brand-box { width: 100%; }
  .splitter { display: none; }
  .chart { min-height: 340px; }
  .scroll { max-height: 55vh; }
  .status { margin-left: 0; }
  header { gap: 14px; }
  .hide-sm { display: none; }
  /* Status on the left and the buttons on the right, more compact; if they still don't fit, the
     buttons go together to the next line instead of breaking their text */
  .head-end { width: 100%; padding-left: 0; flex-wrap: wrap; justify-content: space-between; row-gap: 8px; }
  .info-nav { margin-left: auto; gap: 4px; }
  .info-nav .head-btn { padding: 5px 8px; }
}
