/* ============================================================
   Smart Camera Dashboard — Global Styles
   ============================================================ */

:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --secondary:     #64748b;
  --success:       #16a34a;
  --warning:       #d97706;
  --danger:        #dc2626;
  --info:          #0891b2;
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --sidebar-bg:    #0f172a;
  --sidebar-text:  #94a3b8;
  --sidebar-active:#2563eb;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --radius:        0.75rem;
  --shadow:        0 1px 3px 0 rgba(0,0,0,.1), 0 1px 2px -1px rgba(0,0,0,.1);
  --shadow-md:     0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
  --transition:    0.2s ease;
}

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

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

/* ---- Sidebar ---- */
.sidebar {
  width: 260px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.05);
}

.sidebar-brand .brand-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: #fff;
}

.sidebar-brand .brand-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: #f8fafc;
  line-height: 1.2;
}

.sidebar-brand .brand-sub {
  font-size: 0.7rem;
  color: var(--sidebar-text);
}

.sidebar-nav { flex: 1; padding: 1rem 0; }

.nav-section {
  padding: 0.5rem 1.25rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(148,163,184,.5);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  border-radius: 0;
  transition: all var(--transition);
  position: relative;
}

.nav-item:hover { background: rgba(255,255,255,.05); color: #f8fafc; }

.nav-item.active {
  background: rgba(37,99,235,.15);
  color: #93c5fd;
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.nav-item .nav-icon { width: 18px; text-align: center; font-size: 1rem; }

/* ---- Main layout ---- */
.main-wrapper {
  margin-left: 260px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.875rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.topbar-title { font-weight: 700; font-size: 1.05rem; }
.topbar-sub   { font-size: 0.78rem; color: var(--text-muted); }

.topbar-right { display: flex; align-items: center; gap: 1rem; }

.refresh-btn {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  background: var(--primary);
  color: #fff;
  border: none; border-radius: 6px;
  font-size: 0.82rem; font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}
.refresh-btn:hover { background: var(--primary-dark); }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
  display: inline-block;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ---- Page content ---- */
.page-content { padding: 1.75rem; flex: 1; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

.card-title { font-weight: 600; font-size: 0.9rem; }
.card-body  { padding: 1.25rem; }

/* ---- Stat cards ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem;
  transition: box-shadow var(--transition);
}

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

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.stat-icon.blue   { background: #dbeafe; color: var(--primary); }
.stat-icon.green  { background: #dcfce7; color: var(--success); }
.stat-icon.yellow { background: #fef9c3; color: var(--warning); }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon.cyan   { background: #cffafe; color: var(--info); }

.stat-label { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.2rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-sub   { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ---- Charts grid ---- */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.charts-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

/* ---- Table ---- */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  background: #f8fafc;
  padding: 0.7rem 1rem;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

/* ---- Badges ---- */
.badge {
  display: inline-flex; align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-success   { background: #dcfce7; color: #15803d; }
.badge-warning   { background: #fef9c3; color: #92400e; }
.badge-danger    { background: #fee2e2; color: #b91c1c; }
.badge-info      { background: #cffafe; color: #155e75; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-primary   { background: #dbeafe; color: #1d4ed8; }

/* ---- Filters bar ---- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.filter-group { display: flex; flex-direction: column; gap: 0.25rem; }
.filter-group label { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); }

.filter-input, .filter-select {
  height: 36px;
  padding: 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color var(--transition);
  min-width: 140px;
}

.filter-input:focus, .filter-select:focus { border-color: var(--primary); }

.filter-btn {
  height: 36px;
  padding: 0 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.filter-btn-primary { background: var(--primary); color: #fff; }
.filter-btn-primary:hover { background: var(--primary-dark); }

.filter-btn-secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.filter-btn-secondary:hover { background: var(--border); }

/* ---- Pagination ---- */
.pagination-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.pagination { display: flex; gap: 0.25rem; align-items: center; }

.page-btn {
  min-width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text);
  transition: all var(--transition);
  padding: 0 0.5rem;
}

.page-btn:hover:not(:disabled) { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Thumbnail ---- */
.thumb {
  width: 64px; height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.thumb-placeholder {
  width: 64px; height: 48px;
  border-radius: 6px;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 1.2rem;
  border: 1px solid var(--border);
}

/* ---- Loading spinner ---- */
.spinner-overlay {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.8);
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  z-index: 10;
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ---- Empty state ---- */
.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state .empty-title { font-weight: 600; margin-bottom: 0.25rem; }
.empty-state .empty-sub { font-size: 0.82rem; }

/* ---- Detection detail ---- */
.img-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.img-frame {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.img-frame img {
  width: 100%;
  height: auto;
  display: block;
}

.img-label {
  padding: 0.5rem 0.75rem;
  background: #f8fafc;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.objects-list { list-style: none; }

.object-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.object-item:last-child { border-bottom: none; }

.conf-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.conf-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.5s ease;
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .charts-grid { grid-template-columns: 1fr; }
  .charts-grid-3 { grid-template-columns: 1fr 1fr; }
  .img-compare { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .charts-grid-3 { grid-template-columns: 1fr; }
}
