:root {
  color-scheme: light;
  --bg: #f4f6f1;
  --panel: #ffffff;
  --ink: #1c2522;
  --muted: #65746f;
  --line: #d8ded8;
  --brand: #0b766d;
  --brand-deep: #07524d;
  --accent: #c2412f;
  --warn: #b7791f;
  --valid: #16804c;
  --shadow: 0 18px 48px rgba(24, 37, 35, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background: var(--bg);
}

body.auth-pending {
  overflow: hidden;
}

body.auth-pending .app-shell {
  display: none;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(248, 250, 252, 0.92), rgba(248, 250, 252, 0.94)),
    url("https://tile.openstreetmap.org/7/98/54.png");
  background-size: cover;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(340px, 3fr);
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.map-region {
  position: relative;
  min-width: 0;
  border-right: 1px solid var(--line);
}

#map {
  width: 100%;
  height: 100%;
  background: #dfe8e1;
}

.map-controls {
  position: absolute;
  top: 18px;
  left: 64px;
  z-index: 600;
  display: flex;
  width: min(620px, calc(100% - 92px));
  gap: 10px;
  align-items: flex-start;
}

.search-box {
  position: relative;
  min-width: 0;
  flex: 1;
}

.search-box input {
  width: 100%;
  height: 42px;
  padding: 0 13px;
  border: 1px solid rgba(216, 222, 216, 0.98);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 30px rgba(24, 37, 35, 0.13);
  font: inherit;
  font-size: 14px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11, 118, 109, 0.15), 0 12px 30px rgba(24, 37, 35, 0.13);
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.search-results button {
  display: grid;
  width: 100%;
  gap: 3px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background: #ffffff;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.search-results button:last-child {
  border-bottom: 0;
}

.search-results button:hover,
.search-results button:focus {
  background: #eef5f1;
  outline: none;
}

.search-results small,
.search-empty {
  color: var(--muted);
  font-size: 12px;
}

.search-empty {
  padding: 12px;
}

.mode-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid rgba(216, 222, 216, 0.98);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 30px rgba(24, 37, 35, 0.13);
}

.mode-button {
  height: 42px;
  padding: 0 13px;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--brand-deep);
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 760;
  cursor: pointer;
}

.mode-button:last-child {
  border-right: 0;
}

.mode-button.is-active {
  color: #ffffff;
  background: var(--brand);
}

.map-status {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 500;
  max-width: min(460px, calc(100% - 36px));
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  color: #12201d;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.4;
}

.map-status.is-error {
  color: #711c16;
  border-color: rgba(194, 65, 47, 0.35);
}

.right-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: var(--panel);
}

.admin-panel {
  background: #fff7ed;
}

.panel-header {
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.08;
}

.panel-content {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 22px 24px 28px;
}

.empty-state {
  display: grid;
  min-height: 54vh;
  align-content: center;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state h2 {
  margin: 16px 0 8px;
  color: var(--ink);
  font-size: 22px;
}

.empty-state p {
  max-width: 34ch;
  line-height: 1.55;
}

.empty-icon {
  width: 56px;
  height: 56px;
  border: 2px solid var(--brand);
  border-radius: 50%;
  background:
    linear-gradient(90deg, transparent 48%, rgba(11, 118, 109, 0.16) 50%, transparent 52%),
    linear-gradient(0deg, transparent 48%, rgba(11, 118, 109, 0.16) 50%, transparent 52%);
}

.unit-summary {
  display: grid;
  gap: 16px;
}

.unit-title-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

.unit-title h2 {
  margin: 0 0 6px;
  font-size: 25px;
  line-height: 1.15;
}

.unit-type {
  color: var(--muted);
  font-size: 14px;
}

.badge {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
}

.badge.valid {
  color: #0b5634;
  background: #dff4e9;
}

.badge.pending {
  color: #7c4d08;
  background: #f8eccb;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.meta-item,
.remarks,
.status-group,
.person-row,
.roster-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.meta-item {
  padding: 12px;
}

.label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.value {
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.38;
}

.remarks {
  padding: 13px 14px;
  color: #35433f;
  line-height: 1.5;
}

.viewer-notice {
  padding: 12px 14px;
  border: 1px solid rgba(11, 118, 109, 0.22);
  border-radius: 8px;
  color: #155e75;
  background: #ecfeff;
  font-size: 13px;
  font-weight: 720;
  line-height: 1.5;
}

.strength-summary {
  display: grid;
  gap: 12px;
}

.location-editor {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.movement-coordinate-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.movement-coordinate-fields label {
  display: grid;
  gap: 6px;
}

.movement-coordinate-fields input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
  font-size: 13px;
  outline: none;
}

.movement-coordinate-fields input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11, 118, 109, 0.13);
}

