:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #fffdf8;
  --ink: #202124;
  --muted: #6b6760;
  --line: #d9d2c7;
  --accent: #0f766e;
  --accent-strong: #0b5c55;
  --warn: #b45309;
  --bad: #b91c1c;
  --shadow: 0 14px 40px rgba(38, 31, 22, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 0 14px;
}

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

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

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 10px 11px;
}

select {
  min-height: 40px;
}

textarea {
  resize: vertical;
}

mark {
  background: #fde68a;
  border-radius: 3px;
  color: inherit;
  padding: 0 2px;
}

label span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px;
}

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

.account-panel {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 12px;
}

.auth-form,
.sso-buttons,
.user-panel {
  align-items: center;
  display: flex;
  gap: 8px;
}

.auth-form {
  flex: 1 1 auto;
}

.auth-form input {
  max-width: 220px;
}

.sso-buttons {
  flex-wrap: wrap;
}

.sso-button {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 40px;
  padding: 0 13px;
  text-decoration: none;
  white-space: nowrap;
}

.sso-button:hover {
  border-color: var(--accent);
}

.sso-button.google {
  background: white;
}

.sso-button.apple {
  background: #111827;
  border-color: #111827;
  color: white;
}

.user-panel {
  margin-left: auto;
}

.brand {
  align-items: center;
  display: flex;
  gap: 13px;
  min-width: 280px;
}

.brand-mark {
  align-items: center;
  aspect-ratio: 1;
  background: #111827;
  border-radius: 8px;
  color: white;
  display: grid;
  flex: 0 0 44px;
  font-weight: 900;
  place-items: center;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.25rem, 2vw, 1.8rem);
  line-height: 1.1;
}

h2 {
  font-size: 1rem;
}

h3 {
  font-size: 0.86rem;
  margin: 0;
}

.brand p,
.muted,
small {
  color: var(--muted);
}

.status-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(84px, 1fr));
}

.status-grid span {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  min-height: 58px;
  padding: 8px 10px;
}

.status-grid b {
  font-size: 1.1rem;
}

.status-grid small {
  font-size: 0.74rem;
}

.layout {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
}

.setup,
.workspace {
  display: grid;
  gap: 18px;
}

.tool-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

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

.compact-head {
  margin: 0;
}

.stack {
  display: grid;
  gap: 13px;
}

.archive-channel-manager {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
}

.term-set-controls {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 120px auto auto auto;
}

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

.button-row {
  display: flex;
  gap: 8px;
}

.button-row button {
  flex: 1 1 auto;
}

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

.check-row input {
  flex: 0 0 auto;
  width: auto;
}

.check-row span {
  color: var(--ink);
  font-size: 0.9rem;
  margin: 0;
  text-transform: none;
}

.compact {
  flex: 0 0 auto;
}

.pill {
  background: #ede9dd;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  padding: 5px 9px;
}

.pill[data-state="ready"] {
  background: #dff3ed;
  color: #075e54;
}

.pill[data-state="missing"] {
  background: #fae8e8;
  color: var(--bad);
}

.pill[data-state="warning"] {
  background: #fff7d6;
  color: var(--warn);
}

.job-panel {
  align-items: center;
  background: #f3f0e8;
  border-radius: 8px;
  display: flex;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
}

.job-panel[data-status="failed"] {
  background: #fae8e8;
}

.job-panel[data-status="complete"] {
  background: #dff3ed;
}

.job-panel[data-status="quota-paused"] {
  background: #fff7d6;
}

.progress-dot {
  animation: pulse 1s infinite ease-in-out;
  background: var(--accent);
  border-radius: 50%;
  flex: 0 0 10px;
  height: 10px;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.4;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
}

.inline-form,
.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.log-list {
  background: #111827;
  border-radius: 8px;
  color: #e5e7eb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  margin: 0;
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.search-row {
  margin-bottom: 0;
}

.search-row input[type="search"] {
  flex: 1 1 auto;
}

#search-sort {
  flex: 0 0 150px;
}

