:root {
  --bg: #f4f7fb;
  --surface: #fff;
  --ink: #182230;
  --muted: #617085;
  --line: #dce3ed;
  --brand: #155eef;
  --good: #087443;
  --bad: #b42318;
}

* { box-sizing: border-box; }

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

body {
  width: 100%;
  min-width: 0;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 Inter, Segoe UI, Arial, sans-serif;
  overflow-x: hidden;
}

.nav-toggle { position: fixed; opacity: 0; pointer-events: none; }

.site-header {
  width: 100%;
  max-width: 100%;
  min-height: 64px;
  background: #111827;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 max(24px, calc((100% - 1320px) / 2));
}

.header-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-menu-button {
  width: 40px;
  height: 40px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
}

.nav-menu-button svg,
.drawer-close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.brand {
  min-width: 0;
  flex: 0 0 auto;
  font-size: 20px;
  font-weight: 750;
  color: #fff;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.desktop-nav {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
}

.desktop-nav a,
.desktop-nav button {
  color: #d7deea;
  text-decoration: none;
  white-space: nowrap;
}

.nav-user {
  color: #9aa8bd;
  font-size: 12px;
  border-left: 1px solid #2b3546;
  padding-left: 14px;
  white-space: nowrap;
}

.desktop-nav form { margin: 0; }
.desktop-nav button { background: none; border: 0; cursor: pointer; padding: 0; }

.drawer-overlay,
.mobile-drawer {
  display: none;
}

main {
  width: 100%;
  min-width: 0;
  max-width: 1320px;
  margin: 0 auto;
  padding: 30px 24px 70px;
}

main > *,
section,
article,
form {
  min-width: 0;
}

h1 { font-size: 28px; line-height: 1.18; margin: 0 0 5px; }
h2 { margin-top: 32px; line-height: 1.25; }

.page-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 22px;
}

