/* ====== CarScan - Shared Styles ====== */

:root {
  --primary: #667eea;
  --primary-dark: #4c51bf;
  --secondary: #764ba2;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --text: #2d3748;
  --text-light: #718096;
  --text-muted: #a0aec0;
  --border: #e2e8f0;
  --bg-light: #f7fafc;
  --white: #fff;
  --success: #48bb78;
  --warning: #f6ad55;
  --error: #e53e3e;
  --radius: 12px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

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

body {
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg-gradient);
  min-height: 100vh;
  padding: 20px 15px;
  color: var(--text);
}

.container {
  max-width: 900px;
  margin: 0 auto;
  background: var(--white);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ====== Header + Nav ====== */
header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, #6b46c1 100%);
  color: #fff;
  padding: 24px 30px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 15px;
}

header h1 { font-size: 24px; }
header .subtitle { opacity: 0.85; font-size: 13px; margin-top: 4px; }

nav { display: flex; gap: 8px; flex-wrap: wrap; }

nav a {
  color: #fff;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  transition: background 0.2s;
  opacity: 0.85;
}
nav a:hover { background: rgba(255,255,255,0.15); opacity: 1; }
nav a.active { background: rgba(255,255,255,0.25); opacity: 1; font-weight: bold; }

.content { padding: 30px; }

/* ====== Buttons ====== */
.btn {
  display: inline-block;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  text-decoration: none;
  text-align: center;
}

.btn-primary { background: var(--bg-gradient); color: #fff; }
.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(102, 126, 234, 0.5);
}

.btn-secondary {
  background: var(--bg-light);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: #edf2f7; }

.btn-danger { background: #fed7d7; color: #822727; }
.btn-danger:hover:not(:disabled) { background: #feb2b2; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { display: block; width: 100%; }

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.btn-row .btn { flex: 1; min-width: 140px; }

/* ====== Upload Zone ====== */
.upload-zone {
  border: 3px dashed #cbd5e0;
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  background: var(--bg-light);
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: #ebf4ff;
}
.upload-zone.has-image {
  padding: 10px;
  border-style: solid;
  border-color: var(--primary);
}
.upload-zone .icon { font-size: 48px; margin-bottom: 10px; }
.upload-zone .text { color: var(--text); font-size: 15px; }
.upload-zone .hint { color: var(--text-muted); font-size: 12px; margin-top: 6px; }

input[type="file"] { display: none; }

/* ====== Preview with BBox ====== */
.preview-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}
.preview-wrap img {
  max-width: 100%;
  max-height: 400px;
  border-radius: 10px;
  display: block;
}
.preview-wrap canvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  border-radius: 10px;
}

/* ====== Progress Bar ====== */
.progress {
  display: none;
  margin-top: 20px;
  background: var(--bg-light);
  border-radius: 8px;
  height: 32px;
  overflow: hidden;
  position: relative;
}
.progress.active { display: block; }
.progress-bar {
  height: 100%;
  background: var(--bg-gradient);
  width: 0%;
  transition: width 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: bold;
}

/* ====== Loading Spinner ====== */
.loading { display: none; text-align: center; padding: 20px; }
.loading.active { display: block; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ====== Results ====== */
.results { display: none; margin-top: 30px; }
.results.active { display: block; }

.results h2 {
  font-size: 20px;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 15px;
}

.summary-card {
  background: #fef5e7;
  border-right: 4px solid var(--warning);
  padding: 12px;
  border-radius: 8px;
}
.summary-card .name { font-size: 14px; font-weight: bold; }
.summary-card .count { font-size: 22px; color: #dd6b20; }

.clean-message {
  background: #c6f6d5;
  border-right: 4px solid var(--success);
  padding: 20px;
  border-radius: 10px;
  text-align: center;
  color: #22543d;
}

.detection-list {
  margin-top: 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.detection-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-light);
  border-radius: 8px;
  border-right: 4px solid var(--primary);
  font-size: 14px;
}
.detection-item .badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: bold;
  color: #fff;
}

/* ====== Error / Meta ====== */
.error {
  display: none;
  background: #fed7d7;
  color: #822727;
  padding: 15px;
  border-radius: var(--radius);
  border-right: 4px solid var(--error);
  margin-top: 15px;
}
.error.active { display: block; }

.meta {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 15px;
  text-align: center;
}

/* ====== History ====== */
.history-list { display: flex; flex-direction: column; gap: 15px; }

.history-item {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 15px;
  padding: 12px;
  background: var(--bg-light);
  border-radius: var(--radius);
  align-items: center;
  transition: box-shadow 0.2s;
}
.history-item:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }

.history-thumb {
  width: 100px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  background: #cbd5e0;
}

.history-info .count { font-weight: bold; margin-bottom: 4px; }
.history-info .date { font-size: 12px; color: var(--text-light); }
.history-info .summary-line {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 4px;
}

.history-actions { display: flex; gap: 6px; }
.btn-icon { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

/* ====== Pagination ====== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin-top: 20px;
}
.pagination .page-info { font-size: 14px; color: var(--text-light); }

/* ====== Stats ====== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 15px;
  margin-bottom: 30px;
}
.stat-card {
  background: var(--bg-light);
  padding: 20px;
  border-radius: var(--radius);
  border-top: 4px solid var(--primary);
  text-align: center;
}
.stat-card .value {
  font-size: 32px;
  font-weight: bold;
  color: var(--primary-dark);
}
.stat-card .label {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 6px;
}

.chart { display: flex; flex-direction: column; gap: 12px; }

.chart-row {
  display: grid;
  grid-template-columns: 120px 1fr 40px;
  gap: 12px;
  align-items: center;
}
.chart-row .chart-label { font-size: 14px; }
.chart-row .chart-bar-wrap {
  background: var(--bg-light);
  border-radius: 6px;
  height: 24px;
  overflow: hidden;
}
.chart-row .chart-bar {
  height: 100%;
  background: var(--bg-gradient);
  border-radius: 6px;
  transition: width 0.5s;
}
.chart-row .chart-value {
  font-weight: bold;
  font-size: 14px;
  text-align: center;
}

/* ====== Empty state ====== */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}
.empty .icon { font-size: 48px; margin-bottom: 10px; }

/* ====== Responsive ====== */
@media (max-width: 600px) {
  .header-top { flex-direction: column; align-items: stretch; }
  nav { justify-content: center; }
  .history-item { grid-template-columns: 80px 1fr; }
  .history-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .chart-row { grid-template-columns: 80px 1fr 40px; }
}

/* ====== Modal ====== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  padding: 20px;
  overflow-y: auto;
  align-items: flex-start;
  justify-content: center;
}
.modal.active { display: flex; }

.modal-content {
  background: #fff;
  border-radius: var(--radius);
  max-width: 700px;
  width: 100%;
  margin: 40px auto;
  overflow: hidden;
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-light);
}
.modal-header h3 { font-size: 18px; }

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px 10px;
  border-radius: 6px;
  transition: background 0.2s;
}
.modal-close:hover { background: #e2e8f0; }

.modal-body { padding: 22px; }

/* ====== Camera Section ====== */
.camera-section {
  margin-top: 20px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 2px solid var(--border);
}

.camera-section video {
  width: 100%;
  max-height: 420px;
  display: block;
  background: #000;
}

.camera-section .btn-row {
  margin: 12px;
}