/* he-leido theme - Graphite terminal workstation.
 * Warm greys on near-black with a single amber-yellow accent. Keep styling
 * token-led. Design reference: docs/design-mockups/mockup-5-graphite.html. */

*, *::before, *::after { box-sizing: border-box; }

:root {
  /* Backgrounds */
  --ds-background-page: #0D0D0D;
  --ds-background-surface: #131313;
  --ds-background-surface-raised: #131313;
  --ds-background-surface-overlay: #1E1E1E;
  --ds-background-input: #1A1A1A;
  --ds-background-brand-bold: #B3B3B0;
  --ds-background-brand-bold-hovered: #DEDEDA;
  --ds-background-neutral: rgba(179, 179, 176, 0.08);
  --ds-background-neutral-hovered: rgba(179, 179, 176, 0.14);
  --ds-background-danger-bold: #C97C6C;
  --ds-background-success-bold: #8FA98F;
  --ds-background-warning-bold: #D9A96B;
  --ds-background-warning-bold-hovered: #E5BC85;
  --ds-background-warning-soft: rgba(217, 169, 107, 0.09);
  --ds-background-information-bold: #8C8C89;

  /* Text */
  --ds-text: #B3B3B0;
  --ds-text-subtle: #7C7C79;
  --ds-text-subtlest: #5A5A57;
  --ds-text-inverse: #121212;
  --ds-text-brand: #DEDEDA;
  --ds-text-danger: #D9A96B;
  --ds-text-success: #8FA98F;
  --ds-text-terminal-green: #00FF66;
  --ds-link: #DEDEDA;
  --ds-link-pressed: #FFFFFF;

  /* Borders */
  --ds-border: #3A3A38;
  --ds-border-bold: #8C8C89;
  --ds-border-focused: #B3B3B0;
  --ds-border-brand: #8C8C89;
  --ds-border-danger: #C97C6C;

  /* Space */
  --ds-space-025: 2px;
  --ds-space-050: 4px;
  --ds-space-075: 6px;
  --ds-space-100: 8px;
  --ds-space-150: 12px;
  --ds-space-200: 16px;
  --ds-space-250: 20px;
  --ds-space-300: 24px;
  --ds-space-400: 32px;
  --ds-space-500: 40px;
  --ds-space-600: 48px;
  --ds-space-800: 64px;
  --ds-space-1000: 80px;

  /* Typography - mono-first terminal */
  --ds-font-family-body: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, "Liberation Mono", monospace;
  --ds-font-family-code: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, "Liberation Mono", monospace;
  --ds-font-size-075: 12px;
  --ds-font-size-100: 14px;
  --ds-font-size-200: 16px;
  --ds-font-size-300: 20px;
  --ds-font-size-400: 24px;
  --ds-font-size-500: 29px;
  --ds-line-height-100: 16px;
  --ds-line-height-200: 20px;
  --ds-line-height-300: 24px;
  --ds-line-height-400: 28px;
  --ds-line-height-500: 32px;
  --ds-font-weight-regular: 400;
  --ds-font-weight-medium: 500;
  --ds-font-weight-semibold: 600;
  --ds-font-weight-bold: 700;

  /* Radius - terminal frames are square-ish */
  --ds-radius-050: 1px;
  --ds-radius-100: 2px;
  --ds-radius-200: 2px;
  --ds-radius-300: 3px;
  --ds-radius-400: 3px;

  /* Shadow becomes glow, whisper-level */
  --ds-shadow-raised: 0 0 5px rgba(179, 179, 176, 0.18);
  --ds-shadow-overlay: 0 0 8px rgba(179, 179, 176, 0.14);
}

html {
  min-width: 320px;
  background: var(--ds-background-page);
}

body {
  background: var(--ds-background-page);
  color: var(--ds-text);
  font-family: var(--ds-font-family-body);
  font-size: var(--ds-font-size-100);
  line-height: var(--ds-line-height-300);
  margin: 0;
  padding: clamp(var(--ds-space-300), 5vw, var(--ds-space-800)) clamp(var(--ds-space-150), 4vw, var(--ds-space-500));
}

/* Faint scanline overlay - one deletable rule, no assets */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(222, 222, 218, 0.015) 0px,
    rgba(222, 222, 218, 0.015) 1px,
    transparent 1px,
    transparent 3px
  );
}

::selection { background: rgba(179, 179, 176, 0.22); }

