/* ==========================================================================
   ระบบตรวจจับระดับน้ำอัตโนมัติ CCTV เทศบาลเมืองปทุมธานี
   Design System: Glassmorphism Dark Mode with Cyber-Precision Aesthetics
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-base: #060913;
  --bg-surface: rgba(15, 23, 42, 0.75);
  --bg-surface-elevated: rgba(30, 41, 59, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: rgba(56, 189, 248, 0.4);

  /* Brand Accents */
  --accent-cyan: #00f2fe;
  --accent-blue: #3b82f6;
  --accent-glow: rgba(0, 242, 254, 0.25);

  /* Status Colors */
  --status-normal: #10b981;
  --status-normal-glow: rgba(16, 185, 129, 0.3);
  --status-warning: #f59e0b;
  --status-warning-glow: rgba(245, 158, 11, 0.35);
  --status-critical: #ef4444;
  --status-critical-glow: rgba(239, 68, 68, 0.5);

  /* Typography */
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --font-main: 'Prompt', 'Outfit', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

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

body {
  font-family: var(--font-main);
  background: var(--bg-base);
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(14, 165, 233, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(99, 102, 241, 0.06) 0%, transparent 40%),
    linear-gradient(180deg, #060913 0%, #0a0f1d 100%);
  color: var(--text-main);
  min-height: 100vh;
  padding: 16px;
  overflow-x: hidden;
}

/* ==========================================================================
   Emergency Vignette (Flashing red on Critical Alert)
   ========================================================================== */
.critical-vignette {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 9999;
  box-shadow: inset 0 0 100px 40px rgba(239, 68, 68, 0.7);
  animation: pulse-red-vignette 0.8s infinite alternate ease-in-out;
}

.critical-vignette.hidden {
  display: none;
}

@keyframes pulse-red-vignette {
  0% { opacity: 0.3; }
  100% { opacity: 0.85; }
}

/* ==========================================================================
   Audio Permission Banner
   ========================================================================== */
.audio-banner {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.18), rgba(239, 68, 68, 0.22));
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  padding: 12px 20px;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(245, 158, 11, 0.15);
  animation: slide-down 0.4s ease-out;
}

.audio-banner.hidden {
  display: none;
}

.audio-banner-content {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.audio-icon-pulse {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.25);
  color: #fbbf24;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  animation: pulse-glow 1.5s infinite;
}

.audio-text {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.audio-text strong {
  color: #fef08a;
  font-size: 1rem;
}

.audio-text span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ==========================================================================
   Application Header
   ========================================================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(16px);
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #0284c7, #00f2fe);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.5rem;
  position: relative;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.live-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  background: #10b981;
  border: 2px solid #060913;
  border-radius: 50%;
  animation: pulse-dot 1.5s infinite;
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ffffff, #bae6fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-text p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.digital-clock {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: #38bdf8;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-subtle);
}

.status-pill.connected {
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}
.status-pill.connected .pulse-indicator {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.status-pill.connecting {
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}
.status-pill.connecting .pulse-indicator {
  background: #f59e0b;
  box-shadow: 0 0 8px #f59e0b;
}

.status-pill.disconnected {
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
}
.status-pill.disconnected .pulse-indicator {
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}

.pulse-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse-dot 1.5s infinite;
}

/* Icon Buttons */
.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-main);
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.btn-icon.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
}

/* ==========================================================================
   Dashboard Grid Layout
   ========================================================================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

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

/* Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(16px);
  padding: 20px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: border-color 0.3s ease;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  font-weight: 600;
  color: #e2e8f0;
}

.card-title i {
  color: #38bdf8;
}

/* Meta Tags */
.video-meta-tags {
  display: flex;
  gap: 8px;
}

.meta-tag {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-subtle);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.meta-tag.live-tag {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
  font-weight: 700;
}

.meta-tag.live-tag i {
  font-size: 0.6rem;
  margin-right: 4px;
  animation: pulse-dot 1s infinite;
}

/* ==========================================================================
   Video Viewport
   ========================================================================== */
.video-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-viewport img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Floating overlay bar on video */
.video-floating-toolbar {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: center;
  gap: 10px;
  background: rgba(15, 23, 42, 0.65);
  padding: 8px 14px;
  border-radius: 999px;
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  opacity: 0.9;
  transition: opacity 0.2s ease;
}

.video-viewport:hover .video-floating-toolbar {
  opacity: 1;
}

.btn-glass {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--font-main);
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.btn-glass:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.btn-glass.active {
  background: rgba(14, 165, 233, 0.3);
  border-color: #38bdf8;
  color: #38bdf8;
}

