:root {
  --bg-dark: #ffffff;
  --bg-panel: #f8fafc;
  /* Sidebar, headers - very light gray */
  --bg-card: #ffffff;
  /* Cards */
  --bg-card-hover: #f1f5f9;
  --border-color: #e2e8f0;
  --text-primary: #0f172a;
  /* Slate 900 */
  --text-secondary: #64748b;
  /* Slate 500 */
  --accent-color: #ec4899;
  /* Pinkish red */
  --accent-hover: #db2777;
  --accent-blue: #0ea5e9;
  --status-open: #f97316;
  --status-close: #22c55e;
  --sidebar-width: 250px;
  /* Grid tile minimum width (used for zooming) */
  --tile-min: 180px;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Layout */
#app {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
}

.nav-item {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  text-decoration: none;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.nav-item:hover,
.nav-item.active {
  background-color: #e2e8f0;
  /* Darker hover for light mode */
  color: var(--text-primary);
  border-left: 3px solid var(--accent-color);
}

.nav-item i {
  width: 20px;
  text-align: center;
}

.nav-group {
  margin-top: 5px;
}

.nav-group-title {
  padding: 5px 16px;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.top-bar {
  height: 60px;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 20px;
  justify-content: space-between;
  flex-shrink: 0;
}

.view-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  overflow-x: auto;
}

/* UI Elements */
button {
  cursor: pointer;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: background 0.2s;
}

.btn:hover {
  background: var(--bg-card-hover);
}

.btn-primary {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.8rem;
}

input,
select {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(236, 72, 153, 0.2);
}

/* Table Styles */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-weight: 600;
  background-color: var(--bg-panel);
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
}

.data-table tr:hover td {
  background-color: var(--bg-card-hover);
}

.badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge.open {
  background: #ffedd5;
  color: var(--status-open);
  border: 1px solid #fed7aa;
}

.badge.close {
  background: #dcfce7;
  color: var(--status-close);
  border: 1px solid #bbf7d0;
}

.badge.blue {
  background: #dbeafe;
  color: #2563eb;
  border: 1px solid #bfdbfe;
}

/* Grid Styles -> Wrapped responsive grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min), 1fr));
  gap: 12px;
  width: 100%;
}

/* Row mode: one camera/hour per row with horizontal scroller */
.row-mode .image-grid {
  display: flex;
  overflow-x: auto;
  gap: 12px;
  width: 100%;
  padding-bottom: 8px;
  scrollbar-width: thin;
}

.row-mode .image-grid::-webkit-scrollbar {
  height: 8px;
}

.row-mode .image-grid::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 4px;
}

.image-card {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.image-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  border-color: var(--accent-color);
}

.image-wrapper {
  aspect-ratio: 16/9;
  background: #0b0d10;
  /* darker for better contain visuals */
  /* Light gray usually better than black for placeholders in light mode */
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card-meta {
  padding: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  text-align: center;
}

/* Camera section heading inside view */
.view-container h3 {
  margin: 12px 0 8px;
  font-size: 1rem;
  color: var(--text-primary);
}

/* Subtle separator between camera sections */
.view-container .card+h3 {
  border-top: 1px dashed var(--border-color);
  padding-top: 12px;
}

/* Timeline */
.timeline-slider {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
  position: relative;
  overflow-x: auto;
  gap: 8px;
}

.timeline-slider .tick {
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  flex: 0 0 auto;
  white-space: nowrap;
}

.timeline-slider .tick.active {
  background: #e2e8f0;
  color: var(--text-primary);
}

.timeline-track {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--border-color);
  z-index: 0;
}

.timeline-point {
  z-index: 1;
  background: var(--bg-panel);
  padding: 0 4px;
  cursor: pointer;
}

.timeline-point.active {
  color: var(--accent-color);
  font-weight: bold;
}

/* Utilities */
.flex {
  display: flex;
}

