:root {
  color-scheme: light;
  --ink: #151515;
  --muted: #686b70;
  --line: #d9dde3;
  --soft: #f5f7f9;
  --paper: #ffffff;
  --blue: #2458ff;
  --green: #1f8a5b;
  --amber: #a46213;
  --shadow: 0 20px 50px rgba(24, 32, 44, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #eef2f5;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  object-fit: cover;
}

.brand strong {
  display: block;
  font-size: 22px;
  line-height: 1;
}

.brand span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #34373b;
  cursor: pointer;
  padding: 0 12px;
  text-align: left;
}

.nav-item span {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  color: #2f5ee8;
}

.nav-item.active,
.nav-item:hover {
  border-color: var(--line);
  background: var(--paper);
}

.source-panel,
.auth-panel,
.history-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 16px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 4px;
}

.auth-tab {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.auth-tab.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 6px 16px rgba(24, 32, 44, 0.08);
}

.auth-form {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.auth-form input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  padding: 0 10px;
}

.captcha-row {
  display: grid;
  grid-template-columns: minmax(72px, auto) minmax(0, 1fr) 34px;
  gap: 6px;
  align-items: center;
}

.email-code-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.captcha-row span {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: #30343a;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
}

.captcha-row input {
  min-width: 0;
}

.captcha-row .captcha-refresh {
  min-height: 34px;
  width: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}

.email-code-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  padding: 0 10px;
}

.auth-form input:focus {
  border-color: var(--blue);
}

.auth-form button:not(.email-code-button),
.logout-button {
  min-height: 38px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: white;
  cursor: pointer;
}

.auth-message {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.signed-in {
  display: grid;
  gap: 6px;
}

.user-name {
  font-size: 16px;
}

.user-email {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.history-panel {
  max-height: 260px;
  overflow: hidden;
}

.section-heading.compact {
  margin-bottom: 0;
}

.section-heading.compact h2 {
  font-size: 16px;
}

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

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  cursor: pointer;
  padding: 10px;
  text-align: left;
}

.history-item strong {
  display: block;
  color: #30343a;
  font-size: 13px;
  line-height: 1.35;
}

.history-item span,
.empty-history {
  color: var(--muted);
  font-size: 12px;
}

.empty-history {
  margin: 0;
}

.hidden {
  display: none !important;
}

.panel-label,
.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.source-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #3a3d42;
  font-size: 14px;
}

.workspace {
  padding: 32px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin: 0 auto 28px;
  max-width: 1180px;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(34px, 5vw, 68px);
  line-height: 0.96;
  letter-spacing: 0;
}

.upload-button,
.search-box button,
.ghost-button {
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: white;
  cursor: pointer;
  padding: 0 16px;
  white-space: nowrap;
}

.search-box button:disabled {
  cursor: progress;
  opacity: 0.68;
}

.library-search-form button:disabled {
  cursor: progress;
  opacity: 0.68;
}

.query-surface,
.answer-panel,
.evidence-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.query-surface {
  margin: 0 auto 20px;
  max-width: 1180px;
  overflow: hidden;
}

.query-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  padding: 8px;
}

.tab {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0 14px;
}

.tab.active {
  background: #eaf0ff;
  color: #173ca9;
}

.search-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 18px;
}

textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.5;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 20px;
  margin: 0 auto;
  max-width: 1180px;
}

.answer-panel,
.evidence-panel {
  padding: 22px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.trust-score {
  border: 1px solid rgba(31, 138, 91, 0.26);
  border-radius: 999px;
  background: rgba(31, 138, 91, 0.1);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 10px;
  white-space: nowrap;
}

.answer-block {
  display: grid;
  gap: 16px;
  border-left: 3px solid var(--blue);
  padding-left: 18px;
}

.answer-block p {
  margin: 0;
  color: #25282c;
  font-size: 17px;
  line-height: 1.7;
}

.compare-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.compare-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  color: #25282c;
  font-size: 14px;
}

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

.compare-table th {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.compare-table td:first-child {
  width: 130px;
}

.compare-table td:nth-child(3) {
  width: 160px;
}

.compare-table strong,
.compare-table span,
.compare-table small {
  display: block;
}

.compare-table small,
.compare-table span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.compare-table a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.compare-table a:hover {
  text-decoration: underline;
}

sup {
  color: var(--blue);
  font-weight: 800;
}

.claim-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 24px;
}

.claim {
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 14px;
}

