:root {
  --bg-1: #07151a;
  --bg-2: #0d2730;
  --panel: rgba(9, 29, 36, 0.86);
  --panel-strong: #0f323d;
  --text: #e6f3f7;
  --muted: #8cb7c4;
  --accent: #f2b134;
  --danger: #ff5f56;
  --ok: #58d68d;
  --radius: 16px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Manrope", sans-serif;
  background: radial-gradient(circle at 18% 12%, #154456 0%, transparent 34%),
              radial-gradient(circle at 87% 84%, #15373f 0%, transparent 32%),
              linear-gradient(140deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}

h1, h2 {
  margin: 0;
  font-family: "Chakra Petch", sans-serif;
  letter-spacing: 0.04em;
}

h1 {
  font-size: clamp(1.6rem, 2.2vw, 2.4rem);
}

h2 {
  font-size: 1.1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid rgba(140, 183, 196, 0.2);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.75rem;
  letter-spacing: 0.18em;
}

.topbar-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  padding: 1rem;
}

.card {
  grid-column: span 4;
  background: var(--panel);
  border: 1px solid rgba(140, 183, 196, 0.2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem;
  animation: fade-in 420ms ease both;
}

.card.wide {
  grid-column: span 8;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.row.compact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid rgba(140, 183, 196, 0.25);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  border-radius: 10px;
  padding: 0.56rem 0.62rem;
}

textarea {
  resize: vertical;
}

.btn {
  border: none;
  background: var(--accent);
  color: #18232a;
  font-weight: 700;
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

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

.btn.secondary {
  background: #6cc3dd;
}

.btn.ghost {
  background: transparent;
  border: 1px solid rgba(140, 183, 196, 0.4);
  color: var(--text);
}

.badge,
.status-dot {
  font-size: 0.75rem;
  padding: 0.2rem 0.45rem;
  border: 1px solid rgba(140, 183, 196, 0.3);
  border-radius: 999px;
  color: var(--muted);
}

.badge.bridge-online  { color: #4caf7d; border-color: #4caf7d55; }
.badge.bridge-offline { color: var(--muted); border-color: rgba(140,183,196,0.3); }
.badge.bridge-error   { color: #e05c5c; border-color: #e05c5c55; }

.hint {
  margin: 0 0 0.7rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.fleet-water-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  border: 1px solid rgba(108, 195, 221, 0.45);
  color: #8fe0f1;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.alarm-category-group {
  border: 1px solid rgba(140, 183, 196, 0.25);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.7rem;
}

.alarm-category-group legend {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 0 0.3rem;
}

.alarm-check-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
  color: var(--text);
}

.alarm-check-item input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
}

.alarm-resource-tabs {
  border: 1px solid rgba(140, 183, 196, 0.2);
  border-radius: 10px;
  padding: 0.6rem;
  margin-bottom: 0.6rem;
  background: rgba(0, 0, 0, 0.14);
}

.alarm-plan-hint {
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid rgba(242, 177, 52, 0.22);
  background: rgba(242, 177, 52, 0.08);
  margin-bottom: 0.6rem;
}

.alarm-sequence-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
}

.alarm-sequence-chip {
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  border: 1px solid rgba(108, 195, 221, 0.3);
  background: rgba(108, 195, 221, 0.1);
  color: var(--text);
  font-size: 0.8rem;
}

.alarm-multi-select {
  min-height: 9rem;
}

.alarm-tab-panel {
  margin-bottom: 0.6rem;
}

.btn.active-tab {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(242, 177, 52, 0.38);
}

body.overlay-focus-mode {
  overflow: hidden;
  background: linear-gradient(135deg, #03090f, #071821 52%, #0a2430);
}

body.overlay-focus-mode .topbar {
  display: none;
}

body.overlay-focus-mode .layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 0;
  padding: 0;
  height: 100vh;
}

body.overlay-focus-mode .layout > .card {
  display: none;
}

body.overlay-focus-mode #mapPanel,
body.overlay-focus-mode #dispatchPanel {
  display: block;
}

body.overlay-focus-mode #mapPanel {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  padding: 0;
  z-index: 1;
}

body.overlay-focus-mode #mapPanel .card-head,
body.overlay-focus-mode #mapPanel .row {
  display: none;
}

