:root {
  --bg: #f5f1e8;
  --panel: #fffdf8;
  --panel-strong: #f0eadf;
  --ink: #18231f;
  --muted: #66736d;
  --line: rgba(24, 35, 31, 0.14);
  --accent: #1f6f5b;
  --accent-2: #9a4d2f;
  --accent-3: #385d8a;
  --shadow: 0 18px 40px rgba(24, 35, 31, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    linear-gradient(180deg, rgba(31, 111, 91, 0.08), transparent 260px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 18px;
  max-width: 1500px;
}

.topbar h1,
.search-strip h2,
.provider-header h2 {
  letter-spacing: 0;
  line-height: 1.05;
  margin: 0;
}

.topbar h1 {
  font-size: 28px;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  margin: 0 0 7px;
  text-transform: uppercase;
}

.topbar-actions,
.button-row,
.result-toolbar,
.provider-header {
  align-items: center;
  display: flex;
  gap: 10px;
}

.status-pill,
.provider-badge {
  background: #dce8e2;
  border: 1px solid rgba(31, 111, 91, 0.2);
  border-radius: 999px;
  color: #174c3f;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 10px;
}

.ghost-link {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.workspace {
  display: grid;
  gap: 16px;
  grid-template-columns: 280px minmax(0, 1fr) 340px;
  margin: 0 auto;
  max-width: 1500px;
}

.rail,
.main,
.inspector {
  min-width: 0;
}

.main {
  display: grid;
  gap: 16px;
}

.panel,
.search-strip,
.result-panel,
.provider-panel {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  margin-bottom: 16px;
  padding: 14px;
}

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

.panel-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.panel-heading strong {
  color: var(--accent);
  font-size: 13px;
}

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

.metric-grid div {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.metric-grid span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.metric-grid strong {
  font-size: 20px;
}

.book-list {
  display: grid;
  gap: 8px;
  max-height: 430px;
  overflow: auto;
  padding-right: 2px;
}

.book-button {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: block;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.book-button:hover,
.book-button.active {
  border-color: rgba(31, 111, 91, 0.45);
  box-shadow: inset 3px 0 0 var(--accent);
}

.book-button strong,
.result-card strong,
.provider-card strong {
  display: block;
  line-height: 1.28;
}

.book-button span,
.result-card span,
.provider-card span,
.selected-book span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  line-height: 1.45;
  margin-top: 4px;
}

.file-drop {
  align-items: center;
  background: #ffffff;
  border: 1px dashed rgba(31, 111, 91, 0.5);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  min-height: 72px;
  padding: 12px;
}

.file-drop input {
  inline-size: 1px;
  opacity: 0;
  position: absolute;
}

.file-drop span {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.secondary-button {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  min-height: 36px;
  padding: 0 12px;
}

.secondary-button:hover {
  border-color: rgba(154, 77, 47, 0.46);
}

.search-strip,
.provider-panel {
  padding: 16px;
}

.search-strip {
  align-items: end;
  display: grid;
  gap: 16px;
  grid-template-columns: 250px minmax(0, 1fr);
}

.search-form,
.provider-search {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) 108px;
}

.search-form input,
.provider-search input {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 44px;
  outline: none;
  padding: 0 13px;
  width: 100%;
}

.search-form input:focus,
.provider-search input:focus {
  border-color: rgba(31, 111, 91, 0.55);
  box-shadow: 0 0 0 3px rgba(31, 111, 91, 0.12);
}

.search-form button,
.provider-search button {
  background: var(--ink);
  border-radius: 8px;
  color: #fffdf8;
  font-weight: 800;
}

.result-panel {
  min-height: 420px;
  overflow: hidden;
}

.result-toolbar {
  border-bottom: 1px solid var(--line);
  justify-content: space-between;
  padding: 12px 14px;
}

.result-toolbar > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.segmented {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  padding: 3px;
}

.segmented button {
  background: transparent;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  min-height: 30px;
  padding: 0 11px;
}

.segmented button.segmented-active {
  background: #ffffff;
  color: var(--ink);
}

.results {
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
  padding: 14px;
}

.result-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.result-card p {
  color: #2f3b36;
  line-height: 1.55;
  margin: 10px 0 0;
}

.result-card mark {
  background: rgba(244, 190, 93, 0.45);
  border-radius: 4px;
  color: inherit;
  padding: 0 2px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  background: rgba(56, 93, 138, 0.12);
  border: 1px solid rgba(56, 93, 138, 0.18);
  border-radius: 999px;
  color: #254465;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 7px;
}

.provider-panel {
  display: grid;
  gap: 14px;
}

.provider-header {
  justify-content: space-between;
}

.provider-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

.provider-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: 76px minmax(0, 1fr);
  min-height: 134px;
  padding: 10px;
}

.cover {
  align-items: center;
  background: linear-gradient(135deg, rgba(31, 111, 91, 0.18), rgba(154, 77, 47, 0.2));
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  display: flex;
  font-size: 11px;
  font-weight: 800;
  justify-content: center;
  min-height: 112px;
  overflow: hidden;
  text-align: center;
}

.cover img {
  display: block;
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.provider-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.provider-actions a,
.provider-actions button {
  align-items: center;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  min-height: 32px;
  padding: 0 9px;
  text-decoration: none;
}

.sticky-panel {
  position: sticky;
  top: 16px;
}

.selected-book {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  min-height: 88px;
  padding: 11px;
}

#wikiDraft {
  background: #151d1a;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #eef8f1;
  display: block;
  line-height: 1.45;
  min-height: 290px;
  outline: none;
  padding: 12px;
  resize: vertical;
  width: 100%;
}

.button-row {
  justify-content: stretch;
  margin-top: 10px;
}

.button-row button {
  flex: 1;
}

.outline {
  color: #2f3b36;
  font-size: 12px;
  line-height: 1.55;
  margin-top: 12px;
}

.outline pre {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.empty {
  align-items: center;
  background: rgba(255, 255, 255, 0.52);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  font-weight: 700;
  justify-content: center;
  min-height: 118px;
  padding: 18px;
  text-align: center;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .inspector {
    grid-column: 1 / -1;
  }

  .sticky-panel {
    position: static;
  }
}

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

  .topbar,
  .workspace,
  .search-strip {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    display: grid;
  }

  .workspace {
    display: grid;
  }

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

  .search-form,
  .provider-search {
    grid-template-columns: 1fr;
  }

  .search-form button,
  .provider-search button {
    min-height: 42px;
  }
}