main,
.container {
  width: min(100%, 72rem);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-300);
}

body > main > h1,
.container > h1 {
  color: var(--ds-text-brand);
  font-size: var(--ds-font-size-400);
  font-weight: var(--ds-font-weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: var(--ds-line-height-500);
  margin: 0;
}

body > main > h1::before,
.container > h1::before {
  content: "$ ";
  color: var(--ds-text-subtle);
}

body > main > h1::after,
.container > h1::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: var(--ds-space-075);
  vertical-align: text-bottom;
  background: var(--ds-text-brand);
  animation: cursor-blink 1.1s steps(2, start) infinite;
}

@keyframes cursor-blink {
  to { visibility: hidden; }
}

p {
  margin: 0;
  color: var(--ds-text-subtle);
}

a {
  color: var(--ds-link);
  text-decoration: underline;
}

a:active {
  color: var(--ds-link-pressed);
}

label {
  display: block;
  margin-bottom: var(--ds-space-050);
  color: var(--ds-text-brand);
  font-size: var(--ds-font-size-075);
  font-weight: var(--ds-font-weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

input[type="text"],
input[type="password"],
input[type="file"],
input[type="number"],
textarea {
  width: 100%;
  min-width: 0;
  background: var(--ds-background-input);
  color: var(--ds-text);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-200);
  padding: var(--ds-space-100) var(--ds-space-150);
  font: inherit;
}

input[type="file"] {
  border-style: dashed;
  padding: var(--ds-space-250) var(--ds-space-200);
  cursor: pointer;
}

input[type="file"]:hover {
  border-color: var(--ds-border-bold);
  background: var(--ds-background-neutral);
}

input::file-selector-button {
  background: var(--ds-background-neutral);
  color: var(--ds-text);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-200);
  padding: var(--ds-space-075) var(--ds-space-150);
  margin-right: var(--ds-space-150);
  font: inherit;
  cursor: pointer;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--ds-border-focused);
  box-shadow: var(--ds-shadow-raised);
}

textarea {
  min-height: 132px;
  resize: vertical;
}

::placeholder { color: var(--ds-text-subtlest); }

form {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-150);
  align-items: stretch;
}

button {
  background: var(--ds-background-neutral);
  color: var(--ds-text);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-200);
  padding: var(--ds-space-100) var(--ds-space-200);
  font: inherit;
  font-weight: var(--ds-font-weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 40px;
}

button:hover {
  background: var(--ds-background-neutral-hovered);
  border-color: var(--ds-border-bold);
}

button:focus-visible {
  outline: 2px solid var(--ds-border-focused);
  outline-offset: 2px;
}

button:disabled {
  background: transparent;
  color: var(--ds-text-subtlest);
  border-color: var(--ds-border);
  cursor: not-allowed;
}

button.primary {
  background: var(--ds-background-brand-bold);
  color: var(--ds-text-inverse);
  border-color: transparent;
}

button.primary:hover {
  background: var(--ds-background-brand-bold-hovered);
  border-color: transparent;
}

button.warning {
  background: var(--ds-background-warning-bold);
  color: var(--ds-text-inverse);
  border-color: transparent;
}

button.warning:hover {
  background: var(--ds-background-warning-bold-hovered);
  border-color: transparent;
}

/* Status bar - authed pages only, shown above the page title */
main > .status-bar,
.container > .status-bar {
  order: -1;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: var(--ds-space-200);
  background: var(--ds-background-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-200);
  padding: var(--ds-space-075) var(--ds-space-150);
  font-size: var(--ds-font-size-075);
  letter-spacing: 0.06em;
}

.status-name {
  color: var(--ds-text-brand);
  font-weight: var(--ds-font-weight-bold);
}

.status-logout {
  margin-left: auto;
  color: var(--ds-text-subtle);
  text-decoration: none;
  text-transform: uppercase;
}

.status-logout:hover {
  color: var(--ds-text);
  text-decoration: underline;
}

/* TUI frame panels with bracketed corner labels */
.upload-panel,
.workflow-panel,
.review-form,
.llm-audit-panel,
.markdown-output,
#viewer-container {
  background: var(--ds-background-surface-raised);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-300);
  position: relative;
}

.upload-panel,
.workflow-panel,
.review-form,
.llm-audit-panel,
.markdown-output {
  padding: var(--ds-space-400) var(--ds-space-300) var(--ds-space-300);
  margin-top: var(--ds-space-150);
}