body.overlay-focus-mode .map-style-tabs {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  z-index: 40;
  margin: 0;
  padding: 0.48rem;
  border-radius: 12px;
  background: rgba(5, 20, 28, 0.62);
  border: 1px solid rgba(108, 195, 221, 0.24);
  backdrop-filter: blur(3px);
}

body.overlay-focus-mode #map {
  width: 100%;
  height: 100vh;
  margin: 0;
  border-radius: 0;
}

body.overlay-focus-mode #dispatchPanel {
  grid-column: 1;
  grid-row: 1;
  position: relative;
  z-index: 5;
  height: 100vh;
  overflow-y: auto;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: linear-gradient(180deg, rgba(6, 20, 28, 0.95), rgba(8, 26, 34, 0.93));
  border-right: 1px solid rgba(108, 195, 221, 0.22);
  padding: 1.1rem;
}

body.overlay-focus-mode #dispatchPanel .card-head {
  margin: 0 0 0.8rem;
}

body.overlay-focus-mode #generateIncidentBtn {
  width: 100%;
  max-width: 360px;
  border: 1px solid rgba(108, 195, 221, 0.45);
  background: rgba(8, 30, 40, 0.88);
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42);
}

body.overlay-focus-mode #generateIncidentBtn:hover {
  background: rgba(12, 40, 53, 0.92);
}

@media (max-width: 980px) {
  body.overlay-focus-mode .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  body.overlay-focus-mode #dispatchPanel {
    grid-column: 1;
    grid-row: 1;
    height: auto;
    border-right: none;
    border-bottom: 1px solid rgba(108, 195, 221, 0.22);
  }

  body.overlay-focus-mode #mapPanel {
    grid-column: 1;
    grid-row: 2;
  }

  body.overlay-focus-mode #map {
    height: calc(100vh - 110px);
  }
}

.leaflet-popup-content-wrapper {
  background: linear-gradient(180deg, #0a1d27 0%, #07161f 100%);
  color: var(--text);
  border: 1px solid rgba(108, 195, 221, 0.32);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.45);
}

.leaflet-popup-content {
  color: var(--text);
}

.leaflet-popup-tip {
  background: #07161f;
}

.leaflet-control-layers {
  background: #081722;
  color: var(--text);
  border: 1px solid rgba(108, 195, 221, 0.35);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.5);
  opacity: 1;
}

.leaflet-control-layers-expanded {
  padding: 0.55rem 0.65rem;
  min-width: 170px;
}

.leaflet-control-layers label {
  color: var(--text);
  font-size: 0.82rem;
}

.leaflet-control-layers-toggle {
  filter: invert(1) hue-rotate(160deg) saturate(0.8);
}

.modal-dialog {
  border: none;
  padding: 0;
  background: transparent;
  position: fixed;
  top: 50%;
  left: 50%;
  right: auto;
  transform: translate(-50%, -50%);
  margin: 0;
  max-width: min(640px, calc(100vw - 1.5rem));
  width: min(640px, calc(100vw - 1.5rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  color: var(--text);
  z-index: 1200;
}

.modal-dialog::backdrop {
  background: rgba(2, 10, 13, 0.76);
  backdrop-filter: blur(4px);
}

.modal-card {
  background: linear-gradient(180deg, rgba(12, 38, 46, 0.98), rgba(7, 21, 26, 0.98));
  border: 1px solid rgba(140, 183, 196, 0.28);
  border-radius: 18px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.52);
  padding: 1rem;
}

.modal-card .card-head {
  margin-bottom: 1rem;
}

.modal-card .alarm-resource-tabs {
  max-height: 260px;
  overflow: auto;
}

.modal-card .list {
  max-height: 180px;
}

.modal-card .row:last-child {
  margin-bottom: 0;
}

.modal-card .row.compact {
  align-items: center;
}

.modal-card .hint {
  margin: 0;
}

.keyword-catalog {
  display: grid;
  grid-template-columns: 0.9fr 1.35fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.keyword-catalog-col {
  border: 1px solid rgba(140, 183, 196, 0.22);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.18);
  padding: 0.7rem;
  min-height: 220px;
}

.keyword-search-row {
  margin-bottom: 0.6rem;
}

.keyword-search-row label {
  width: 100%;
}

.keyword-favorite-head {
  margin-top: 0.7rem;
}

.keyword-favorite-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.7rem;
  min-height: 2rem;
}

