/* ========================================
   Camera Popup - MapLibre Popup Style
   ======================================== */

/* Override MapLibre popup defaults */
.maplibregl-popup.camera-popup {
  max-width: none !important;
}

.maplibregl-popup.camera-popup .maplibregl-popup-content {
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.maplibregl-popup.camera-popup .maplibregl-popup-tip {
  border-top-color: #fafafa;
}

/* Popup Content */
.camera-popup-content {
  background: #fff;
}

/* Popup Header */
.camera-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #fafafa;
  border-bottom: 1px solid #eee;
}

.camera-popup-title {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.camera-popup-title .camera-id {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
}

.camera-popup-title .camera-time {
  font-size: 11px;
  color: #888;
}

/* Header Buttons */
.camera-popup-buttons {
  display: flex;
  gap: 6px;
}

.cam-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 5px;
  background: #f0f0f0;
  color: #555;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.cam-btn:hover {
  background: #e0e0e0;
  color: #333;
}

.cam-btn.settings-btn:hover {
  background: #e0e0e0;
  color: #1a1a1a;
}

.cam-btn.record-btn {
  color: #d44;
}

.cam-btn.record-btn:hover {
  background: #ffe5e5;
}

.cam-btn.record-btn.recording {
  background: #d44;
  color: #fff;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.cam-btn.close-btn:hover {
  background: #ffe5e5;
  color: #d44;
}

/* MJPEG Button */
.cam-btn.mjpeg-btn {
  color: #48a;
}

.cam-btn.mjpeg-btn:hover {
  background: #e5f0f5;
  color: #369;
}

.cam-btn.mjpeg-btn.active {
  background: #48a;
  color: #fff;
  animation: pulse 2s infinite;
}

.cam-btn.mjpeg-btn.active:hover {
  background: #369;
}

/* Popup Body */
.camera-popup-body {
  padding: 0;
}

/* Frame Container - Default 320x180 (16:9) with zoom support */
.camera-frame-container {
  width: 320px;
  height: 180px;
  background: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Zoom Levels */
.camera-frame-container.zoom-0 {
  width: 320px;
  height: 180px;
}

.camera-frame-container.zoom-1 {
  width: 640px;
  height: 360px;
}

.camera-frame-container.zoom-2 {
  width: 1280px;
  height: 720px;
}

/* Loading State */
.camera-frame-container .camera-loading,
.camera-frame-container .camera-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #888;
  font-size: 13px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s;
}

.camera-frame-container.loading .camera-loading {
  opacity: 1;
  visibility: visible;
}

.camera-frame-container.error .camera-error {
  opacity: 1;
  visibility: visible;
  color: #e55;
}

/* Spinner - dark background (popup) */
.camera-frame-container .spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Spinner - light background (settings) */
.settings-loading .spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(0,0,0,0.1);
  border-top-color: #333;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Frame Image */
.camera-frame-container .camera-frame {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  transition: opacity 0.2s ease;
}

.camera-frame-container.loaded .camera-frame {
  display: block;
}

/* Zoom Button Styles */
.cam-btn.zoom-btn {
  background: #e8f0ff;
  color: #3366cc;
}

.cam-btn.zoom-btn:hover {
  background: #d0e0ff;
  color: #2255bb;
}

.cam-btn.zoom-btn[data-zoom="1"] {
  background: #d0e0ff;
}

.cam-btn.zoom-btn[data-zoom="2"] {
  background: #3366cc;
  color: #fff;
}

.cam-btn.zoom-btn[data-zoom="2"]:hover {
  background: #2255bb;
}

/* ========================================
   Settings Drawer
   ======================================== */

.settings-drawer {
  position: fixed;
  inset: 0;
  z-index: 6000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.settings-drawer.active {
  opacity: 1;
  visibility: visible;
}

.settings-drawer .settings-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.settings-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 380px;
  max-width: 100%;
  height: 100%;
  background: #fff;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.settings-drawer.active .settings-panel {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
}

.settings-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #1a1a1a;
}

.settings-header .close-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 24px;
  color: #888;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-header .close-btn:hover {
  background: #f0f0f0;
  color: #333;
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.settings-loading,
.settings-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #888;
  gap: 12px;
}

.settings-error {
  color: #d44;
}

.settings-footer {
  padding: 16px 20px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Settings Form */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.settings-section h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
}

