:root {
  /* Tropical Theme - Based on Logo Colors */
  --tropical-primary: #00a249;
  /* Primary green from logo */
  --tropical-secondary: #1daf64;
  /* Secondary green from logo */
  --tropical-accent: #08a856;
  /* Accent green from logo */
  --tropical-light: #26b26a;
  /* Light green from logo */

  /* Background - Tropical Gradient */
  --bg-primary: #0a1f12;
  /* Dark tropical green */
  --bg-secondary: #0d2b17;
  /* Darker tropical green */
  --bg-tertiary: #051009;
  /* Very dark green */
  --bg: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-tertiary) 100%);

  /* Cards with tropical glass effect */
  --card: rgba(0, 162, 73, 0.08);
  /* Tropical green tint */
  --card-border: rgba(0, 162, 73, 0.2);
  --card-hover: rgba(0, 162, 73, 0.12);

  /* Text colors */
  --text: #f0fdf4;
  /* Very light green tint */
  --text-secondary: #bbf7d0;
  /* Light green */
  --text-muted: #86efac;
  /* Medium green */

  /* Primary colors from logo */
  --pri: var(--tropical-primary);
  /* #00a249 */
  --accent: var(--tropical-secondary);
  /* #1daf64 */
  --accent-bright: #22c55e;
  /* Bright green */

  /* Status colors with tropical theme */
  --ok: var(--tropical-light);
  /* Success green */
  --warn: #fbbf24;
  /* Warning yellow */
  --error: #f87171;
  /* Error red */

  /* Glass effects with tropical tint */
  --glass-bg: rgba(0, 162, 73, 0.15);
  --glass-border: rgba(0, 162, 73, 0.3);
  --glass-hover: rgba(29, 175, 100, 0.2);

  /* Shadows with green tint */
  --shadow-sm: 0 2px 8px rgba(0, 162, 73, 0.15);
  --shadow-md: 0 4px 16px rgba(0, 162, 73, 0.2);
  --shadow-lg: 0 8px 32px rgba(0, 162, 73, 0.25);
  --shadow-xl: 0 16px 64px rgba(0, 162, 73, 0.3);

  /* Border radius */
  --border-radius-sm: 8px;
  --border-radius-md: 12px;
  --border-radius-lg: 16px;
  --border-radius-xl: 20px;
}

* {
  box-sizing: border-box
}

/* Tropical Logo Watermark */
/* body::before {
  content: '';
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  height: 300px;
  background-image: url('tropical-logo.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.06;
  z-index: 0;
  pointer-events: none;
  filter: brightness(1.5) saturate(1.2);
} */

/* Additional tropical pattern overlay */
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(0, 162, 73, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(29, 175, 100, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(8, 168, 86, 0.06) 0%, transparent 50%);
  z-index: -2;
  pointer-events: none;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
  min-height: 100vh;
  overflow-x: hidden;
}

header {
  padding: 24px;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  background-image:
    linear-gradient(90deg, transparent, rgba(0, 162, 73, 0.05), transparent);
}

header h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--tropical-primary), var(--tropical-secondary), var(--tropical-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0, 162, 73, 0.3);
  position: relative;
}

header h1::before {
  content: '🌿';
  margin-right: 10px;
  background: none;
  -webkit-text-fill-color: var(--tropical-primary);
}

header h1 span {
  color: var(--text-secondary);
  font-weight: 500;
}

.brand img {
  height: 48px;
  width: auto;
  display: block
}

main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 16px;
  display: grid;
  gap: 16px
}

.card {
  background: var(--card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius-xl);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
  z-index: 1;
  transition: all 0.3s ease;
}

@media (min-width: 1024px) {
  .card:hover {
    /* background: var(--card-hover); */
    border-color: var(--tropical-primary);
    box-shadow: var(--shadow-xl);
    transform: translateY(-2px);
  }
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--tropical-primary), var(--tropical-secondary), var(--tropical-light));
  opacity: 0.7;
}

