/* Reefer Control Fleet - Premium Design System (Sleek Dark Mode) */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  /* Color Palette */
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-surface: rgba(22, 28, 45, 0.7);
  --bg-surface-hover: rgba(31, 41, 55, 0.8);
  --bg-surface-active: rgba(55, 65, 81, 0.9);
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #3b82f6;

  /* Accents */
  --accent-blue: #0ea5e9;
  --accent-blue-rgb: 14, 165, 233;
  --accent-purple: #8b5cf6;
  --accent-color: var(--accent-blue);

  /* Status Colors */
  --status-normal: #10b981;
  --status-normal-rgb: 16, 185, 129;
  --status-warning: #f59e0b;
  --status-warning-rgb: 245, 158, 11;
  --status-danger: #ef4444;
  --status-danger-rgb: 239, 68, 68;
  --status-inactive: #6b7280;

  /* Text Colors */
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Glassmorphism & Shadows */
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.47);
  --glass-blur: blur(12px);
  --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Animations */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.95); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulseGlow {
  0% { box-shadow: 0 0 0 0 rgba(var(--status-danger-rgb), 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(var(--status-danger-rgb), 0); }
  100% { box-shadow: 0 0 0 0 rgba(var(--status-danger-rgb), 0); }
}

/* UI Layout Classes */
.fade-in {
  animation: fadeIn 0.4s ease forwards;
}

/* Login Screen */
#login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(circle at center, #1e1b4b 0%, #030712 100%);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  transition: var(--transition-smooth);
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  box-shadow: var(--glass-shadow);
  backdrop-filter: var(--glass-blur);
  padding: 2.5rem;
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 110px;
  background: var(--accent-blue);
  color: #fff;
  border-radius: 16px;
  margin-bottom: 1.5rem;
  padding: 25px;
}

.login-card h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: -0.025em;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 2rem;
}

.form-group {
  margin-bottom: 1.25rem;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
}

.input-field {
  width: 100%;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: var(--transition-smooth);
}

.input-field:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.btn-primary {
  width: 100%;
  padding: 12px 24px;
  background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-purple) 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition-smooth);
  margin-top: 1rem;
}

.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.error-message {
  color: var(--status-danger);
  font-size: 13px;
  margin-top: 0.75rem;
  display: none;
}

/* App Main Shell */
#app-shell {
  display: flex;
  min-height: 100vh;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#app-shell.active {
  opacity: 1;
}

/* Sidebar styling */
.sidebar {
  width: 260px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-brand svg {
  color: var(--accent-blue);
}

.sidebar-brand i {
  color: var(--accent-blue);
  font-size: 20px;
}

.sidebar-menu {
  list-style: none;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.menu-item:hover, .menu-item.active {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.menu-item.active {
  border-left: 3px solid var(--accent-blue);
  padding-left: 13px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: var(--accent-blue);
}

.user-details {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
}

.user-role {
  font-size: 11px;
  color: var(--text-muted);
}

.btn-logout {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition-smooth);
}

.btn-logout:hover {
  color: var(--status-danger);
}

/* Main Content Area */
.main-content {
  margin-left: 260px;
  flex-grow: 1;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  justify-content: flex-start !important; /* ❗️ Force top alignment for all views (v1.45) */
}

/* Views management */
.view-section {
  display: none;
  /* Removed min-height to prevent vertical stretching artifacts (v1.46) */
}

.view-section#view-chat {
  height: calc(100vh - 120px);
}

.view-section.active {
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: relative;
  z-index: 5;
  justify-content: flex-start !important; /* ❗️ Anchor content to the top (v1.44/v1.45) */
  flex-grow: 0 !important; /* ❗️ Prevent excessive stretching (v1.45) */
  margin-top: 0 !important;
  margin-bottom: auto !important; /* ❗️ Push remaining space to the bottom (v1.46) */
}

/* Specific View Overrides for Top Alignment (v1.46) */
#view-orders.view-section.active,
#view-active-reefers.view-section.active {
  justify-content: flex-start !important;
  margin-top: 0 !important;
  margin-bottom: auto !important;
}