.gap-2 {
  gap: 8px;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.p-4 {
  padding: 16px;
}

.mb-4 {
  margin-bottom: 16px;
}

.mr-2 {
  margin-right: 8px;
}

.mt-2 {
  margin-top: 8px;
}

.w-full {
  width: 100%;
}

.text-sm {
  font-size: 0.875rem;
}

.text-2xl {
  font-size: 1.5rem;
}

.font-bold {
  font-weight: 700;
}

.text-secondary {
  color: var(--text-secondary);
}

.text-red-500 {
  color: #ef4444;
}

.text-orange-500 {
  color: #f97316;
}

.text-green-500 {
  color: #22c55e;
}

/* Detail View */
.detail-view {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  height: calc(100vh - 100px);
}

.detail-main {
  background: #000;
  /* Images usually look best on black regardless of theme */
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.detail-main img {
  max-width: 100%;
  max-height: 100%;
}

.detail-sidebar {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

/* Compare view */
.compare-root {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.compare-header {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 12px;
}

.compare-filters {
  display: grid;
  grid-template-columns: 220px 1fr 1fr 140px;
  gap: 10px;
  align-items: end;
}

.compare-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.compare-field>span {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.compare-header input,
.compare-header select {
  width: 100%;
  height: 36px;
  padding: 6px 10px;
  font-size: 0.88rem;
}

.compare-header .btn {
  height: 36px;
  padding: 6px 12px;
  white-space: nowrap;
}

.compare-layout {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) 320px;
  gap: 16px;
  height: calc(100vh - 120px);
}

.compare-stage {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.compare-card {
  height: 100%;
}

.compare-card .image-wrapper {
  aspect-ratio: 16/10;
  min-height: 280px;
}

.compare-card .p-4 {
  padding: 12px;
}

.compare-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

@media (max-width: 1100px) {
  .compare-filters {
    grid-template-columns: 1fr 1fr;
  }

  .compare-filters>.btn {
    grid-column: span 2;
  }

  .compare-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .compare-panel {
    max-height: 420px;
  }

  .compare-card .image-wrapper {
    min-height: 240px;
  }
}

@media (max-width: 640px) {
  .compare-card .image-wrapper {
    aspect-ratio: 4/3;
    min-height: 200px;
  }
}

.compare-panel .panel-title {
  font-weight: 700;
  color: var(--accent-color);
  font-size: 0.95rem;
}

.compare-panel .panel-section {
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

.ticket-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ticket-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
}

.ticket-item .ticket-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.ticket-item .ticket-desc {
  font-size: 0.85rem;
  color: var(--text-primary);
  line-height: 1.25rem;
}

.ticket-item .ticket-meta {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.ba-slider {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 8px;
}

.ba-slider img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.ba-after {
  clip-path: inset(0 0 0 50%);
}

.ba-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  left: 50%;
  background: var(--accent-color);
}

.ba-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 2px solid var(--accent-color);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.range-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.range-row input[type="range"] {
  width: 100%;
}

.textarea {
  min-height: 90px;
  resize: vertical;
}

.hour-matrix {
  display: grid;
  grid-auto-rows: auto;
  gap: 8px;
  min-width: 1200px;
}

.hour-matrix-header,
.hour-matrix-row {
  display: grid;
  grid-template-columns: 220px repeat(24, minmax(74px, 1fr));
  gap: 6px;
  align-items: stretch;
}

.hour-matrix-header {
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  padding: 8px 0;
  z-index: 3;
  border-bottom: 1px solid var(--border-color);
}

.hour-left-header,
.hour-col-header {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  text-align: center;
}

.hour-left-header {
  text-align: left;
}

.hour-left {
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
}

.hour-cell {
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 90px;
  position: relative;
  transition: all 0.2s ease;
  cursor: pointer;
}

.hour-cell:hover {
  background: var(--bg-card-hover);
  border-color: #cbd5e1;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.hour-thumb {
  width: 100%;
  height: 54px;
  border-radius: 6px;
  background: #000;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.hour-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.hour-cell:hover .hour-thumb img {
  transform: scale(1.05);
}

.hour-meta {
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.hour-badge {
  margin-top: 6px;
  font-size: 0.70rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-secondary);
}

.hour-badge.dark {
  background: rgba(15, 23, 42, 0.08);
  color: #0f172a;
}

.hour-badge.bright {
  background: rgba(234, 179, 8, 0.18);
  color: #854d0e;
}

.hour-badge.normal {
  background: rgba(34, 197, 94, 0.14);
  color: #166534;
}

.hour-yolo-badge {
  margin-top: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: rgba(59, 130, 246, 0.10);
  color: #1d4ed8;
  line-height: 1.05rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Hourly Gallery Modal Styles */
.hourly-gallery-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.gallery-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 16px 20px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.95));
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.gallery-header h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.gallery-header p {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.close-gallery {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.close-gallery:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.hourly-left-list {
  max-height: 70vh;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hourly-left-list>div {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.hourly-left-list>div:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-color);
}

.hourly-left-list>div.active {
  background: #eff6ff;
  border-color: #3b82f6;
}

.hourly-preview {
  position: relative;
  height: 70vh;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  overflow: hidden;
}

/* Improved button styles for gallery */
.btn-roi-draw,
.btn-roi-toggle,
.btn-roi-clear,
.btn-open-new {
  background: #1e293b;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-roi-draw:hover,
.btn-roi-toggle:hover,
.btn-roi-clear:hover,
.btn-open-new:hover {
  background: #334155;
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.btn-roi-draw:active,
.btn-roi-toggle:active,
.btn-roi-clear:active,
.btn-open-new:active {
  transform: translateY(0);
}

.ticket-submit {
  width: 100%;
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ticket-submit:hover {
  background: #2563eb;
  transform: translateY(-1px);
}

.ticket-submit:active {
  transform: translateY(0);
}

.dashboard-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.dashboard-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 12px;
}

.dash-kpi-big {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dash-kpi-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dash-kpi-title {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}

.dash-kpi-muted {
  font-weight: 600;
  color: #ef4444;
  margin-left: 8px;
}

.dash-kpi-value {
  font-size: 32px;
  line-height: 1;
  font-weight: 800;
  color: var(--text-primary);
}

.dash-kpi-sub {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-secondary);
}

.dash-kpi-divider {
  height: 1px;
  background: var(--border-color);
}

.dash-kpi-blue {
  color: #2563eb;
}

.dash-kpi-purple {
  color: #7c3aed;
}

.dash-kpi-orange {
  color: #f97316;
}

.dash-kpi-yellow {
  color: #eab308;
}

.dash-kpi-green {
  color: #22c55e;
}

.dash-kpi-row {
  display: flex;
  gap: 18px;
  margin-top: 10px;
}

.dash-kpi-mini-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

.dash-kpi-mini-val {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
}

.dash-chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.dash-chart-title {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 700;
}

.dash-chart-layout {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px;
  align-items: start;
}

.dash-chart-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 6px;
}

.dash-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.dash-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.dash-inline-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.dash-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dash-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
}

.dash-dot.orange {
  background: #f97316;
}

.dash-dot.blue {
  background: #2563eb;
}

.dash-dot.green {
  background: #22c55e;
}

@media (max-width: 920px) {
  .dash-chart-layout {
    grid-template-columns: 1fr;
  }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1000;
}

.modal {
  width: min(900px, 100%);
  max-height: 90vh;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-panel);
}

.modal-body {
  padding: 14px 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.modal-field input,
.modal-field select,
.modal-field textarea {
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
}

.modal-field textarea {
  resize: vertical;
}

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