.upload-panel::before,
.workflow-panel::before,
.review-form::before,
.llm-audit-panel::before,
.viewer-page::before,
.markdown-output::before {
  position: absolute;
  top: -9px;
  left: var(--ds-space-200);
  z-index: 1;
  background: var(--ds-background-page);
  color: var(--ds-text-brand);
  font-size: var(--ds-font-size-075);
  font-weight: var(--ds-font-weight-semibold);
  letter-spacing: 0.14em;
  line-height: var(--ds-line-height-100);
  padding: 0 var(--ds-space-075);
}

.upload-panel::before { content: "[ UPLOAD ]"; }
.workflow-panel::before { content: "[ BOILERPLATE CHECK ]"; }
.review-form::before { content: "[ REVIEW ]"; }
.llm-audit-panel::before { content: "[ LLM PROMPT ]"; }
.markdown-output::before { content: "[ OUTPUT ]"; }

.upload-panel {
  max-width: 36rem;
}

.page-range-fieldset {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-100);
}

.page-range-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--ds-space-150);
}

.viewer-page {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-250);
  position: relative;
  margin-top: var(--ds-space-150);
}

/* The viewer clips its own overflow, so its corner label hangs off
 * .viewer-page instead (the viewer is its first child). */
.viewer-page::before { content: "[ DOCUMENT ]"; }

#viewer-container {
  height: clamp(24rem, 62vh, 42rem);
  padding: var(--ds-space-300);
  overflow: hidden;
  background: var(--ds-background-surface-overlay);
}

.page-block {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--ds-font-family-code);
  font-size: var(--ds-font-size-100);
  line-height: var(--ds-line-height-300);
  color: var(--ds-text);
  background: transparent;
  margin: 0;
}

.comparison-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--ds-space-200);
  min-height: 0;
  overflow: hidden;
  font-family: var(--ds-font-family-body);
}

.comparison-pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-100);
}

.comparison-pane h2 {
  color: var(--ds-text-brand);
  font-size: var(--ds-font-size-075);
  font-weight: var(--ds-font-weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: var(--ds-line-height-200);
  margin: 0;
}

.comparison-text {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--ds-background-input);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-200);
  color: var(--ds-text);
  font-family: var(--ds-font-family-code);
  font-size: var(--ds-font-size-100);
  line-height: var(--ds-line-height-300);
  margin: 0;
  padding: var(--ds-space-200);
}

.rendered-markdown {
  white-space: normal;
  font-family: var(--ds-font-family-body);
}

.rendered-markdown > :first-child {
  margin-top: 0;
}

.rendered-markdown > :last-child {
  margin-bottom: 0;
}

.rendered-markdown h1,
.rendered-markdown h2,
.rendered-markdown h3 {
  color: var(--ds-text-brand);
  line-height: var(--ds-line-height-400);
  margin: var(--ds-space-200) 0 var(--ds-space-100);
}

.rendered-markdown p,
.rendered-markdown ul,
.rendered-markdown ol,
.rendered-markdown blockquote {
  margin: 0 0 var(--ds-space-150);
  color: var(--ds-text);
}

.rendered-markdown code,
.rendered-markdown pre {
  font-family: var(--ds-font-family-code);
}

.rendered-markdown pre {
  overflow: auto;
  background: var(--ds-background-input);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-200);
  padding: var(--ds-space-150);
}

.removed-text {
  background: var(--ds-background-warning-soft);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-050);
  color: var(--ds-text-danger);
  padding: 0 var(--ds-space-025);
}

.viewer-toolbar,
#nav-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--ds-space-150);
}

#page-counter {
  color: var(--ds-text-subtle);
  font-size: var(--ds-font-size-100);
  font-weight: var(--ds-font-weight-medium);
  letter-spacing: 0.06em;
  min-width: 7rem;
  text-align: center;
}

#identify-form,
.review-form,
.llm-audit-panel {
  gap: var(--ds-space-200);
}