/* Header inside views */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: nowrap; /* ❗️ Prevent "X" button from wrapping (v1.34) */
}

.view-title {
  flex: 1;
  min-width: 0;
}

.view-title h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.view-title p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* KPI Dashboard Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  backdrop-filter: var(--glass-blur);
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.kpi-icon.blue { background: rgba(14, 165, 233, 0.1); color: var(--accent-blue); }
.kpi-icon.green { background: rgba(16, 185, 129, 0.1); color: var(--status-normal); }
.kpi-icon.warning { background: rgba(245, 158, 11, 0.1); color: var(--status-warning); }
.kpi-icon.danger { background: rgba(239, 68, 68, 0.1); color: var(--status-danger); }

.kpi-info {
  display: flex;
  flex-direction: column;
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 2px;
}

/* Grid of Cards (Vessels) */
.vessels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.vessel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.vessel-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.15);
  background: var(--bg-surface-hover);
}

.vessel-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.vessel-name-title {
  font-size: 18px;
  font-weight: 700;
}

.vessel-imo-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.vessel-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.vessel-status-dot.normal { background-color: var(--status-normal); box-shadow: 0 0 10px var(--status-normal); }
.vessel-status-dot.warning { background-color: var(--status-warning); box-shadow: 0 0 10px var(--status-warning); }
.vessel-status-dot.danger {
  background-color: var(--status-danger);
  animation: pulseGlow 2s infinite;
}

.vessel-details-brief {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.vessel-details-brief div {
  display: flex;
  justify-content: space-between;
}

.vessel-details-brief span {
  font-weight: 500;
  color: var(--text-primary);
}

.vessel-stats-mini {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: center;
}

.mini-stat {
  display: flex;
  flex-direction: column;
  padding: 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
}

.mini-stat-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
}

.mini-stat-value {
  font-size: 15px;
  font-weight: 700;
  margin-top: 2px;
}

.mini-stat-value.normal { color: var(--status-normal); }
.mini-stat-value.warning { color: var(--status-warning); }
.mini-stat-value.danger { color: var(--status-danger); }

/* Table View Container */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
}

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

.search-bar {
  position: relative;
  width: 100%;
  max-width: 320px;
  align-self: center;
}

.search-bar i:first-of-type {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
}

.search-bar .input-field {
  padding-left: 40px;
  padding-right: 32px;
}

.clear-search {
  position: absolute;
  right: 12px;
  left: auto !important;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  transition: var(--transition-smooth);
  z-index: 5;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
}

.clear-search:hover {
  color: var(--status-danger);
  transform: translateY(-50%) scale(1.15);
}

.filters-row {
  display: flex;
  gap: 10px;
}

.select-filter {
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.select-filter:focus {
  border-color: var(--accent-blue);
}

/* Custom Styled Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
}

.custom-table th {
  padding: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
}

.custom-table td {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.custom-table tbody tr {
  transition: var(--transition-smooth);
}

.custom-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.custom-table tbody tr.clickable {
  cursor: pointer;
}

/* Badge System */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge.normal { background: rgba(16, 185, 129, 0.12); color: var(--status-normal); }
.badge.warning { background: rgba(245, 158, 11, 0.12); color: var(--status-warning); }
.badge.danger { background: rgba(239, 68, 68, 0.12); color: var(--status-danger); }
.badge.inactive { background: rgba(107, 114, 128, 0.12); color: var(--status-inactive); }

/* Details Layout for Containers */
.details-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 24px;
  width: 100%;
  overflow-x: hidden; /* ❗️ Prevent horizontal overflow (v1.34) */
}

.reefer-temps-dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  text-align: center;
}

.reefer-temps-dashboard .data-group:first-child {
  border-right: 1px solid var(--border-color);
}

.info-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.data-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.data-value {
  font-size: 15px;
  font-weight: 500;
}

.data-value.temp-large {
  font-size: 36px;
  font-weight: 700;
  color: var(--text-primary);
}

.temp-unit {
  font-size: 16px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Charts Card */
.chart-container {
  min-height: 320px;
  width: 100%;
  margin-top: 10px;
}

.interval-picker {
  display: flex;
  background: rgba(255,255,255,0.05);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
}

.interval-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.interval-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.05);
}

