/* Wildfire Monitoring System – Web UI */
:root {
  --bg-dark: #1e2633;
  --bg-panel: #2c3647;
  --fg-light: #e0e6ed;
  --fg-accent: #7dd3fc;
  --green-live: #22c55e;
  --red-alert: #ef4444;
  --font: "DejaVu Sans", "Liberation Sans", Ubuntu, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--fg-light);
  min-height: 100vh;
}

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: var(--bg-panel);
  padding: 2rem 2.5rem;
  border-radius: 12px;
  min-width: 320px;
}
.login-box h1 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
  text-align: center;
}
.login-subtitle {
  margin: 0 0 1.5rem;
  text-align: center;
  color: var(--fg-accent);
  font-size: 0.9rem;
}
.login-form label {
  display: block;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}
.login-form input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border: 1px solid #4a5568;
  border-radius: 6px;
  background: var(--bg-dark);
  color: var(--fg-light);
}
.login-form button {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.6rem;
  font-size: 1rem;
  font-weight: bold;
  background: var(--fg-accent);
  color: var(--bg-dark);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.login-form button:hover { opacity: 0.9; }
.error { color: var(--red-alert); margin-top: 0.75rem; font-size: 0.9rem; }
.hidden { display: none !important; }

/* Main layout */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  background: var(--bg-dark);
  border-bottom: 1px solid #374151;
}
.app-title {
  font-size: 1rem;
  font-weight: bold;
  margin: 0;
}
.app-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.camera-id { font-size: 0.9rem; font-weight: bold; }
.live-badge {
  background: var(--green-live);
  color: white;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: bold;
}

.main-container {
  display: flex;
  height: calc(100vh - 48px);
  overflow: hidden;
}
.video-column {
  flex: 1;
  min-width: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-column > img,
.video-column > .video-placeholder {
  flex: 1;
  align-self: stretch;
  object-fit: contain;
}
.video-column img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.video-placeholder {
  color: #666;
  text-align: center;
  padding: 2rem;
}

/* Function buttons under video (blue, white text) */
.video-column {
  position: relative;
  flex-direction: column;
}
.function-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: stretch;
  align-items: stretch;
  gap: 10px;
  padding: 14px;
  background: var(--bg-dark);
  border-top: 1px solid #374151;
}
.func-btn {
  flex: 1;
  min-width: 120px;
  background: var(--bg-panel);
  color: var(--fg-light);
  border: 1px solid #374151;
  padding: 12px 18px;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
}
.func-btn:hover {
  background: #374151;
  color: var(--fg-accent);
}
.modal-btn.btn-file {
  background: var(--bg-panel);
  color: var(--fg-accent);
  padding: 6px 12px;
  margin-right: 8px;
}
.modal-btn.btn-file:hover { background: #374151; }
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-dark);
  overflow-y: auto;
  padding: 12px;
}

.panel {
  background: var(--bg-panel);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}
.panel-title {
  font-size: 0.75rem;
  font-weight: bold;
  margin-bottom: 8px;
  color: var(--fg-light);
}
.panel-row {
  font-size: 0.85rem;
  margin-bottom: 4px;
}
.panel-label { color: var(--fg-accent); }
.panel-value { color: var(--fg-light); }
/* Alert Status: white text; green = NORMAL, red = ACTIVE (flashing when within 3 min) */
.alert-status {
  font-size: 0.9rem;
  font-weight: bold;
  padding: 8px 12px;
  color: #fff;
  border-radius: 4px;
}
.alert-normal { background-color: var(--green-live); }
.alert-active { background-color: var(--red-alert); }
.alert-active-flash { background-color: var(--red-alert); }
.alert-active-flash-off { background-color: #1a1a1a; }

/* ACTION TAKEN panel (matches FireClient: border and title color by status) */
.action-taken-panel {
  border: 2px solid transparent;
  border-radius: 4px;
}
.action-taken-normal { border-color: var(--green-live); }
.action-taken-normal .action-taken-title { color: var(--green-live); }
.action-taken-active { border-color: var(--red-alert); }
.action-taken-active .action-taken-title { color: var(--red-alert); }
.action-taken-text { font-size: 0.85rem; margin-top: 4px; }

.confidence-bar-wrap {
  height: 24px;
  background: #1a202c;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 4px;
}
.confidence-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--green-live), var(--red-alert));
  width: 0%;
  transition: width 0.2s;
}

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.controls select, .controls input {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #4a5568;
  background: var(--bg-panel);
  color: var(--fg-light);
  font-size: 0.85rem;
}
.controls button {
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
}
.btn-connect { background: var(--green-live); color: #fff; }
.btn-disconnect { background: #6b7280; color: #fff; }
.btn-disconnect:hover { background: #4b5563; }
.controls button:disabled { opacity: 0.6; cursor: not-allowed; }

/* Menu bar */
.menubar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 0;
  border-bottom: 1px solid #374151;
  margin-bottom: 8px;
}
.menubar button, .menubar a {
  padding: 4px 10px;
  font-size: 0.8rem;
  background: transparent;
  color: var(--fg-accent);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.menubar button:hover, .menubar a:hover {
  background: var(--bg-panel);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--bg-panel);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
}
.modal h2 { margin-top: 0; font-size: 1.1rem; }
.modal-actions { margin-top: 1rem; display: flex; gap: 8px; }
.modal-actions button {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
}
.modal-actions .btn-primary { background: var(--fg-accent); color: var(--bg-dark); }
.modal-map { min-width: 480px; }
#mapContainer { width: 100%; height: 400px; margin: 10px 0; border-radius: 8px; background: #1a202c; }
.modal-configure { min-width: 520px; }
.config-instruction { font-size: 0.9rem; color: var(--fg-accent); margin: 0 0 8px; }
.config-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 8px; }
.config-toolbar select { padding: 6px 10px; border-radius: 6px; border: 1px solid #4a5568; background: var(--bg-dark); color: var(--fg-light); }
.config-status { font-size: 0.85rem; margin: 0 0 8px; min-height: 1.4em; }
#configMapContainer { width: 100%; height: 400px; margin: 10px 0; border-radius: 8px; background: #1a202c; }
.device-list { list-style: none; padding: 0; margin: 0; }
.device-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #374151;
}
.device-list li span { flex: 1; }
.device-list button { margin-left: 8px; padding: 4px 8px; font-size: 0.8rem; }
.device-list li.selected { background: var(--bg-panel); }
.add-device-row { display: flex; gap: 8px; margin-top: 12px; }
.add-device-row input { flex: 1; padding: 6px; border-radius: 4px; border: 1px solid #4a5568; background: var(--bg-dark); color: var(--fg-light); }
.device-manager-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.stats-controls { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.stats-controls label { font-size: 0.9rem; }
.stats-input, .stats-select { padding: 4px 8px; border-radius: 4px; border: 1px solid #4a5568; background: var(--bg-dark); color: var(--fg-light); max-width: 280px; }
.stats-select[multiple] { min-height: 100px; }
.stats-chart-wrap { width: 100%; height: 320px; margin: 10px 0; position: relative; }
.stats-chart-wrap canvas { max-width: 100%; max-height: 100%; }
.modal-statistics { min-width: 520px; }
.modal-devices { min-width: 400px; }

/* Logout */
.logout-btn {
  background: transparent;
  color: var(--fg-accent);
  border: 1px solid var(--fg-accent);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
.logout-btn:hover { background: var(--bg-panel); }
