:root {
  --paper: #f4f0e7;
  --paper-deep: #e9e2d4;
  --surface: #fffdf8;
  --surface-muted: #f7f4ed;
  --ink: #172238;
  --ink-soft: #566071;
  --line: #d9d2c5;
  --blue: #173e67;
  --blue-bright: #245d92;
  --blue-pale: #e8f0f7;
  --amber: #d99b2b;
  --amber-pale: #fff1c9;
  --red: #a9433b;
  --red-pale: #f8e7e3;
  --green: #347154;
  --shadow: 0 18px 50px rgba(28, 39, 54, 0.1);
  --radius: 18px;
  --font-sans: Inter, "Segoe UI", Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  --tg-button-text: #fff;
  --tg-safe-top: 0px;
  --tg-safe-right: 0px;
  --tg-safe-bottom: 0px;
  --tg-safe-left: 0px;
  --tg-content-safe-top: 0px;
  --tg-content-safe-bottom: 0px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 980px;
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 62, 103, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 62, 103, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 36px 36px;
  font-family: var(--font-sans);
  line-height: 1.55;
}

button,
textarea,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(36, 93, 146, 0.32);
  outline-offset: 3px;
}

.app-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  padding: 14px 32px;
  color: #fff;
  background: var(--ink);
  border-bottom: 4px solid var(--amber);
}

.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--ink);
  background: var(--amber);
  border-radius: 8px 13px 8px 13px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 17px;
  letter-spacing: 0.01em;
}

.brand small {
  color: #aeb9c8;
  font-size: 12px;
}

.model-status {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: #d6dee8;
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #aeb9c8;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
}

.model-status.is-loaded .status-dot {
  background: #6bd59a;
}

.model-status.is-busy .status-dot {
  background: var(--amber);
}

.app-shell {
  width: min(1500px, calc(100% - 56px));
  margin: 0 auto;
  padding: 34px 0 48px;
}

.screen {
  min-height: calc(100vh - 160px);
}

.gate-screen {
  display: grid;
  place-items: center;
}