.review-form h2,
.llm-audit-panel h2,
.markdown-output h2 {
  color: var(--ds-text-brand);
  font-size: var(--ds-font-size-200);
  font-weight: var(--ds-font-weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: var(--ds-line-height-300);
  margin: 0;
}

.review-form h2::before,
.llm-audit-panel h2::before,
.markdown-output h2::before {
  content: "> ";
  color: var(--ds-text-subtle);
}

.current-status {
  color: var(--ds-text-terminal-green);
  text-shadow: 0 0 6px rgba(0, 255, 102, 0.35);
  margin: 0;
  min-height: var(--ds-line-height-300);
  white-space: pre-wrap;
}

.llm-audit-panel {
  display: flex;
  flex-direction: column;
}

.llm-audit-drawer {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-200);
}

.llm-audit-drawer > summary {
  color: var(--ds-text-brand);
  cursor: pointer;
  font-size: var(--ds-font-size-200);
  font-weight: var(--ds-font-weight-bold);
  letter-spacing: 0.08em;
  line-height: var(--ds-line-height-300);
  text-transform: uppercase;
}

.llm-audit-drawer > summary::marker {
  color: var(--ds-text-terminal-green);
}

.llm-prompt-text {
  max-height: 24rem;
  overflow: auto;
}

.action-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--ds-space-150);
}

.preset-save-row {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: minmax(12rem, 1fr) auto;
  align-items: end;
}

.htmx-indicator {
  color: var(--ds-text-subtle);
  font-style: italic;
  opacity: 0;
  transition: opacity 200ms;
}

.htmx-request .htmx-indicator {
  opacity: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--ds-space-100) 0 var(--ds-space-150);
}

th,
td {
  border-bottom: 1px solid var(--ds-border);
  padding: var(--ds-space-150);
  text-align: left;
  vertical-align: top;
}

th:first-child,
td:first-child {
  width: 5.5rem;
}

th {
  color: var(--ds-text-subtle);
  font-size: var(--ds-font-size-075);
  font-weight: var(--ds-font-weight-semibold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-bottom-color: var(--ds-border-bold);
}

tbody tr:hover td {
  background: rgba(179, 179, 176, 0.05);
}

td input[type="checkbox"] {
  width: auto;
  margin: var(--ds-space-025) 0 0;
  accent-color: var(--ds-background-brand-bold);
}

.example {
  color: var(--ds-text);
  margin-bottom: var(--ds-space-075);
}

.pattern {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  background: var(--ds-background-warning-soft);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-100);
  color: var(--ds-text-danger);
  font-family: var(--ds-font-family-code);
  font-size: var(--ds-font-size-075);
  line-height: var(--ds-line-height-200);
  padding: var(--ds-space-025) var(--ds-space-075);
}

.markdown-output {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-150);
}

.markdown-output pre {
  max-height: 52vh;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--ds-background-input);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-200);
  color: var(--ds-text);
  font-family: var(--ds-font-family-code);
  font-size: var(--ds-font-size-100);
  line-height: var(--ds-line-height-300);
  margin: 0;
  padding: var(--ds-space-200);
}

@media (max-width: 700px) {
  body {
    padding: var(--ds-space-300) var(--ds-space-150);
  }

  body > main > h1,
  .container > h1 {
    font-size: var(--ds-font-size-300);
    line-height: var(--ds-line-height-400);
  }

  .upload-panel::before,
  .workflow-panel::before,
  .review-form::before,
  .viewer-page::before,
  .markdown-output::before {
    font-size: 10px;
    letter-spacing: 0.1em;
  }

  #viewer-container,
  .workflow-panel,
  .upload-panel,
  .review-form,
  .markdown-output {
    padding: var(--ds-space-200);
  }

  .workflow-panel,
  .upload-panel,
  .review-form,
  .markdown-output {
    padding-top: var(--ds-space-300);
  }

  #viewer-container {
    height: clamp(22rem, 68vh, 36rem);
  }

  .comparison-page {
    grid-template-columns: minmax(0, 1fr);
  }

  .status-bar {
    flex-wrap: wrap;
    gap: var(--ds-space-100);
  }

  .viewer-toolbar,
  .action-row {
    justify-content: stretch;
  }

  .viewer-toolbar button,
  .action-row button {
    flex: 1 1 auto;
  }

  .preset-save-row {
    grid-template-columns: 1fr;
  }

  #page-counter {
    flex: 1 0 100%;
    order: -1;
  }

  th,
  td {
    padding: var(--ds-space-100);
  }
}

@media (prefers-reduced-motion: reduce) {
  body > main > h1::after,
  .container > h1::after {
    animation: none;
  }

  .htmx-indicator {
    transition: none;
  }
}