.card-header {
  padding: 24px 28px 16px;
  border-bottom: 1px solid var(--card-border);
  background: linear-gradient(135deg, rgba(0, 162, 73, 0.03), rgba(29, 175, 100, 0.02));
}

.card-body {
  padding: 24px 28px;
  position: relative;
}

.card h2 {
  margin: 0 0 10px 0;
  font-size: 18px
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap
}

/* Enhanced Form Elements */
input[type="text"],
input[type="number"],
input[type="file"] {
  background: rgba(15, 20, 28, 0.8);
  color: var(--text);
  border: 1px solid var(--card-border);
  padding: 12px 16px;
  border-radius: var(--border-radius-md);
  outline: none;
  min-width: 280px;
  font-size: 14px;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

input:focus {
  border-color: var(--pri);
  box-shadow: 0 0 0 3px rgba(77, 163, 255, 0.15);
  background: rgba(15, 20, 28, 0.95);
}

/* Enhanced Buttons */
button {
  background: rgba(21, 32, 51, 0.8);
  color: var(--text);
  border: 1px solid var(--card-border);
  padding: 12px 20px;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
  font-weight: 500;
  backdrop-filter: blur(10px);
  min-height: 44px;
}

button:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--pri);
  box-shadow: var(--shadow-md);
}

button.primary {
  background: linear-gradient(135deg, var(--tropical-primary), var(--tropical-secondary));
  border: none;
  color: white;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

button.primary::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

button.primary:hover::before {
  left: 100%;
}

button.primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  background: linear-gradient(135deg, var(--tropical-secondary), var(--tropical-light));
}

button.outline {
  background: transparent;
  border: 1px solid var(--card-border);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.hint {
  color: var(--text-secondary);
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.webcam video {
  width: 300px;
  border-radius: 12px;
  border: 1px solid #263247
}

.webcam canvas {
  display: none
}

.hide {
  display: none
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.card-img {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid #263247;
  background: #0f141c;
}

.card-img img {
  width: 100%;
  display: block
}

.badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, .6);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid #263247;
}

footer {
  padding: 20px;
  text-align: center;
  color: #86a0ba
}

/* Overlay loading */
/* Overlay loading */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, .65);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
}

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid #2b3952;
  border-top-color: #4da3ff;
  animation: spin 1s linear infinite;
  margin-bottom: 12px;
}

.loading-text {
  color: #c8d6ea;
  font-size: 14px;
  margin-bottom: 10px
}

.progress {
  width: min(420px, 80%);
  height: 8px;
  background: #0f141c;
  border: 1px solid #263247;
  border-radius: 999px;
  overflow: hidden
}

.progress .bar {
  height: 100%;
  background: linear-gradient(90deg, #4da3ff, #9d7bff);
}

.hide {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* (tuỳ chọn) skeleton khi đang chờ kết quả */
.skel {
  background: #0f141c;
  height: 160px;
  border-radius: 14px;
  border: 1px solid #263247;
  position: relative;
  overflow: hidden;
}

.skel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .06), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

/* ===== KẾT QUẢ ===== */
.results {
  position: relative;
}

.results .toolbar {
  position: sticky;
  /* dính phía trên khi cuộn */
  top: 8px;
  z-index: 5;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid #263247;
  background: rgba(15, 20, 28, .85);
  backdrop-filter: blur(6px);
  border-radius: 12px;
}

/* grid responsive: tự lấp đầy cột */
.results .grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* thẻ ảnh */
.card-img {
  position: relative;
  border: 1px solid #263247;
  border-radius: 14px;
  overflow: hidden;
  background: #0f141c;
  transition: transform .15s ease, box-shadow .15s ease;
}

.card-img:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}

.card-img img {
  display: block;
  width: 100%;
  aspect-ratio: 4/3;
  /* đồng nhất ô ảnh */
  object-fit: cover;
}