.keyword-favorite-chip {
  border: 1px solid rgba(242, 177, 52, 0.5);
  background: rgba(242, 177, 52, 0.12);
  color: var(--text);
  border-radius: 999px;
  padding: 0.42rem 0.72rem;
  cursor: pointer;
  font-size: 0.82rem;
}

.keyword-favorite-chip:hover {
  filter: brightness(1.08);
}

.keyword-favorite-empty {
  color: var(--muted);
  font-size: 0.84rem;
  padding: 0.2rem 0;
}

.keyword-catalog-head {
  font-family: "Chakra Petch", sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.8rem;
  margin-bottom: 0.55rem;
}

.keyword-group-list,
.keyword-detail-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.keyword-group-btn,
.keyword-detail-btn {
  border: 1px solid rgba(140, 183, 196, 0.3);
  background: rgba(0, 0, 0, 0.16);
  color: var(--text);
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  text-align: left;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.keyword-group-btn {
  width: 100%;
}

.keyword-detail-btn {
  flex: 1 1 220px;
}

.keyword-detail-item {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
  width: 100%;
}

.keyword-star-btn {
  flex: 0 0 auto;
  min-width: 2.1rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(140, 183, 196, 0.3);
  background: rgba(0, 0, 0, 0.16);
  color: var(--muted);
  border-radius: 12px;
  cursor: pointer;
}

.keyword-star-btn.active {
  color: var(--accent);
  border-color: rgba(242, 177, 52, 0.7);
  background: rgba(242, 177, 52, 0.1);
}

.keyword-star-btn:hover {
  color: var(--accent);
}

.keyword-group-btn:hover,
.keyword-detail-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(108, 195, 221, 0.75);
}

.keyword-group-btn.active,
.keyword-detail-btn.active {
  border-color: var(--accent);
  background: rgba(242, 177, 52, 0.12);
  box-shadow: inset 0 0 0 1px rgba(242, 177, 52, 0.3);
}

.keyword-btn-title {
  display: block;
  font-weight: 700;
  color: var(--text);
}

.keyword-btn-meta {
  display: block;
  margin-top: 0.18rem;
  font-size: 0.78rem;
  color: var(--muted);
}

#map.map-pick-active {
  cursor: crosshair;
}

#map.map-pick-active .leaflet-container {
  cursor: crosshair;
}

.log,
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 220px;
  overflow: auto;
}

.log li,
.list li {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(140, 183, 196, 0.16);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  display: flex;
  flex-direction: column;
}

.list li.clickable-entry {
  cursor: pointer;
}

.list li.clickable-entry:hover,
.list li.clickable-entry:focus-visible {
  border-color: rgba(108, 195, 221, 0.7);
  background: rgba(108, 195, 221, 0.12);
  outline: none;
}

.primary {
  color: var(--text);
}

.secondary-line {
  color: var(--muted);
  font-size: 0.82rem;
}

.list-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

.btn-small {
  background: rgba(108, 195, 221, 0.2);
  border: 1px solid rgba(108, 195, 221, 0.5);
  color: #6cc3dd;
  padding: 0.3rem 0.6rem;
  border-radius: 5px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-small:hover {
  background: rgba(108, 195, 221, 0.4);
  border-color: #6cc3dd;
}

#map {
  width: 100%;
  height: 320px;
  border-radius: 12px;
  margin-bottom: 0.7rem;
}

#map.map-theme-dark .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) saturate(0.7) brightness(0.82) contrast(1.08);
}

.map-style-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
}

.map-style-tab {
  border: 1px solid rgba(140, 183, 196, 0.35);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.38rem 0.72rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.map-style-tab.active {
  border-color: rgba(242, 177, 52, 0.82);
  color: #ffe1a4;
  background: rgba(242, 177, 52, 0.16);
}

.map-style-tabs {
  display: none !important;
}

.pager-preview {
  margin-top: 0.6rem;
  border-radius: 12px;
  border: 1px dashed rgba(140, 183, 196, 0.4);
  padding: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

body.pager-classic .pager-preview {
  background: rgba(242, 177, 52, 0.2);
}

body.pager-nightops .pager-preview {
  background: rgba(108, 195, 221, 0.2);
}

body.pager-highcontrast .pager-preview {
  background: #ffffff;
  color: #000000;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1200px) {
  .card,
  .card.wide {
    grid-column: span 6;
  }
}

@media (max-width: 860px) {
  .topbar {
    position: static;
  }

  .card,
  .card.wide {
    grid-column: span 12;
  }

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