.strength-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.strength-group {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.strength-group h4 {
  margin: 0 0 10px;
  color: var(--brand-deep);
  font-size: 14px;
}

.strength-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.strength-row strong {
  color: var(--ink);
}

.strength-footnotes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.movement-summary {
  display: grid;
  gap: 10px;
}

.movement-list {
  display: grid;
  gap: 10px;
}

.movement-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--warn);
  border-radius: 8px;
  background: #ffffff;
}

.movement-card.is-stopped {
  border-left-color: var(--muted);
  opacity: 0.78;
}

.movement-card-heading {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}

.movement-status {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.movement-status.active {
  background: var(--warn);
}

.movement-edit-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.movement-editor-state {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f8faf9;
  font-size: 12px;
  font-weight: 700;
}

.movement-editor-state.is-new {
  border-color: rgba(217, 119, 6, 0.4);
  color: #7c2d12;
  background: #fff7ed;
}

.movement-edit-chip {
  display: inline-flex;
  min-height: 34px;
  max-width: 100%;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #ffffff;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.movement-edit-chip span {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.movement-edit-chip small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.movement-edit-chip.is-active {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(13, 132, 120, 0.16);
}

.compact-button {
  justify-self: start;
}

.movement-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.admin-login {
  display: grid;
  gap: 16px;
  max-width: 420px;
  width: min(420px, 100%);
  margin: 0 auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.admin-login h2 {
  margin-bottom: 8px;
  font-size: 22px;
}

.admin-login p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.admin-login label {
  display: grid;
  gap: 7px;
}

.admin-login input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  font: inherit;
  background: #ffffff;
}

.admin-login input:focus {
  outline: 3px solid rgba(11, 118, 109, 0.18);
  outline-offset: 1px;
}

.admin-session {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.admin-session button {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--brand-deep);
  background: #ffffff;
  font: inherit;
  font-size: 12px;
  font-weight: 760;
  cursor: pointer;
}

.admin-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.admin-tab-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--brand-deep);
  background: #ffffff;
  font: inherit;
  font-size: 12px;
  font-weight: 780;
  cursor: pointer;
}

.admin-tab-button.is-active {
  color: #ffffff;
  background: var(--brand);
}

.admin-tab-panel {
  display: grid;
  gap: 12px;
}

.admin-help {
  padding: 10px 12px;
  border: 1px solid rgba(11, 118, 109, 0.18);
  border-radius: 8px;
  color: #155e75;
  background: #ecfeff;
  font-size: 13px;
  line-height: 1.45;
}

.assignment-warning {
  padding: 10px 12px;
  border: 1px solid rgba(194, 65, 47, 0.28);
  border-radius: 8px;
  color: #7c2d12;
  background: #fff7ed;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.section-title h3 {
  margin: 0;
  font-size: 17px;
}

.section-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.count-pill {
  min-width: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--brand);
  font-size: 12px;
  font-weight: 750;
  text-align: center;
}

.status-groups {
  display: grid;
  gap: 12px;
}

.status-group {
  overflow: hidden;
}

.status-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  background: #eef5f1;
  font-weight: 780;
}

.person-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.person-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  padding: 9px;
  background: #ffffff;
}

.person-row.is-clickable {
  cursor: pointer;
}

.person-row.is-clickable:hover,
.person-row.is-clickable:focus {
  outline: 2px solid rgba(11, 118, 109, 0.18);
  outline-offset: 1px;
  background: #f7fbfa;
}

.open-history-hint {
  align-self: center;
  color: var(--brand);
  font-size: 12px;
  font-weight: 780;
}

.person-actions {
  display: grid;
  gap: 6px;
}

.person-actions button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  color: var(--brand-deep);
  background: #e7f1ee;
  font: inherit;
  font-size: 12px;
  font-weight: 760;
  cursor: pointer;
}

.person-photo,
.person-photo-fallback {
  width: 46px;
  height: 46px;
  border-radius: 8px;
}

.person-photo {
  object-fit: cover;
}

.person-photo-fallback {
  display: grid;
  place-items: center;
  color: #ffffff;
  background: var(--brand-deep);
  font-weight: 800;
}

.person-name {
  margin: 0 0 3px;
  overflow-wrap: anywhere;
  font-weight: 760;
}