.settings-form .form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-form .form-group label {
  font-size: 14px;
  color: #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-form .form-group label .val {
  font-weight: 600;
  color: #333;
  font-size: 13px;
}

.settings-form .form-group.checkbox {
  flex-direction: row;
}

.settings-form .form-group.checkbox label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.settings-form input[type="range"] {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: #e0e0e0;
  appearance: none;
}

.settings-form input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #333;
  cursor: pointer;
}

.settings-form select,
.settings-form input[type="number"] {
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}

.settings-form select:focus,
.settings-form input[type="number"]:focus {
  outline: none;
  border-color: #333;
}

.settings-form input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #333;
}

/* Buttons */
.btn-primary,
.btn-secondary {
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: #333;
  color: #fff;
}

.btn-primary:hover {
  background: #1a1a1a;
}

.btn-primary:disabled {
  background: #aaa;
  cursor: not-allowed;
}

.btn-secondary {
  background: #f0f0f0;
  color: #333;
}

.btn-secondary:hover {
  background: #e0e0e0;
}

/* ========================================
   Responsive
   ======================================== */

/* Zoom level 2 max constraints */
.camera-frame-container.zoom-2 {
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 120px);
}

@media (max-width: 1400px) {
  .camera-frame-container.zoom-2 {
    width: 960px;
    height: 540px;
  }
}

@media (max-width: 1000px) {
  .camera-frame-container.zoom-2 {
    width: 640px;
    height: 360px;
  }
}

/* Mobile: smaller camera popups */
@media (max-width: 768px) {
  .camera-frame-container {
    width: 216px;
    height: 122px;
  }

  .camera-frame-container.zoom-0 {
    width: 216px;
    height: 122px;
  }

  .camera-frame-container.zoom-1 {
    width: 432px;
    height: 243px;
  }

  .camera-frame-container.zoom-2 {
    width: 648px;
    height: 365px;
  }

  .camera-popup-header {
    padding: 3px 6px;
  }

  .camera-popup-title .camera-id {
    font-size: 10px;
  }

  .camera-popup-title .camera-time {
    font-size: 9px;
  }

  .cam-btn {
    width: 20px;
    height: 20px;
  }

  .cam-btn svg {
    width: 12px;
    height: 12px;
  }

  .camera-popup-buttons {
    gap: 3px;
  }
}

@media (max-width: 700px) {
  /* Mobil: Varsayılan küçük, tıklayınca büyük */
  .camera-frame-container {
    width: 280px;
    height: 158px;
  }

  .camera-frame-container.zoom-0 {
    width: 280px;
    height: 158px;
  }

  .camera-frame-container.zoom-1 {
    width: 100vw;
    max-width: 100vw;
    height: auto;
    aspect-ratio: 16/9;
  }

  .camera-frame-container.zoom-2 {
    width: 100vw;
    max-width: 100vw;
    height: auto;
    aspect-ratio: 16/9;
  }

  .settings-panel {
    width: 100%;
  }
}

/* ========================================
   AI Detection Panel
   ======================================== */

/* AI button - same style as other buttons */
.cam-btn.ai-btn {
  font-weight: 900;
  font-size: 10px;
  color: #555;
}

.cam-btn.ai-btn:hover {
  color: #333;
}

/* AI Vision Panel - Matrix/Terminal Style */
.ai-panel {
  background: rgba(10, 10, 10, 0.90);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 255, 0, 0.2);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 255, 0, 0.1), 0 0 20px rgba(0, 0, 0, 0.5);
  width: 400px;
  opacity: 0;
  transform: translateX(-10px) scale(0.95);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.ai-panel.active {
  opacity: 1;
  transform: translateX(0) scale(1);
}

/* AI Panel Header */
.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(10, 26, 10, 0.5);
  border-bottom: 1px solid rgba(0, 255, 0, 0.15);
  border-radius: 8px 8px 0 0;
}

.ai-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  font-family: 'Consolas', 'Monaco', 'Lucida Console', monospace;
  letter-spacing: 1px;
}

.ai-panel-header .ai-panel-close {
  background: transparent;
  border: none;
  color: #666;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.2s;
}

.ai-panel-header .ai-panel-close:hover {
  color: #aaa;
}

