:root {
  --panel: rgba(10, 20, 32, 0.94);
  --panel-soft: rgba(18, 34, 50, 0.94);
  --border: rgba(163, 197, 225, 0.22);
  --text: #eef7ff;
  --muted: #9eb4c7;
  --accent: #47b9ff;
  --accent-strong: #168ed8;
  --danger: #ff8181;
  --success: #55d694;
  --warning: #ffc66d;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: #050b11;
  color: var(--text);
}

button,
input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.loading-screen,
.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 30% 20%, rgba(30, 116, 178, 0.25), transparent 34%),
    radial-gradient(circle at 75% 75%, rgba(33, 96, 143, 0.18), transparent 30%),
    #050b11;
  z-index: 10000;
}

.loading-card,
.login-card {
  width: min(430px, 100%);
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(11, 24, 38, 0.96);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
}

.loading-card { text-align: center; }
.loading-card h1 { margin: 14px 0 4px; }
.loading-card p { margin: 0; color: var(--muted); }
.spinner { width: 38px; height: 38px; margin: 0 auto; border: 3px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-card header { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 50%; background: linear-gradient(145deg, var(--accent), #1c4d73); font-weight: 800; }
.login-card h1 { margin: 0; font-size: 1.55rem; }
.login-card header p { margin: 3px 0 0; color: var(--muted); }
.login-card label { display: grid; gap: 7px; margin: 14px 0; font-size: 0.9rem; color: #c9d8e5; }
.optional { color: var(--muted); font-size: 0.8rem; }
.login-card input,
.search-field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  outline: none;
}
.login-card input { padding: 12px 13px; }
.login-card input:focus,
.search-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(71, 185, 255, 0.12); }
.primary-button { width: 100%; margin-top: 8px; padding: 12px; border: 0; border-radius: 9px; color: #fff; background: linear-gradient(180deg, var(--accent), var(--accent-strong)); font-weight: 700; }
.primary-button:disabled { opacity: 0.55; cursor: wait; }
.form-error { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 0.88rem; }
.mock-hint { margin: 12px 0 0; color: var(--warning); font-size: 0.82rem; line-height: 1.4; }

.application {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #050b11;
}

.map-viewport,
.map-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#googleMapContainer {
  background: #d7e3ed;
}

#cesiumContainer {
  background: #050b11;
  touch-action: none;
  overscroll-behavior: none;
}

#cesiumContainer canvas {
  width: 100%;
  height: 100%;
  touch-action: none;
}

.sidebar {
  position: absolute;
  z-index: 1000;
  top: 12px; bottom: 74px; left: 12px;
  width: 360px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--panel);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.42);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: transform 180ms ease;
}

.sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 15px 16px; border-bottom: 1px solid var(--border); }
.product-line { display: flex; align-items: baseline; gap: 7px; min-width: 0; }
.product-name { font-size: 1.1rem; font-weight: 750; white-space: nowrap; }
.app-version { color: var(--muted); font-size: 0.68rem; font-weight: 700; letter-spacing: 0.035em; white-space: nowrap; }
.account-name { margin-top: 3px; color: var(--muted); font-size: 0.83rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 275px; }
.icon-button { border: 0; background: transparent; color: var(--text); font-size: 1.5rem; line-height: 1; padding: 4px 7px; border-radius: 6px; }
.icon-button:hover { background: rgba(255, 255, 255, 0.08); }

.map-mode-section {
  padding: 11px 14px 12px;
  border-bottom: 1px solid var(--border);
}
.section-label {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.map-mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.20);
}
.map-mode-button {
  min-height: 34px;
  padding: 7px 8px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 650;
}
.map-mode-button:hover { color: var(--text); }
.map-mode-button.active {
  color: #fff;
  background: linear-gradient(180deg, rgba(71, 185, 255, 0.95), rgba(22, 142, 216, 0.95));
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.25);
}
.map-mode-button:disabled { opacity: 0.55; cursor: wait; }

