:root {
  --bg: #f5f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #64707d;
  --line: #d8dee5;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --shadow: 0 12px 36px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.shell,
.login-shell {
  display: grid;
  gap: 14px;
  min-height: 100vh;
  padding: 18px;
}

.login-shell {
  align-content: center;
  justify-items: center;
}

.toolbar,
.stats,
.map-section,
.grid-section,
.links-section,
.login-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel {
  width: min(560px, calc(100vw - 36px));
  border: 0;
  background: transparent;
  box-shadow: none;
  border-radius: 8px;
  padding: 0;
}

.login-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: stretch;
}

.login-form h2 {
  margin: 0 0 6px;
  font-size: 20px;
  line-height: 1.1;
}

.login-form span {
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
}

.login-form .error-text {
  color: var(--danger);
}

.login-message {
  margin: 16px 2px 0;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.login-message.error-text {
  color: var(--danger);
}

.toolbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: end;
  padding: 14px;
  border-radius: 8px;
}

.brand h1 {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.1;
}

.status-pill {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-pill.error {
  border-color: rgba(180, 35, 24, 0.35);
  color: var(--danger);
}

.filters {
  display: grid;
  grid-template-columns: minmax(130px, 0.65fr) minmax(180px, 0.85fr) minmax(170px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

input,
select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.login-form input {
  min-height: 54px;
  border: 2px solid #b8bdc3;
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
}

.login-form input::placeholder {
  color: #b8bdc3;
}

.password-control {
  position: relative;
  display: block;
}

.password-control input {
  padding-right: 74px;
}

.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  min-width: 48px;
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transform: translateY(-50%);
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.primary-button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 8px 15px;
  font-weight: 700;
  cursor: pointer;
}

.login-button {
  min-height: 58px;
  border-radius: 10px;
  font-size: 20px;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 13px;
  font-weight: 700;
  cursor: pointer;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border-radius: 8px;
}

.stats article {
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  border-right: 1px solid var(--line);
}

.stats article:last-child {
  border-right: 0;
}

.stats span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stats strong {
  font-size: 24px;
  line-height: 1;
}

.links-section {
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
}

.links-section summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  list-style: none;
}

.links-section summary::-webkit-details-marker {
  display: none;
}

.links-section summary::before {
  content: ">";
  color: var(--accent);
}

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

.link-summary {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.links-content {
  min-width: 0;
  border-top: 1px solid var(--line);
  padding: 12px 14px 14px;
}

.link-form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) minmax(160px, 1.2fr) auto;
  gap: 10px;
  align-items: end;
}

.link-message {
  min-height: 20px;
  margin: 9px 0;
  color: var(--accent-strong);
  font-size: 13px;
}

.error-text {
  color: var(--danger);
}

.links-table-wrap {
  width: 100%;
  max-width: 100%;
  max-height: 280px;
  overflow: auto;
}

.links-table {
  min-width: 900px;
}

.link-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.link-actions button {
  min-height: 30px;
  white-space: nowrap;
  padding: 5px 9px;
  font-size: 12px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}

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

.map-section {
  position: relative;
  min-height: 44vh;
  overflow: hidden;
  border-radius: 8px;
}

.map,
.fallback-map {
  width: 100%;
  height: 44vh;
  min-height: 360px;
}

.fallback-map {
  position: relative;
  background:
    linear-gradient(rgba(23, 32, 42, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 32, 42, 0.08) 1px, transparent 1px),
    #ecf1f4;
  background-size: 44px 44px;
}

.fallback-dot {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(23, 32, 42, 0.28);
  transform: translate(-50%, -50%);
}

.fallback-dot::after {
  position: absolute;
  left: 50%;
  top: calc(100% + 6px);
  width: max-content;
  max-width: 160px;
  transform: translateX(-50%);
  color: var(--ink);
  content: attr(data-label);
  font-size: 11px;
  font-weight: 700;
}

.legend {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-width: min(540px, calc(100% - 24px));
  border: 1px solid rgba(216, 222, 229, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 8px;
  backdrop-filter: blur(8px);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.grid-section {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: clamp(280px, 34vh, 520px);
  min-height: 260px;
  overflow: hidden;
  border-radius: 8px;
}

.grid-header {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.segment {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(84px, 1fr));
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.segment-button {
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 700;
}

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

.segment-button.active {
  background: #e5f3f1;
  color: var(--accent-strong);
}

.last-updated {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable both-edges;
}

.table-wrap::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

.table-wrap::-webkit-scrollbar-track {
  background: #eef2f5;
}

.table-wrap::-webkit-scrollbar-thumb {
  border: 3px solid #eef2f5;
  border-radius: 999px;
  background: #98a6b3;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #718091;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef2f5;
  color: #465260;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

td {
  font-size: 13px;
}

.type-cell {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
}

.type-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.muted {
  color: var(--muted);
}

.empty-state {
  height: 96px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

@media (max-width: 980px) {
  .toolbar,
  .filters,
  .link-form,
  .login-form {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats article:nth-child(2) {
    border-right: 0;
  }

  .stats article:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 10px;
  }

  .grid-header {
    align-items: stretch;
    flex-direction: column;
  }

  .segment {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .map,
  .fallback-map {
    min-height: 310px;
  }

  .grid-section {
    height: 360px;
  }

  .login-form {
    gap: 16px;
  }

  .login-form span {
    font-size: 17px;
  }

  .login-form input {
    min-height: 52px;
    font-size: 17px;
  }

  .login-button {
    min-height: 56px;
    font-size: 19px;
  }
}