.claim span {
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.claim p {
  margin: 12px 0 0;
  color: #34373b;
  line-height: 1.55;
}

.ghost-button {
  border-color: var(--line);
  background: white;
  color: var(--ink);
}

.paper-card {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 16px 0;
}

.paper-card:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.source-type {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

a {
  color: inherit;
}

.paper-card h3 a,
.source-node {
  color: #1747c8;
  text-decoration: none;
}

.paper-card h3 a:hover,
.source-node:hover {
  text-decoration: underline;
}

.source-unavailable {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.paper-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.card-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  color: #4f5358;
  font-size: 12px;
  padding: 5px 8px;
}

.admin-view {
  margin: 0 auto;
  max-width: 1180px;
}

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.admin-header h1 {
  max-width: 820px;
  font-size: clamp(32px, 4vw, 56px);
}

.admin-status {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  padding: 9px 12px;
  white-space: nowrap;
}

.admin-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.admin-metrics article,
.admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.admin-metrics article {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.admin-metrics span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.admin-metrics strong {
  font-size: 26px;
  line-height: 1;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 18px;
}

.admin-card {
  padding: 20px;
}

.library-search-card {
  margin-bottom: 18px;
}

.library-search-status {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  padding: 9px 12px;
  white-space: nowrap;
}

.library-search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.library-search-form input {
  min-height: 42px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  padding: 0 12px;
}

.library-search-form input:focus {
  border-color: var(--blue);
}

.library-search-form button {
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: white;
  cursor: pointer;
  padding: 0 16px;
}

.library-search-results {
  display: grid;
  gap: 10px;
  max-height: 460px;
  overflow: auto;
}

.library-source-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 14px;
}

.library-source-card h3 {
  margin-top: 6px;
}

.library-source-card small {
  display: block;
  margin-top: 6px;
  color: #4f5358;
}

.library-source-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.users-card {
  grid-column: 1 / -1;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.admin-settings-form,
.email-settings-form,
.invite-form {
  display: grid;
  gap: 12px;
}

.admin-settings-form label,
.email-settings-form label,
.invite-form label {
  display: grid;
  gap: 7px;
  color: #30343a;
  font-size: 13px;
  font-weight: 800;
}

.admin-settings-form input,
.email-settings-form input,
.invite-form input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  padding: 0 11px;
}

.admin-settings-form .toggle-label,
.email-settings-form .toggle-label,
.mini-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-settings-form .toggle-label input,
.email-settings-form .toggle-label input,
.mini-toggle input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--blue);
  padding: 0;
}

.admin-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.admin-form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

.admin-form-footer button,
.email-settings-form button,
.invite-form button {
  min-height: 40px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: white;
  cursor: pointer;
  padding: 0 14px;
}

.admin-message {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.email-message {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.admin-user-list,
.invite-list,
.library-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.admin-user-row,
.invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 11px;
}

.editable-user {
  align-items: stretch;
  flex-wrap: wrap;
}

.user-edit-main {
  display: grid;
  flex: 1 1 230px;
  gap: 5px;
  min-width: 0;
}

.user-edit-main input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 10px;
}

.mini-toggle {
  flex: 0 0 auto;
  color: #30343a;
  font-size: 12px;
  font-weight: 800;
}

.user-row-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.user-row-actions .ghost-button {
  min-height: 36px;
  padding: 0 10px;
}

.citation-style-select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  padding: 0 12px;
}

.citation-output {
  min-height: 220px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: #25282c;
  font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: auto;
  padding: 16px;
  white-space: pre-wrap;
}

.graph-canvas {
  display: grid;
  min-height: 320px;
  place-items: center;
}

.graph-canvas:has(.graph-column) {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 18px;
  place-items: stretch;
}

.graph-column {
  display: grid;
  gap: 12px;
}

.graph-node {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 13px;
}

.claim-node {
  border-left: 3px solid var(--blue);
  color: #173ca9;
  font-weight: 800;
}

.source-node {
  border-left: 3px solid var(--green);
  color: var(--green);
  font-weight: 800;
}

.graph-node span {
  color: #3a3d42;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
}

.graph-links {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 28px;
  font-weight: 900;
}

.admin-user-row > div:not(.user-row-actions) {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.admin-user-row strong,
.invite-row strong {
  color: #30343a;
  overflow-wrap: anywhere;
}

.admin-user-row span,
.invite-row span,
.invite-row small {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.admin-user-row small {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 8px;
}

@media (max-width: 940px) {
  .app-shell,
  .content-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    gap: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .source-panel {
    display: none;
  }

  .auth-panel,
  .history-panel {
    display: none;
  }

  .workspace {
    padding: 22px;
  }

  .claim-list {
    grid-template-columns: 1fr;
  }

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

  .graph-canvas:has(.graph-column) {
    grid-template-columns: 1fr;
  }

  .graph-links {
    transform: rotate(90deg);
  }
}

@media (max-width: 620px) {
  .topbar,
  .admin-header,
  .section-heading,
  .search-box {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .search-box {
    display: grid;
  }

  .search-box button,
  .upload-button,
  .library-search-form button,
  .library-source-card .ghost-button {
    width: 100%;
  }

  .library-search-form,
  .library-source-card {
    grid-template-columns: 1fr;
  }

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

  .admin-metrics {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 40px;
  }
}
