/* ===========================
   RESET & BASE
=========================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card2: #21253a;
  --border: #2e3352;
  --border-hover: #4a5180;
  --text: #e8eaf6;
  --text-muted: #8892b0;
  --blue: #4f8ef7;
  --blue-light: #6ba3ff;
  --orange: #f7914f;
  --green: #4caf79;
  --red: #f75050;
  --yellow: #f7c84f;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

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

/* ===========================
   HEADER
=========================== */
.header {
  background: linear-gradient(135deg, #0d1b4e 0%, #1a1d27 100%);
  border-bottom: 1px solid var(--border);
  padding: 28px 0 22px;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  text-align: center;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--blue-light);
  margin-bottom: 6px;
}
.logo-icon { font-size: 1.4rem; }
.logo-ai {
  background: linear-gradient(90deg, var(--blue), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.header-sub { color: var(--text-muted); font-size: 0.95rem; }

/* ===========================
   MAIN
=========================== */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 36px 24px 60px;
}

/* ===========================
   UPLOAD SECTION
=========================== */
.upload-section {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 20px;
  align-items: center;
}

.upload-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.card-label h3 { font-size: 1rem; font-weight: 700; }

.badge {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 6px;
}
.badge-blue  { background: rgba(79,142,247,0.18); color: var(--blue-light); border: 1px solid rgba(79,142,247,0.3); }
.badge-orange { background: rgba(247,145,79,0.18); color: var(--orange); border: 1px solid rgba(247,145,79,0.3); }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--blue);
  background: rgba(79,142,247,0.06);
}
.drop-icon { font-size: 2.4rem; margin-bottom: 10px; }
.drop-primary { font-size: 0.9rem; color: var(--text); }
.drop-primary .link { color: var(--blue-light); text-decoration: underline; }
.drop-secondary { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

.img-preview {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  line-height: 0;
}
.img-preview img {
  width: 100%;
  height: 260px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}
.remove-btn {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 28px; height: 28px;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.remove-btn:hover { background: var(--red); }

.vs-badge {
  width: 48px; height: 48px;
  background: var(--bg-card2);
  border: 2px solid var(--border);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ===========================
   ACTION
=========================== */
.action-row {
  display: flex;
  justify-content: center;
  margin: 28px 0;
}
.compare-btn {
  background: linear-gradient(135deg, #2563eb, #4f8ef7);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 36px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  transition: all 0.2s;
  box-shadow: 0 4px 18px rgba(79,142,247,0.35);
}
.compare-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(79,142,247,0.5);
}
.compare-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-icon { font-size: 1.1rem; }

/* ===========================
   LOADING
=========================== */
.loading-state {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
}
.loader-ring {
  width: 48px; height: 48px;
  border: 4px solid rgba(79,142,247,0.2);
  border-top-color: var(--blue);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===========================
   RESULTS
=========================== */
.results { animation: fadeUp 0.4s ease; }
@keyframes fadeUp {
  from { opacity:0; transform:translateY(16px); }
  to   { opacity:1; transform:translateY(0); }
}

/* Summary banner */
.summary-banner {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 22px;
  border-radius: var(--radius);
  margin-bottom: 28px;
  border: 1px solid;
}
.summary-banner.pass {
  background: rgba(76,175,121,0.1);
  border-color: rgba(76,175,121,0.3);
}
.summary-banner.fail {
  background: rgba(247,80,80,0.1);
  border-color: rgba(247,80,80,0.35);
}
.summary-icon { font-size: 2rem; flex-shrink: 0; line-height: 1; }
.summary-text { font-size: 0.95rem; color: var(--text); margin-bottom: 6px; }
.issue-count {
  font-size: 0.82rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  display: inline-block;
}
.issue-count.count-pass { background: rgba(76,175,121,0.2); color: var(--green); }
.issue-count.count-fail { background: rgba(247,80,80,0.2); color: var(--red); }

/* Comparison grid */
.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}
.img-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-label {
  background: var(--bg-card2);
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.marked-badge {
  font-size: 0.7rem;
  font-weight: 700;
  background: rgba(247,145,79,0.2);
  color: var(--orange);
  border: 1px solid rgba(247,145,79,0.3);
  padding: 2px 8px;
  border-radius: 20px;
}
.img-panel img {
  width: 100%;
  display: block;
  max-height: 420px;
  object-fit: contain;
  background: #0a0c14;
}

/* Annotation layer */
.annotation-wrap {
  position: relative;
  line-height: 0;
}
#annotation-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.annotation-tag {
  position: absolute;
  transform: translateY(-100%);
  max-width: 180px;
  padding: 4px 8px 4px 6px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.3;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  white-space: normal;
  word-break: break-word;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
  pointer-events: auto;
  cursor: default;
  z-index: 10;
}
.annotation-tag::after {
  content: '';
  position: absolute;
  bottom: -6px; left: 10px;
  border: 6px solid transparent;
  border-top-width: 6px;
  border-bottom: 0;
}
/* severity colours */
.tag-cao {
  background: rgba(247,80,80,0.92);
  color: #fff;
  border: 1px solid rgba(255,100,100,0.5);
}
.tag-cao::after { border-top-color: rgba(247,80,80,0.92); }

.tag-trung-binh {
  background: rgba(247,145,79,0.92);
  color: #fff;
  border: 1px solid rgba(247,145,79,0.5);
}
.tag-trung-binh::after { border-top-color: rgba(247,145,79,0.92); }

.tag-thap {
  background: rgba(247,200,79,0.92);
  color: #1a1a1a;
  border: 1px solid rgba(247,200,79,0.5);
}
.tag-thap::after { border-top-color: rgba(247,200,79,0.92); }

.annotation-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #fff;
  flex-shrink: 0;
  margin-top: 3px;
}

/* Issue list */
.issue-list-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}
.issue-list-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.issue-list { display: flex; flex-direction: column; gap: 12px; }

.issue-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  background: var(--bg-card2);
  border-radius: 10px;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}
.issue-item:hover { border-color: var(--border-hover); }

.issue-number {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  flex-shrink: 0;
}
.num-cao      { background: rgba(247,80,80,0.2);   color: var(--red); }
.num-trung-binh { background: rgba(247,145,79,0.2); color: var(--orange); }
.num-thap     { background: rgba(247,200,79,0.2);  color: var(--yellow); }

.issue-content {}
.issue-object { font-weight: 700; font-size: 0.92rem; margin-bottom: 3px; }
.issue-desc   { font-size: 0.83rem; color: var(--text-muted); }
.issue-location { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; font-style: italic; }

.severity-pill {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.pill-cao       { background: rgba(247,80,80,0.2);   color: var(--red);    border: 1px solid rgba(247,80,80,0.3); }
.pill-trung-binh { background: rgba(247,145,79,0.2); color: var(--orange); border: 1px solid rgba(247,145,79,0.3); }
.pill-thap      { background: rgba(247,200,79,0.2);  color: var(--yellow); border: 1px solid rgba(247,200,79,0.3); }

/* ===========================
   FOOTER
=========================== */
.footer {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

/* ===========================
   RESPONSIVE
=========================== */
@media (max-width: 768px) {
  .upload-section {
    grid-template-columns: 1fr;
  }
  .vs-badge { margin: 0 auto; }
  .comparison-grid { grid-template-columns: 1fr; }
  .header-title { font-size: 1.5rem; }
}