.person-detail {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.career-panel {
  display: grid;
  gap: 16px;
}

.career-profile {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.career-profile h2 {
  margin-bottom: 8px;
  overflow-wrap: anywhere;
  font-size: 24px;
}

.career-photo,
.career-photo-fallback {
  width: 72px;
  height: 72px;
  border-radius: 8px;
}

.career-photo {
  object-fit: cover;
}

.career-photo-fallback {
  display: grid;
  place-items: center;
  color: #ffffff;
  background: var(--brand-deep);
  font-size: 22px;
  font-weight: 850;
}

.career-meta,
.career-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.career-meta span,
.career-item-meta span {
  display: inline-grid;
  gap: 2px;
  min-width: 92px;
  padding: 7px 9px;
  border-radius: 8px;
  color: var(--ink);
  background: #eef5f1;
  font-size: 12px;
  line-height: 1.25;
}

.career-meta strong,
.career-item-meta strong {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.career-timeline {
  display: grid;
  gap: 10px;
}

.career-item {
  display: grid;
  gap: 10px;
  padding: 13px;
  border-left: 3px solid var(--brand);
  border-radius: 8px;
  background: #ffffff;
}

.career-item h4 {
  margin: 0 0 4px;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.career-item p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.roster-form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.roster-editor-title {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.roster-fields {
  display: grid;
  gap: 10px;
}

.roster-fields label {
  display: grid;
  gap: 6px;
}

.roster-fields input,
.roster-fields select,
.roster-fields textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
  font-size: 14px;
  outline: none;
}

.roster-fields input:focus,
.roster-fields select:focus,
.roster-fields textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11, 118, 109, 0.13);
}

.roster-fields textarea {
  resize: vertical;
}

.person-suggestions {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.person-suggestions button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background: #ffffff;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.person-suggestions button:last-child {
  border-bottom: 0;
}

.person-suggestions button:hover,
.person-suggestions button:focus {
  background: #eef5f1;
  outline: none;
}

.person-suggestions small {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.edit-roster-button {
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 760;
  cursor: pointer;
}

.primary-button {
  min-height: 38px;
  padding: 0 14px;
  color: #ffffff;
  background: var(--brand);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.secondary-button,
.edit-roster-button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--brand-deep);
  background: #e7f1ee;
}

.danger-button {
  color: #7f1d1d;
  background: #fee2e2;
}

.edit-roster-button {
  align-self: center;
}

.form-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.form-status.is-error {
  color: #9a2b20;
}

.empty-roster {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfa;
  line-height: 1.5;
}

.unit-div-icon {
  border: 0;
  background: transparent;
}

.movement-div-icon {
  border: 0;
  background: transparent;
}

.unit-marker {
  position: relative;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 3px solid #ffffff;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 6px 18px rgba(7, 82, 77, 0.35);
}

.unit-marker::after {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffffff;
}

.unit-marker-image {
  width: 42px;
  height: 42px;
  overflow: hidden;
  border-color: #ffffff;
  color: #ffffff;
  background:
    var(--unit-icon-url) center / contain no-repeat,
    linear-gradient(135deg, #0b766d, #c2412f);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.3);
}

.unit-marker-image::after {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  border: 1px solid rgba(15, 23, 42, 0.18);
  background: transparent;
  pointer-events: none;
}

.unit-marker-image .unit-marker-fallback {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: #ffffff;
  font-size: 10px;
  font-weight: 850;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  opacity: 0;
}

.unit-marker-image:not([style*="url('http"]) .unit-marker-fallback {
  opacity: 1;
}

.movement-marker {
  display: block;
  width: 28px;
  height: 28px;
  border: 3px solid #ffffff;
  border-radius: 50% 50% 50% 0;
  background: var(--warn);
  box-shadow: 0 8px 20px rgba(120, 53, 15, 0.32);
  transform: rotate(-45deg);
}

.movement-marker::after {
  content: "";
  position: absolute;
  top: 7px;
  left: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffffff;
}

.movement-marker.is-draft {
  background: #2563eb;
}

.leaflet-popup-content {
  min-width: 180px;
  margin: 12px 14px;
  line-height: 1.45;
}

.popup-title {
  margin-bottom: 4px;
  font-weight: 800;
}

.popup-type {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 58vh 42vh;
  }

  .map-region {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .right-panel {
    min-height: 0;
  }

  .panel-header {
    padding: 18px 18px 14px;
  }

  .panel-content {
    padding: 16px 18px 22px;
  }

  .map-controls {
    left: 58px;
    width: calc(100% - 76px);
  }
}

@media (max-width: 560px) {
  .app-shell {
    grid-template-rows: 52vh 48vh;
  }

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

  .movement-meta {
    grid-template-columns: 1fr;
  }

  .unit-title-row {
    flex-direction: column;
  }

  .badge {
    align-self: flex-start;
  }

  .person-row {
    grid-template-columns: 46px minmax(0, 1fr);
  }

  .edit-roster-button {
    grid-column: 1 / -1;
  }

  .map-controls {
    left: 12px;
    right: 12px;
    width: auto;
    flex-direction: column;
  }

  .mode-toggle,
  .search-box {
    width: 100%;
  }

  .mode-button {
    flex: 1;
  }
}
