:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #66717f;
  --line: #d8dee6;
  --accent: #0f6b7a;
  --accent-strong: #0b4f59;
  --danger: #8a1f1f;
  --danger-bg: #fff1f1;
  --soft: #eef5f7;
  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(--text);
  overflow-x: hidden;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 48px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 240px;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

h3 {
  font-size: 15px;
}

p {
  color: var(--muted);
  margin: 8px 0 0;
}

.status-pill {
  min-width: 96px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
  margin: 16px 0;
}

.panel,
.notice {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.notice {
  line-height: 1.5;
  color: var(--muted);
}

.notice.urgent {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #f0b9b9;
}

label {
  display: block;
  margin-top: 14px;
  font-weight: 650;
  font-size: 14px;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
}

textarea {
  resize: vertical;
}

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

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

button.secondary {
  border: 1px solid var(--line);
  background: #edf2f5;
  color: var(--text);
}

button.secondary:hover:not(:disabled) {
  background: #dde7ec;
}

button:disabled {
  cursor: not-allowed;
  background: #a8b3bd;
}

.button-link {
  display: inline-grid;
  min-height: 44px;
  place-items: center;
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

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

.button-link.secondary {
  border: 1px solid var(--line);
  background: #edf2f5;
  color: var(--text);
}

.account-box {
  display: grid;
  gap: 4px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.account-box span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
}

.upload-panel button {
  width: 100%;
  margin-top: 16px;
}

.upload-panel.preset-mode label,
.upload-panel.preset-mode #uploadButton,
.upload-panel.preset-mode #buyAnalysisButton {
  display: none;
}

.fineprint,
.progress,
.empty {
  font-size: 14px;
  color: var(--muted);
}

.progress {
  min-height: 20px;
  margin-top: 12px;
}

.progress-meter {
  position: relative;
  height: 28px;
  margin-top: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 240ms ease;
}

.progress-meter span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 750;
  color: var(--text);
}

.share-box {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.share-box span {
  color: var(--muted);
}

.share-box a,
.meta-list dd,
.chat-entry,
.section-card {
  overflow-wrap: anywhere;
}

.share-box button {
  padding: 8px 10px;
  min-height: 38px;
}

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

.section-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.results-panel {
  margin-bottom: 16px;
}

.advanced-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.advanced-panel h3 {
  margin-bottom: 8px;
}

.markdown {
  line-height: 1.55;
}

.markdown ul {
  padding-left: 20px;
}

.markdown code {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
}

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

.section-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
}

.section-card .meta {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 10px;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 80px;
  max-height: 56vh;
  overflow: auto;
  margin: 12px 0;
}

.chat-entry {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.chat-entry.question {
  border-left: 4px solid #7d6f2a;
}

.chat-entry.answer {
  border-left: 4px solid var(--accent);
}

.chat-gate {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--text);
}

.chat-gate span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.chat-gate button {
  flex: 0 0 auto;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 10px;
  align-items: end;
}

.meta-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 12px;
  font-size: 14px;
}

.meta-list dt {
  color: var(--muted);
}

.meta-list dd {
  margin: 0;
}

@media (max-width: 860px) {
  .shell {
    width: min(100% - 16px, 1180px);
    margin: 8px auto 28px;
  }

  .topbar,
  .grid,
  .chat-form {
    display: block;
  }

  .topbar-actions {
    justify-content: stretch;
    min-width: 0;
    width: 100%;
  }

  .topbar-actions > * {
    flex: 1 1 120px;
  }

  h1 {
    font-size: 25px;
  }

  h2 {
    font-size: 17px;
  }

  .panel,
  .notice {
    padding: 14px;
  }

  .notice {
    font-size: 14px;
  }

  .status-pill {
    margin-top: 12px;
    width: 100%;
  }

  .grid .panel + .panel {
    margin-top: 12px;
  }

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

  .chat-form button {
    width: 100%;
    margin-top: 10px;
  }

  .chat-gate {
    display: grid;
    grid-template-columns: 1fr;
  }

  .chat-gate button,
  .button-link {
    width: 100%;
  }

  .section-header {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
  }

  .section-header button,
  .section-actions {
    width: 100%;
  }

  .meta-list {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .meta-list dd {
    margin-bottom: 8px;
  }

  .share-box {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .share-box button {
    width: 100%;
  }

  .chat-log {
    max-height: none;
  }

  textarea {
    min-height: 104px;
  }
}

@media (max-width: 420px) {
  .shell {
    width: calc(100% - 12px);
  }

  h1 {
    font-size: 23px;
  }

  .panel,
  .notice {
    border-radius: 6px;
    padding: 12px;
  }
}
