:root {
  color-scheme: light dark;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-soft: #fbfcf8;
  --surface-strong: #202124;
  --surface-strong-hover: #34363a;
  --text: #1d1f23;
  --text-strong: #ffffff;
  --reason: #42464d;
  --muted: #636a72;
  --line: #d7d9d1;
  --line-strong: #aeb3ab;
  --green: #147d50;
  --green-bg: #e4f4eb;
  --amber: #9b5a00;
  --amber-bg: #fff0d5;
  --red: #b3261e;
  --red-bg: #ffe4e1;
  --gray-bg: #eceee8;
  --blue: #1b66c9;
  --focus: #111111;
  --shadow: rgba(0, 0, 0, 0.1);
  --button-hover-bg: #fafbf8;
  --input-bg: #ffffff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15171a;
  --surface: #1d2024;
  --surface-soft: #23262b;
  --surface-strong: #e8eaef;
  --surface-strong-hover: #d2d4d8;
  --text: #e8eaef;
  --text-strong: #15171a;
  --reason: #c8ccd2;
  --muted: #9aa0a6;
  --line: #34373c;
  --line-strong: #4a4d52;
  --green: #4ade80;
  --green-bg: #11321f;
  --amber: #f5b042;
  --amber-bg: #3a2710;
  --red: #f47373;
  --red-bg: #3a1818;
  --gray-bg: #2a2d32;
  --blue: #6aa9f5;
  --focus: #ffffff;
  --shadow: rgba(0, 0, 0, 0.5);
  --button-hover-bg: #25282d;
  --input-bg: #23262b;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --bg: #15171a;
    --surface: #1d2024;
    --surface-soft: #23262b;
    --surface-strong: #e8eaef;
    --surface-strong-hover: #d2d4d8;
    --text: #e8eaef;
    --text-strong: #15171a;
    --reason: #c8ccd2;
    --muted: #9aa0a6;
    --line: #34373c;
    --line-strong: #4a4d52;
    --green: #4ade80;
    --green-bg: #11321f;
    --amber: #f5b042;
    --amber-bg: #3a2710;
    --red: #f47373;
    --red-bg: #3a1818;
    --gray-bg: #2a2d32;
    --blue: #6aa9f5;
    --focus: #ffffff;
    --shadow: rgba(0, 0, 0, 0.5);
    --button-hover-bg: #25282d;
    --input-bg: #23262b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 0 14px;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--button-hover-bg);
}

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

button.primary {
  background: var(--surface-strong);
  border-color: var(--surface-strong);
  color: var(--text-strong);
}

button.primary:hover:not(:disabled) {
  background: var(--surface-strong-hover);
  border-color: var(--surface-strong-hover);
}

button.btn-utility {
  min-height: 34px;
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0 12px;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.intro {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.15rem;
}

.status-pill {
  min-width: 96px;
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--gray-bg);
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.status-pill.running {
  background: var(--green-bg);
  color: var(--green);
}

.controls,
.summary-strip,
.results-section {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
}

.controls {
  padding: 16px;
}

.control-row {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(140px, 180px);
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  padding: 0 10px;
}

.inline-input {
  display: grid;
  grid-template-columns: minmax(64px, 96px) auto;
  gap: 8px;
  align-items: center;
  justify-content: start;
}

.country-picker {
  grid-template-columns: minmax(160px, 1fr) auto auto;
  justify-content: stretch;
}

.country-input-wrap {
  position: relative;
}

.country-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 4px 16px var(--shadow);
  display: none;
}

.country-dropdown.open {
  display: block;
}

.country-option {
  padding: 8px 12px;
  font-size: 0.88rem;
  cursor: pointer;
}

.country-option:hover,
.country-option.active {
  background: var(--gray-bg);
}

.product-panel,
.region-panel {
  margin-top: 16px;
}

.section-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.product-grid,
.region-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.product-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.select-chip {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--surface-soft);
  cursor: pointer;
}

.select-chip input {
  width: 16px;
  min-height: 16px;
  margin: 0;
  accent-color: var(--surface-strong);
}

.chip-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-content {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.chip-icon {
  flex: 0 0 auto;
  height: 26px;
  width: 44px;
  object-fit: cover;
  border-radius: 3px;
  background: #1b2838;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin-top: 14px;
  overflow: hidden;
}

.summary-strip > div {
  display: grid;
  gap: 2px;
  min-height: 74px;
  padding: 14px 16px;
  background: var(--surface);
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 800;
}

.metric-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.results-section {
  margin-top: 14px;
  padding: 16px;
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.message-area {
  min-height: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.message-area:not(:empty) {
  margin-bottom: 12px;
}

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

.result-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-soft);
}

.result-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.region-title {
  display: grid;
  gap: 2px;
}

.region-code {
  font-size: 1.25rem;
  font-weight: 850;
}

.region-full-name {
  color: var(--muted);
  font-size: 0.9rem;
}

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  transition: background 0.15s, color 0.15s;
}

