:root {
  --cr-ink: #0B1220;
  --cr-panel: #172033;
  --cr-brand: #0CC0DF;
  --cr-red: #DC2626;
  --cr-border: #2A3550;
  --cr-text: #E5E9F0;
  --cr-muted: #94A3B8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--cr-ink);
  color: var(--cr-text);
  overflow: hidden;
}

.cr-hidden { display: none !important; }

/* Floats over the top of the grid rather than pushing it down - .cr-grid's
   height is a fixed calc() based on the header alone, so an in-flow banner
   would overflow the viewport when shown. */
.cr-sync-banner {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  z-index: 600;
  padding: 8px 20px;
  background: #78350F;
  color: #FDE68A;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.cr-test-alert-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  font-size: clamp(20px, 4vw, 48px);
  font-weight: 800;
  color: #fff;
  animation: cr-emergency-flash 1s ease-in-out infinite;
}

.cr-screen { width: 100vw; height: 100vh; }
.cr-centered {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(12, 192, 223, 0.10), transparent 45%),
    radial-gradient(circle at 80% 75%, rgba(12, 192, 223, 0.08), transparent 45%),
    var(--cr-ink);
}

.cr-brand-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 26px;
}

.cr-brand-logo { height: 56px; width: auto; }

.cr-loading-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--cr-border);
  border-top-color: var(--cr-brand);
  animation: cr-spin 0.8s linear infinite;
}

@keyframes cr-spin {
  to { transform: rotate(360deg); }
}

.cr-brand-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--cr-text);
}

.cr-brand-subtitle {
  font-size: 13px;
  color: var(--cr-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cr-card {
  background: var(--cr-panel);
  border: 1px solid var(--cr-border);
  border-radius: 16px;
  padding: 32px;
  width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.cr-card h1, .cr-card h2 {
  margin: 0 0 8px 0;
  font-size: 19px;
  color: var(--cr-brand);
  text-align: center;
}

.cr-card label { font-size: 13px; color: var(--cr-muted); }

.cr-card input, .cr-card select {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--cr-border);
  background: var(--cr-ink);
  color: var(--cr-text);
  font-size: 14px;
}

.cr-card button {
  margin-top: 8px;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--cr-brand);
  color: #06222b;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  letter-spacing: 0.02em;
  transition: filter 0.15s ease;
}

.cr-card button:hover { filter: brightness(1.08); }
.cr-card button:disabled { filter: grayscale(0.4) brightness(0.8); cursor: not-allowed; }

.cr-link-button {
  background: none !important;
  color: var(--cr-muted) !important;
  font-weight: 400 !important;
  text-align: left;
  padding: 4px !important;
}

.cr-error { color: var(--cr-red); font-size: 13px; min-height: 16px; }

.cr-layout-options { display: flex; flex-direction: column; gap: 10px; }

.cr-layout-options button {
  margin-top: 0;
  background: var(--cr-ink);
  color: var(--cr-text);
  border: 1px solid var(--cr-border);
  text-align: left;
  padding: 14px 16px;
}

.cr-layout-options button:hover {
  filter: none;
  border-color: var(--cr-brand);
  color: var(--cr-brand);
}

.cr-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--cr-panel);
  border-bottom: 1px solid var(--cr-border);
  gap: 12px;
}

