:root {
  --bg: #0d0f14;
  --surface: #161b25;
  --surface2: #1e2635;
  --border: #2a3348;
  --accent: #6c63ff;
  --accent2: #00d4aa;
  --pt-color: #6c63ff;
  --onnx-color: #f7a800;
  --text: #e2e8f0;
  --muted: #8892a4;
  --danger: #ff6b6b;
  --success: #4caf82;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────── */
header {
  background: linear-gradient(135deg, #0d0f14 0%, #1a1030 50%, #0d1420 100%);
  border-bottom: 1px solid var(--border);
  padding: 2rem 1.5rem 1.5rem;
  text-align: center;
}
.header-inner { max-width: 900px; margin: 0 auto; }
.logo { display: flex; align-items: center; justify-content: center; gap: .6rem; margin-bottom: .5rem; }
.logo-text { font-size: 2rem; font-weight: 800; letter-spacing: -.5px; }
.accent { color: var(--accent); }
.tagline { color: var(--muted); font-size: .95rem; }

/* ── Main ────────────────────────────────────────────────────── */
main { flex: 1; max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; width: 100%; }

/* ── Upload ──────────────────────────────────────────────────── */
.upload-section { display: flex; flex-direction: column; align-items: center; gap: 1.2rem; }

.upload-zone {
  width: 100%; max-width: 640px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: var(--surface);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(108,99,255,.06);
}
.upload-icon { font-size: 3rem; margin-bottom: .8rem; }
.upload-title { font-size: 1.1rem; font-weight: 500; margin-bottom: .4rem; }
.upload-sub { color: var(--muted); font-size: .85rem; }
.link { color: var(--accent); text-decoration: underline; cursor: pointer; }

.preview-wrap { position: relative; max-width: 640px; width: 100%; }
.preview-wrap img { width: 100%; border-radius: var(--radius); border: 1px solid var(--border); display: block; }
.btn-clear {
  position: absolute; top: .6rem; right: .6rem;
  background: rgba(0,0,0,.7); color: #fff; border: none;
  padding: .3rem .7rem; border-radius: 999px; cursor: pointer;
  font-size: .8rem; backdrop-filter: blur(4px);
}
.btn-clear:hover { background: var(--danger); }

.mode-tabs { display: flex; gap: .5rem; }
.tab {
  padding: .55rem 1.2rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; font-size: .9rem;
  transition: all .15s;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tab:hover:not(.active) { border-color: var(--accent); color: var(--text); }

.btn-run {
  padding: .8rem 2.8rem; background: var(--accent); color: #fff;
  border: none; border-radius: 999px; font-size: 1rem; font-weight: 600;
  cursor: pointer; transition: opacity .15s, transform .1s;
  box-shadow: 0 4px 16px rgba(108,99,255,.4);
}
.btn-run:hover:not(:disabled) { opacity: .9; transform: translateY(-1px); }
.btn-run:disabled { opacity: .4; cursor: not-allowed; }

/* ── Loading ─────────────────────────────────────────────────── */
.loading { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 3rem; }
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

/* ── Error ───────────────────────────────────────────────────── */
.error-box {
  background: rgba(255,107,107,.1); border: 1px solid var(--danger);
  color: var(--danger); border-radius: var(--radius-sm);
  padding: 1rem 1.5rem; max-width: 640px; margin: 0 auto; width: 100%;
}

/* ── Results ─────────────────────────────────────────────────── */
.results { margin-top: 2.5rem; }
.results-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 768px) { .results-grid { grid-template-columns: 1fr; } }

.result-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.result-card.full-width { max-width: 760px; margin: 0 auto; }

.card-header {
  display: flex; align-items: center; gap: .75rem;
  padding: .9rem 1.2rem; border-bottom: 1px solid var(--border);
}
.card-header.pytorch { background: rgba(108,99,255,.1); }
.card-header.onnx    { background: rgba(247,168,0,.08); }

.badge {
  font-size: .75rem; font-weight: 700; letter-spacing: .08em;
  padding: .25rem .65rem; border-radius: 999px; text-transform: uppercase;
}
.card-header.pytorch .badge { background: var(--pt-color); color: #fff; }
.card-header.onnx    .badge { background: var(--onnx-color); color: #000; }
#singleHeader .badge { background: var(--accent); color: #fff; }

.det-count { color: var(--muted); font-size: .85rem; }

.result-img { width: 100%; display: block; }

.det-table-wrap { overflow-x: auto; padding: .5rem; }
.det-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.det-table th { text-align: left; padding: .5rem .75rem; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); }
.det-table td { padding: .45rem .75rem; border-bottom: 1px solid rgba(255,255,255,.04); }
.det-table tr:last-child td { border-bottom: none; }
.conf-bar {
  display: inline-flex; align-items: center; gap: .5rem; white-space: nowrap;
}
.conf-track { width: 60px; height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.conf-fill { height: 100%; border-radius: 3px; background: var(--accent2); }

/* ── IoU Panel ───────────────────────────────────────────────── */
.iou-panel {
  margin-top: 1.5rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem;
}
.iou-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 1.2rem; }
.iou-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
@media (max-width: 600px) { .iou-summary { grid-template-columns: repeat(2,1fr); } }
.iou-stat {
  background: var(--surface2); border-radius: var(--radius-sm);
  padding: 1rem; text-align: center;
}
.iou-label { display: block; font-size: .75rem; color: var(--muted); margin-bottom: .4rem; }
.iou-value { font-size: 1.5rem; font-weight: 700; color: var(--accent2); }

.iou-bars { display: flex; flex-direction: column; gap: .75rem; }
.iou-row { display: grid; grid-template-columns: 130px 1fr 55px; align-items: center; gap: .75rem; }
.iou-row-label { font-size: .82rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iou-track { height: 10px; background: var(--border); border-radius: 5px; overflow: hidden; }
.iou-fill { height: 100%; border-radius: 5px; transition: width .5s ease; }
.iou-fill.match   { background: var(--success); }
.iou-fill.nomatch { background: var(--danger); }
.iou-row-val { font-size: .82rem; font-weight: 600; text-align: right; }

/* ── Footer ──────────────────────────────────────────────────── */
footer {
  text-align: center; padding: 1.5rem;
  color: var(--muted); font-size: .8rem;
  border-top: 1px solid var(--border);
}

.hidden { display: none !important; }
