:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --bg-hover: #f4f4f4;
  --border: #e0e0e0;
  --text: #111111;
  --text-2: #555555;
  --text-3: #999999;
  --accent: #f6821f;
  --accent-dim: rgba(246, 130, 31, 0.07);
  --green: #16a34a;
  --blue: #2563eb;
  --red: #dc2626;
  --shadow: 0 18px 45px rgba(17, 17, 17, 0.08);
  --radius: 18px;
  --radius-sm: 12px;
  --content: 1180px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 68px;
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(250, 250, 250, 0.92);
  backdrop-filter: blur(16px);
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 1.02rem;
  font-weight: 760;
  text-decoration: none;
  white-space: nowrap;
}

.app-brand::before {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 5px var(--accent-dim);
  content: "";
}

.app-header nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

.app-header nav a,
.identity-label,
.btn {
  border-radius: 999px;
}

.app-header nav a {
  padding: 8px 12px;
  color: var(--text-2);
  font-size: 0.94rem;
  font-weight: 650;
  text-decoration: none;
}

.app-header nav a:hover,
.app-header nav a[aria-current="page"] {
  background: var(--accent-dim);
  color: var(--accent);
}

.app-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-2);
  font-size: 0.9rem;
}

.identity-label {
  max-width: 220px;
  overflow: hidden;
  padding: 7px 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-button,
.btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-weight: 700;
}

.logout-button {
  padding: 8px 12px;
  border-radius: 999px;
}

.logout-button:hover,
.btn:hover {
  border-color: rgba(246, 130, 31, 0.45);
  background: var(--accent-dim);
}

#main-content,
.login-shell {
  width: min(100%, var(--content));
  margin: 0 auto;
  padding: 38px 24px 56px;
}

.page-shell,
.page-stack {
  display: grid;
  gap: 22px;
}

.page-title {
  display: grid;
  gap: 6px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1.04;
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.08rem;
  letter-spacing: -0.02em;
}

.page-description {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--text-2);
  font-size: 1rem;
}

.card,
.login-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: 0 1px 0 rgba(17, 17, 17, 0.02);
}

.card {
  padding: 22px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  position: relative;
  overflow: hidden;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}

.stat-card::after {
  position: absolute;
  right: -28px;
  bottom: -36px;
  width: 92px;
  height: 92px;
  border-radius: 999px;
  background: var(--accent-dim);
  content: "";
}

.stat-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-2);
  font-size: 0.8rem;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-value {
  position: relative;
  z-index: 1;
  display: block;
  font-size: 1.75rem;
  font-weight: 820;
  letter-spacing: -0.04em;
}

.filter-form,
.import-form,
.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.filter-label {
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 760;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
  width: 138px;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  outline: none;
}

.file-field {
  flex: 1 1 320px;
}

.file-field input[type="file"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-2);
  cursor: pointer;
}

.file-field input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background-color 160ms ease;
}

.file-field input[type="file"]::file-selector-button:hover {
  border-color: rgba(246, 130, 31, 0.45);
  background: var(--accent-dim);
}

.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-dim);
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 1px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-2);
  font-weight: 760;
  user-select: none;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease;
}

.chip:hover {
  border-color: rgba(246, 130, 31, 0.35);
  background: var(--accent-dim);
}

.chip input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  display: inline-grid;
  place-content: center;
  transition:
    background-color 160ms ease,
    border-color 160ms ease;
}

.chip input[type="checkbox"]::before {
  content: "";
  width: 9px;
  height: 9px;
  transform: scale(0);
  transition: transform 160ms ease;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  background: #ffffff;
}

.chip input[type="checkbox"]:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.chip input[type="checkbox"]:checked::before {
  transform: scale(1);
}

.chip:has(input:checked) {
  border-color: rgba(246, 130, 31, 0.45);
  background: var(--accent-dim);
  color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 16px;
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  border-color: #e47313;
  background: #e47313;
}

.table-card {
  padding: 0;
}

/* ── API docs code blocks (Prism.js) ── */

[data-page="api-docs"] pre {
  margin: 12px 0;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

[data-page="api-docs"] code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  font-size: 0.88rem;
}

[data-page="api-docs"] :not(pre) > code {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-hover);
  font-size: 0.88em;
}

.table-header,
.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
}

.table-header {
  border-bottom: 1px solid var(--border);
}

