:root {
  color-scheme: dark;
  --bg-main: #090a0a;
  --bg-card: #101315;
  --bg-card-hover: #15191c;
  --bg-subtle: rgba(255, 255, 255, 0.03);
  --border-main: rgba(225, 227, 219, 0.12);
  --border-strong: rgba(225, 227, 219, 0.24);
  --text-main: #e5e4df;
  --text-muted: rgba(221, 222, 216, 0.55);
  --text-dim: rgba(221, 222, 216, 0.35);
  
  --color-extreme: #ef4444;
  --color-extreme-bg: rgba(239, 68, 68, 0.12);
  --color-extreme-border: rgba(239, 68, 68, 0.45);
  
  --color-possible: #f97316;
  --color-possible-bg: rgba(249, 115, 22, 0.12);
  --color-possible-border: rgba(249, 115, 22, 0.45);
  
  --color-huge: #f59e0b;
  --color-huge-bg: rgba(245, 158, 11, 0.12);
  --color-huge-border: rgba(245, 158, 11, 0.45);
  
  --color-green: #10b981;
  --color-blue: #3b82f6;
  
  --font-main: 'Archivo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Space Mono', monospace, ui-monospace;
}

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

html, body {
  width: 100%;
  min-height: 100%;
  background: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
}

.grain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.9'/%3E%3C/svg%3E");
}

/* Header */
.terminal-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(9, 10, 10, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-main);
  padding: 0.85rem 3vw;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.back-link {
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: color 0.2s, transform 0.2s;
}

.back-link:hover {
  color: #fff;
  transform: translateX(-2px);
}

.back-arrow {
  color: var(--color-green);
  font-weight: 800;
}

.division-tag {
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: var(--color-green);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  padding: 4px 10px;
  border-radius: 20px;
  font-family: var(--font-mono);
}

.pulsing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-green);
  box-shadow: 0 0 8px var(--color-green);
  animation: pulse-glow 1.8s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(0.75); }
}

.telemetry-coord {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
  letter-spacing: 0.15em;
}

/* Main Container */
.terminal-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 2.5rem 3vw 6rem;
  display: flex;
  flex-direction: column;
  gap: 2.25rem;
}

/* Title Section */
.title-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.title-badge {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--color-green);
  letter-spacing: 0.22em;
}

.main-title {
  font-size: clamp(2.2rem, 5.5vw, 4.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 0.95;
  color: #fff;
}

.main-subtitle {
  font-size: clamp(0.95rem, 1.4vw, 1.25rem);
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.02em;
}

.philosophy-strip {
  margin-top: 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--text-main);
  flex-wrap: wrap;
}

.philosophy-tag {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  font-weight: 800;
  color: #f87171;
  background: rgba(239, 68, 68, 0.2);
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.12em;
}

/* Telemetry Dashboard Grid */
.telemetry-dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.telemetry-card {
  background: var(--bg-card);
  border: 1px solid var(--border-main);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: border-color 0.2s, transform 0.2s;
}

.telemetry-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.card-label {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
}

.card-val {
  font-size: 1.75rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #fff;
  line-height: 1.1;
}

.card-val.text-red { color: var(--color-extreme); text-shadow: 0 0 16px rgba(239, 68, 68, 0.4); }
.card-val.text-amber { color: var(--color-possible); text-shadow: 0 0 16px rgba(249, 115, 22, 0.4); }
.card-val.text-orange { color: var(--color-huge); text-shadow: 0 0 16px rgba(245, 158, 11, 0.3); }

.card-sub {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.time-row {
  display: flex;
  gap: 0.75rem;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--text-main);
  margin-top: 2px;
}

.time-countdown {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--color-green);
  margin-top: 4px;
}

/* Alert Box */
.terminal-alert {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.alert-icon {
  font-size: 1.5rem;
}

.alert-body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.alert-body strong {
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  color: #fbbf24;
}

.alert-body p {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.alert-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}

.alert-btn {
  background: #f59e0b;
  color: #090a0a;
  border: none;
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: all 0.2s;
}

.alert-btn:hover {
  background: #fbbf24;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
}

.alert-link {
  color: #fbbf24;
  text-decoration: underline;
  font-size: 0.72rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  padding: 6px 0;
}

/* Controls Section */
.controls-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-main);
}

