/* === OCEAN TECH THEME - Dashboard Pro Layout (FIXED) === */

/* --- General Theme --- */
* {
  box-sizing: border-box; /* CRITICAL: Prevents overflow issues */
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  background-color: #f4fbfc;
  color: #243b53;
  font-size: 18px;
  transition: background 0.4s, color 0.4s;
  overflow-x: hidden; /* Prevent horizontal scroll */
}

/* --- Header --- */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(90deg, #00334e, #006b8f);
  padding: 15px 40px;
  border-bottom: 4px solid #00b8d9;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.header-title h1 {
  font-size: clamp(1.5rem, 4vw, 2.5rem); /* Responsive font size */
  color: #00e0ff;
  margin: 0;
  text-shadow: 0 0 8px rgba(0, 224, 255, 0.4);
}

.header-title p {
  margin: 4px 0 0 0;
  color: #e0f7fa;
  font-size: clamp(0.85rem, 2vw, 1.05rem);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-shrink: 0; /* Prevent logos from shrinking too much */
}

.header-right img {
  height: 70px;
  width: auto;
  max-width: 200px; /* Limit maximum width */
  object-fit: contain;
  background-color: #ffffff;
  border-radius: 10px;
  border: 1px solid #b0c4de;
  padding: 4px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.header-right img:hover {
  transform: scale(1.1);
  box-shadow: 0 0 10px rgba(0, 184, 217, 0.6);
}

/* --- DASHBOARD GRID: 3 COLUMNS (FIXED) --- */
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(250px, 1fr) minmax(400px, 2.2fr) minmax(250px, 1fr);
  gap: 20px;
  padding: 25px;
  max-width: 100%;
}

/* --- Left Side: Cameras --- */
.left-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0; /* Allow shrinking */
}

/* --- Center: Mode Control + Map --- */
.center-side {
  display: flex;
  flex-direction: column;
  gap: 15px;
  min-width: 0; /* Allow shrinking */
}

/* --- MODE CONTROL SECTION --- */
.control-section {
  padding: 12px 18px;
  background: linear-gradient(135deg, #e0f7fa 0%, #b2ebf2 100%);
  border: 3px solid #00b8d9;
}

.control-section h3 {
  margin: 0 0 8px 0;
  color: #004c6d;
  font-size: 1.1em;
  border-bottom: 2px solid #00b8d9;
  padding-bottom: 4px;
}

.mode-control-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background-color: rgba(255, 255, 255, 0.7);
  padding: 8px 14px;
  border-radius: 8px;
  border: 2px solid #00b8d9;
  flex-wrap: wrap; /* Allow wrapping on small screens */
}

.mode-label {
  color: #004c6d;
  font-weight: 700;
  font-size: 1em;
}

.mode-toggle {
  display: flex;
  gap: 10px;
  flex-wrap: wrap; /* Allow wrapping */
}

.mode-btn {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 0.95em;
  font-weight: 700;
  border: 2px solid #004c6d;
  background-color: #ffffff;
  color: #004c6d;
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.mode-btn.active {
  background: linear-gradient(145deg, #005f7a, #0086a5);
  color: white;
  border-color: #00b8d9;
  box-shadow: 0 4px 12px rgba(0, 184, 217, 0.4);
}

.mode-btn:hover {
  background-color: #00b8d9;
  color: white;
  transform: scale(1.05);
}

/* --- Map Section (FIXED WIDTH ISSUE) --- */
.map-section {
  width: 100%; /* Changed from 97% to 100% */
  padding: 20px;
  flex-grow: 1;
  min-width: 0; /* Allow shrinking */
}

.map-title {
  margin: 0 0 15px 0;
  color: #004c6d;
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 76, 109, 0.2);
}

#map {
  width: 100%;
  height: 660px;
  max-height: 70vh; /* Adaptive height */
  border-radius: 10px;
  border: 3px solid #00b8d9;
  box-shadow: 0 6px 20px rgba(0, 184, 217, 0.3);
}

/* --- Right Side: Sensor Cards --- */
.right-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0; /* Allow shrinking */
}

/* --- Section Card --- */
.section {
  background-color: #ffffff;
  padding: 20px;
  border-radius: 14px;
  border: 1px solid #cfd8dc;
  box-shadow: 0 6px 14px rgba(0, 76, 109, 0.08),
              inset 1px 1px 4px rgba(255,255,255,0.4);
  transition: transform 0.3s ease, box-shadow 0.4s ease;
  min-width: 0; /* Allow content to shrink */
}

.section:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 184, 217, 0.25);
}

