:root {
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.35;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: #f5f7fb;
  color: #1f2937;
  text-rendering: optimizeLegibility;
}

.topbar {
  padding: 0.9rem 1.25rem;
  background: #0f172a;
  color: #f8fafc;
  border-bottom: 1px solid #1e293b;
}

.topbar-inner {
  max-width: 1500px;
  margin: 0 auto;
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.topbar-subtitle {
  margin: 0.45rem 0 0;
  color: #cbd5e1;
  max-width: 86ch;
  font-size: 1.15rem;
  line-height: 1.45;
  text-wrap: pretty;
}

.topbar-link {
  color: #93c5fd;
  text-decoration: none;
  border-bottom: 1px solid rgba(147, 197, 253, 0.5);
  font-weight: 500;
}

.topbar-link:hover {
  color: #bfdbfe;
  border-bottom-color: rgba(191, 219, 254, 0.9);
}

.topbar-link:focus {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
  border-bottom-color: transparent;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1rem;
  padding: 1rem;
  max-width: 1500px;
  margin: 0 auto;
  min-width: 0;
}

.panel {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 0.85rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  min-width: 0;
}

.filters {
  align-self: start;
  position: sticky;
  top: 1rem;
}

.filters h2 {
  margin-top: 0;
  font-size: 1.05rem;
}

.filters-disclosure {
  min-width: 0;
}

.filters-disclosure summary {
  list-style: none;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 700;
  color: #1f2937;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}

.filters-disclosure summary::before {
  content: "▸";
  font-size: 0.85rem;
  transition: transform 0.15s ease;
}

.filters-disclosure[open] summary::before {
  transform: rotate(90deg);
}

.filters-disclosure summary::-webkit-details-marker {
  display: none;
}

.filters label {
  display: block;
  margin-bottom: 0.6rem;
  font-size: 0.88rem;
  color: #374151;
}

.filters input,
.filters select,
.filters button {
  width: 100%;
  margin-top: 0.25rem;
  min-height: 2.6rem;
  padding: 0.48rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font: inherit;
}

.filters input:focus,
.filters select:focus,
.filters button:focus,
.modal-close-btn:focus,
.link-button:focus {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.filters button {
  background: #111827;
  color: #ffffff;
  cursor: pointer;
}

.content {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

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

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 0.6rem;
}

.metric {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0.65rem;
}

.metric .label {
  font-size: 0.75rem;
  color: #6b7280;
}

.metric .value {
  margin-top: 0.2rem;
  font-weight: 600;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.panel-header small {
  color: #6b7280;
}

.filter-summary {
  margin: 0 0 0.55rem;
  font-size: 0.82rem;
  color: #4b5563;
}

#map {
  width: 100%;
  height: 420px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  max-width: 100%;
}

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}

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

.companies-table {
  min-width: 620px;
}

.contracts-table {
  min-width: 1040px;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.55rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 1;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:focus {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr:nth-child(even) {
  background: #fcfdff;
}

.link-button {
  border: none;
  background: none;
  color: #1d4ed8;
  padding: 0;
  margin: 0;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
  text-align: left;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
}

.modal-content {
  position: relative;
  width: min(980px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  overflow: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.95rem;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  background: #ffffff;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.08rem;
}

.modal-close-btn {
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #111827;
  border-radius: 6px;
  width: 2rem;
  height: 2rem;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.modal-body {
  padding: 0.85rem 0.95rem 1rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(200px, 1fr));
  gap: 0.35rem 1rem;
  margin-bottom: 0.85rem;
}

.detail-item {
  display: grid;
  gap: 0.1rem;
}

.detail-key {
  font-size: 0.74rem;
  color: #6b7280;
}

.detail-value {
  font-size: 0.88rem;
  word-break: break-word;
}

.modal-section-title {
  margin: 0.5rem 0;
  font-size: 0.95rem;
}

.inline-table-wrap {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: auto;
  max-height: 280px;
}

.json-block {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.78rem;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0.6rem;
}

.json-disclosure {
  margin-top: 0.65rem;
}

.json-disclosure-summary {
  list-style: none;
  cursor: pointer;
  color: #1f2937;
  font-size: 0.88rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.45rem;
}

.json-disclosure-summary::-webkit-details-marker {
  display: none;
}

.json-disclosure-summary .arrow {
  transition: transform 0.15s ease;
  font-size: 0.85rem;
}

.json-disclosure[open] .json-disclosure-summary .arrow {
  transform: rotate(180deg);
}

@media (max-width: 760px) {
  .topbar {
    padding: 0.9rem 0.9rem;
  }

  .topbar h1 {
    font-size: 1.55rem;
  }

  .topbar-subtitle {
    margin-top: 0.35rem;
    font-size: 0.95rem;
    line-height: 1.4;
  }

  .layout {
    padding: 0.55rem;
    gap: 0.65rem;
  }

  .panel {
    padding: 0.7rem;
    border-radius: 10px;
  }

  .panel-header {
    margin-bottom: 0.35rem;
  }

  .panel-header h2 {
    font-size: 1rem;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(110px, 1fr));
  }

  .metric .label {
    font-size: 0.7rem;
  }

  .metric .value {
    font-size: 0.98rem;
  }

  #map {
    height: 300px;
  }

  .table-wrap {
    max-height: 320px;
  }

  th,
  td {
    font-size: 0.82rem;
    padding: 0.46rem 0.48rem;
  }

  .modal {
    place-items: stretch;
  }

  .modal-content {
    width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }

  .modal-header {
    padding: 0.7rem 0.8rem;
  }

  .modal-header h2 {
    font-size: 1rem;
  }

  .modal-body {
    padding: 0.7rem 0.8rem 1rem;
  }

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

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

  .filters {
    position: static;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}