/* === Variables === */
:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22253a;
  --border: #2a2d3e;
  --text: #e4e4e7;
  --text-muted: #8b8d9e;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

/* === Reset === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent-hover); }

/* === Overlay === */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.95);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s;
}
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.overlay-content {
  text-align: center;
  max-width: 420px;
  padding: 2rem;
}
.logo-large {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
}
.overlay-subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 1.1rem;
}
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 3px;
  transition: width 0.3s;
}
.progress-text {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.privacy-note-small {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 1.5rem;
  opacity: 0.7;
}

/* === Image preview overlay === */
.preview-overlay {
  position: fixed;
  z-index: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  width: 320px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95);
  transition: opacity 0.15s, transform 0.15s;
}
.preview-overlay.visible {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}
.preview-overlay img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}
.preview-info {
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.preview-info span:first-child {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--danger);
}
.preview-info span:last-child {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* === Header === */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.header-left {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}
header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}
.tagline {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.status {
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-weight: 500;
}
.status.offline {
  color: var(--text-muted);
  background: var(--surface-hover);
}
.status.loading {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
}
.status.active {
  color: var(--success);
  background: var(--success-bg);
}
.status.paused {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
}

/* === Main layout === */
main {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 0;
  min-height: calc(100vh - 64px - 400px);
}

/* === Panels === */
.panel {
  padding: 1.25rem;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  max-height: calc(100vh - 64px);
}
.panel-right {
  border-right: none;
  border-left: 1px solid var(--border);
}
.panel h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.panel-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Behavior list */
#behavior-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
#behavior-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: default;
}
#behavior-list li .behavior-text {
  flex: 1;
}
#behavior-list li .remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 4px;
  opacity: 0;
  transition: opacity 0.2s;
}
#behavior-list li:hover .remove-btn {
  opacity: 1;
}
#behavior-list li .remove-btn:hover {
  color: var(--danger);
}
#behavior-list li .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
#behavior-list li .status-dot.detecting {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

/* Add behavior */
.add-behavior {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.add-behavior input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.add-behavior input:focus {
  border-color: var(--accent);
}
.add-behavior button {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.add-behavior button:hover {
  background: var(--accent-hover);
}

/* Sensitivity */
.sensitivity-control {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.sensitivity-control label {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.sensitivity-control input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.sensitivity-control span {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
}

/* === Camera === */
.camera-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
}
.camera-container {
  position: relative;
  width: 100%;
  max-width: 720px;
  aspect-ratio: 4 / 3;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--border);
}
.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
}
.camera-placeholder p {
  color: var(--text-muted);
}
.camera-placeholder .small {
  font-size: 0.8rem;
  opacity: 0.6;
}
.camera-placeholder.hidden {
  display: none;
}
.alert-flash {
  position: absolute;
  inset: 0;
  border: 4px solid var(--danger);
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.alert-flash.active {
  opacity: 1;
  animation: flash 0.6s ease-in-out 3;
}
@keyframes flash {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}
.camera-controls {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* Buttons */
.btn-primary {
  padding: 0.6rem 1.5rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  padding: 0.6rem 1.5rem;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--border); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
  padding: 0.5rem 0;
  transition: color 0.2s;
}
.btn-text:hover { color: var(--danger); }

/* === Catch list (compact text rows) === */
.catch-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
}
.empty-state {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 2rem 1rem;
  line-height: 1.7;
}
.catch-count {
  font-size: 0.8rem;
  background: var(--danger-bg);
  color: var(--danger);
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-weight: 600;
}
.catch-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--danger);
  cursor: pointer;
  transition: background 0.15s;
  animation: slideIn 0.25s ease;
}
.catch-item:hover {
  background: var(--border);
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.catch-item-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.catch-item-behavior {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--danger);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.catch-item-confidence {
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.7;
  flex-shrink: 0;
}

/* === Ad section (above footer, always visible) === */
.ad-section {
  padding: 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.ad-container {
  max-width: 728px;
  width: 100%;
  text-align: center;
}
.ad-container ins {
  min-height: 90px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-note {
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.5;
  margin-top: 0.35rem;
}

/* === Footer === */
footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.privacy-section {
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 2rem 2rem;
  text-align: center;
}
.privacy-section h3 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}
.privacy-main {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}
.privacy-proofs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  text-align: left;
}
.proof {
  background: var(--bg);
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.proof h4 {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}
.proof p {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.footer-bottom {
  text-align: center;
  padding: 1rem 2rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* === Responsive === */
@media (max-width: 1024px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
  }
  .panel-right {
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .camera-container {
    max-width: 100%;
  }
  .preview-overlay {
    /* On narrow screens, center the preview */
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%);
  }
  .preview-overlay.visible {
    transform: translateX(-50%) scale(1);
  }
}

@media (max-width: 600px) {
  header {
    padding: 0.75rem 1rem;
  }
  .header-left {
    flex-direction: column;
    gap: 0.15rem;
  }
  header h1 {
    font-size: 1.2rem;
  }
  .panel {
    padding: 1rem;
  }
  .privacy-proofs {
    grid-template-columns: 1fr;
  }
  .preview-overlay {
    width: 280px;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