/* badge similarity */
.card-img .badge {
  position: absolute;
  left: 8px;
  top: 8px;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  color: #e8f0ff;
  border: 1px solid rgba(255, 255, 255, .15);
}

/* checkbox chọn ảnh (góc phải) */
.card-img .pick-wrap {
  position: absolute;
  right: 8px;
  top: 8px;
  background: rgba(0, 0, 0, .45);
  border-radius: 8px;
  padding: 4px 6px;
}

/* tên file dưới ảnh */
.card-img .file {
  display: block;
  font-size: 12px;
  color: #a9b8d4;
  padding: 8px 10px;
  border-top: 1px solid #233146;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* nút tải */
.btn-download {
  background: linear-gradient(90deg, #4da3ff, #9d7bff);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease;
}

.btn-download.secondary {
  background: linear-gradient(90deg, #00c6ff, #0072ff);
}

.btn-download:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, .35);
  opacity: .95;
}

.btn-download:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.mirror {
  transform: scaleX(-1);
}

/* ===== Responsive capture area ===== */
.card {
  max-width: 1200px;
  margin: 24px auto
}

/* Vùng webcam: 2 cột (video | panel) trên màn hình rộng, 1 cột trên mobile */
.webcam-wrap {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 12px;
  align-items: start;
}

@media (max-width: 1024px) {
  .webcam-wrap {
    grid-template-columns: 1fr 240px;
  }
}

@media (max-width: 768px) {
  .webcam-wrap {
    grid-template-columns: 1fr;
  }
}

/* Khung video co giãn đúng tỉ lệ, không bể khung */
.video-shell {
  width: 100%;
  aspect-ratio: 3 / 4;
  /* Giữ tỷ lệ dọc cho khuôn mặt */
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}

.video-shell video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform-origin: center center;
  /* phục vụ xoay/mirror */
}

/* Panel nút bấm responsive: tự chia cột theo chiều rộng */
.control-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.control-panel .row-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Nút, input dễ bấm trên mobile */
button,
input[type="file"],
input[type="number"],
input[type="text"] {
  touch-action: manipulation;
}

button {
  min-height: 40px
}

/* Thẻ cảnh báo dưới khu vực ảnh truy vấn */
#camWarning {
  white-space: pre-line
}

/* ===== Responsive Results grid: 5→1 cột theo màn hình ===== */
.results-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px
}

@media (max-width:1280px) {
  .results-grid {
    grid-template-columns: repeat(4, 1fr)
  }
}

@media (max-width:1024px) {
  .results-grid {
    grid-template-columns: repeat(3, 1fr)
  }
}

@media (max-width:768px) {
  .results-grid {
    grid-template-columns: repeat(2, 1fr)
  }
}

@media (max-width:420px) {
  .results-grid {
    grid-template-columns: 1fr
  }
}

/* Thẻ ảnh kết quả giữ tỷ lệ đồng đều */
.res-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block
}

/* ===== Streaming Search UI ===== */
.streaming-status {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 16px;
  background: var(--card);
  border: 1px solid #263247;
  border-radius: 12px;
  margin-bottom: 16px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: #0f141c;
  border: 1px solid #263247;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--pri), var(--accent));
  transition: width 0.3s ease;
  border-radius: 999px;
}

/* New result badge */
.new-badge {
  background: linear-gradient(90deg, #ff6b6b, #ff8e53);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  font-weight: 600;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

/* Streaming result animations */
.streaming-result {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.streaming-result.slide-in {
  opacity: 1;
  transform: translateY(0);
}

/* Enhanced result card styling */
.res-card {
  position: relative;
  background: var(--card);
  border: 1px solid #263247;
  border-radius: 14px;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.res-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.res-check {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  padding: 4px;
  cursor: pointer;
}

.res-num-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  background: rgba(77, 163, 255, 0.9);
  color: white;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.res-body {
  padding: 12px;
}

.res-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--text);
  display: flex;
  align-items: center;
}

.res-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.res-id {
  font-size: 11px;
  color: var(--muted);
  opacity: 0.7;
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
}