.cr-header > div:first-child {
  display: flex;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.cr-header-event {
  margin-left: 12px;
  color: var(--cr-brand);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cr-header-right { display: flex; align-items: center; gap: 16px; flex: none; }
.cr-header-account { color: var(--cr-muted); font-size: 13px; white-space: nowrap; }
.cr-header-clock { color: var(--cr-text); font-size: 14px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

.cr-header-btn {
  padding: 8px 16px;
  border: 1px solid var(--cr-border);
  border-radius: 8px;
  background: transparent;
  color: var(--cr-text);
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
}

.cr-header-btn:hover { border-color: var(--cr-brand); color: var(--cr-brand); }

.cr-grid {
  display: grid;
  height: calc(100vh - 56px);
  gap: 4px;
  background: var(--cr-border);
}

.cr-grid-1 { grid-template-columns: 1fr; }
.cr-grid-2 { grid-template-columns: 1fr 1fr; }
.cr-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

/* Map full-height on the left, two stacked panels on the right. The right
   column is a plain flex stack (not a grid child itself) rather than
   further grid-template-rows, so it can sit as a single grid item next to
   the map panel. */
.cr-grid-split { grid-template-columns: 1.4fr 1fr; }

.cr-split-right {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.cr-split-right .cr-panel { flex: 1; min-height: 0; }

.cr-panel {
  background: var(--cr-ink);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

/* A floating segmented control in the corner of each panel, rather than a
   plain <select> - meant to read clearly as "click here to change what
   this panel shows" on a display nobody has used before, and to still be
   usable at a glance on a small screen (icon-only below 700px, see the
   media query further down). */
.cr-view-switcher {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 500; /* above Leaflet's own controls */
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(11, 18, 32, 0.72);
  border: 1px solid var(--cr-border);
  backdrop-filter: blur(4px);
}

.cr-view-switcher button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--cr-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.cr-view-switcher button svg {
  width: 15px;
  height: 15px;
  flex: none;
}

.cr-view-switcher button:hover { color: var(--cr-text); }

.cr-view-switcher button.cr-view-switcher-active {
  background: var(--cr-brand);
  color: #06222b;
}

.cr-panel-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  /* Reserves a strip at the top so the floating view switcher (44px tall
     including its own offset) never sits on top of the map's top-right
     controls or the table's header row - it gets its own space instead of
     overlapping content. */
  padding-top: 44px;
}

.cr-map { width: 100%; height: 100%; }

.cr-tooltip {
  background: rgba(11, 18, 32, 0.9) !important;
  border: none !important;
  color: #fff !important;
  font-weight: 600;
  font-size: 12px;
}

/* Leaflet's divIcon wrapper adds its own white box/border by default -
   strip that so only the pin SVG itself shows. */
.cr-incident-pin {
  background: transparent !important;
  border: none !important;
}

.cr-map-link-toggle {
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(11, 18, 32, 0.72);
  border: 1px solid var(--cr-border);
  backdrop-filter: blur(4px);
  color: var(--cr-muted);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.cr-map-link-toggle input { cursor: pointer; }

/* This is an unattended display - there is nobody to scroll it. Rather than
   a scrollbar, fit-to-container.js shrinks --cr-fit-font-size (and, via em
   units below, row padding along with it) until every row fits inside the
   wrapper with no overflow, on any screen size. */
.cr-table-wrap {
  width: 100%;
  height: 100%;
  overflow: hidden;
  --cr-fit-font-size: 13px;
}

.cr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--cr-fit-font-size);
}

.cr-table th, .cr-table td {
  padding: 0.6em 0.75em;
  border-bottom: 1px solid var(--cr-border);
  text-align: left;
  white-space: nowrap;
}

.cr-table th {
  position: sticky;
  top: 0;
  background: var(--cr-panel);
  color: var(--cr-muted);
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cr-empty { text-align: center; color: var(--cr-muted); padding: 24px; }

.cr-status {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.cr-status-allocated { background: #7C3AED33; color: #C4B5FD; }
.cr-status-outstanding { background: #D9770633; color: #FCD34D; }
.cr-status-complete { background: #16A34A33; color: #86EFAC; }
.cr-status-unknown { background: #64748B33; color: var(--cr-muted); }

.cr-crew-status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}

/* Purely a visual alert for an unattended screen - no action is taken here,
   the real handling happens in the Dispatcher Console (see crew-list-view.js). */
.cr-crew-row-emergency {
  animation: cr-emergency-flash 1s ease-in-out infinite;
  font-weight: 700;
  color: #FCA5A5;
}

@keyframes cr-emergency-flash {
  0%, 100% { background: rgba(220, 38, 38, 0.15); }
  50% { background: rgba(220, 38, 38, 0.55); }
}

/* A slower, amber pulse for "this has been outstanding too long" - visually
   distinct from the crew emergency red flash above, since it's a lower
   urgency, non-emergency condition. */
.cr-incident-row-alert {
  animation: cr-outstanding-alert-pulse 2s ease-in-out infinite;
  font-weight: 700;
}

@keyframes cr-outstanding-alert-pulse {
  0%, 100% { background: rgba(217, 119, 6, 0.12); }
  50% { background: rgba(217, 119, 6, 0.4); }
}

/* This app has to work on whatever screen a control room happens to have -
   a 2 or 3-panel grid forced into equal side-by-side columns becomes
   unreadably narrow on a small or portrait screen, so it stacks into rows
   instead below these widths. */
@media (max-width: 1100px) {
  .cr-grid-3 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr 1fr;
  }

  .cr-grid-split {
    grid-template-columns: 1fr;
    grid-template-rows: 1.4fr 1fr;
  }

  .cr-split-right { flex-direction: row; }
}

@media (max-width: 800px) {
  .cr-grid-2 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
}

@media (max-width: 700px) {
  .cr-card { width: min(340px, 88vw); padding: 24px; }
  .cr-brand-logo { height: 44px; }
  .cr-header { padding: 0 12px; }
  .cr-header-account { display: none; } /* Least important header text - drop it first. */

  /* Icon-only once space is tight - the label text is still available via
     the button's title tooltip. */
  .cr-view-switcher button span { display: none; }
  .cr-view-switcher button { padding: 7px; }
}

@media (max-width: 420px) {
  .cr-header strong { font-size: 13px; }
  .cr-header-event { margin-left: 6px; font-size: 13px; }
  .cr-header-btn { padding: 6px 10px; font-size: 12px; }
}

/* Table cells are nowrap by default so columns stay aligned on a wide
   screen. On a narrow stacked panel that would silently clip long values
   instead (overflow is hidden, not scrollable, by design) - letting text
   wrap here instead means it's still fully readable, just taller; the
   fit-to-container shrink still keeps the whole table on screen either way. */
@media (max-width: 800px) {
  .cr-table th, .cr-table td { white-space: normal; }
}
