* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Polymarket-faithful dark palette */
  --bg-page:     #0E1118;
  --bg-panel:    #131820;
  --bg-toolbar:  #161C26;
  --bg-spread:   #0B0F15;

  --hairline:    #232A36;
  --hairline-soft: #1A2029;

  --text:        #B5BAC4;
  --text-strong: #E8EAEE;
  --text-muted:  #6E7480;
  --text-faint:  #4A5060;

  --ask:         #ED4D3D;
  --ask-soft:    rgba(237, 77, 61, 0.10);
  --bid:         #2BB670;
  --bid-soft:    rgba(43, 182, 112, 0.10);

  --rebate:      #F0A93C;
}

[data-theme="light"] {
  --bg-page:     #f4e9da;
  --bg-panel:    #ede3d6;
  --bg-toolbar:  #e3d6c2;
  --bg-spread:   #d9ccb6;

  --hairline:    #c4b598;
  --hairline-soft: #d4c4b0;

  --text:        #3d2b22;
  --text-strong: #1e1410;
  --text-muted:  #8a7060;
  --text-faint:  #b3a392;

  --ask:         #B73826;
  --ask-soft:    rgba(183, 56, 38, 0.10);
  --bid:         #1F8A53;
  --bid-soft:    rgba(31, 138, 83, 0.10);

  --rebate:      #B97A1B;
}

body {
  font-family: 'DM Mono', monospace;
  background: var(--bg-page);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 16px 14px;
}
html.embedded body { min-height: auto; padding: 0; }

.container {
  width: 100%;
  max-width: 540px;
}

/* ── Panel ─────────────────────────────────────────── */
.ob-panel {
  background: var(--bg-panel);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

/* ── Panel head: "Order Book" + collapse ───────────── */
.ob-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--hairline-soft);
}
.ob-head-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: 0.005em;
}
.ob-head-info {
  color: var(--text-faint);
  display: inline-flex;
}
.ob-head-collapse {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.ob-head-collapse:hover { color: var(--text-strong); background: var(--bg-toolbar); }

/* ── Toolbar: tabs + tools ─────────────────────────── */
.ob-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
}

.ob-tabs {
  display: flex;
  gap: 18px;
  align-items: center;
}

.ob-tab {
  background: none;
  border: none;
  padding: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-faint);
  cursor: pointer;
  position: relative;
  letter-spacing: 0.005em;
  transition: color 0.15s;
}
.ob-tab:hover { color: var(--text); }
.ob-tab.is-active { color: var(--text-strong); }
.ob-tab.is-active::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  bottom: -11px;
  height: 2px;
  background: var(--text-strong);
}

/* ── Source attribution (snapshot vs live) ──────────────
 * Vive en el footer del panel, no en una barra extra. Comparte el
 * lenguaje visual con .ob-tab (texto + underline activo) para que el
 * widget tenga una sola convención de tabs. La fecha del snapshot o
 * la nota de "live" cuelga a la derecha como metadata, en mismo
 * registro que .ob-foot-label (uppercase mono). */
.ob-source {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 16px 12px;
  margin-top: 6px;
  border-top: 1px solid var(--hairline-soft);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
.ob-source-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0;
  background: transparent;
  border: 0;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.18s ease;
}
.ob-source-tab:hover { color: var(--text); }
.ob-source-tab.is-active { color: var(--text-strong); }
.ob-source-tab.is-active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -7px;
  height: 1.5px;
  background: var(--text-strong);
}
.ob-source-sep {
  width: 1px;
  height: 9px;
  background: var(--hairline);
  align-self: center;
}
.ob-source-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background 0.2s ease;
}
.ob-source-tab[data-mode="live"].is-active .ob-source-pulse {
  background: var(--bid);
  box-shadow: 0 0 0 0 rgba(43, 182, 112, 0.55);
  animation: ob-source-pulse 1.8s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}
.ob-source-tab[data-mode="live"]:hover .ob-source-pulse { background: var(--bid); }
@keyframes ob-source-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(43, 182, 112, 0.5); }
  70%  { box-shadow: 0 0 0 5px rgba(43, 182, 112, 0); }
  100% { box-shadow: 0 0 0 0 rgba(43, 182, 112, 0); }
}
.ob-source-meta {
  margin-left: auto;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}