.interval-btn.active {
  background: var(--accent-blue);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Tooltip custom style for analysis */
#chartjs-tooltip {
  opacity: 1;
  position: absolute;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  border-radius: 3px;
  transition: all .1s ease;
  pointer-events: none;
  transform: translate(-50%, 0);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
.btn-back {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition-smooth);
}

.btn-back:hover {
  color: var(--text-primary);
  transform: translateX(-3px);
}

/* Alert Boxes */
.alert-box {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 8px;
  padding: 16px;
  color: var(--text-primary);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.alert-box i {
  color: var(--status-danger);
  font-size: 18px;
  margin-top: 2px;
}

.alert-content h4 {
  font-weight: 600;
  margin-bottom: 4px;
}

.alert-content p {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Grid layout for Route Progress (Vessel Page) */
.vessel-header-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.route-bar-widget {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 16px;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.route-point {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.route-point.right {
  text-align: right;
}

.route-point-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.route-point-name {
  font-weight: 700;
  font-size: 15px;
}

.route-progress-line {
  flex-grow: 1;
  margin: 0 20px;
  height: 4px;
  background: var(--border-color);
  position: relative;
  border-radius: 2px;
}

.route-progress-fill {
  position: absolute;
  left: 0;
  height: 100%;
  background: var(--accent-blue);
  border-radius: 2px;
}

/* Interactive elements animations */
button {
  cursor: pointer;
}
select, input, button {
  font-family: inherit;
}

/* Vessel Sub-Tabs Navigation */
.vessel-tabs-bar {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 24px;
}

.vessel-sub-tab {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  padding: 12px 20px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition-smooth);
  display: flex;
  align-items: center;
  gap: 8px;
}

.vessel-sub-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.02);
}

.vessel-sub-tab.active {
  color: var(--text-primary);
  font-weight: 600;
  border-bottom: 2px solid var(--accent-blue) !important;
}

.vessel-tab-content {
  display: none;
}

.vessel-tab-content.active {
  display: flex;
}

/* Order Sub-tabs style inside panels */
.btn-subtab {
  background: var(--bg-surface-active);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 18px;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-subtab:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.btn-subtab.active {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
  font-weight: 600;
}

/* Active Filters Badges */
.active-filter-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6; /* Accent blue color */
  border: 1px solid rgba(59, 130, 246, 0.2);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  margin-top: 5px;
}

.active-filter-badge button {
  background: transparent;
  border: none;
  color: #3b82f6;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 12px;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.active-filter-badge button:hover {
  opacity: 1;
}

/* Chat System Styles (v86) */
#chat-threads-list { border-top: none; }
.thread-item {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  position: relative;
  transition: var(--transition-smooth);
  user-select: none;
  touch-action: manipulation;
}
.thread-item:active {
  background: var(--bg-surface-active);
}
.thread-item:last-child { border-bottom: none; }
.thread-item:hover { background: var(--bg-surface-hover); }
.thread-item.active {
  background: rgba(59, 130, 246, 0.1);
  border-left: 3px solid var(--accent-blue);
}
.thread-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; color: var(--text-primary); }
.thread-last-msg { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.unread-count-badge {
  background: var(--status-danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.chat-header-link {
  color: var(--accent-blue);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  font-size: 12px;
}

.picker-item {
  font-size: 18px;
  font-weight: 700;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}
.picker-item:last-child { border-bottom: none; }

.read-only-notice {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.2);
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--status-warning);
  text-align: center;
  margin-bottom: 10px;
}

#chat-messages-container {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  background: rgba(0,0,0,0.05);
}

.message-bubble {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
}

.msg-body {
  white-space: pre-wrap; /* ❗️ Preserve formatting for text only (v1.41.1) */
  word-break: break-word;
  margin: 0 !important;
  padding: 0 !important;
}
.message-bubble.mine {
  align-self: flex-end;
  background: var(--accent-blue);
  color: white;
  border-bottom-right-radius: 2px;
}
.message-bubble.theirs {
  align-self: flex-start;
  background: var(--bg-surface-active);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}
