:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-subtle: #fbfbfc;
  --line: #e2e5e9;
  --line-strong: #cdd2d8;
  --text: #1f2328;
  --muted: #667085;
  --muted-strong: #475467;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --green: #067647;
  --green-soft: #ecfdf3;
  --amber: #946200;
  --amber-soft: #fff7e6;
  --red: #b42318;
  --red-soft: #fff1f0;
  --radius: 8px;
  --shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
  --transition: 160ms ease-out;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  gap: 12px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px 20px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
}

.title-group {
  min-width: 0;
}

.kicker {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  color: var(--text);
  font-size: 26px;
  font-weight: 680;
  line-height: 1.15;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.language-switch select {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 620;
  outline: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 999px;
  background: #98a2b3;
}

.status-pill.is-ready::before {
  background: var(--green);
}

.status-pill.is-error {
  color: var(--red);
}

.status-pill.is-error::before {
  background: var(--red);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 88px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 620;
  white-space: nowrap;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
}

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

.button-primary {
  border-color: #1d4ed8;
  background: var(--blue);
  color: #fff;
}

.button-primary:hover {
  background: #1d4ed8;
}

.button-secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted-strong);
}

.button-secondary:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.summary-panel,
.controls-panel,
.data-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-panel {
  display: grid;
  grid-template-columns: 1.2fr repeat(4, 1fr);
  overflow: hidden;
}

.summary-item {
  min-height: 74px;
  padding: 13px 14px;
  border-left: 1px solid var(--line);
}

.summary-item:first-child {
  border-left: 0;
}

.summary-primary {
  background: var(--surface-subtle);
}

.summary-item span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
  letter-spacing: 0;
}

.summary-item strong {
  display: block;
  color: var(--text);
  font-size: 28px;
  font-weight: 680;
  line-height: 1;
  letter-spacing: 0;
}

.controls-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1.45fr) repeat(3, minmax(138px, 0.45fr)) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
  letter-spacing: 0;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
  color: var(--text);
  outline: none;
  transition: background-color var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.field input {
  padding: 0 12px;
}

.field input::placeholder {
  color: #98a2b3;
}

.field select {
  padding: 0 34px 0 10px;
}

.field input:hover,
.field select:hover {
  border-color: var(--line-strong);
  background: #fff;
}

.field input:focus,
.field select:focus {
  border-color: rgba(37, 99, 235, 0.52);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.data-panel {
  overflow: hidden;
}

.table-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 56px;
  padding: 0 12px 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.table-count {
  margin: 0;
  color: var(--muted-strong);
  font-size: 14px;
  font-weight: 620;
}

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-status {
  min-width: 68px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.table-scroll {
  max-height: calc(100vh - 314px);
  min-height: 330px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1080px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

th,
td {
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 42px;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
  letter-spacing: 0;
}

td {
  height: 52px;
  color: var(--muted-strong);
}

tbody tr {
  background: var(--surface);
  transition: background-color var(--transition);
}

tbody tr:hover {
  background: #f8fafc;
}

.sort-button {
  width: 100%;
  min-height: 42px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  text-align: left;
}

.sort-button::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  vertical-align: middle;
}

.sort-button.is-asc::after {
  border-bottom: 6px solid var(--blue);
}

.sort-button.is-desc::after {
  border-top: 6px solid var(--blue);
}

.name-cell {
  min-width: 210px;
  color: var(--text);
  font-weight: 620;
}

.street-cell {
  min-width: 320px;
}

.mono {
  font-family: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 620;
  white-space: nowrap;
}

.badge-rdi-residential {
  border-color: #abefc6;
  background: var(--green-soft);
  color: var(--green);
}

.badge-rdi-commercial {
  border-color: #fedf89;
  background: var(--amber-soft);
  color: var(--amber);
}

.badge-rdi-unknown,
.badge-cmra-unknown {
  border-color: var(--line);
  background: #f2f4f7;
  color: var(--muted-strong);
}

.badge-cmra-n {
  border-color: #bfdbfe;
  background: var(--blue-soft);
  color: #1d4ed8;
}

.badge-cmra-y {
  border-color: #fecdca;
  background: var(--red-soft);
  color: var(--red);
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--blue);
  font-size: 13px;
  font-weight: 620;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}

.link-button:hover {
  border-color: #bfdbfe;
  background: var(--blue-soft);
  color: #1d4ed8;
}

.empty-state {
  padding: 42px 16px;
  color: var(--muted);
  font-weight: 620;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (max-width: 980px) {
  .app-shell {
    padding: 16px 14px 24px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

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

  .summary-item {
    border-top: 1px solid var(--line);
  }

  .summary-item:nth-child(-n + 2) {
    border-top: 0;
  }

  .summary-item:nth-child(odd) {
    border-left: 0;
  }

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

  .search-field {
    grid-column: 1 / -1;
  }

  .table-scroll {
    max-height: none;
  }
}

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

  h1 {
    font-size: 24px;
  }

  .summary-panel,
  .controls-panel {
    grid-template-columns: 1fr;
  }

  .summary-item,
  .summary-item:nth-child(-n + 2) {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .summary-item:first-child {
    border-top: 0;
  }

  .table-topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .pager {
    justify-content: space-between;
  }

  .pager .button {
    flex: 1;
  }
}