.ghost,
.icon-button,
.term-filter {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.ghost:hover,
.icon-button:hover,
.term-filter:hover {
  background: #f3f0e8;
}

.icon-button {
  border-radius: 50%;
  flex: 0 0 26px;
  font-size: 0.72rem;
  height: 26px;
  min-height: 26px;
  padding: 0;
  width: 26px;
}

.quota-summary {
  display: grid;
  gap: 10px;
}

.quota-bar {
  background: #ede9dd;
  border-radius: 999px;
  height: 9px;
  overflow: hidden;
}

.quota-bar span {
  background: var(--accent);
  display: block;
  height: 100%;
  transition: width 0.2s ease;
  width: 0;
}

.quota-bar span[data-state="warning"] {
  background: var(--warn);
}

.quota-bar span[data-state="missing"] {
  background: var(--bad);
}

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

.quota-grid span {
  background: #faf7f0;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  min-height: 50px;
  padding: 8px 9px;
}

.quota-grid b {
  font-size: 0.95rem;
}

.term-filter {
  border: 0;
  border-radius: 4px;
  color: #075985;
  flex: 1 1 auto;
  font-weight: 800;
  justify-self: start;
  min-height: 30px;
  overflow-wrap: anywhere;
  padding: 3px 4px;
  text-align: left;
}

.term-filter:focus-visible,
.match-chip:focus-visible,
.term.clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.match-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: -4px;
}

.match-chip {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 999px;
  color: #7c2d12;
  font-size: 0.78rem;
  font-weight: 800;
  min-height: 30px;
  padding: 0 10px;
}

.match-chip:hover {
  background: #fde68a;
}

.mini-list,
.run-list {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.archive-channel-list {
  max-height: 380px;
  overflow: auto;
}

.channel-label {
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.35;
  min-width: 0;
  overflow-wrap: anywhere;
}

.mini-list li,
.run-list li {
  align-items: center;
  background: #faf7f0;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-height: 38px;
  padding: 7px 9px;
  word-break: break-word;
}

.run-list li {
  align-items: start;
  cursor: pointer;
  flex-direction: column;
}

.run-list li:hover {
  border-color: var(--accent);
}

.search-panel {
  position: sticky;
  top: 12px;
  z-index: 2;
}

.results {
  display: grid;
  gap: 10px;
}

.result {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 13px;
}

.match-details {
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 8px;
}

.match-details summary {
  color: #075985;
  cursor: pointer;
  font-weight: 800;
  line-height: 1.4;
}

.match-lines {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.match-line {
  background: #faf7f0;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  gap: 6px;
  padding: 10px;
}

.match-line-meta {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.result-meta {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.term {
  background: #fef3c7;
  border-radius: 999px;
  color: #7c2d12;
  font-size: 0.76rem;
  font-weight: 800;
  padding: 4px 8px;
}

.term.clickable {
  cursor: pointer;
}

.term.clickable:hover {
  background: #fde68a;
}

.date {
  color: var(--muted);
  font-size: 0.78rem;
}

.result-title {
  color: #075985;
  font-weight: 800;
  text-decoration: none;
}

.result-title:hover {
  text-decoration: underline;
}

.comment {
  color: #30302d;
  line-height: 1.45;
}

.byline,
.empty {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 960px) {
  .topbar,
  .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    display: grid;
  }

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

  .layout {
    display: grid;
  }

  .search-panel {
    position: static;
  }
}

@media (max-width: 620px) {
  .shell {
    padding: 14px;
  }

  .account-panel,
  .auth-form,
  .sso-buttons,
  .user-panel {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
  }

  .auth-form input {
    max-width: none;
  }

  .form-grid,
  .search-row,
  .inline-form,
  .button-row,
  .term-set-controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  .compact {
    justify-self: start;
  }
}