.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.action-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-action {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-action.warning {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  color: #000;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.3);
}
.btn-action.warning:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.btn-action.critical {
  background: linear-gradient(135deg, #dc2626, #ef4444);
  color: #fff;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
}
.btn-action.critical:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.stream-source-info {
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ==========================================================================
   Telemetry Column & Water Gauge Tank
   ========================================================================== */
.telemetry-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.status-badge {
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge.normal {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.status-badge.warning {
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(245, 158, 11, 0.5);
  color: #fbbf24;
  animation: pulse-badge 1s infinite alternate;
}

.status-badge.critical {
  background: rgba(239, 68, 68, 0.25);
  border: 1px solid rgba(239, 68, 68, 0.6);
  color: #f87171;
  animation: pulse-badge 0.6s infinite alternate;
}

@keyframes pulse-badge {
  0% { transform: scale(0.97); filter: brightness(1); }
  100% { transform: scale(1.03); filter: brightness(1.25); }
}

.gauge-and-metric {
  display: flex;
  gap: 24px;
  align-items: stretch;
}

/* Water Gauge Cylinder Tube */
.water-gauge-container {
  display: flex;
  gap: 12px;
  height: 270px;
}

.gauge-scale {
  position: relative;
  width: 90px;
  height: 100%;
}

.scale-mark {
  position: absolute;
  right: 0;
  transform: translateY(50%);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.scale-mark.critical {
  color: #ef4444;
  font-weight: 700;
}

.scale-mark.warning {
  color: #f59e0b;
  font-weight: 700;
}

.gauge-tube {
  position: relative;
  width: 60px;
  height: 100%;
  background: rgba(15, 23, 42, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 30px;
  overflow: hidden;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}

.gauge-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 5;
}

.gauge-line.line-critical {
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}

.gauge-line.line-warning {
  background: #f59e0b;
  box-shadow: 0 0 8px #f59e0b;
}

/* Animated Liquid in Tube */
.gauge-liquid {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(180deg, rgba(6, 182, 212, 0.8) 0%, rgba(3, 105, 161, 0.95) 100%);
  transition: height 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: visible;
}

.gauge-liquid.status-warning {
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.85) 0%, rgba(180, 83, 9, 0.95) 100%);
}

.gauge-liquid.status-critical {
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.85) 0%, rgba(185, 28, 28, 0.95) 100%);
}

.liquid-wave {
  position: absolute;
  top: -12px;
  left: -50%;
  width: 200%;
  height: 24px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 40%;
  animation: wave-motion 4s infinite linear;
}

.liquid-wave.wave-2 {
  top: -8px;
  opacity: 0.4;
  animation: wave-motion 6s infinite linear reverse;
}

@keyframes wave-motion {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.water-surface-line {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: #fff;
  box-shadow: 0 0 10px #fff;
}

.surface-val {
  position: absolute;
  right: -58px;
  top: -10px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: #fff;
  display: none;
}

/* Metrics Panel */
.metrics-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: space-between;
}

.metric-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
}

.metric-box.hero-metric {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.9), rgba(30, 41, 59, 0.6));
  border-color: rgba(56, 189, 248, 0.3);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.metric-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.metric-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.metric-number {
  font-family: var(--font-mono);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  color: #ffffff;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.metric-unit {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 500;
}

.metric-subtext {
  font-size: 0.82rem;
  color: #38bdf8;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.metric-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-val-sm {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: #e2e8f0;
}

.color-warning { color: #fbbf24; }
.color-critical { color: #f87171; }

/* Chart Container */
.chart-card {
  padding: 18px;
}

.chart-container {
  position: relative;
  height: 170px;
  width: 100%;
}

.live-pulse-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

/* ==========================================================================
   Snapshot Gallery Section
   ========================================================================== */
.snapshots-card {
  margin-top: 4px;
}

.snapshots-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 6px;
}

.snapshots-gallery::-webkit-scrollbar {
  width: 6px;
}
.snapshots-gallery::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.gallery-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: #000;
  cursor: pointer;
  aspect-ratio: 4 / 3;
  transition: transform 0.2s, border-color 0.2s;
}

.gallery-item:hover {
  transform: translateY(-2px);
  border-color: #38bdf8;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.9) 100%);
  padding: 6px 10px;
  font-size: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
}
.gallery-empty i {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.btn-glass-sm {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-glass-sm:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  animation: modal-pop 0.25s ease-out;
}

@keyframes modal-pop {
  0% { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.btn-close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 20px;
}

.modal-image-body {
  padding: 0;
  background: #000;
  display: flex;
  justify-content: center;
}

.modal-image-body img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-primary-glow {
  background: linear-gradient(135deg, #0284c7, #00f2fe);
  color: #000;
  font-weight: 700;
  font-family: var(--font-main);
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  box-shadow: 0 4px 15px rgba(0, 242, 254, 0.35);
  transition: all 0.2s;
}

.btn-primary-glow:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-subtle);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 1rem;
}

.form-group input:focus {
  outline: none;
  border-color: #38bdf8;
}

.form-help {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ==========================================================================
   Animations
   ========================================================================= */
@keyframes pulse-dot {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

@keyframes pulse-glow {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(245, 158, 11, 0); }
  100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

@keyframes slide-down {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