.table-summary,
.status-text {
  margin: 0;
  color: var(--text-2);
  font-size: 0.92rem;
}

.table-scroll {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.data-table tbody tr {
  transition:
    background-color 160ms ease,
    color 160ms ease;
}

.data-table tbody tr[data-tower-id] {
  cursor: pointer;
}

.data-table tbody tr:hover {
  background: var(--bg-hover);
}

.empty-row td {
  padding: 34px 16px;
  color: var(--text-3);
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 800;
}

.badge-lte {
  background: rgba(37, 99, 235, 0.1);
  color: var(--blue);
}

.badge-nr {
  background: rgba(22, 163, 74, 0.1);
  color: var(--green);
}

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

.pagination-meta {
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 700;
}

.alert-region {
  min-height: 0;
}

.alert {
  padding: 13px 15px;
  border: 1px solid rgba(220, 38, 38, 0.22);
  border-radius: var(--radius-sm);
  background: rgba(220, 38, 38, 0.08);
  color: #991b1b;
  font-weight: 650;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(17, 17, 17, 0.45);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(100%, 980px);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--bg-card);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin-bottom: 0;
}

.modal-body {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(320px, 1.1fr);
  gap: 18px;
  padding: 22px;
}

.detail-list {
  display: grid;
  grid-template-columns: minmax(110px, 0.72fr) minmax(0, 1fr);
  gap: 10px 14px;
  margin: 0;
}

.summary-list {
  display: grid;
  grid-template-columns: minmax(150px, 0.32fr) minmax(0, 1fr);
  gap: 10px 16px;
  margin: 0;
}

.summary-list dt {
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.summary-list dd {
  margin: 0;
  font-weight: 760;
  word-break: break-word;
}

.detail-list dt {
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.detail-list dd {
  margin: 0;
  font-weight: 700;
  word-break: break-word;
}

.map-card {
  position: relative;
  overflow: hidden;
  min-height: 520px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.modal-body .map-card {
  min-height: 360px;
}

.map-canvas,
.detail-map {
  width: 100%;
  min-height: 280px;
}

.map-canvas {
  height: min(68vh, 720px);
}

.detail-map {
  height: 100%;
  border-radius: var(--radius-sm);
}

.map-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.popup-card {
  display: grid;
  gap: 4px;
  min-width: 180px;
}

.popup-title {
  font-weight: 800;
}

.popup-line {
  color: var(--text-2);
  font-size: 0.88rem;
}

.popup-link {
  width: max-content;
  margin-top: 4px;
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.popup-link:hover {
  text-decoration: underline;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.login-card {
  width: min(100%, 430px);
  padding: 40px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin-bottom: 8px;
  font-size: 2.25rem;
}

.login-card p {
  color: var(--text-2);
}

.login-card form {
  display: grid;
  gap: 20px;
  margin-top: 28px;
}

.login-card .field {
  gap: 8px;
}

.login-card .field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
}

.login-card .btn {
  width: 100%;
  margin-top: 8px;
}

.login-card .alert {
  margin: 16px 0 0;
}

.login-footer {
  margin: 24px 0 0;
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal-body {
    grid-template-columns: 1fr;
  }

  .detail-map {
    height: 360px;
  }
}

@media (max-width: 768px) {
  .app-header {
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 18px;
  }

  .app-header nav {
    order: 3;
    width: 100%;
  }

  .app-identity {
    margin-left: auto;
  }

  #main-content,
  .login-shell {
    padding: 26px 16px 42px;
  }

  .card,
  .login-card {
    padding: 18px;
  }

  .stats-grid {
    gap: 10px;
  }

  .filter-form,
  .map-toolbar {
    align-items: stretch;
  }

  .field,
  .field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  .btn {
    width: 100%;
  }

  .chip-group {
    width: 100%;
  }

  .chip {
    flex: 1 1 120px;
    justify-content: center;
  }

  .table-header,
  .pagination-bar {
    padding: 16px 18px;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .modal-panel {
    max-height: calc(100vh - 24px);
    border-radius: 18px;
  }

  .modal-body,
  .modal-header {
    padding: 18px;
  }

  .modal-body .map-card {
    min-height: 280px;
  }

  .map-canvas {
    height: 62vh;
    min-height: 360px;
  }
}

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

  .identity-label {
    display: none;
  }

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