.toolbar { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.search-field input { padding: 9px 10px; }
.button-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin-top: 9px; }
.button-row button,
.filters button { padding: 7px 8px; border: 1px solid var(--border); border-radius: 7px; color: var(--text); background: rgba(255, 255, 255, 0.055); }
.button-row button:hover { border-color: rgba(71, 185, 255, 0.7); }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 0.84rem; }
.filters label { display: flex; align-items: center; gap: 7px; color: #dbe8f2; }
.filters input { accent-color: var(--accent); }
.filters .cesium-only { grid-column: 1 / -1; }
.count { min-width: 22px; padding: 1px 5px; border-radius: 9px; background: rgba(255, 255, 255, 0.08); color: var(--muted); text-align: center; font-size: 0.75rem; }

.status-strip { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 7px; padding: 9px 14px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 0.78rem; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 3px rgba(255, 198, 109, 0.12); }
.status-dot.connected { background: var(--success); box-shadow: 0 0 0 3px rgba(85, 214, 148, 0.12); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 3px rgba(255, 129, 129, 0.12); }
#lastUpdated { font-variant-numeric: tabular-nums; }

.asset-list-section { min-height: 0; display: flex; flex: 1; flex-direction: column; }
.asset-list-section h2 { margin: 0; padding: 11px 14px 7px; color: var(--muted); font-size: 0.78rem; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; }
.asset-list { min-height: 0; overflow: auto; padding: 0 7px 9px; }
.asset-item { width: 100%; display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 9px; padding: 9px 8px; border: 0; border-radius: 8px; color: var(--text); background: transparent; text-align: left; }
.asset-item:hover,
.asset-item.selected { background: rgba(71, 185, 255, 0.10); }
.asset-icon { width: 30px; height: 30px; display: grid; place-items: center; }
.asset-icon img { display: block; max-width: 30px; max-height: 30px; object-fit: contain; image-rendering: auto; }
.asset-item.vessel .asset-icon { background: transparent; }
.asset-main { min-width: 0; }
.asset-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.88rem; font-weight: 650; }
.asset-subtitle { display: block; margin-top: 2px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.75rem; }
.asset-age { color: var(--muted); font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.asset-age.stale { color: var(--warning); }
.empty-list { padding: 28px 18px; color: var(--muted); text-align: center; font-size: 0.86rem; }

.details-panel { max-height: 52%; overflow: auto; border-top: 1px solid var(--border); background: var(--panel-soft); padding: 14px; }
.details-heading { display: flex; justify-content: space-between; align-items: flex-start; }
.details-heading h2 { margin: 2px 0 10px; font-size: 1rem; }
.asset-type { color: var(--accent); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.details-panel dl { display: grid; grid-template-columns: minmax(92px, auto) 1fr; gap: 7px 12px; margin: 0; font-size: 0.79rem; }
.details-panel dt { color: var(--muted); }
.details-panel dd { margin: 0; overflow-wrap: anywhere; }

.expand-sidebar { position: absolute; z-index: 999; left: 14px; top: 14px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel); color: var(--text); box-shadow: 0 6px 24px rgba(0,0,0,.35); }
.map-notice { position: absolute; z-index: 1001; left: 50%; bottom: 28px; transform: translateX(-50%); max-width: min(650px, calc(100% - 30px)); padding: 10px 14px; border: 1px solid var(--border); border-radius: 9px; background: rgba(11, 24, 38, 0.96); color: #dbe8f2; box-shadow: 0 8px 30px rgba(0,0,0,.4); font-size: 0.84rem; }

.cesium-attribution {
  position: absolute;
  z-index: 900;
  right: 8px;
  bottom: 6px;
  max-width: min(65vw, 720px);
  padding: 3px 6px;
  border-radius: 4px;
  background: rgba(5, 11, 17, 0.72);
  color: rgba(255, 255, 255, 0.92);
  font-size: 10px;
  line-height: 1.25;
  text-align: right;
  pointer-events: none;
}

.google-marker-label {
  color: #fff !important;
  font-weight: 700 !important;
  text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000, 0 0 4px #000;
}

.cesium-viewer-bottom { left: 375px !important; }
.cesium-widget-credits { padding-left: 5px; }


.map-popup {
  position: absolute;
  z-index: 1100;
  width: min(360px, calc(100vw - 28px));
  padding: 14px 14px 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.97);
  color: #172331;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.42);
  transform: translate(-50%, calc(-100% - 18px));
}
.map-popup::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.97);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: translateX(-50%) rotate(45deg);
}
.map-popup-close { position: absolute; top: 5px; right: 7px; min-width: 32px; min-height: 32px; border: 0; background: transparent; color: #4d5965; font-size: 1.55rem; line-height: 1; }
.map-popup-content { padding-right: 22px; }
.map-popup-title { margin: 0 0 7px; color: #172331; font-size: 1rem; font-weight: 750; }
.map-popup-grid { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; font-size: 0.82rem; }
.map-popup-grid dt { color: #687786; }
.map-popup-grid dd { margin: 0; overflow-wrap: anywhere; }
.map-popup-actions { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 7px; margin-top: 11px; }
.map-popup-actions button { min-height: 32px; padding: 6px 9px; border: 1px solid #b9c6d1; border-radius: 7px; background: #f5f8fa; color: #18344a; font-size: 0.78rem; }

.gm-style .itracer-info-window { min-width: 250px; color: #1b2a36; }
.gm-style .itracer-info-window h3 { margin: 0 0 8px; font: 700 15px/1.2 "Segoe UI", sans-serif; }
.gm-style .itracer-info-window dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; font: 13px/1.35 "Segoe UI", sans-serif; }
.gm-style .itracer-info-window dt { color: #687786; }
.gm-style .itracer-info-window dd { margin: 0; overflow-wrap: anywhere; }
.gm-style .itracer-info-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.gm-style .itracer-info-actions button { padding: 5px 8px; border: 1px solid #b7c4ce; border-radius: 6px; background: #f5f8fa; color: #18344a; cursor: pointer; }

.modal-backdrop {
  position: fixed;
  z-index: 20000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 6, 12, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.history-dialog {
  width: min(680px, 100%);
  max-height: min(780px, calc(100dvh - 36px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(11, 24, 38, 0.99);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.58);
}
.dialog-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.dialog-header h2 { margin: 0; font-size: 1.25rem; }
.dialog-header p { margin: 5px 0 0; color: var(--muted); font-size: 0.82rem; }
.history-time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 17px; }
.history-time-grid label { display: grid; gap: 6px; color: #c9d8e5; font-size: 0.84rem; }
.history-time-grid input { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: rgba(0,0,0,.25); color: var(--text); color-scheme: dark; }
.history-assets-heading { display: flex; justify-content: space-between; align-items: center; margin: 17px 0 8px; color: var(--muted); font-size: 0.78rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; }
.text-button { min-height: 0; padding: 4px 7px; border: 0; background: transparent; color: var(--accent); font-size: .78rem; text-transform: none; letter-spacing: 0; }
.history-asset-list { min-height: 120px; max-height: 310px; overflow: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; padding: 8px; border: 1px solid var(--border); border-radius: 9px; background: rgba(0,0,0,.17); }
.history-asset-option { display: grid; grid-template-columns: auto 28px minmax(0,1fr); align-items: center; gap: 7px; min-height: 38px; padding: 5px 6px; border-radius: 6px; color: #dce8f1; font-size: .82rem; }
.history-asset-option:hover { background: rgba(71,185,255,.08); }
.history-asset-option img { max-width: 27px; max-height: 27px; object-fit: contain; }
.history-summary { margin: 10px 0 0; color: var(--muted); font-size: .8rem; }
.dialog-actions { display: grid; grid-template-columns: auto 1fr 1.2fr; gap: 8px; margin-top: 14px; }
.dialog-actions button { min-height: 40px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); background: rgba(255,255,255,.055); }
.dialog-actions .primary-button { margin: 0; border: 0; }


/* IntegrityQ branding and desktop panel behavior. */
.login-integrity-logo { display: block; width: min(300px, 82%); height: auto; margin: 0 auto 20px; }
.login-legal { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: .76rem; line-height: 1.42; }
.login-legal p { margin: 7px 0; }
.login-legal a { color: #78ccff; }
.sidebar-title-block { min-width: 0; flex: 1; }
.panel-integrity-logo { width: 88px; height: auto; margin: 0 7px 0 10px; opacity: .96; }
.map-integrity-logo { position: absolute; z-index: 850; left: 14px; bottom: 39px; width: 126px; height: auto; filter: drop-shadow(0 2px 5px rgba(0,0,0,.68)); pointer-events: none; }
.sidebar.collapsed { transform: translateX(calc(-100% - 26px)); }
.filter-disabled { opacity: .46; cursor: not-allowed; }
.filter-disabled input { cursor: not-allowed; }
.coming-soon { color: var(--muted); font-size: .68rem; white-space: nowrap; }

@media (max-width: 700px) {
  .loading-screen,
  .login-screen {
    min-height: 100vh;
    min-height: 100dvh;
    overflow: auto;
    padding:
      max(14px, env(safe-area-inset-top))
      14px
      max(14px, env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .loading-card,
  .login-card {
    width: 100%;
    max-width: 430px;
    padding: 20px;
    border-radius: 14px;
  }

  .login-card header { gap: 12px; margin-bottom: 18px; }
  .brand-mark { width: 48px; height: 48px; flex: 0 0 48px; }
  .login-card h1 { font-size: 1.35rem; }
  .login-integrity-logo { width: min(250px, 78%); margin-bottom: 16px; }
  .panel-integrity-logo { width: 78px; margin-left: 5px; }
  .map-integrity-logo { left: max(10px, env(safe-area-inset-left)); bottom: max(39px, calc(31px + env(safe-area-inset-bottom))); width: 112px; }


  /* iOS zooms the page when a focused input is smaller than 16 px. */
  .login-card input,
  .search-field input,
  button { font-size: 16px; }

  button,
  input { touch-action: manipulation; }
  button { min-height: 40px; -webkit-tap-highlight-color: transparent; }
  .primary-button { min-height: 46px; }

  .sidebar {
    inset: auto;
    top: max(8px, env(safe-area-inset-top));
    right: 8px;
    bottom: max(74px, calc(58px + env(safe-area-inset-bottom)));
    left: 8px;
    width: auto;
    max-width: none;
    border-radius: 11px;
  }

  .sidebar.collapsed { transform: translateX(calc(-100% - 18px)); }
  .sidebar-header { padding: 12px 13px; }
  .map-mode-section { padding: 9px 12px 10px; }
  .map-mode-button { min-height: 38px; }
  .toolbar { padding: 10px 12px; }
  .button-row { grid-template-columns: 1fr 1fr; gap: 6px; }
  .button-row button { padding: 8px 6px; }
  .filters { gap: 9px 10px; padding: 10px 12px; }
  .status-strip { padding: 8px 12px; }

  .asset-list,
  .details-panel {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .details-panel { max-height: 45%; padding: 12px; }
  .details-panel dl { grid-template-columns: minmax(84px, auto) 1fr; gap: 6px 10px; }

  .expand-sidebar {
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
  }

  .map-notice {
    bottom: max(18px, env(safe-area-inset-bottom));
    max-width: calc(100% - 24px);
    padding: 9px 11px;
  }

  .cesium-viewer-bottom {
    left: 0 !important;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .cesium-widget-credits {
    max-width: calc(100vw - 12px);
    padding-right: env(safe-area-inset-right);
    font-size: 9px;
  }

  .cesium-viewer-toolbar {
    top: max(6px, env(safe-area-inset-top));
    right: max(6px, env(safe-area-inset-right));
  }

  .cesium-viewer-fullscreenContainer {
    right: env(safe-area-inset-right);
    bottom: env(safe-area-inset-bottom);
  }

  .cesium-attribution {
    right: max(6px, env(safe-area-inset-right));
    bottom: max(6px, env(safe-area-inset-bottom));
    max-width: calc(100vw - 18px);
    font-size: 9px;
  }
  .map-popup {
    width: min(340px, calc(100vw - 20px));
    max-height: 58vh;
    overflow: auto;
  }

  .modal-backdrop {
    align-items: end;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .history-dialog {
    max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
    padding: 15px;
    border-radius: 13px;
  }

  .history-time-grid,
  .history-asset-list {
    grid-template-columns: 1fr;
  }

  .history-asset-list { max-height: 34vh; }
  .dialog-actions { grid-template-columns: 1fr 1fr; }
  .dialog-actions .primary-button { grid-column: 1 / -1; }
}


@media (max-width: 420px) {
  .filters { font-size: 0.8rem; }
  .account-name { max-width: 235px; }
  .asset-item { grid-template-columns: 30px minmax(0, 1fr) auto; gap: 7px; padding: 8px 6px; }
}
