:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f5f7fa;
  color: #1d2733;
}

.app-header {
  padding: 1rem 1.25rem;
  background: #13233a;
  color: #fff;
}

.app-header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
}

.app-header p {
  margin: 0;
  opacity: 0.9;
}

.app-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1rem;
  padding: 1rem;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: calc(100vh - 120px);
  overflow: auto;
  padding-right: 0.35rem;
}

.panel {
  background: #fff;
  border: 1px solid #d7dee7;
  border-radius: 8px;
  padding: 0.75rem;
}

.panel h2 {
  margin: 0 0 0.55rem;
  font-size: 1rem;
}

.hidden {
  display: none;
}

.mode-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

label {
  display: block;
  margin: 0.3rem 0;
  font-size: 0.9rem;
  font-weight: 600;
}

select,
button,
.file-input-label {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid #bcc7d4;
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
}

button {
  cursor: pointer;
}

button:hover {
  background: #f1f5f9;
}

button.danger {
  border-color: #e09aa2;
  color: #7f1d1d;
}

.button-row {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.button-row > * {
  flex: 1;
}

.file-input-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
}

.file-input-label input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.subtle {
  margin: 0.45rem 0 0;
  color: #5b6b7f;
  font-size: 0.85rem;
}

.status {
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

.status.info {
  background: #e9f2ff;
  color: #1e3a5f;
}

.status.warn {
  background: #fff3d6;
  color: #614400;
}

.status.error {
  background: #fde8ea;
  color: #7f1d1d;
}

.map-panel {
  min-width: 0;
}

#mapViewport {
  width: 100%;
  height: calc(100vh - 120px);
  border: 1px solid #d7dee7;
  border-radius: 8px;
  background: #fff;
  overflow: auto;
  cursor: grab;
}

#mapStage {
  position: relative;
  display: inline-block;
}

#mapImage {
  display: block;
  max-width: none;
}

#mapCanvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#mapViewport:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

#mapViewport.panning {
  cursor: grabbing;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th,
td {
  border-bottom: 1px solid #e5ebf2;
  text-align: left;
  padding: 0.35rem 0.3rem;
  vertical-align: top;
}

thead th {
  background: #f8fafc;
  position: sticky;
  top: 0;
}

.table-wrap {
  margin-top: 0.5rem;
  max-height: 280px;
  overflow: auto;
  border: 1px solid #e5ebf2;
  border-radius: 6px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.6rem;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: #5b6b7f;
}

.legend-title {
  width: 100%;
  font-weight: 600;
  color: #1d2733;
  font-size: 0.82rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 4px;
  border-radius: 2px;
}

.leg-tooltip {
  position: absolute;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(30, 41, 59, 0.35);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  color: #0f172a;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  transform: translate(-50%, -50%);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: normal;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
}

@media (max-width: 1080px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .control-panel,
  #mapViewport {
    max-height: none;
    height: auto;
  }
}