.filter-group {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.filter-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-main);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.filter-btn:hover {
  color: var(--text-main);
  border-color: var(--border-strong);
}

.filter-btn.active {
  background: rgba(225, 227, 219, 0.15);
  border-color: rgba(225, 227, 219, 0.6);
  color: #fff;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.1);
}

.filter-btn.btn-extreme.active {
  background: var(--color-extreme-bg);
  border-color: var(--color-extreme-border);
  color: #fca5a5;
}

.filter-btn.btn-possible.active {
  background: var(--color-possible-bg);
  border-color: var(--color-possible-border);
  color: #fdba74;
}

.filter-btn.btn-huge.active {
  background: var(--color-huge-bg);
  border-color: var(--color-huge-border);
  color: #fde68a;
}

.retailer-and-search {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.retailer-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.retailer-label {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.12em;
}

.terminal-select {
  background: var(--bg-card);
  border: 1px solid var(--border-main);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.terminal-select:focus {
  border-color: var(--color-green);
}

.terminal-select.small {
  padding: 6px 10px;
  font-size: 0.72rem;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

.terminal-search {
  background: var(--bg-card);
  border: 1px solid var(--border-main);
  color: #fff;
  padding: 8px 30px 8px 32px;
  border-radius: 6px;
  font-size: 0.75rem;
  width: 240px;
  outline: none;
  font-family: inherit;
  transition: width 0.2s, border-color 0.2s;
}

.terminal-search:focus {
  width: 280px;
  border-color: var(--color-green);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.search-clear-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  display: none;
}

.search-clear-btn.visible {
  display: block;
}

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
}

.section-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.sort-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sort-label {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.12em;
}

/* Products Grid */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.5rem;
}

/* Product Card */
.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border-main);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.25s, box-shadow 0.25s;
  position: relative;
}

.product-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-strong);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.product-card.card-extreme {
  border-color: var(--color-extreme-border);
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.15);
}

.product-card.card-extreme:hover {
  border-color: var(--color-extreme);
  box-shadow: 0 12px 35px rgba(239, 68, 68, 0.3);
}

.product-card.card-possible {
  border-color: var(--color-possible-border);
}

.product-card.card-possible:hover {
  border-color: var(--color-possible);
  box-shadow: 0 12px 30px rgba(249, 115, 22, 0.25);
}

/* Card Header & Badges */
.card-top-bar {
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-main);
  background: var(--bg-subtle);
}

.classification-badge {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-extreme {
  background: var(--color-extreme-bg);
  color: #fca5a5;
  border: 1px solid var(--color-extreme-border);
}

.badge-possible {
  background: var(--color-possible-bg);
  color: #fdba74;
  border: 1px solid var(--color-possible-border);
}

.badge-huge {
  background: var(--color-huge-bg);
  color: #fde68a;
  border: 1px solid var(--color-huge-border);
}

.just-found-badge {
  font-size: 0.65rem;
  font-weight: 700;
  font-family: var(--font-mono);
  background: #10b981;
  color: #090a0a;
  padding: 2px 7px;
  border-radius: 12px;
  animation: just-found-pulse 1.5s infinite;
}

@keyframes just-found-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.75; transform: scale(0.95); }
}

/* Card Image & Visual Area */
.card-media-wrap {
  position: relative;
  height: 180px;
  background: #181d20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: hidden;
}

.product-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.3s ease;
}

.product-card:hover .product-img {
  transform: scale(1.05);
}

.retailer-corner-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  font-size: 0.62rem;
  font-family: var(--font-mono);
  font-weight: 700;
  background: rgba(9, 10, 10, 0.85);
  border: 1px solid var(--border-main);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-main);
}

/* Card Body */
.card-body {
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1;
}

