* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--catalog-shell-text);
  background: var(--catalog-shell-bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.patent-shell {
  --catalog-shell-bg: #f7f2ec;
  --catalog-shell-panel: #fffdf9;
  --catalog-shell-border: #decfc4;
  --catalog-shell-text: #211c18;
  --catalog-shell-muted: #786d64;
  --catalog-shell-accent: #2a231f;
  --catalog-shell-accent-weak: #efe4dc;
}

.patent-search-form {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.patent-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 14px;
}

.patent-shell .patent-title-row h1 {
  flex: 0 0 auto;
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.patent-data-note {
  min-width: 0;
  color: var(--catalog-shell-muted);
  font-size: 11px;
  line-height: 1.35;
  white-space: nowrap;
}

.field-label {
  color: var(--catalog-shell-muted);
  font-size: 12px;
  font-weight: 700;
}

.patent-select,
.patent-query-row input,
.patent-advanced input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--catalog-shell-border);
  border-radius: 6px;
  background: #fffdf9;
  color: var(--catalog-shell-text);
}

.patent-select {
  padding: 0 10px;
}

.patent-query-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.patent-query-wrap {
  position: relative;
  min-width: 0;
}

.patent-query-wrap > span {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-52%);
  color: var(--catalog-shell-muted);
  font-size: 20px;
  pointer-events: none;
}

.patent-query-row input {
  padding: 0 38px 0 34px;
}

#patentQuery::-webkit-search-cancel-button {
  display: none;
  appearance: none;
  -webkit-appearance: none;
}

#patentClearButton {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 28px;
  height: 28px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--catalog-shell-muted);
  font-size: 18px;
}

#patentClearButton[hidden] {
  display: none;
}

.patent-advanced {
  border-top: 1px solid var(--catalog-shell-border);
  padding-top: 8px;
}

.patent-advanced summary {
  width: max-content;
  color: #5f4a3c;
  cursor: pointer;
  font-size: 12px;
  font-weight: 760;
}

.patent-advanced-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 9px;
}

.patent-advanced-grid label {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.patent-advanced-grid label:nth-child(-n+3) {
  grid-column: 1 / -1;
}

.patent-advanced-grid span {
  color: var(--catalog-shell-muted);
  font-size: 11px;
  font-weight: 700;
}

.patent-advanced-grid input {
  height: 34px;
  padding: 0 8px;
}

.library-note {
  min-height: 34px;
  margin: 10px 0 0;
  color: var(--catalog-shell-muted);
  font-size: 12px;
  line-height: 1.45;
}

.patent-results {
  overflow: auto;
  min-height: 0;
  padding: 10px 10px 14px;
}

.patent-result-row {
  width: 100%;
  text-align: left;
  border: 1px solid var(--catalog-shell-border);
  border-radius: 6px;
  background: #fffdf9;
  padding: 10px;
  white-space: normal;
}

.patent-start-section {
  margin-bottom: 18px;
}

.patent-start-section h2 {
  margin: 0 0 8px;
  color: var(--catalog-shell-text);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .02em;
}

.patent-start-card {
  display: block;
  width: 100%;
  margin-bottom: 7px;
  border: 1px solid var(--catalog-shell-border);
  border-radius: 7px;
  background: #fffdf9;
  padding: 10px;
  text-align: left;
  white-space: normal;
}

.patent-start-card strong,
.patent-start-card span {
  display: block;
}

.patent-start-card strong { font-size: 13px; line-height: 1.4; }
.patent-start-card span { margin-top: 4px; color: var(--catalog-shell-muted); font-size: 11px; }

.patent-example-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.patent-example-chips button { padding: 6px 8px; border-radius: 999px; font-size: 11px; }
.patent-result-row:hover,
.patent-result-row.selected {
  border-color: #b8967e;
  background: #f5eee7;
}

.patent-result-title {
  font-size: 14px;
  font-weight: 760;
  line-height: 1.35;
}

.patent-result-meta {
  margin-top: 5px;
  color: var(--catalog-shell-muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.patent-result-snippet {
  margin-top: 7px;
  color: #4f433b;
  font-size: 12px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.source-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--catalog-shell-border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--catalog-shell-text);
  text-decoration: none;
  background: #fffdf9;
  white-space: nowrap;
  transition: background-color .2s ease, border-color .2s ease, transform .2s ease;
}

.source-link:hover {
  border-color: #b8967e;
  background: #faf7f2;
  transform: translateY(-1px);
}

.patent-content {
  background:
    linear-gradient(90deg, rgba(184, 150, 126, .055) 1px, transparent 1px),
    linear-gradient(rgba(184, 150, 126, .055) 1px, transparent 1px),
    #fffdf9;
  background-size: 54px 54px;
}

.patent-pane {
  display: none;
  max-width: 1080px;
  line-height: 1.72;
  font-size: 16px;
}

.patent-pane.active {
  display: block;
}

.patent-pane[hidden] {
  display: none;
}

.patent-welcome {
  max-width: 980px;
  margin: 0 auto;
  padding: 36px 0;
}

.patent-welcome[hidden] { display: none; }
.patent-welcome .welcome-eyebrow { color: #8a6751; font-size: 12px; font-weight: 800; letter-spacing: .08em; }
.patent-welcome h2 { margin: 8px 0 10px; font-size: 30px; line-height: 1.25; }
.patent-welcome > p { color: var(--catalog-shell-muted); line-height: 1.65; }
.patent-welcome-section { margin-top: 28px; }
.patent-welcome-section h3 { margin: 0 0 10px; font-size: 14px; }
.patent-office-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.patent-office-links a { border: 1px solid var(--catalog-shell-border); border-radius: 8px; background: #fffdf9; padding: 12px; color: var(--catalog-shell-text); font-weight: 760; text-align: center; text-decoration: none; }
.patent-office-links a:hover { border-color: #b8967e; background: #f5eee7; }
.patent-source-note { margin-top: 24px; border-left: 3px solid #b8967e; padding-left: 12px; font-size: 12px; }

.patent-generated {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.patent-original {
  margin: 0;
  max-width: 1080px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #211c18;
  font: 14px/1.72 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.more-button {
  margin-top: 18px;
}

.inline-status {
  color: var(--catalog-shell-muted);
}

.inline-error {
  color: #9f2f2f;
}

@media (max-width: 900px) and (orientation: portrait) {
  .patent-query-row {
    grid-template-columns: 1fr;
  }

  .patent-query-row button {
    width: 100%;
  }

  #patentClearButton { width: 28px; }
  .patent-office-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