@media (prefers-reduced-motion: reduce) {
  .ob-source-tab[data-mode="live"].is-active .ob-source-pulse {
    animation: none;
  }
}

.ob-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.ob-rebate {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--rebate);
  letter-spacing: 0.005em;
}
.ob-spread-chip {
  font-family: 'DM Mono', monospace;
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-strong);
  background: var(--bg-toolbar);
  border: 1px solid var(--hairline);
  border-radius: 5px;
  padding: 2px 7px;
  letter-spacing: 0.01em;
}

/* ── Column headers ────────────────────────────────── */
.ob-cols {
  display: grid;
  grid-template-columns: 110px 1fr 1fr 1fr;
  align-items: center;
  padding: 8px 16px 8px 12px;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-top: 1px solid var(--hairline-soft);
  border-bottom: 1px solid var(--hairline-soft);
}
.ob-cols .r { text-align: right; }
.ob-cols .col-label { color: var(--text-muted); padding-left: 4px; }

/* ── Body sections ─────────────────────────────────── */
.ob-section {
  display: flex;
  flex-direction: column;
  position: relative;
}

.ob-row {
  display: grid;
  grid-template-columns: 110px 1fr 1fr 1fr;
  align-items: center;
  padding: 6px 16px 6px 12px;
  font-size: 0.82rem;
  position: relative;
  z-index: 1;
}

.ob-row > .row-side  { padding-left: 4px; }
.ob-row > .price     { text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; }
.ob-row > .size      { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.ob-row > .total     { text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.ob-asks .ob-row .price { color: var(--ask); }
.ob-bids .ob-row .price { color: var(--bid); }

/* Per-row depth bar on the LEFT side, width proportional to cumulative depth. */
.ob-row .depth-bar {
  position: absolute;
  top: 0; bottom: 0;
  left: 0;
  pointer-events: none;
  z-index: 0;
  transition: width 0.4s ease;
}
.ob-asks .ob-row .depth-bar { background: var(--ask); opacity: 0.10; }
.ob-bids .ob-row .depth-bar { background: var(--bid); opacity: 0.10; }

.ob-asks .ob-row:hover { background: var(--ask-soft); }
.ob-bids .ob-row:hover { background: var(--bid-soft); }

.ob-empty {
  padding: 18px 16px;
  text-align: center;
  font-size: 0.74rem;
  color: var(--text-muted);
  font-style: italic;
  letter-spacing: 0.02em;
}
.ob-empty[data-state="loading"]::after {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.4;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.2; } 50% { opacity: 0.7; } }

/* ── Side badges (Asks/Bids) attached to the section ── */
.ob-asks::before,
.ob-bids::before {
  content: '';
  position: absolute;
  left: 16px;
  width: 38px;
  height: 22px;
  border-radius: 5px;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
}
.ob-asks::before {
  bottom: 8px;
  background: var(--ask);
  color: #ffffff;
  content: 'Asks';
}
.ob-bids::before {
  top: 8px;
  background: var(--bid);
  color: #ffffff;
  content: 'Bids';
}

/* ── Spread row ────────────────────────────────────── */
.ob-spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg-spread);
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.74rem;
  color: var(--text-muted);
}
.ob-foot-label {
  color: var(--text-muted);
  margin-right: 4px;
}
.ob-spread span#last-trade,
.ob-spread span#spread-value {
  color: var(--text-strong);
  font-family: 'DM Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 460px) {
  .container { max-width: 100%; }
  .ob-cols, .ob-row { grid-template-columns: 80px 1fr 1fr 1fr; padding-right: 12px; }
  .ob-row { padding-left: 10px; font-size: 0.74rem; }
  .ob-cols { padding-left: 10px; }
  .ob-toolbar { padding: 10px 12px; gap: 8px; }
  .ob-source { padding: 10px 12px 12px; flex-wrap: wrap; column-gap: 10px; }
  .ob-source-meta { margin-left: 0; flex-basis: 100%; text-align: right; padding-top: 4px; }
  .ob-rebate span { display: none; }
  .ob-asks::before, .ob-bids::before { left: 10px; }
}
