* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #18202f;
  --muted: #667085;
  --line: #d9dee8;
  --line-strong: #b7c0ce;
  --green: #16784a;
  --green-soft: #e7f5ee;
  --red: #b42318;
  --red-soft: #fef0ed;
  --blue: #1d5fd0;
  --focus: #111827;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button,
input,
select {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

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

.title {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
}

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

.key-input,
.search-input,
.select-input {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 11px;
  min-width: 0;
}

.key-input {
  width: 190px;
}

.button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 13px;
  cursor: pointer;
  font-weight: 600;
}

.button:hover {
  border-color: #8d99ab;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 160px;
  gap: 10px;
  margin-bottom: 14px;
}

.summary {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 0 14px;
  color: var(--muted);
}

.summary strong {
  color: var(--text);
}

.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px 16px;
  color: var(--muted);
}

.notice.error {
  border-color: #f2b8b5;
  color: var(--red);
  background: var(--red-soft);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--panel);
}

.sources-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

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

.sources-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #fbfcfe;
}

.sources-table tr:last-child td {
  border-bottom: 0;
}

.source-name {
  display: block;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.source-url {
  display: block;
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.badge.on {
  background: var(--green-soft);
  color: var(--green);
}

.badge.off {
  background: var(--red-soft);
  color: var(--red);
}

.meta {
  color: var(--muted);
  white-space: nowrap;
}

.toggle {
  min-width: 92px;
}

.toggle.on {
  border-color: #8bc8ac;
  color: var(--green);
}

.toggle.off {
  border-color: #f0a9a3;
  color: var(--red);
}

.htmx-request .button,
.button.htmx-request {
  opacity: 0.65;
  pointer-events: none;
}

.status-line {
  min-height: 20px;
  margin-top: 12px;
  color: var(--muted);
}

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

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 20px, 680px);
    padding-top: 18px;
  }

  .topbar,
  .key-form {
    align-items: stretch;
    flex-direction: column;
  }

  .key-input {
    width: 100%;
  }

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

  .table-wrap {
    border: 0;
    background: transparent;
    overflow: visible;
  }

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

  .sources-table thead {
    display: none;
  }

  .sources-table tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    margin-bottom: 10px;
    overflow: hidden;
  }

  .sources-table td {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--line);
  }

  .sources-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
    flex: 0 0 92px;
  }

  .sources-table td:last-child {
    border-bottom: 0;
  }

  .source-name,
  .source-url {
    max-width: calc(100vw - 150px);
  }
}