/* Terminal Container - 16:9 ratio */
.ai-terminal {
  background: rgba(5, 5, 5, 0.5);
  border-radius: 0 0 8px 8px;
  padding: 12px;
  font-family: 'Consolas', 'Monaco', 'Lucida Console', monospace;
  height: 225px;
  display: flex;
  flex-direction: column;
}

/* Terminal Output - fixed height with scroll */
.ai-terminal-output {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 8px;
  font-size: 11px;
  line-height: 1.5;
  padding-right: 6px;
  height: 170px;
}

.terminal-line {
  color: #0f0;
  text-shadow: 0 0 5px #0f0;
  margin-bottom: 4px;
  word-wrap: break-word;
}

.terminal-line.system {
  color: #0ff;
  text-shadow: 0 0 5px #0ff;
}

.terminal-line.error {
  color: #f55;
  text-shadow: 0 0 5px #f00;
}

/* Terminal Input */
.ai-terminal-input-line {
  display: flex;
  align-items: center;
  gap: 6px;
  border-top: 1px solid #0f02;
  padding-top: 8px;
}

.ai-terminal-prompt {
  color: #0f0;
  font-weight: bold;
  text-shadow: 0 0 5px #0f0;
}

.ai-terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #0f0;
  font-family: 'Consolas', 'Monaco', 'Lucida Console', monospace;
  font-size: 12px;
  outline: none;
  caret-color: #0f0;
  text-shadow: 0 0 3px #0f0;
}

.ai-terminal-input::placeholder {
  color: #0f04;
  text-shadow: none;
}

/* Terminal Scrollbar - Matrix style */
.ai-terminal-output::-webkit-scrollbar {
  width: 4px;
}

.ai-terminal-output::-webkit-scrollbar-track {
  background: #111;
}

.ai-terminal-output::-webkit-scrollbar-thumb {
  background: #0f03;
  border-radius: 2px;
}

.ai-terminal-output::-webkit-scrollbar-thumb:hover {
  background: #0f05;
}

/* ========================================
   AI Alarm Popup
   ======================================== */

.ai-alarm {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 360px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(220, 53, 69, 0.4);
  border: 2px solid #dc3545;
  z-index: 10000;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
}

.ai-alarm.active {
  opacity: 1;
  transform: translateX(0);
  animation: alarm-pulse 1s infinite;
}

@keyframes alarm-pulse {
  0%, 100% { box-shadow: 0 8px 32px rgba(220, 53, 69, 0.4); }
  50% { box-shadow: 0 8px 48px rgba(220, 53, 69, 0.7); }
}

.ai-alarm-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #dc3545;
  color: #fff;
  border-radius: 10px 10px 0 0;
}

.ai-alarm-icon {
  font-size: 24px;
  animation: shake 0.5s infinite;
}

@keyframes shake {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

.ai-alarm-title {
  flex: 1;
  font-weight: 700;
  font-size: 16px;
}

.ai-alarm-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  opacity: 0.8;
}

.ai-alarm-close:hover {
  opacity: 1;
}

.ai-alarm-body {
  padding: 16px;
}

.ai-alarm-type {
  font-size: 14px;
  font-weight: 600;
  color: #dc3545;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.ai-alarm-desc {
  font-size: 15px;
  color: #333;
  margin-bottom: 8px;
  line-height: 1.4;
}

.ai-alarm-action {
  font-size: 13px;
  color: #666;
  padding: 8px 12px;
  background: #f8f9fa;
  border-radius: 6px;
  margin-bottom: 12px;
}

.ai-alarm-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #999;
}

/* Mobile: Smaller alarm popup */
@media (max-width: 768px) {
  .ai-alarm {
    width: 300px;
    right: 10px;
    top: 10px;
  }

  .ai-alarm-header {
    padding: 10px 12px;
  }

  .ai-alarm-icon {
    font-size: 20px;
  }

  .ai-alarm-title {
    font-size: 14px;
  }

  .ai-alarm-body {
    padding: 12px;
  }

  .ai-alarm-desc {
    font-size: 13px;
  }

  /* AI Panel mobile - daha geniş */
  .ai-panel {
    width: calc(100vw - 20px);
    max-width: 360px;
  }

  .ai-panel-title {
    font-size: 11px;
  }

  .ai-terminal {
    height: 200px;
    padding: 10px;
  }

  .ai-terminal-output {
    font-size: 10px;
  }

  .ai-terminal-input {
    font-size: 11px;
  }
}