.message-meta {
  font-size: 10px;
  margin-top: 6px;
  opacity: 0.7;
}

.presence-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.05);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  white-space: normal; /* ❗️ Allow wrapping for long vessel names (v1.35) */
  text-align: right;
  max-width: 150px;
}
.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-inactive);
}
.presence-dot.online {
  background: var(--status-normal);
  box-shadow: 0 0 8px var(--status-normal);
}

/* User Profile & Sidebar Interaction (v99) */
.user-info.clickable {
  cursor: pointer;
  padding: 8px;
  margin-left: -8px;
  border-radius: 10px;
  transition: var(--transition-smooth);
}

.user-info.clickable:hover {
  background: rgba(255, 255, 255, 0.05);
}

.alert.success {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: 8px;
}

.msg-status-v { color: #ffffff !important; margin-left: 5px; font-weight: bold; font-size: 10px; opacity: 1; }
.msg-status-vv { color: #ffffff !important; margin-left: 5px; font-weight: bold; font-size: 10px; opacity: 1; }
.msg-status-read { color: #ffffff !important; margin-left: 5px; font-weight: bold; font-size: 10px; opacity: 1; }

/* --- RESPONSIVE DESIGN (v1.32) --- */

/* Mobile Header (Hidden on Desktop) */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  z-index: 150;
  align-items: center;
  justify-content: space-between;
}

.btn-icon-menu {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 20px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

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

.mobile-app-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.user-avatar.mini {
  width: 32px;
  height: 32px;
  font-size: 12px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 180;
}

.btn-chat-back {
  display: none;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-smooth);
}
.btn-chat-back:hover {
  background: rgba(255,255,255,0.1);
  color: var(--accent-blue);
}

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

@media (max-width: 768px) {
  /* ❗️ Global overflow lock for mobile stability (v1.42.2) */
  body, #app-shell, .main-content {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
  }

  body {
    padding-top: 60px;
  }

  .mobile-header {
    display: flex;
  }

  /* Off-canvas Sidebar */
  .sidebar {
    left: -260px;
    z-index: 200;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 20px 0 50px rgba(0,0,0,0.5);
  }

  body.sidebar-open .sidebar {
    transform: translateX(260px);
  }

  body.sidebar-open .sidebar-overlay {
    display: block;
  }

  .main-content {
    margin-left: 0;
    padding: 16px;
    gap: 20px;
    justify-content: flex-start !important;
  }

  .view-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  /* ❗️ Neutralize animation transform for fixed positioning safety (v1.33.1) */
  #view-chat.active {
    animation: none !important;
    transform: none !important;
  }

  .view-title h1 {
    font-size: 22px;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .vessels-grid {
    grid-template-columns: 1fr;
  }

  /* Table Adjustments */
  .custom-table th, .custom-table td {
    padding: 12px 10px;
    font-size: 13px;
  }

  /* Chat Responsive Logic */
  .chat-container-layout {
    flex-direction: column;
    position: relative;
  }

  .chat-threads-panel {
    width: 100% !important;
    display: flex !important; /* Threads list visible by default */
    position: relative;
    z-index: 5;
  }

  .chat-messages-panel {
    display: none !important; /* Hard hide message area when not active */
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0 !important; /* Force bottom dock (v1.38) */
    width: 100% !important; /* Force full width (v1.33.1) */
    height: calc(100dvh - 60px) !important; /* Use dynamic viewport height (v1.33) */
    z-index: 200;
    border-radius: 0;
    border: none;
    background-color: var(--bg-primary); /* Solid background */
  }

  body.chat-active .chat-threads-panel {
    display: none !important; /* Hide threads list when chat is active */
  }

  body.chat-active .chat-messages-panel {
    display: flex !important; /* Show message area as full-screen modal */
  }

  .btn-chat-back {
    display: flex !important;
    margin-right: -4px;
  }

  /* Chat Specific Mobile Fixes (v1.32.1) */
  #chat-active-layout {
    height: 100%;
  }

  .chat-container-layout > .panel:last-child .chat-header-search-wrap {
    display: none !important; /* Hide search in chat header on mobile */
  }

  .chat-container-layout > .panel:last-child div[style*="padding: 16px 24px"] {
    padding: 10px 12px !important;
  }

  .chat-container-layout > .panel:last-child div[style*="padding: 10px 12px"] > div:first-child {
    flex-wrap: wrap !important; /* ❗️ Allow header content to wrap (v1.35) */
    gap: 8px !important;
  }

  #chat-header-presence {
    flex-shrink: 1 !important;
    min-width: 0 !important;
    order: 2; /* Position after title */
  }

  .presence-chip {
    max-width: 100% !important; /* Allow full width on second line if wrapped */
    padding: 4px 8px !important;
    gap: 4px !important;
  }

  #chat-messages-container {
    padding: 16px 12px !important;
  }

  .message-bubble {
    max-width: 88% !important;
  }

  #chat-message-form {
    gap: 8px !important;
  }

  #chat-message-form button[type="submit"] {
    width: 70px !important;
    padding: 0 12px !important;
  }

  #chat-message-input {
    width: auto !important; /* Allow flex: 1 to control width (v1.33.1) */
    min-width: 0 !important;
  }

  #chat-active-layout div[style*="padding: 20px 24px"] {
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom)) 12px !important; /* Safe area aware (v1.38) */
    background: var(--bg-secondary) !important;
    position: sticky !important;
    bottom: 0 !important;
    z-index: 10 !important;
  }

  /* Hide thread title in active header on mobile to save space (v1.36) */
  #chat-header-title {
    display: none !important;
  }

  /* Modal responsiveness */
  .panel[style*="max-width"] {
    width: 95% !important;
    max-width: 95% !important;
    margin: 10px;
    padding: 16px !important;
  }

  .panel[style*="max-width"] .view-header {
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
  }

  .view-title h1 {
    font-size: 18px !important;
    white-space: normal !important; /* Allow reefer number to wrap if needed */
  }

  #view-reefer-details {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    padding: 8px !important; /* Minimal padding */
  }

  #view-reefer-details .view-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
    padding: 0 4px !important;
  }

  #view-reefer-details .view-header > div:last-child {
    width: 100% !important;
    justify-content: space-between !important;
    gap: 8px !important;
  }

  .reefer-temps-dashboard {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
    padding: 0 !important;
  }

  .reefer-temps-dashboard .data-group {
    border-right: none !important;
    padding: 12px 0 !important;
    border-bottom: 1px solid var(--border-color);
    width: 100% !important;
    text-align: center !important;
  }

  .reefer-temps-dashboard .data-group:last-child {
    border-bottom: none !important;
  }

  .details-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
    width: 100% !important;
    margin: 0 !important;
  }

  .info-column {
    width: 100% !important;
    gap: 16px !important;
  }

  .panel {
    padding: 12px !important; /* Reduce panel padding on all mobile views (v1.42) */
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  /* ❗️ Force table containers to stay within panel bounds (v1.42.2) */
  .table-responsive {
    display: block !important;
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .chart-container {
    max-width: 100% !important;
  }

  .vessel-details-brief div {
    flex-wrap: wrap !important;
    gap: 4px !important;
  }

  .data-value.temp-large {
    font-size: 32px !important;
  }

  /* Fix for Analyze History Modal on Mobile (v1.34.1) */
  #modal-chart-zoom > div:first-child {
    display: flex !important;
    flex-direction: column !important;
    padding: 12px 16px !important;
    gap: 12px !important;
    height: auto !important;
    position: relative !important;
  }

  #btn-close-analysis {
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    width: auto !important;
    padding: 6px 12px !important;
    font-size: 12px !important;
    z-index: 10 !important;
  }

  #modal-chart-zoom .interval-picker {
    width: 100% !important;
    justify-content: center !important;
    margin-top: 10px !important;
  }

  .vessel-tabs-bar {
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 4px;
  }

  .vessel-sub-tab {
    padding: 10px 14px;
    font-size: 13px;
  }

  .login-card {
    padding: 2rem 1.5rem;
  }
}

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

  .mini-stat-value {
    font-size: 13px;
  }
}
