:root {
  --bg: #ffffff;
  --surface: #f7f7f5;
  --panel: #ffffff;
  --ink: #191919;
  --muted: #737373;
  --line: #deded9;
  --line-strong: #c8c8c1;
  --accent: #0b7a54;
  --accent-soft: #e6f3ed;
  --warn: #a35d0b;
  --danger: #b42318;
  --shadow: 0 14px 38px rgba(20, 20, 20, 0.08);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0;
}

button, textarea, input {
  font: inherit;
  letter-spacing: 0;
}

button {
  min-height: 36px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  padding: 0 15px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

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

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 0 22px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.mark {
  width: 33px;
  height: 33px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 10px;
  font-weight: 850;
}

.brand strong {
  display: block;
  font-size: 14px;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 1px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}

.auth-status,
.user-badge {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.user-badge {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.login-button,
.ghost-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.login-button {
  background: var(--ink);
  color: #fff;
}

.ghost-button {
  background: var(--panel);
  color: var(--ink);
}

.settings {
  position: relative;
}

.settings summary {
  list-style: none;
  min-height: 36px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.settings summary::-webkit-details-marker {
  display: none;
}

.settings-panel {
  position: absolute;
  right: 0;
  top: 44px;
  width: 280px;
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.settings:not([open]) .settings-panel {
  display: none;
}

.settings-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

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

.login-link {
  min-height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.chat-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.thread {
  width: min(780px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 34px 0 24px;
  overflow: auto;
}

.turn {
  display: flex;
  margin: 0 0 18px;
}

.turn.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(680px, 100%);
  border-radius: 22px;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.5;
}

.turn.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
}

.turn.user .bubble {
  max-width: min(540px, 88%);
  background: var(--ink);
  color: #fff;
}

.bubble p {
  margin: 0;
}

.bubble p + p {
  margin-top: 8px;
}

.hello {
  font-size: 22px;
  line-height: 1.18;
  font-weight: 800;
}

.component {
  min-width: min(640px, calc(100vw - 44px));
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  overflow: hidden;
}

.component-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.component-title {
  display: grid;
  gap: 2px;
}

.component-title strong {
  font-size: 14px;
}

.component-title span {
  color: var(--muted);
  font-size: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #fff;
  font-size: 12px;
  white-space: nowrap;
}

.status.ok {
  color: var(--accent);
  border-color: #aad7c0;
  background: var(--accent-soft);
}

.status.warn {
  color: var(--warn);
  border-color: #e0bb82;
  background: #fff7e8;
}

.status.fail {
  color: var(--danger);
  border-color: #e2aaa4;
  background: #fff1ef;
}

.component-body {
  padding: 13px 14px 14px;
}

.component-body p {
  color: var(--muted);
  font-size: 14px;
}

.facts {
  display: grid;
  gap: 8px;
  margin-top: 11px;
}

.fact {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.fact strong {
  color: var(--ink);
  font-weight: 750;
  text-align: right;
  overflow-wrap: anywhere;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: var(--surface);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.download {
  color: var(--ink);
  font-weight: 800;
}

.auth-gate {
  width: min(780px, calc(100vw - 32px));
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 13px 14px;
}

.auth-gate[hidden] {
  display: none;
}

.auth-gate div {
  display: grid;
  gap: 3px;
}

.auth-gate strong {
  font-size: 14px;
}

.auth-gate span {
  color: var(--muted);
  font-size: 13px;
}

.literature-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.paper {
  display: grid;
  gap: 5px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.paper a {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.paper-meta,
.paper-abstract {
  color: var(--muted);
  font-size: 12px;
}

.paper-abstract {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.project-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.project-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

.project-item div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.project-item strong,
.project-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-item strong {
  font-size: 13px;
}

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

.small-button {
  min-height: 30px;
  padding: 0 11px;
  font-size: 12px;
}

.composer {
  width: min(780px, calc(100vw - 32px));
  margin: 0 auto 18px;
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 10px;
}

.composer.locked {
  opacity: 0.56;
}

.attachment-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 2px 8px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 0 9px;
  color: var(--muted);
  font-size: 12px;
}

.composer textarea {
  width: 100%;
  max-height: 190px;
  min-height: 48px;
  border: 0;
  outline: 0;
  resize: none;
  padding: 8px 9px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.attach {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.attach input {
  display: none;
}

.run-status {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
}

.progress {
  height: 6px;
  flex: 1;
  max-width: 180px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}

.progress div {
  width: 0%;
  height: 100%;
  background: var(--ink);
  transition: width 260ms ease;
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 14px;
  }

  .brand small {
    display: none;
  }

  .top-actions {
    gap: 7px;
  }

  .auth-status {
    display: none;
  }

  .user-badge {
    max-width: 96px;
  }

  .login-button,
  .ghost-button,
  .settings summary {
    min-height: 34px;
    padding: 0 11px;
  }

  .thread {
    width: calc(100vw - 24px);
    padding-top: 22px;
  }

  .bubble {
    font-size: 14px;
  }

  .hello {
    font-size: 20px;
  }

  .component {
    min-width: 0;
  }

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

  .composer {
    width: calc(100vw - 18px);
    margin-bottom: 10px;
    border-radius: 20px;
  }

  .auth-gate {
    width: calc(100vw - 18px);
    align-items: flex-start;
    flex-direction: column;
    margin-bottom: 10px;
    border-radius: 18px;
  }

  .composer-actions {
    flex-wrap: wrap;
  }

  .run-status {
    order: 3;
    flex-basis: 100%;
  }

  .settings-panel {
    right: -4px;
    width: calc(100vw - 28px);
  }
}
