/* ==========================================================================
   EPITA Smart Classroom - Modern SaaS & Tech Dashboard Theme
   ========================================================================== */

:root {
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  
  --accent-cyan: #06b6d4;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --border: #e2e8f0;
  --border-focus: #818cf8;
  
  --ok: #10b981;
  --ok-bg: #ecfdf5;
  --ok-border: #a7f3d0;
  
  --warn: #f59e0b;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  
  --err: #ef4444;
  --err-bg: #fef2f2;
  
  --na: #64748b;
  --na-bg: #f1f5f9;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

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

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header & Top Navigation ---------- */
.top-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  color: #ffffff;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-md);
}

.header-container {
  max-width: 1350px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent-cyan) 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.brand-text h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-text p {
  font-size: 0.85rem;
  color: #94a3b8;
}

.header-badges {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge.ok {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.badge.wait {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.badge.err {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

/* ---------- Main Cockpit Layout ---------- */
.cockpit-container {
  max-width: 1350px;
  margin: 1.5rem auto;
  padding: 0 1.25rem 3rem;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.5rem;
}

@media (max-width: 1024px) {
  .cockpit-container {
    grid-template-columns: 1fr;
  }
}

/* ---------- Cards & Panels ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--bg-subtle);
}

.card-title h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-badge {
  font-size: 0.75rem;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
}

/* ---------- Engine Picker (Radio Pills) ---------- */
.engine-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
}

.engine-header {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-bottom: 0.5rem;
}

.engine-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

@media (max-width: 600px) {
  .engine-options {
    grid-template-columns: 1fr;
  }
}

.engine-option {
  position: relative;
  border: 1.5px solid var(--border);
  background: #ffffff;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: all 0.2s ease;
}

.engine-option:hover {
  border-color: var(--primary);
  background: #fafafa;
}

.engine-option input[type="radio"]:checked + .engine-info b {
  color: var(--primary);
}

.engine-option:has(input[type="radio"]:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
}

.engine-info b {
  display: block;
  font-size: 0.88rem;
  color: var(--text-main);
}

.engine-info span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Gemini Key Config */
.gemini-config {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
}

.gemini-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.gemini-row input {
  flex: 1;
  min-width: 220px;
  padding: 0.45rem 0.75rem;
  border: 1px solid #93c5fd;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.88rem;
  background: #ffffff;
}

.gemini-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.link-hint {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  font-size: 0.82rem;
  white-space: nowrap;
}

.link-hint:hover {
  text-decoration: underline;
}

.hint-small {
  font-size: 0.76rem;
  color: #1e40af;
  margin-top: 0.4rem;
}

/* ---------- Buttons & Action Bar ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

button, .file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  background: var(--primary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

button:hover:not(:disabled), .file-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

button:active:not(:disabled), .file-btn:active {
  transform: translateY(0);
}

button.secondary, .file-btn.secondary {
  background: #ffffff;
  color: var(--text-main);
  border: 1px solid var(--border);
}

button.secondary:hover:not(:disabled), .file-btn.secondary:hover {
  background: var(--bg-subtle);
  border-color: #cbd5e1;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* ---------- Video & Results Views ---------- */
.views-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

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

.view-card {
  background: #0f172a;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
}

.view-card-header {
  background: #1e293b;
  color: #e2e8f0;
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
}

video {
  width: 100%;
  aspect-ratio: 16/9;
  background: #020617;
  object-fit: contain;
  display: block;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #020617;
  overflow: hidden;
}

.canvas-wrapper canvas {
  width: 100%;
  height: 100%;
  aspect-ratio: 16/9;
  background: #020617;
  object-fit: contain;
  display: block;
}

.analysis-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  color: #ffffff;
  z-index: 10;
  animation: fadeIn 0.2s ease-out;
}

.analysis-overlay[hidden] {
  display: none !important;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #6366f1;
  border-right-color: #06b6d4;
  border-radius: 50%;
  animation: spinOverlay 0.8s linear infinite;
}

.overlay-text {
  text-align: center;
  background: rgba(30, 41, 59, 0.88);
  padding: 0.55rem 1.25rem;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

.overlay-text b {
  display: block;
  font-size: 0.92rem;
  color: #ffffff;
  letter-spacing: 0.01em;
}

.overlay-text span {
  display: block;
  font-size: 0.75rem;
  color: #94a3b8;
  margin-top: 0.15rem;
}

@keyframes spinOverlay {
  to { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

/* ---------- Sliders ---------- */
.slider-box {
  background: var(--bg-subtle);
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  margin-top: 1rem;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.45rem;
}

.slider-label b {
  color: var(--primary);
  font-size: 0.95rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.msg {
  min-height: 1.5rem;
  color: var(--err);
  font-size: 0.85rem;
  font-weight: 500;
  margin: 0.4rem 0;
}

/* ---------- KPI Grid (Right Column) ---------- */
.kpis-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
}

.kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
}

.kpi-card.ok::before { background: var(--ok); }
.kpi-card.warn::before { background: var(--warn); }
.kpi-card.na::before { background: var(--na); }

.kpi-val {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  margin-bottom: 0.2rem;
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ---------- Modern Interactive Audit Table ---------- */
.audit-table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #ffffff;
  margin-bottom: 1.25rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  text-align: left;
}

th {
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
}

td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: #f8fafc;
}

/* Input Target Numbers with stepper feel */
td input[type="number"] {
  width: 4.2rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-main);
  text-align: center;
  background: #ffffff;
}

td input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* Status Chips */
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-chip.ok {
  background: var(--ok-bg);
  color: #065f46;
  border: 1px solid var(--ok-border);
}

.status-chip.warn {
  background: var(--warn-bg);
  color: #92400e;
  border: 1px solid var(--warn-border);
}

.status-chip.na {
  background: var(--na-bg);
  color: var(--na);
  border: 1px solid var(--border);
}

/* Gap badge */
.gap-badge {
  font-weight: 700;
  font-size: 0.85rem;
}
.gap-badge.positive { color: #d97706; }
.gap-badge.negative { color: #dc2626; }
.gap-badge.zero { color: #059669; }

/* ---------- Detections Stream (Tags) ---------- */
.detections-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.detection-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
}

.detection-count {
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: 9999px;
}

.detection-conf {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ---------- Report Drawer & Footer ---------- */
.report-box {
  background: #0f172a;
  color: #cbd5e1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  padding: 1.25rem;
  border-radius: var(--radius-md);
  max-height: 380px;
  overflow-y: auto;
  white-space: pre-wrap;
  border: 1px solid #1e293b;
  margin-top: 0.85rem;
}

/* ---------- Multi-Views Filmstrip (Plusieurs images pour 1 audit) ---------- */
.views-strip-container {
  margin-top: 1rem;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  border: 1px solid var(--border);
}

.views-strip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.65rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.views-strip-header .meta-info {
  color: var(--primary);
  font-weight: 600;
}

.views-strip-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.views-strip {
  display: flex;
  gap: 0.65rem;
  overflow-x: auto;
  padding-bottom: 0.4rem;
  min-height: 80px;
  align-items: center;
}

.views-strip:empty::after {
  content: "Aucun angle capturé pour le moment. Prenez une photo ou importez des fichiers.";
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  padding: 0.5rem 0;
}

.view-thumb {
  position: relative;
  flex: 0 0 105px;
  height: 65px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2.5px solid var(--border);
  cursor: pointer;
  background: #020617;
  transition: all 0.18s ease;
}

.view-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.view-thumb.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.25);
}

.view-thumb:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.view-thumb-badge {
  position: absolute;
  bottom: 2px;
  left: 3px;
  background: rgba(15, 23, 42, 0.88);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
}

.view-thumb-count {
  position: absolute;
  top: 2px;
  right: 3px;
  background: var(--primary);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.05rem 0.35rem;
  border-radius: 9999px;
}

.view-thumb-del {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  background: rgba(239, 68, 68, 0.95);
  color: #fff;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: bold;
  border: none;
  cursor: pointer;
  z-index: 5;
}

.view-thumb:hover .view-thumb-del {
  display: flex;
}

/* ---------- Historique des Audits ---------- */
.history-section {
  max-width: 1350px;
  margin: 0 auto 3rem;
  padding: 0 1.25rem;
}

.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  box-shadow: var(--shadow-sm);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--bg-subtle);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.history-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-sm {
  padding: 0.38rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
}

.btn-danger {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.btn-danger:hover:not(:disabled) {
  background: #fee2e2;
  color: #b91c1c;
}

.empty-history {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.empty-history span {
  display: block;
  font-size: 2.2rem;
  margin-bottom: 0.5rem;
  opacity: 0.6;
}

/* ---------- Anomalies d'Agencement (Chaises renversées, sur table...) ---------- */
.anomalies-card {
  border-left: 4px solid var(--err);
}

.anomalies-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
}

.anomaly-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  color: #991b1b;
  animation: fadeIn 0.2s ease;
}

.anomaly-desc {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
}

.anomaly-tag {
  background: #ef4444;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.12rem 0.45rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.anomaly-angle {
  font-size: 0.75rem;
  color: #7f1d1d;
  background: #fee2e2;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-weight: 600;
}

footer {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 2rem 1rem;
  border-top: 1px solid var(--border);
  background: #ffffff;
}