.page-title p { margin: 0; color: var(--muted); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.cards article,
.detail-grid article,
.login-card,
.word-card,
.upload-card,
.empty-card,
.analysis-chart {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.cards span { display: block; color: var(--muted); }
.cards strong { display: block; font-size: 28px; margin-top: 6px; }

.filters,
.bulk-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 14px;
  border-radius: 8px;
  margin: 18px 0;
}

input,
select,
button,
.button,
textarea {
  max-width: 100%;
  font: inherit;
  border: 1px solid #bfc9d8;
  border-radius: 7px;
  padding: 9px 12px;
  background: #fff;
  color: var(--ink);
}

input { min-width: 190px; }
textarea { width: 100%; min-height: 180px; resize: vertical; }
button, .button { cursor: pointer; text-decoration: none; display: inline-block; }
button:disabled { cursor: not-allowed; opacity: .55; }
.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.danger { border-color: #f2b8b5; color: var(--bad); }

.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

table { width: 100%; min-width: max-content; border-collapse: collapse; white-space: nowrap; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); background: #f9fbfd; }
td a { color: var(--brand); text-decoration: none; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 9px;
  background: #eef2f7;
}

.badge.active,
.badge.success { background: #dcfae6; color: var(--good); }
.badge.missing,
.badge.failed { background: #fee4e2; color: var(--bad); }
.badge.running { background: #fff1c2; color: #854a0e; }

.empty { text-align: center; color: var(--muted); padding: 34px; }
.login-card { max-width: 420px; margin: 8vh auto; }
.stack { display: grid; gap: 16px; }
.stack label { display: grid; gap: 6px; }
.alert { padding: 10px 14px; border-radius: 7px; margin: 0 0 14px; }
.alert.error { background: #fee4e2; color: var(--bad); }
.alert.success { background: #dcfae6; color: var(--good); }
.alert.info { background: #e8f1ff; color: #174ea6; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.detail-grid h3 { margin-top: 0; }
.detail-grid p { overflow-wrap: anywhere; }
.muted { color: var(--muted); }

.recently-new td,
.recently-revived td,
.new-customer-row td {
  font-weight: 700;
  background: #fffbea;
}

.recently-new td { background: #eefbf3; }

.revived-badge,
.new-customer-badge,
.new-host-badge {
  display: inline-block;
  margin-left: 7px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #fff1c2;
  color: #854a0e;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.new-customer-badge { background: #e8f1ff; color: #174ea6; }
.new-host-badge { background: #dcfae6; color: var(--good); }

.word-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 18px;
}

.word-card { align-self: start; }
.word-card h2,
.upload-card h2 { margin-top: 0; }
.word-list-form { display: inline; }
.word-list-form button { color: var(--bad); }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 18px 0;
  flex-wrap: wrap;
}

.pagination a { color: var(--ink); }
.upload-card, .empty-card { margin-bottom: 18px; }
.small-value { font-size: 17px !important; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag { padding: 6px 10px; border-radius: 999px; background: #e8f1ff; color: #174ea6; }

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0;
}

.tabs a {
  padding: 9px 13px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
}

.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.bulk-bar { align-items: center; margin-bottom: 10px; }
.bulk-bar input { min-width: auto; }
.conflict { color: #b54708; font-size: 17px; }

.analysis-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 390px);
  gap: 14px;
  align-items: stretch;
  margin: 18px 0;
}

.analysis-summary .cards { margin: 0; }
.chart-title { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.chart-title span, .chart-label span { color: var(--muted); }
.chart-title strong { font-size: 18px; }
.chart-row { display: grid; gap: 7px; margin: 13px 0; }
.chart-label { display: flex; justify-content: space-between; gap: 12px; }
.chart-track { height: 12px; border-radius: 999px; background: #edf1f7; overflow: hidden; }
.chart-track span { display: block; height: 100%; min-width: 2px; border-radius: inherit; }
.chart-track .matched { background: #087443; }
.chart-track .maptriks-only { background: #155eef; }
.chart-track .location-only { background: #b54708; }
.analysis-filters select, .analysis-filters input { max-width: 100%; }
.analysis-table-wrap { max-width: 100%; overflow-x: hidden; }
.analysis-table { width: 100%; min-width: 0; table-layout: fixed; white-space: normal; }
.analysis-table th, .analysis-table td {
  padding: 10px 11px;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.analysis-table th:nth-child(1), .analysis-table td:nth-child(1) { width: 36px; text-align: center; }
.analysis-table th:nth-child(2), .analysis-table td:nth-child(2) { width: 14%; }
.analysis-table th:nth-child(3), .analysis-table td:nth-child(3) { width: 18%; }
.analysis-table th:nth-child(4), .analysis-table td:nth-child(4) { width: 16%; }
.analysis-table th:nth-child(5), .analysis-table td:nth-child(5) { width: 24%; }
.analysis-table th:nth-child(6), .analysis-table td:nth-child(6) { width: 12%; }
.analysis-table th:nth-child(7), .analysis-table td:nth-child(7) { width: 8%; }
.analysis-table th:nth-child(8), .analysis-table td:nth-child(8) { width: 12%; font-size: 12px; }
.analysis-table input { min-width: auto; }
.analysis-tabs a { max-width: 100%; overflow-wrap: anywhere; }
.analysis-bulk label { display: flex; align-items: center; gap: 6px; min-width: 0; }
.analysis-bulk input { min-width: auto; }

@media (min-width: 900px) {
  .site-header { padding-left: 18px; padding-right: max(18px, calc((100% - 1320px) / 2)); }
  .desktop-nav { gap: 15px; }
  main:has(.analysis-page) { max-width: 1180px; margin-left: 0; margin-right: auto; padding-left: 18px; }
}

@media (max-width: 950px) {
  .analysis-summary { grid-template-columns: 1fr; }
  .analysis-table-wrap { overflow-x: auto; }
  .analysis-table { min-width: 820px; }
  .analysis-filters > * { flex: 1 1 220px; }
  .analysis-bulk > * { flex: 1 1 auto; }
}

@media (max-width: 850px) {
  .site-header {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: 56px;
    align-items: center;
    flex-direction: row;
    padding: 8px 12px;
    box-shadow: 0 1px 0 rgba(255,255,255,.08);
  }

  .header-main {
    width: 100%;
  }

  .nav-menu-button {
    flex: 0 0 auto;
    display: inline-flex;
  }

  .nav-menu-button:active,
  .drawer-close:active {
    background: rgba(255,255,255,.09);
  }

  .desktop-nav {
    display: none;
  }

  .nav-user {
    border-left: 0;
    padding-left: 0;
  }

  .drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: block;
    background: rgba(15, 23, 42, .42);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
  }

  .mobile-drawer {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    display: flex;
    width: min(280px, calc(100vw - 48px));
    max-width: calc(100vw - 48px);
    min-width: 0;
    flex-direction: column;
    background: #fff;
    color: var(--ink);
    box-shadow: 16px 0 42px rgba(16, 24, 40, .22);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }

  .nav-toggle:checked ~ .drawer-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .nav-toggle:checked ~ .mobile-drawer {
    transform: translateX(0);
  }

  .drawer-head {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px 10px 16px;
    border-bottom: 1px solid var(--line);
  }

  .drawer-brand {
    min-width: 0;
    color: var(--ink);
    font-size: 17px;
    font-weight: 800;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .drawer-close {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: var(--muted);
    cursor: pointer;
  }

  .drawer-nav {
    min-width: 0;
    display: grid;
    gap: 4px;
    padding: 10px;
  }

  .drawer-nav a,
  .drawer-nav button {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 0;
    border-radius: 8px;
    padding: 10px 12px;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-weight: 650;
    text-align: left;
    text-decoration: none;
  }

  .drawer-nav a:active,
  .drawer-nav button:active {
    background: #eef4ff;
  }

  .drawer-nav span {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: #eef4ff;
    color: var(--brand);
    font-size: 14px;
    font-weight: 800;
  }

  .drawer-nav form {
    margin: 6px 0 0;
    padding-top: 10px;
    border-top: 1px solid var(--line);
  }

  .drawer-user {
    margin: 8px 2px 0;
    padding: 12px;
    border-radius: 8px;
    background: #f6f8fb;
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
  }

  main {
    width: 100%;
    max-width: 100%;
    padding: 18px 10px 56px;
    overflow-x: hidden;
  }

  .page-title { align-items: flex-start; flex-direction: column; gap: 12px; }
  .page-title .button, .page-title form, .page-title button { width: 100%; }
  .word-layout { grid-template-columns: 1fr; }
  .filters > *, .bulk-bar > * { flex: 1 1 100%; }
  .filters button, .filters .button, .bulk-bar button { width: 100%; text-align: center; }
  input, select { width: 100%; min-width: 0; }
  .table-wrap {
    overflow: visible;
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  table {
    white-space: normal;
    border-collapse: separate;
    border-spacing: 0;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
  }

  th,
  td {
    border-bottom: 0;
    padding: 0;
    text-align: left;
  }

  td {
    display: grid;
    grid-template-columns: minmax(96px, 38%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
  }

  td:first-child {
    display: block;
    padding: 12px;
    background: #f9fbfd;
    font-weight: 750;
  }

  td:first-child::before {
    display: block;
    margin-bottom: 5px;
  }

  .empty {
    display: block;
    padding: 28px 14px;
    text-align: center;
  }

  .empty::before {
    content: none;
  }

  tr:has(.empty) {
    box-shadow: none;
  }

  .analysis-table {
    min-width: 0;
  }

  .analysis-table th,
  .analysis-table td {
    width: 100% !important;
    font-size: inherit;
  }

  .analysis-table td:first-child {
    display: grid;
    grid-template-columns: minmax(96px, 38%) minmax(0, 1fr);
    font-weight: 400;
  }

  .analysis-table td:first-child::before {
    margin-bottom: 0;
  }

  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards article { padding: 14px; }
  .cards strong { font-size: 24px; }
}

@media (max-width: 520px) {
  body { font-size: 13px; }
  h1 { font-size: 23px; }
  h2 { font-size: 18px; }
  .brand { font-size: 18px; }
  .cards { grid-template-columns: 1fr; }
  th, td { padding: 10px 11px; }
  .login-card { margin: 4vh auto; padding: 16px; }
  .tag { max-width: 100%; overflow-wrap: anywhere; }
  .new-host-badge, .revived-badge, .new-customer-badge { margin: 6px 0 0; }
}