.badge-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.info-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--amber-bg);
  color: var(--amber);
  font-size: 0.7rem;
  font-weight: 700;
  cursor: help;
  white-space: nowrap;
}

.badge.available {
  background: var(--green-bg);
  color: var(--green);
}

.badge.pending,
.badge.reservation {
  background: var(--amber-bg);
  color: var(--amber);
}

.badge.error,
.badge.restricted,
.badge.unsupported {
  background: var(--red-bg);
  color: var(--red);
}

.badge.unpublished,
.badge.out,
.badge.unknown {
  background: var(--gray-bg);
  color: var(--muted);
}

.reason {
  color: var(--reason);
  line-height: 1.45;
  font-size: 0.92rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.detail {
  display: grid;
  gap: 2px;
  min-width: 0;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.detail span:first-child {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.detail span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.model-list {
  display: grid;
  gap: 6px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.model-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}

.product-section {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: grid;
  gap: 12px;
}

.product-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.product-section-name {
  font-size: 1rem;
  font-weight: 800;
}

.model-name,
.model-delivery {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-name {
  font-weight: 800;
}

.model-delivery {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.model-status {
  justify-self: end;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.changelog-list {
  display: grid;
  gap: 6px;
}

.changelog-entry {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.changelog-time {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  font-weight: 700;
}

.changelog-product {
  font-size: 0.88rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.changelog-region {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.source-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--gray-bg);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.last-stock-hint {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.history-as-of {
  margin: -8px 0 14px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.history-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--gray-bg);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  vertical-align: middle;
}

h1 .history-link {
  font-size: 0.66em;
}

.history-link:hover {
  background: var(--surface-soft);
  text-decoration: none;
}

.history-toolbar {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.history-toolbar-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px 16px;
  align-items: end;
}

.field.grow {
  grid-column: span 2;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 2px;
  gap: 2px;
}

.segmented button {
  min-height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0 10px;
  cursor: pointer;
}

.segmented button:hover:not(.active) {
  background: var(--gray-bg);
  color: var(--text);
}

.segmented button.active {
  background: var(--surface-strong);
  color: var(--text-strong);
}

.filter-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 4px 12px 4px 4px;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.filter-chip img {
  height: 26px;
  width: 44px;
  object-fit: cover;
  border-radius: 999px;
  background: #1b2838;
}

.filter-chip:hover {
  background: var(--surface-soft);
  border-color: var(--line-strong);
}

.filter-chip.active {
  background: var(--surface-strong);
  border-color: var(--surface-strong);
  color: var(--text-strong);
}

.history-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.history-table-wrap {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

.history-table tbody tr:last-child td {
  border-bottom: none;
}

.history-table tbody tr:hover {
  background: var(--surface-soft);
}

.history-table th {
  font-weight: 800;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  white-space: nowrap;
}

.history-table th[data-sort] {
  cursor: pointer;
  user-select: none;
}

.history-table th[data-sort]:hover {
  color: var(--text);
}

.history-table th.sorted {
  color: var(--text);
}

.history-table th.sorted::after {
  content: ' ▾';
  color: var(--muted);
}

.col-product {
  min-width: 180px;
}

.cell-product {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.cell-product-icon {
  flex: 0 0 auto;
  height: 28px;
  width: 44px;
  object-fit: cover;
  border-radius: 4px;
  background: #1b2838;
}

.cell-product-name {
  font-weight: 700;
  white-space: nowrap;
}

.col-region {
  white-space: nowrap;
}

.cell-region-code {
  font-weight: 850;
  letter-spacing: 0.02em;
  margin-right: 6px;
}

.cell-region-name {
  color: var(--muted);
  font-size: 0.82rem;
}

.col-events {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.col-actions {
  white-space: nowrap;
}

.col-actions a {
  margin-right: 8px;
}

.recheck-btn {
  min-height: 28px;
  padding: 0 10px;
  font-size: 0.78rem;
}

@media (max-width: 760px) {
  .history-table th,
  .history-table td {
    padding: 8px 10px;
  }
  .cell-product-icon {
    height: 22px;
    width: 36px;
  }
  .cell-region-name {
    display: none;
  }
}

.browse-grid {
  margin-top: 32px;
  padding: 16px 0;
}

.browse-grid h2 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 10px;
}

.browse-grid ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px 16px;
}

.browse-grid a {
  text-decoration: none;
  color: var(--text);
}

.browse-grid a:hover {
  text-decoration: underline;
}

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 40px;
  padding: 20px 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding-top: 0;
  padding-bottom: 0;
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

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

  .control-row,
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .button-row button {
    flex: 1 1 145px;
  }

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

  .model-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .model-delivery {
    grid-column: 1 / -1;
  }
}