.gate-card {
  width: min(480px, 100%);
  padding: 40px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.gate-card h1 {
  margin: 18px 0 8px;
  font-family: var(--font-serif);
}

.startup-recovery {
  margin-top: 20px;
  padding: 16px 18px;
  border: 1px solid color-mix(in srgb, var(--red) 35%, var(--line));
  border-radius: 12px;
  background: color-mix(in srgb, var(--red) 6%, var(--surface));
  text-align: left;
}

.startup-recovery ol {
  margin: 10px 0 0;
  padding-left: 22px;
}

.startup-recovery li + li {
  margin-top: 8px;
}

.gate-spinner {
  display: inline-block;
  width: 36px;
  height: 36px;
  border: 4px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: gate-spin 0.8s linear infinite;
}

@keyframes gate-spin {
  to { transform: rotate(360deg); }
}

.empty-screen {
  display: grid;
  grid-template-columns: minmax(420px, 0.95fr) minmax(430px, 1.05fr);
  gap: 72px;
  align-items: center;
  max-width: 1240px;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--blue-bright);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.empty-copy h1 {
  max-width: 680px;
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(46px, 5vw, 76px);
  font-weight: 500;
  letter-spacing: -0.045em;
  line-height: 0.98;
}

.lead {
  max-width: 620px;
  margin: 26px 0 32px;
  color: var(--ink-soft);
  font-size: 18px;
}

.trust-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.trust-list li {
  display: flex;
  gap: 12px;
  align-items: center;
  font-weight: 650;
}

.trust-list span {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: var(--blue);
  background: var(--blue-pale);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 900;
}

.upload-card,
.progress-card,
.log-panel,
.error-card,
.notebook-panel,
.viewer-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.upload-card {
  padding: 22px;
}

.drop-zone {
  display: grid;
  min-height: 360px;
  place-items: center;
  align-content: center;
  padding: 36px;
  text-align: center;
  background:
    linear-gradient(135deg, rgba(36, 93, 146, 0.05), transparent 60%),
    var(--surface-muted);
  border: 2px dashed #9aabbb;
  border-radius: 14px;
  cursor: pointer;
}

.drop-zone.is-dragging {
  background: var(--blue-pale);
  border-color: var(--blue-bright);
}

.drop-zone strong {
  margin-top: 18px;
  font-family: var(--font-serif);
  font-size: 27px;
  font-weight: 600;
}

.drop-zone span:last-child {
  color: var(--ink-soft);
}

.drop-icon {
  display: grid;
  width: 74px;
  height: 74px;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 20px 28px 20px 28px;
  font-size: 42px;
  line-height: 1;
}

.file-hint {
  margin: 14px 4px 0;
  color: var(--ink-soft);
  font-size: 13px;
  text-align: center;
}

.file-preview {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px;
  padding: 16px;
  background: var(--blue-pale);
  border-radius: 12px;
}

.file-preview strong,
.file-preview span {
  display: block;
}

.file-preview span {
  color: var(--ink-soft);
  font-size: 13px;
}

.url-upload {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.url-divider {
  display: block;
  margin-bottom: 10px;
  color: var(--ink-soft);
  font-size: 13px;
  text-align: center;
}

.url-input-row {
  display: flex;
  gap: 10px;
}

.url-input-row input {
  min-width: 0;
  flex: 1;
  padding: 12px 14px;
  color: var(--ink);
  background: var(--surface-muted);
  border: 1px solid #9aabbb;
  border-radius: 9px;
  font: inherit;
}

.url-input-row input:focus {
  border-color: var(--blue-bright);
  outline: 2px solid var(--blue-pale);
}

.subtitle-choice {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 13px;
}

.url-settings {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 13px;
}

.url-settings summary {
  cursor: pointer;
  font-weight: 750;
}

.url-settings p {
  margin: 10px 0 0;
}

.cookie-warning {
  padding: 10px 12px;
  color: var(--red);
  background: var(--red-pale);
  border-left: 4px solid var(--red);
}

.material-source-url {
  display: inline-block;
  margin-top: 4px;
  color: var(--blue);
  font-size: 13px;
}

.material-source-url[hidden] {
  display: none;
}

.inline-error {
  margin: 14px 0 0;
  padding: 10px 12px;
  color: var(--red);
  background: var(--red-pale);
  border-left: 4px solid var(--red);
}

.button {
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 750;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.button-primary {
  color: var(--tg-button-text);
  background: var(--blue);
}

.button-secondary {
  color: var(--blue);
  background: #fff;
  border-color: #91a6bb;
}

.button-danger {
  color: var(--red);
  background: #fff;
  border-color: #d4a39e;
}

.button-quiet {
  color: var(--ink-soft);
  background: var(--surface-muted);
  border-color: var(--line);
}

.export-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.export-link[hidden] {
  display: none;
}

.text-button {
  padding: 4px 0;
  color: var(--blue-bright);
  background: none;
  border: 0;
  border-bottom: 1px solid currentColor;
  cursor: pointer;
  font-size: 13px;
}

.button-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.muted {
  color: var(--ink-soft);
}

.material-warning {
  color: #8a5a08;
  font-size: 13px;
  font-weight: 600;
  margin: 5px 0 0;
}

.section-heading,
.material-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-heading {
  max-width: 1100px;
  margin: 28px auto 24px;
}

.section-heading h1,
.material-identity h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 600;
}

.section-heading h1 {
  font-size: 38px;
}

.section-heading p:last-child,
.material-identity p {
  margin: 5px 0 0;
}

.process-screen {
  max-width: 1100px;
  margin: 0 auto;
}

.progress-card {
  padding: 30px;
}

.progress-summary {
  display: grid;
  grid-template-columns: 115px 1fr;
  gap: 26px;
  align-items: center;
}

.progress-summary > span {
  color: var(--blue);
  font-family: var(--font-serif);
  font-size: 54px;
  line-height: 1;
}

.progress-summary strong,
.progress-summary span {
  display: block;
}

.progress-summary div span {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 14px;
}

.progress-track {
  height: 13px;
  margin: 26px 0 30px;
  overflow: hidden;
  background: var(--paper-deep);
  border-radius: 999px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: var(--blue-bright);
  border-radius: inherit;
}

.stage-checklist {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stage-checklist li {
  min-height: 74px;
  padding: 13px;
  color: var(--ink-soft);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
}

.stage-checklist .stage-symbol {
  display: block;
  margin-bottom: 5px;
  font-size: 19px;
  font-weight: 900;
}

.stage-checklist li.is-done {
  color: var(--green);
  background: #edf6f0;
  border-color: #b7d5c3;
}

.stage-checklist li.is-active {
  color: var(--blue);
  background: var(--blue-pale);
  border-color: #a9bfd3;
}

.log-panel {
  margin-top: 18px;
  padding: 16px 20px;
  box-shadow: none;
}

summary {
  cursor: pointer;
  font-weight: 750;
}

.job-log {
  max-height: 250px;
  margin: 14px 0 0;
  padding: 14px 14px 14px 40px;
  overflow: auto;
  color: #d5deea;
  background: #202d42;
  border-radius: 10px;
  font-family: Consolas, monospace;
  font-size: 12px;
}

.job-log li + li {
  margin-top: 5px;
}

.error-screen {
  display: grid;
  place-items: center;
}

.error-card {
  width: min(720px, 100%);
  padding: 42px;
  border-top: 6px solid var(--red);
}

.error-symbol {
  display: grid;
  width: 60px;
  height: 60px;
  margin-bottom: 20px;
  place-items: center;
  color: #fff;
  background: var(--red);
  border-radius: 50%;
  font-family: var(--font-serif);
  font-size: 38px;
  font-weight: 700;
}

.error-card h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 38px;
  font-weight: 600;
}

.error-message {
  margin: 18px 0 24px;
  font-size: 17px;
}

.technical-details {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.technical-details pre {
  max-height: 260px;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  color: #e5edf7;
  background: #202d42;
  border-radius: 8px;
  font-size: 12px;
}

.work-screen {
  min-height: 0;
}

.material-bar {
  margin-bottom: 18px;
  padding: 0 4px;
}

.material-identity {
  display: flex;
  gap: 14px;
  align-items: center;
}

.material-identity h1 {
  max-width: 650px;
  overflow: hidden;
  font-size: 26px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kind-badge {
  display: grid;
  min-width: 60px;
  height: 60px;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 13px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(520px, 0.92fr) minmax(480px, 1.08fr);
  gap: 20px;
  min-height: 720px;
  height: calc(100vh - 190px);
}

.notebook-panel,
.viewer-panel {
  min-width: 0;
  overflow: hidden;
}

.notebook-panel {
  display: flex;
  flex-direction: column;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 10px 12px 0;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--line);
}

.tab {
  position: relative;
  padding: 12px 18px 13px;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  font-weight: 750;
}

.tab.is-active {
  color: var(--blue);
  border-bottom-color: var(--amber);
}

.tab-count {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  margin-left: 4px;
  place-items: center;
  background: var(--paper-deep);
  border-radius: 99px;
  font-size: 11px;
}

.tab-view {
  height: 100%;
  padding: 28px;
  overflow: auto;
}

.view-heading,
.subheading,
.chat-heading {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: space-between;
}

.view-heading h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 600;
}

.coverage-badge {
  padding: 6px 9px;
  color: var(--blue);
  background: var(--blue-pale);
  border-radius: 99px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.summary-abstract {
  margin-top: 24px;
  color: #28354a;
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.72;
}

.summary-abstract p {
  margin: 0;
}

.summary-abstract.is-empty {
  display: grid;
  gap: 12px;
  justify-items: start;
  color: var(--ink-soft);
  background: var(--surface-muted);
  border: 1px dashed var(--line);
}

.summary-abstract.is-empty strong {
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 22px;
}

.content-section {
  margin-top: 32px;
  padding-top: 25px;
  border-top: 1px solid var(--line);
}

.content-section h3,
.transcript-heading h3 {
  margin: 0 0 14px;
  font-size: 15px;
}

.subheading span,
.transcript-heading span {
  color: var(--ink-soft);
  font-size: 12px;
}

.outline-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.outline-list li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 11px 0;
  border-bottom: 1px solid #ebe5da;
}

.outline-level {
  color: #87919f;
  font-family: var(--font-serif);
  font-size: 12px;
}

.locator-button,
.question-chip {
  cursor: pointer;
}

.locator-button {
  padding: 2px 0;
  color: var(--blue-bright);
  background: none;
  border: 0;
  border-bottom: 1px solid currentColor;
  font-size: 12px;
  white-space: nowrap;
}

.outline-title-button {
  padding: 0;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}

.question-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.question-chip {
  padding: 8px 11px;
  color: var(--blue);
  background: var(--blue-pale);
  border: 1px solid #b9cadb;
  border-radius: 9px;
  font-size: 13px;
  text-align: left;
}

.theses-list {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

.thesis-card {
  padding: 18px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-left: 4px solid var(--amber);
  border-radius: 10px;
}

.thesis-card p {
  margin: 0 0 12px;
}

.source-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.source-index {
  display: inline-grid;
  width: 25px;
  height: 25px;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 900;
}

.chat-view {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  margin: 18px -8px 0;
  padding: 0 8px 20px;
  overflow: auto;
}

.chat-empty {
  display: grid;
  min-height: 240px;
  place-items: center;
  align-content: center;
  color: var(--ink-soft);
  text-align: center;
}

.chat-empty span {
  font-size: 40px;
}

.chat-message {
  max-width: 92%;
  margin-bottom: 16px;
}

.chat-message.is-user {
  margin-left: auto;
  padding: 12px 15px;
  color: #fff;
  background: var(--blue);
  border-radius: 14px 14px 3px 14px;
}

.chat-message.is-assistant {
  padding: 15px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 3px 14px 14px 14px;
}

.chat-message p {
  margin: 0;
  white-space: pre-wrap;
}

.answer-sources {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.answer-sources strong {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.search-details {
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 12px;
}

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

.search-grid span {
  display: flex;
  justify-content: space-between;
}

.refusal-card {
  max-width: 100%;
  padding: 18px;
  background: #f2f3f4;
  border: 1px solid #c9ced4;
  border-left: 5px solid #707b88;
  border-radius: 4px 14px 14px 4px;
}

.refusal-card h3 {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: 21px;
}

.refusal-hint {
  color: var(--ink-soft);
  font-size: 13px;
}

.closest-fragment {
  margin-top: 14px;
  padding: 14px;
  background: #fff;
  border: 1px solid #d4d7da;
  border-radius: 9px;
}

.closest-fragment header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.score-badge {
  color: var(--ink-soft);
  font-family: Consolas, monospace;
  font-size: 12px;
}

.chat-composer {
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.chat-composer label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 750;
}

.chat-composer textarea {
  width: 100%;
  resize: vertical;
  padding: 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #aeb8c2;
  border-radius: 10px;
}

.composer-footer {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.composer-footer > span {
  color: var(--ink-soft);
  font-size: 11px;
}

.viewer-panel {
  display: flex;
  flex-direction: column;
  background: #e7e2d8;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 80px;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.viewer-header h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 600;
}

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

.viewer-close {
  display: none;
}

.viewer-locator {
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

.viewer-empty {
  display: grid;
  flex: 1;
  place-items: center;
  align-content: center;
  color: #687280;
  text-align: center;
}

.viewer-empty span {
  font-size: 60px;
}

.viewer-empty p {
  margin: 4px 0 0;
}

.pdf-viewer,
.document-viewer,
.media-viewer {
  flex: 1;
  min-height: 0;
}

.pdf-viewer {
  display: flex;
  flex-direction: column;
}

.page-canvas {
  flex: 1;
  min-height: 0;
  padding: 20px;
  overflow: auto;
  text-align: center;
}

.page-canvas img {
  max-width: 100%;
  background: #fff;
  box-shadow: 0 12px 30px rgba(21, 31, 44, 0.2);
}

.page-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.document-viewer {
  padding: 34px;
  overflow: auto;
  background: var(--surface-muted);
}

.document-section {
  color: var(--ink-soft);
  font-size: 13px;
}

.document-viewer blockquote {
  margin: 22px 0;
  padding: 26px;
  background: #fff;
  border-left: 5px solid var(--amber);
  box-shadow: 0 10px 28px rgba(28, 39, 54, 0.08);
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 1.7;
}

.document-viewer mark {
  background: var(--amber-pale);
}

.media-viewer {
  padding: 22px;
  overflow: hidden;
}

.media-viewer video {
  width: 100%;
  max-height: 44%;
  background: #111;
  border-radius: 10px;
}

.media-viewer audio {
  width: 100%;
}

.transcript-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 20px 0 8px;
}

.transcript-list {
  max-height: calc(100% - 150px);
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.transcript-list li {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid #d0cbc1;
  cursor: pointer;
  font-size: 13px;
}

.transcript-list li.is-active {
  background: var(--amber-pale);
  border-left: 4px solid var(--amber);
}

.transcript-time {
  color: var(--blue);
  font-family: Consolas, monospace;
  font-size: 11px;
}

.confirm-dialog {
  width: min(520px, calc(100% - 40px));
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.confirm-dialog::backdrop {
  background: rgba(14, 23, 38, 0.58);
}

.confirm-dialog form {
  padding: 30px;
}

.confirm-dialog h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 600;
}

.confirm-dialog .button-row {
  justify-content: flex-end;
  margin-top: 24px;
}

.toast {
  position: fixed;
  z-index: 20;
  right: 26px;
  bottom: 26px;
  max-width: 420px;
  padding: 13px 16px;
  color: #fff;
  background: var(--ink);
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.outline-link {
  grid-column: 1 / -1;
  padding-left: calc((var(--outline-level, 1) - 1) * 18px);
  color: var(--ink);
  font-weight: 650;
}

.thesis-card {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 12px;
}

.thesis-number {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 850;
}

.source-caption {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.source-button.is-approximate {
  border-style: dashed;
  color: var(--ink-soft);
}

.approximate-source,
.stream-note,
.no-candidate {
  color: var(--ink-soft);
  font-size: 12px;
}

.refusal-kicker {
  margin-bottom: 8px;
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 700;
}

.candidate-heading {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
}

.candidate-snippet {
  margin: 9px 0 12px;
  white-space: pre-wrap;
}

.retrieval-item {
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.retrieval-item span {
  color: var(--ink-soft);
}

.transcript-segment {
  display: grid;
  width: 100%;
  grid-template-columns: 62px 1fr;
  gap: 10px;
  padding: 10px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid #d0cbc1;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}

.transcript-segment.is-active {
  padding-left: 6px;
  background: var(--amber-pale);
  border-left: 4px solid var(--amber);
}

.transcript-text {
  white-space: pre-wrap;
}

.toast[data-tone="error"] {
  background: var(--red);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.progress-card.is-queued {
  border: 3px solid var(--amber);
}

.progress-card.is-queued .progress-summary strong,
.progress-card.is-queued .progress-summary > span {
  font-size: 1.2em;
}

@media (max-width: 760px) {
  html {
    min-width: 0;
    overflow-x: hidden;
  }

  body {
    min-height: 100dvh;
    padding-right: var(--tg-safe-right);
    padding-left: var(--tg-safe-left);
    background: var(--paper);
  }

  body.viewer-open {
    overflow: hidden;
  }

  .app-header {
    min-height: 58px;
    padding: calc(8px + var(--tg-safe-top)) 14px 8px;
    border-bottom-width: 2px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand small,
  .model-status {
    display: none;
  }

  .app-shell {
    width: 100%;
    padding: 14px 12px calc(18px + var(--tg-safe-bottom));
  }

  .screen {
    min-height: calc(100dvh - 88px - var(--tg-safe-top));
  }

  .gate-card {
    padding: 28px 20px;
  }

  .empty-screen {
    display: flex;
    flex-direction: column;
    gap: 24px;
    align-items: stretch;
  }

  .empty-copy h1 {
    font-size: 38px;
  }

  .lead {
    margin: 16px 0;
    font-size: 16px;
  }

  .trust-list {
    display: none;
  }

  .upload-card {
    padding: 14px;
  }

  .drop-zone {
    min-height: 180px;
    padding: 20px;
  }

  .url-input-row,
  .section-heading,
  .material-bar,
  .composer-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .url-input-row .button,
  .file-preview .button,
  .composer-footer .button,
  .gate-card .button {
    width: 100%;
  }

  .section-heading {
    gap: 12px;
    margin: 8px 0 16px;
  }

  .progress-card,
  .log-panel,
  .error-card {
    border-radius: 13px;
  }

  .progress-card.is-queued {
    position: sticky;
    top: calc(8px + var(--tg-content-safe-top));
    z-index: 2;
    box-shadow: 0 12px 32px rgba(28, 39, 54, 0.2);
  }

  .material-bar {
    gap: 14px;
    margin-bottom: 12px;
  }

  .material-identity {
    align-items: flex-start;
  }

  .material-identity h1 {
    max-width: calc(100vw - 110px);
    font-size: 21px;
  }

  .kind-badge {
    min-width: 48px;
    height: 48px;
  }

  .material-bar > .button-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .material-bar .button,
  .material-bar .export-link {
    min-width: 0;
    justify-content: center;
    text-align: center;
  }

  .workspace-grid {
    display: block;
    min-height: calc(100dvh - 210px);
    height: calc(100dvh - 190px - var(--tg-safe-top) - var(--tg-safe-bottom));
  }

  .notebook-panel {
    height: 100%;
    border-radius: 13px;
  }

  .tabs {
    padding: 6px 4px 0;
  }

  .tab {
    flex: 1;
    padding: 10px 6px;
    font-size: 13px;
  }

  .tab-view {
    padding: 15px;
  }

  .view-heading h2 {
    font-size: 25px;
  }

  .chat-view {
    padding-bottom: var(--tg-content-safe-bottom);
  }

  .chat-messages {
    margin-top: 8px;
  }

  .chat-message {
    max-width: 98%;
  }

  .chat-composer textarea {
    max-height: 120px;
    resize: none;
  }

  .composer-footer > span {
    display: none;
  }

  .viewer-panel {
    position: fixed;
    z-index: 50;
    inset: 0;
    width: 100%;
    height: 100dvh;
    padding-top: var(--tg-safe-top);
    padding-right: var(--tg-safe-right);
    padding-bottom: var(--tg-safe-bottom);
    padding-left: var(--tg-safe-left);
    visibility: hidden;
    border: 0;
    border-radius: 0;
    opacity: 0;
    transform: translateX(100%);
    transition: transform 180ms ease, opacity 180ms ease;
    pointer-events: none;
  }

  .viewer-panel.is-mobile-open {
    visibility: visible;
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
  }

  .viewer-header {
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
    min-height: 64px;
    padding: 10px 12px;
  }

  .viewer-header h2 {
    font-size: 18px;
  }

  .viewer-header-actions {
    flex-direction: row;
    justify-content: space-between;
    min-width: 0;
  }

  .viewer-locator {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .viewer-close {
    display: inline-flex;
  }

  .telegram-mode .viewer-close {
    display: none;
  }

  .page-canvas {
    padding: 10px;
  }

  .page-navigation {
    padding: 8px 10px;
  }

  .document-viewer {
    padding: 18px;
  }

  .media-viewer {
    padding-bottom: var(--tg-content-safe-bottom);
  }

  .media-viewer video,
  .media-viewer audio {
    width: 100%;
  }

  .confirm-dialog {
    width: calc(100% - 24px);
    max-width: none;
  }
}