.product-title {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.35;
  color: #fff;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Pricing Grid Block */
.pricing-block {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-main);
  border-radius: 8px;
}

.price-col {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.strike-price {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: line-through;
  font-family: var(--font-mono);
}

.glitch-price {
  font-size: 1.65rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #fff;
  line-height: 1;
}

.discount-tag {
  font-size: 0.9rem;
  font-weight: 800;
  font-family: var(--font-mono);
  padding: 4px 8px;
  border-radius: 6px;
  text-align: center;
}

.card-extreme .discount-tag {
  background: var(--color-extreme);
  color: #090a0a;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

.card-possible .discount-tag {
  background: var(--color-possible);
  color: #090a0a;
}

.card-huge .discount-tag {
  background: var(--color-huge);
  color: #090a0a;
}

/* History Baseline Row */
.history-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Confidence Score Bar */
.confidence-box {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.confidence-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.68rem;
  font-family: var(--font-mono);
}

.confidence-title {
  color: var(--text-muted);
  font-weight: 600;
}

.confidence-num {
  font-weight: 800;
  color: #fff;
}

.confidence-track {
  width: 100%;
  height: 6px;
  background: #181d20;
  border-radius: 3px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}

.card-extreme .confidence-fill { background: var(--color-extreme); }
.card-possible .confidence-fill { background: var(--color-possible); }
.card-huge .confidence-fill { background: var(--color-huge); }

/* Flags & Stock Info */
.flags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  font-size: 0.65rem;
  font-family: var(--font-mono);
}

.flag-pill {
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-main);
  color: var(--text-muted);
}

.flag-pill.warning {
  background: rgba(249, 115, 22, 0.12);
  border-color: rgba(249, 115, 22, 0.35);
  color: #fdba74;
}

.flag-pill.danger {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-weight: 700;
}

/* Card Actions */
.card-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

.btn-buy {
  background: var(--text-main);
  color: var(--bg-main);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 8px 12px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  text-align: center;
}

.btn-buy:hover {
  background: #fff;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.3);
}

.card-extreme .btn-buy {
  background: var(--color-extreme);
  color: #fff;
}

.card-extreme .btn-buy:hover {
  background: #f87171;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.5);
}

.btn-inspect {
  background: transparent;
  border: 1px solid var(--border-main);
  color: var(--text-muted);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-inspect:hover {
  border-color: var(--border-strong);
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 4rem 1.5rem;
  background: var(--bg-card);
  border: 1px dashed var(--border-main);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.empty-radar {
  font-size: 2.5rem;
  animation: pulse-glow 2s infinite ease-in-out;
}

.empty-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-main);
}

.empty-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 540px;
  line-height: 1.5;
}

/* History Section */
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.history-card {
  background: #0d0f11;
  border: 1px solid rgba(225, 227, 219, 0.08);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  opacity: 0.85;
  transition: opacity 0.2s, border-color 0.2s;
}

.history-card:hover {
  opacity: 1;
  border-color: var(--border-strong);
}

.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-badge {
  font-size: 0.62rem;
  font-family: var(--font-mono);
  font-weight: 700;
  color: #94a3b8;
  background: rgba(148, 163, 184, 0.12);
  padding: 2px 6px;
  border-radius: 3px;
}

.history-duration {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  font-weight: 700;
  color: #f87171;
}

.history-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.3;
}

.history-price-line {
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.history-price-line strong {
  color: #fff;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  padding-top: 6px;
}

/* Subsystem Terminal Daemon Status Card */
.daemon-terminal-card {
  background: #0b0e10;
  border: 1px solid var(--border-main);
  border-radius: 10px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.daemon-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.daemon-title {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text-muted);
}

.daemon-live-tag {
  font-size: 0.62rem;
  font-family: var(--font-mono);
  color: var(--color-green);
  font-weight: 700;
  letter-spacing: 0.12em;
}

.daemon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

.subsystem-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  font-family: var(--font-mono);
}

.subsystem-name {
  color: var(--text-muted);
}