.section h3 {
  margin: 0 0 15px 0;
  color: #004c6d;
  font-size: 1.3em;
  border-bottom: 3px solid #00b8d9;
  padding-bottom: 8px;
}

/* --- Image Section (FIXED) --- */
.image-section {
  height: auto; /* Changed from fixed height */
  display: flex;
  flex-direction: column;
}

.image-section h3 {
  flex-shrink: 0;
}

.image-section img {
  width: 100%;
  height: auto; /* Changed from fixed 360px */
  max-height: 360px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid #004c6d;
  box-shadow: 0 2px 8px rgba(0, 76, 109, 0.2);
  transition: transform 0.3s ease;
  flex-shrink: 0;
}

.image-section img:hover {
  transform: scale(1.02);
}

/* --- SENSOR CARD --- */
.sensor-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 0;
  border: 3px solid #00b8d9;
  box-shadow: 0 4px 12px rgba(0, 184, 217, 0.2);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  overflow: hidden;
  min-width: 0; /* Allow shrinking */
}

.sensor-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0, 184, 217, 0.35);
}

.sensor-card h4 {
  margin: 0;
  background: linear-gradient(135deg, #003d5c 0%, #004c6d 100%);
  color: #ffffff;
  font-size: 1.1em;
  font-weight: 700;
  text-align: center;
  padding: 12px 15px;
  border-bottom: 3px solid #00b8d9;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.sensor-values {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 16px;
}

.sensor-item {
  display: grid;
  grid-template-columns: minmax(70px, 100px) 1fr minmax(40px, 60px);
  gap: 10px;
  align-items: center;
  background-color: #f8f9fa;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  transition: all 0.2s ease;
  min-height: 45px;
}

.sensor-item:hover {
  background-color: #e0f7fa;
  border-color: #00b8d9;
  transform: scale(1.02);
}

.sensor-label {
  font-weight: 600;
  color: #004c6d;
  font-size: 0.95em;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sensor-value {
  font-weight: 700;
  color: #00b8d9;
  font-size: 1.15em;
  font-family: 'Courier New', monospace;
  text-align: right;
  animation: valueUpdate 0.5s ease;
  padding-right: 8px;
}

@keyframes valueUpdate {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); color: #00e0ff; }
  100% { transform: scale(1); }
}

.sensor-unit {
  font-size: 0.85em;
  color: #64748b;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

/* --- BOTTOM SECTION (FIXED) --- */
.bottom-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  padding: 0 25px 25px 25px;
  max-width: 100%;
}

/* --- GPS LOG SECTION --- */
.gps-log-section {
  flex-grow: 1;
  min-width: 0;
}

/* --- TABLES --- */
.full-width-table {
  padding: 20px;
  min-width: 0;
}

/* --- SCROLLABLE TABLE CONTAINER --- */
.table-container {
  overflow-y: auto;
  overflow-x: auto; /* Allow horizontal scroll if needed */
  border: 2px solid #00b8d9;
  border-radius: 10px;
  margin-top: 12px;
  background-color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 184, 217, 0.15);
}

.table-container table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.0em;
  margin: 0;
  min-width: 400px; /* Minimum width to prevent cramping */
}

.table-container thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(135deg, #003d5c 0%, #004c6d 100%);
  color: #ffffff;
  font-weight: 600;
  border-bottom: 3px solid #00b8d9;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(0, 76, 109, 0.3);
}

.table-container thead th {
  padding: 14px 16px;
  text-align: left;
  font-size: 0.95em;
  background: linear-gradient(135deg, #003d5c 0%, #004c6d 100%);
}

.table-container tbody td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #cfd8dc;
  transition: background 0.2s ease;
  font-size: 0.9em;
}

.table-container tbody tr:nth-child(even) {
  background-color: #e0f7fa;
}

.table-container tbody tr:hover {
  background-color: rgba(0, 184, 217, 0.2);
}

.table-container tbody tr:last-child td {
  border-bottom: none;
}

/* Custom Scrollbar */
.table-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.table-container::-webkit-scrollbar-track {
  background: #e0f7fa;
  border-radius: 10px;
}

.table-container::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #00b8d9, #004c6d);
  border-radius: 10px;
  border: 2px solid #e0f7fa;
}

.table-container::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #00e0ff, #00b8d9);
}

/* Custom Leaflet Popup Styling */
.leaflet-popup-content-wrapper {
  background-color: #ffffff;
  border: 2px solid #00b8d9;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 184, 217, 0.3);
}

