/* tiles.css — Wave 5 config-driven Trading/Market tiles + C2 color machine.
 *
 * The left border carries the C2 color; the embedded keyword (.tile-keyword)
 * is the colorblind-safe fallback so color is never the only signal. All hex
 * values match the backend tile_state machine exactly (tile_state.rs). */

.tile-group { margin-bottom: 18px; }
.tile-group-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 8px 2px;
}
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.tile {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 4px solid var(--tile-border, #9e9e9e);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.tile:hover { box-shadow: 0 0 0 1px var(--tile-border, var(--border)); }

/* P4.1 restore: GREEN held-position highlight. Applied by applyTileTelemetry
   (core.js) via the .tile-held class whenever we hold a position in this
   market. A green ring + subtle green wash so a held market reads instantly,
   independent of the C2 left-border color (which may be orange/red at risk). */
.tile.tile-held {
  box-shadow: 0 0 0 2px #2e7d32, 0 0 10px rgba(46, 125, 50, 0.35);
  background:
    linear-gradient(0deg, rgba(46, 125, 50, 0.10), rgba(46, 125, 50, 0.10)),
    var(--bg-secondary);
}
.tile.tile-held:hover {
  box-shadow: 0 0 0 2px #2e7d32, 0 0 14px rgba(46, 125, 50, 0.5);
}

.tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.tile-id { display: flex; flex-direction: column; line-height: 1.2; }
.tile-sub { font-size: var(--text-xs); color: var(--text-muted); }
.tile-label { font-size: var(--text-md); font-weight: 700; color: var(--text-primary); }

/* Embedded KEYWORD — colorblind-safe accessibility fallback.
 * Tinted pill, color follows the tile border; hidden when empty (no_edge). */
.tile-keyword {
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 4px;
  color: #0b0e14;
  background: var(--tile-border, #9e9e9e);
  white-space: nowrap;
}
.tile-keyword:empty { display: none; }

.tile-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.tile-row strong { color: var(--text-primary); font-weight: 600; }
.tile-pos-row strong { color: var(--text-secondary); }

.tile-progress {
  height: 3px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}
.tile-progress-fill {
  height: 100%;
  background: var(--tile-border, var(--accent));
  width: 0%;
  transition: width 1s linear;
}

.tile-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}
.tile-health {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* D2 per-market PANIC: cancel resting orders + sell held shares for THIS
   market. Arm-then-confirm — default outline, .armed fills red + pulses. */
.tile-panic {
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--red);
  background: transparent;
  border: 1px solid var(--red);
  border-radius: 4px;
  padding: 3px 12px;
  cursor: pointer;
}
.tile-panic:hover { background: rgba(220, 38, 38, 0.12); }
.tile-panic:active { transform: translateY(1px); }
.tile-panic.armed {
  color: #fff;
  background: var(--red);
  border-color: #b91c1c;
  animation: tile-panic-pulse 0.8s ease-in-out infinite;
}
@keyframes tile-panic-pulse { 50% { opacity: 0.6; } }

/* D2 per-market Auto toggle — flips this market's auto_trade gate. */
.tile-auto {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: 4px;
  padding: 3px 12px;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--border, #444);
  color: var(--text-muted);
}
.tile-auto.on { color: var(--green, #2e7d32); border-color: var(--green, #2e7d32); }
.tile-auto.off { color: var(--text-muted); }
.tile-auto:active { transform: translateY(1px); }

/* ---- Config-driven flat tabs (R3): dot + label, underline on active ---- */
.flat-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px 5px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
}
.flat-tab:hover { color: var(--text-primary); }
.flat-tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.flat-tab .tab-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--tab-dot, #9e9e9e);
  display: inline-block;
}

/* ---- IA rebuild: Home overview, sub-market breadcrumb, Trading tabs ---- */

/* Per-tile mini-cone + target on the Home overview tiles. The HelmCone
   ({mini:true}) SVG fills this box; height is fixed so the tile grid stays
   tidy. The C2 border color still rides on .tile (left border + keyword). */
.tile-cone {
  height: 96px;
  width: 100%;
  margin: 2px 0;
  background: var(--bg-primary, #0b0e14);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tile-cone svg { width: 100%; height: 100%; display: block; }

/* Home tiles are clickable cards. */
.tile.home-tile { cursor: pointer; }

/* Persistent breadcrumb on the deep per-market cockpit (sub-market page). */
.submarket-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px 12px;
  font-size: var(--text-sm);
}
.crumb-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: var(--text-sm);
  padding: 0;
}
.crumb-link:hover { text-decoration: underline; }
.crumb-sep { color: var(--text-muted); }
.crumb-current { color: var(--text-primary); font-weight: 700; }

/* P4.1 market-TYPE badge: tags the open cockpit with the active market's TYPE
   (Crypto/Ladder/Perpetual). Color-coded per type so the operator instantly
   sees which cockpit shape is bound. */
.crumb-type-badge {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--bg-tertiary);
}
.crumb-type-badge[data-market-type="crypto"]    { color: #38bdf8; border-color: rgba(56,189,248,0.5); }
.crumb-type-badge[data-market-type="ladder"]    { color: #eab308; border-color: rgba(234,179,8,0.5); }
.crumb-type-badge[data-market-type="perpetual"] { color: #a78bfa; border-color: rgba(167,139,250,0.5); }

/* Trading-page Level 2 "< Back <Category>" control. */
.trading-back {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 6px 12px;
}
.trading-back:hover { color: var(--text-primary); border-color: var(--text-muted); }
.trading-back-cat { color: var(--text-primary); }