.subsystem-val.status-online {
  color: var(--color-green);
  font-weight: 700;
}

.subsystem-val.status-waiting {
  color: var(--color-possible);
  font-weight: 700;
}

/* Modal Dialog */
.modal,
.terminal-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  padding: 1.5rem;
}

.modal.open,
.terminal-modal.open {
  display: grid !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
}

.modal-dialog {
  position: relative;
  z-index: 1001;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8);
  animation: modal-enter 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-enter {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-main);
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  display: grid;
  place-items: center;
  transition: all 0.2s;
  z-index: 10;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.modal-content {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Modal Inner Layout */
.modal-head {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
}

.modal-img-wrap {
  width: 110px;
  height: 110px;
  background: #181d20;
  border-radius: 8px;
  padding: 0.5rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-img-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.modal-head-info {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
  line-height: 1.3;
}

/* Modal Price Comparison Matrix */
.modal-stats-matrix {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.matrix-stat {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-main);
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.matrix-label {
  font-size: 0.62rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
}

.matrix-val {
  font-size: 1.15rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #fff;
}

/* Interactive SVG Price Graph */
.chart-container {
  background: #0a0d0e;
  border: 1px solid var(--border-main);
  border-radius: 10px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  font-family: var(--font-mono);
}

.chart-title {
  color: var(--text-muted);
  font-weight: 700;
}

.chart-anomaly-callout {
  color: var(--color-extreme);
  font-weight: 700;
}

.price-svg-chart {
  width: 100%;
  height: 160px;
}

.chart-legend {
  display: flex;
  gap: 1rem;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.legend-dot.baseline { background: #64748b; }
.legend-dot.crash { background: var(--color-extreme); }

/* Anomaly Notes List */
.anomaly-notes-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-main);
  border-radius: 10px;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.notes-title {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

.notes-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-main);
}

.notes-list li {
  position: relative;
  padding-left: 1.25rem;
  line-height: 1.4;
}

.notes-list li::before {
  content: '▶';
  position: absolute;
  left: 0;
  font-size: 0.65rem;
  color: var(--color-green);
}

/* Modal Bottom CTA */
.modal-cta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  border-top: 1px solid var(--border-main);
  padding-top: 1.25rem;
}

.retailer-disclaimer {
  font-size: 0.68rem;
  color: var(--text-dim);
  line-height: 1.4;
}

/* Responsive Breakpoints */
@media (max-width: 860px) {
  .products-grid {
    grid-template-columns: 1fr;
  }
  .controls-section {
    flex-direction: column;
    align-items: stretch;
  }
  .retailer-and-search {
    flex-direction: column;
    align-items: stretch;
  }
  .terminal-search {
    width: 100%;
  }
  .terminal-search:focus {
    width: 100%;
  }
}

@media (max-width: 600px) {
  .terminal-header {
    padding: 0.75rem 1rem;
  }
  .header-right .telemetry-coord {
    display: none;
  }
  .terminal-main {
    padding: 1.5rem 1rem 4rem;
    gap: 1.5rem;
  }
  .modal-head {
    flex-direction: column;
  }
  .modal-img-wrap {
    width: 100%;
    height: 140px;
  }
  .modal-cta-row {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ===================================================================
   ADDITIONAL STYLES: Multi-Retailer, Expiry, Live Scan, Force Button
   =================================================================== */

/* text-green for status */
.text-green { color: #10b981; text-shadow: 0 0 16px rgba(16, 185, 129, 0.4); }

/* Force Scan Button in Header */
.force-scan-btn {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.1em;
  padding: 5px 11px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.force-scan-btn:hover {
  background: #ef4444;
  color: #090a0a;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.5);
}

/* Expired / Corrected Card styling */
.product-card.card-expired {
  opacity: 0.65;
  border-color: rgba(100, 116, 139, 0.3) !important;
  box-shadow: none !important;
}

.product-card.card-expired:hover {
  opacity: 0.85;
  transform: translateY(-2px);
}

.expired-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 10, 10, 0.58);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}

.expired-badge {
  background: rgba(100, 116, 139, 0.8);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  font-family: var(--font-mono);
  padding: 6px 12px;
  border-radius: 4px;
  letter-spacing: 0.1em;
}

.glitch-price.price-struck {
  text-decoration: line-through;
  color: #64748b;
}

.btn-buy.btn-expired {
  background: rgba(100, 116, 139, 0.2);
  color: #64748b;
  border: 1px solid rgba(100, 116, 139, 0.3);
}
.btn-buy.btn-expired:hover {
  background: rgba(100, 116, 139, 0.3);
  box-shadow: none;
}

/* New flash animation for just-arrived extreme errors */
@keyframes card-new-flash {
  0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  50%  { box-shadow: 0 0 0 16px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}
.product-card.card-new-flash {
  animation: card-new-flash 0.8s ease-out 2;
}

/* ===================================================================
   ADVANCED RADAR: Audio Siren, 1-Click Buy, Anomaly Flags
   =================================================================== */

.audio-toggle-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.audio-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}

.audio-toggle-btn.muted {
  opacity: 0.5;
}

/* 1-Click Instant Buy Button */
.btn-1click-buy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 8px 12px;
  border-radius: 6px;
  text-decoration: none;
  border: none;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.35);
  transition: all 0.2s;
}

.btn-1click-buy:hover {
  background: #f87171;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.6);
  transform: translateY(-1px);
}

/* Anomaly Tags & Badges */
.anomaly-tag {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  font-size: 0.65rem;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.zscore-badge {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fcd34d;
  font-size: 0.65rem;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Radar Live Progress Bar */
.radar-progress-track {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  margin: 6px 0 4px 0;
  overflow: hidden;
}

.radar-progress-bar {
  height: 100%;
  background: #10b981;
  width: 100%;
  box-shadow: 0 0 8px #10b981;
  transition: width 0.2s linear;
}

/* ===================================================================
   EXPANDED GLITCH INTELLIGENCE: Sparklines, Postcode, Price Match, Longevity
   =================================================================== */

/* Outage / Glitch Surge Banner */
.outage-surge-banner {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.25) 0%, rgba(185, 28, 28, 0.15) 100%);
  border: 1px solid rgba(239, 68, 68, 0.5);
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fca5a5;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.2);
}

.surge-pulse {
  font-size: 1.2rem;
  animation: pulse-siren 1s infinite alternate;
}

@keyframes pulse-siren {
  from { transform: scale(1); }
  to { transform: scale(1.2); }
}

/* Postcode Input Box */
.postcode-wrap {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0 8px;
}

.postcode-icon {
  font-size: 0.85rem;
  margin-right: 4px;
}

.postcode-input {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 6px 4px;
  outline: none;
  width: 130px;
  text-transform: uppercase;
}
.postcode-input::placeholder {
  color: var(--text-dim);
  text-transform: none;
}

/* Mini SVG Sparkline on Card Face */
.card-sparkline-wrap {
  margin: 6px 0 8px 0;
  height: 24px;
  width: 100%;
}
.card-sparkline-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Longevity Clock Badge */
.longevity-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-muted);
}
.longevity-badge.critical {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  animation: pulse-urgent 1.5s infinite alternate;
}
.longevity-badge.high {
  background: rgba(245, 158, 11, 0.18);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fcd34d;
}

@keyframes pulse-urgent {
  from { opacity: 0.8; }
  to { opacity: 1; filter: brightness(1.2); }
}

/* Click & Collect Badge */
.flag-pill.collect {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

/* Price Match Claim Button */
.btn-pricematch {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #93c5fd;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.btn-pricematch:hover {
  background: rgba(59, 130, 246, 0.25);
  color: #fff;
  border-color: #3b82f6;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

/* CeX Flip and Top SKU Badges */
.flag-pill.cex {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
  font-weight: 800;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.25);
}

.flag-pill.watchlist {
  background: rgba(245, 158, 11, 0.2);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fbbf24;
  font-weight: 800;
}