.leaflet-popup-tip {
  background-color: #ffffff;
  border: 2px solid #00b8d9;
}

/* --- Responsive Design (IMPROVED) --- */

/* Large Desktop */
@media (max-width: 1600px) {
  .dashboard-grid {
    grid-template-columns: minmax(220px, 1fr) minmax(400px, 2fr) minmax(220px, 1fr);
  }
}

/* Desktop/Laptop */
@media (max-width: 1400px) {
  .dashboard-grid {
    grid-template-columns: minmax(200px, 1fr) minmax(350px, 2fr) minmax(200px, 1fr);
    gap: 15px;
    padding: 20px;
  }
  
  #map {
    height: 500px;
  }
  
  .image-section img {
    max-height: 280px;
  }
  
  .sensor-item {
    grid-template-columns: 90px 1fr 55px;
    padding: 10px 14px;
  }
  
  .sensor-value {
    font-size: 1.05em;
  }
  
  body {
    font-size: 16px;
  }
}

/* Tablet Landscape */
@media (max-width: 1200px) {
  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
    gap: 15px;
  }
  
  .left-side {
    grid-column: 1;
    grid-row: 1 / 3;
  }
  
  .center-side {
    grid-column: 2;
    grid-row: 1;
  }
  
  .right-side {
    grid-column: 2;
    grid-row: 2;
  }
  
  #map {
    height: 400px;
  }
  
  .bottom-section {
    grid-template-columns: 1fr;
  }
  
  .mode-control-wrapper {
    flex-direction: column;
    align-items: stretch;
  }
  
  .mode-toggle {
    width: 100%;
    justify-content: center;
  }
}

/* Tablet Portrait */
@media (max-width: 992px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  
  .left-side,
  .center-side,
  .right-side {
    grid-column: 1;
    grid-row: auto;
  }
  
  #map {
    height: 450px;
  }
  
  .bottom-section {
    grid-template-columns: 1fr;
    padding: 0 20px 20px 20px;
  }
}

/* Mobile Landscape */
@media (max-width: 768px) {
  .main-header {
    flex-direction: column;
    gap: 15px;
    padding: 15px 20px;
  }
  
  .header-title h1 {
    font-size: 1.8em;
    text-align: center;
  }
  
  .header-title p {
    font-size: 0.9em;
    text-align: center;
  }
  
  .header-right {
    justify-content: center;
  }
  
  .header-right img {
    height: 40px;
    max-width: 60px;
  }
  
  .dashboard-grid {
    padding: 15px;
    gap: 15px;
  }
  
  #map {
    height: 350px;
  }
  
  .image-section img {
    max-height: 220px;
  }
  
  .table-container {
    max-height: 250px !important;
  }
  
  .mode-btn {
    flex: 1;
    padding: 10px 15px;
  }
  
  .sensor-item {
    grid-template-columns: 80px 1fr 50px;
    padding: 10px 12px;
    gap: 8px;
  }
  
  .sensor-label {
    font-size: 0.9em;
  }
  
  .sensor-value {
    font-size: 1em;
  }
  
  .sensor-values {
    padding: 15px 12px;
    gap: 6px;
  }
  
  body {
    font-size: 15px;
  }
}

/* Mobile Portrait */
@media (max-width: 600px) {
  .dashboard-grid,
  .bottom-section {
    padding: 12px;
    gap: 12px;
  }
  
  .section {
    padding: 15px;
  }
  
  .sensor-card {
    padding: 0;
  }
  
  .image-section img {
    max-height: 180px;
  }
  
  #map {
    height: 300px;
  }
  
  .table-container {
    max-height: 200px !important;
  }
  
  .table-container table {
    font-size: 0.85em;
    min-width: 350px;
  }
  
  .sensor-item {
    grid-template-columns: 70px 1fr 45px;
    padding: 8px 10px;
  }
  
  .sensor-value {
    font-size: 0.95em;
  }
  
  .sensor-values {
    padding: 12px 10px;
  }
  
  body {
    font-size: 14px;
  }
  
  .mode-btn {
    font-size: 0.85em;
    padding: 8px 12px;
  }
}

/* Small Mobile */
@media (max-width: 480px) {
  .header-right img {
    height: 35px;
    max-width: 50px;
  }
  
  #map {
    height: 250px;
  }
  
  .image-section img {
    max-height: 150px;
  }
  
  .bottom-section {
    grid-template-columns: 1fr;
  }
  
  .table-container table {
    min-width: 320px;
  }
  
  .sensor-card h4 {
    font-size: 1em;
    padding: 10px;
  }
}