:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --ink: #0f172a;
  --ink-muted: #475569;
  --ink-soft: #94a3b8;
  --accent: #0284c7;
  --accent-soft: #e0f2fe;
  --accent-ink: #0369a1;
  --ok: #059669;
  --ok-soft: #d1fae5;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --err: #dc2626;
  --err-soft: #fee2e2;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 20px 45px -12px rgba(15, 23, 42, 0.22);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.market-tag {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

.topbar-price {
  display: flex;
  align-items: center;
  gap: 14px;
}

.price-block {
  text-align: right;
}

.price-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.price-value {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.sync-time {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-ghost:hover {
  background: var(--bg);
  color: var(--ink);
  border-color: var(--ink-soft);
}

.dashboard {
  max-width: 1240px;
  margin: 20px auto;
  padding: 0 20px 32px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.rig-panel {
  padding: 18px;
}

.rig-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.rig-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.status-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.status-pill.err {
  background: var(--err-soft);
  color: var(--err);
}

.status-pill-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.status-pill.has-issues {
  cursor: help;
}

.issues-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 310px;
  max-width: min(310px, 85vw);
  background: var(--ink);
  color: #f8fafc;
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: var(--shadow-lg);
  z-index: 30;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  pointer-events: none;
}

.status-pill-wrap:hover .issues-tooltip.active,
.status-pill-wrap:focus-within .issues-tooltip.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.issues-tooltip-list {
  margin: 0;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  line-height: 1.4;
}

.issues-tooltip-list li.err {
  color: #fca5a5;
}

.issues-tooltip-list li.warn {
  color: #fcd34d;
}

.rig-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.rig-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.hotspot {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  z-index: 5;
}

.dot-ring {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface);
  border: 2.5px solid var(--accent);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.hotspot:hover .dot-ring,
.hotspot.active .dot-ring {
  transform: scale(1.12);
}

.dot-core {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.hotspot.selected .dot-ring {
  border-color: var(--ok);
  background: var(--ok);
}

.hotspot.selected .dot-core {
  background: transparent;
  width: 12px;
  height: 12px;
}

.hotspot.selected .dot-core::after {
  content: '';
  display: block;
  width: 5px;
  height: 9px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(2px, -1px);
}

.hotspot.skipped-ok .dot-ring {
  border-style: dashed;
  border-color: var(--ink-soft);
  background: var(--surface-subtle);
}

.hotspot.skipped-ok .dot-core {
  background: var(--ink-soft);
  width: 6px;
  height: 6px;
}

.hotspot.has-error .dot-ring {
  border-color: var(--err);
  background: var(--err-soft);
}

.hotspot.has-error .dot-core {
  background: var(--err);
}

.hotspot.has-warn .dot-ring {
  border-color: var(--warn);
  background: var(--warn-soft);
}

.hotspot.has-warn .dot-core {
  background: var(--warn);
}

.dot-warn-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.dot-warn-badge.err {
  background: var(--err);
}

.dot-warn-badge.warn {
  background: var(--warn);
}

.dot-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.dot-sub {
  font-weight: 600;
  color: var(--ok);
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}

.summary-panel {
  padding: 18px;
}

.summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.summary-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.wattage-readout {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.parts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.part-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.part-row:hover {
  border-color: var(--accent);
  background: var(--surface-subtle);
}

.part-row.has-error {
  border-color: #fecaca;
  background: #fffafa;
}

.part-row.has-warn {
  border-color: #fde68a;
  background: #fffdf5;
}

.part-meta {
  min-width: 0;
}

.part-cat {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
}

.part-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.part-name.empty {
  color: var(--ink-soft);
  font-weight: 500;
}

.part-warning {
  margin-top: 4px;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 5px;
}

.part-warning.err {
  background: var(--err-soft);
  color: var(--err);
}

.part-warning.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.part-warning.info {
  background: var(--bg);
  color: var(--ink-muted);
}

.part-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.part-price {
  font-size: 13.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.price-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.price-source {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.row-skip-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.row-skip-btn:hover {
  border-color: var(--ink-soft);
  color: var(--ink);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 88vh;
}

.modal-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-skip {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 7px;
  cursor: pointer;
}

.btn-skip:hover {
  color: var(--ink);
  border-color: var(--ink-soft);
}

.btn-close {
  background: none;
  border: none;
  color: var(--ink-muted);
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 6px;
}

.btn-close:hover {
  background: var(--bg);
  color: var(--ink);
}

.ram-bars-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
}

.ram-bars-bar.visible {
  display: flex;
}

.ram-bars-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
}

.ram-bars-options {
  display: flex;
  gap: 6px;
}

.bar-pill {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 7px;
  cursor: pointer;
}

.bar-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.tab-btn.active {
  color: var(--accent-ink);
  border-bottom-color: var(--accent);
  background: var(--surface);
}

.modal-body {
  padding: 16px 18px 20px;
  overflow-y: auto;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.autocomplete-wrap {
  position: relative;
}

.text-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.dropdown-list {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
}

.dropdown-item {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background: var(--surface-subtle);
}

.dropdown-item.selected-item {
  background: var(--accent-soft);
}

.item-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.item-sub {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.item-price {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.compat-tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  background: var(--warn-soft);
  color: var(--warn);
}

.need-row {
  display: flex;
  gap: 8px;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 9px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--accent-ink);
}

.ai-result {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 10px;
  display: none;
}

.ai-result.visible {
  display: block;
}

.ai-result-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.ai-result-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.ai-result-price {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}

.ai-result-reason {
  margin: 5px 0 10px;
  font-size: 12.5px;
  color: var(--ink-muted);
}

@media (max-width: 900px) {
  .dashboard {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .topbar-inner {
    flex-direction: column;
    align-items: flex-start;
  }
  .topbar-price {
    width: 100%;
    justify-content: space-between;
  }
  .price-block {
    text-align: left;
  }
  .dot-label {
    font-size: 10px;
    padding: 1px 5px;
  }
}
