:root {
  color-scheme: light dark;
  /* Soft, muted "latte" palette -- deliberately low-contrast/low-saturation
     to avoid the glare of near-white backgrounds or fully-saturated accents. */
  --bg: #ede2d0;
  --surface: #f6efe3;
  --fg: #4a3728;
  --muted: #8d7963;
  --accent: #8b5e3c;
  --accent-hover: #74492d;
  --accent-contrast: #fbf5ea;
  --border: #d3c2a8;
  --error: #a8483d;
  --error-bg: rgba(168, 72, 61, 0.08);
  --mark-high: rgba(168, 72, 61, 0.25);
  --mark-medium: rgba(139, 94, 60, 0.25);
  --mark-low: rgba(141, 121, 99, 0.25);
  --shadow: 0 1px 3px rgba(74, 55, 40, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* "Dark roast" -- warm dark brown, never near-black, and a muted
       (not neon) caramel accent so the page doesn't glare in low light. */
    --bg: #2c2019;
    --surface: #362820;
    --fg: #ddd0bd;
    --muted: #a8927a;
    --accent: #b8875a;
    --accent-hover: #c99b6e;
    --accent-contrast: #241a14;
    --border: #4f3d2d;
    --error: #d08b83;
    --error-bg: rgba(208, 139, 131, 0.12);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  --bg: #2c2019;
  --surface: #362820;
  --fg: #ddd0bd;
  --muted: #a8927a;
  --accent: #b8875a;
  --accent-hover: #c99b6e;
  --accent-contrast: #241a14;
  --border: #4f3d2d;
  --error: #d08b83;
  --error-bg: rgba(208, 139, 131, 0.12);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--fg);
  background: var(--bg);
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 0 0.5rem;
}

.page-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-controls__label {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.header-controls #language-select {
  margin-bottom: 0;
}

#theme-toggle,
#docs-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

#theme-toggle:hover {
  background: var(--border);
  transform: rotate(15deg);
}

#docs-toggle:hover {
  background: var(--border);
  transform: translateY(-2px);
}

/* ---- Docs panel: the project's own README/architecture, in-app ---- */

.docs-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
  background: rgba(30, 20, 14, 0.45);
  animation: fade-in 0.2s ease both;
}

.docs-overlay[hidden] {
  display: none;
}

.docs-panel {
  display: flex;
  flex-direction: column;
  width: min(46rem, 100%);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgba(30, 20, 14, 0.25);
  animation: panel-in 0.28s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.docs-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.4rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.docs-panel__header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.docs-panel__close {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  color: var(--fg);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.docs-panel__close:hover {
  background: var(--border);
}

.docs-panel__tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.9rem 1.4rem;
  border-bottom: 1px solid var(--border);
}

.docs-panel__tabs button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  color: var(--fg);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.docs-panel__tabs button:hover {
  background: var(--bg);
  transform: translateY(-1px);
}

.docs-panel__tabs button[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.docs-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem 1.4rem;
  line-height: 1.6;
  animation: content-in 0.3s ease both;
}

.docs-panel__body h1,
.docs-panel__body h2,
.docs-panel__body h3 {
  line-height: 1.3;
}

.docs-panel__body h1 {
  font-size: 1.3rem;
  margin-top: 0;
}

.docs-panel__body h2 {
  font-size: 1.05rem;
  margin-top: 1.8rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}

.docs-panel__body code {
  background: var(--bg);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 0.85em;
}

.docs-panel__body pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8rem;
  overflow-x: auto;
}

.docs-panel__body pre code {
  background: none;
  padding: 0;
}

.docs-panel__body a {
  color: var(--accent);
}

.docs-panel__body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.docs-panel__body th,
.docs-panel__body td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: left;
}

.docs-panel__body img {
  max-width: 100%;
  border-radius: 6px;
}

.docs-panel__footer {
  padding: 0.9rem 1.4rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}

.docs-panel__footer a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.docs-panel__footer a:hover {
  text-decoration: underline;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes panel-in {
  from {
    transform: translateX(3rem);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

#demo-banner {
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  margin: 0 0 1rem;
  font-size: 0.9rem;
  font-weight: 600;
}

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

.dropzone {
  display: block;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  margin-bottom: 1rem;
  background: var(--surface);
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}

.dropzone:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--surface) 85%, var(--accent) 15%);
}

.dropzone.dropzone--active {
  border-color: var(--accent);
  border-style: solid;
  background: color-mix(in srgb, var(--surface) 80%, var(--accent) 20%);
  transform: scale(1.015);
}

.dropzone input[type="file"] {
  display: block;
  margin: 1rem auto 0;
}

#analyze-form label[for="language-select"] {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}

#language-select {
  display: block;
  margin-bottom: 1rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
}

button {
  font-family: inherit;
}

button[type="submit"] {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.4rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

button[type="submit"]:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

button[type="submit"]:active {
  transform: translateY(0);
}

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.7rem;
  margin: 0.9rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.examples[hidden] {
  display: none;
}

.examples__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.examples__buttons button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  color: var(--fg);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.examples__buttons button:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--surface) 85%, var(--accent) 15%);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

#status {
  margin-top: 1rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#status[hidden] {
  display: none;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.status-spinner {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: status-spin 0.8s linear infinite;
}

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

.status-progress-track {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}

.status-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s linear;
}

#error-message {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--error);
  color: var(--error);
  background: var(--error-bg);
  border-radius: 0 6px 6px 0;
}

.sections {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ---- Workspace: the "book" that fills in as each stage completes ---- */

.workspace {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: zone-in 0.4s ease both;
}

.workspace[hidden] {
  display: none;
}

.workspace__panes {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: stretch;
}

.workspace__panes > .zone {
  flex: 1 1 320px;
  min-width: 0;
}

/* A reopened history entry only has the stored PDF -- no original file and
   no analysis -- so those two zones stand down and the report takes over. */
.workspace--report-only .zone--raw,
.workspace--report-only .zone--document {
  display: none;
}

.zone {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1.1rem 1.1rem;
  box-shadow: var(--shadow);
  animation: zone-in 0.45s ease both;
  transition: box-shadow 0.25s ease, border-color 0.25s ease, transform 0.25s ease;
}

.zone:hover {
  border-color: color-mix(in srgb, var(--border) 45%, var(--accent) 55%);
  box-shadow: 0 6px 18px rgba(74, 55, 40, 0.13);
  transform: translateY(-2px);
}

:root[data-theme="dark"] .zone:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.zone__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
}

.zone__title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* flex: 0 0 auto, not flex: 1 -- inside a column flex container a grow
   factor resolves the height from the content and silently overrides the
   fixed heights below, which is what keeps these panes scrollable. */
.zone__body {
  position: relative;
  flex: 0 0 auto;
  min-height: 0;
}

.zone__placeholder {
  margin: 0;
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.zone--raw .zone__body {
  height: min(13rem, 28vh);
}

.workspace__panes .zone__body {
  height: min(30rem, 62vh);
}

/* ---- Skeleton placeholders while a stage is still loading ---- */

.skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.35rem 0;
}

.skeleton[hidden] {
  display: none;
}

.skeleton__line {
  height: 0.7rem;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--border) 25%,
    color-mix(in srgb, var(--border) 55%, var(--surface) 45%) 50%,
    var(--border) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

.skeleton__line--short {
  width: 62%;
}

@keyframes skeleton-shimmer {
  to {
    background-position: -200% 0;
  }
}

@keyframes zone-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes content-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.25rem 1.25rem 1.25rem;
  box-shadow: var(--shadow);
}

.section summary {
  cursor: pointer;
  padding: 0.9rem 0;
  font-weight: 600;
  color: var(--fg);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.section summary::after {
  content: "▾";
  color: var(--muted);
  transition: transform 0.15s ease;
}

.section:not([open]) summary::after {
  transform: rotate(-90deg);
}

.copy-button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
  color: var(--fg);
  cursor: pointer;
  margin-bottom: 0.75rem;
  transition: background-color 0.15s ease;
}

.copy-button:hover {
  background: var(--border);
}

#extracted-text {
  height: 100%;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 0.85rem;
  line-height: 1.55;
  background: var(--bg);
  animation: content-in 0.35s ease both;
}

#extracted-text[hidden] {
  display: none;
}

.zone[hidden] {
  display: none;
}

#extracted-text mark {
  border-radius: 3px;
  padding: 0 2px;
  cursor: help;
}

#extracted-text mark.severity-high {
  background: var(--mark-high);
}

#extracted-text mark.severity-medium {
  background: var(--mark-medium);
}

#extracted-text mark.severity-low {
  background: var(--mark-low);
}

.analysis {
  height: 100%;
  overflow-y: auto;
  padding-right: 0.35rem;
  animation: content-in 0.4s ease both;
}

.analysis[hidden] {
  display: none;
}

.analysis p {
  line-height: 1.6;
  margin: 0 0 0.9rem;
}

.analysis__label {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 1.1rem 0 0.3rem;
}

.analysis__label:first-child {
  margin-top: 0;
}

/* A technical footnote, deliberately quiet: interesting to someone reading
   the project, never competing with the analysis itself. Sits in the actions
   row -- pushed to the far end -- rather than inside the analysis pane,
   which scrolls. */
.analysis__cost {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.analysis__cost[hidden] {
  display: none;
}

@media (max-width: 700px) {
  .analysis__cost {
    margin-left: 0;
  }
}

.analysis__context {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-size: 0.85rem;
}

[data-role="analysis-red-flags"] {
  list-style: none;
  padding: 0;
  margin: 0;
}

[data-role="analysis-red-flags"] li {
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.5rem;
  border-left: 4px solid var(--muted);
  border-radius: 0 6px 6px 0;
  background: var(--bg);
  line-height: 1.5;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

[data-role="analysis-red-flags"] li:hover {
  transform: translateX(3px);
  box-shadow: var(--shadow);
}

[data-role="analysis-red-flags"] li.severity-high {
  border-color: var(--error);
}

[data-role="analysis-red-flags"] li.severity-medium {
  border-color: var(--accent);
}

[data-role="analysis-red-flags"] li.severity-low {
  border-color: var(--muted);
}

#report-preview,
#original-preview,
#original-preview-image {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  object-fit: contain;
  background: var(--bg);
  animation: content-in 0.35s ease both;
}

#report-preview[hidden],
#original-preview[hidden],
#original-preview-image[hidden] {
  display: none;
}

.workspace__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  animation: content-in 0.35s ease both;
}

.workspace__actions[hidden] {
  display: none;
}

#download-link {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 8px;
  padding: 0.55rem 1.2rem;
  text-decoration: none;
  font-weight: 600;
  transition: background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

#download-link:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

#download-markdown-button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--fg);
  transition: background-color 0.15s ease;
}

#download-markdown-button:hover {
  background: var(--border);
}

#history-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

#history-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  transition: background-color 0.15s ease;
}

#history-list li:hover {
  background: var(--bg);
}

#history-list li:last-child {
  border-bottom: none;
}

#history-list button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  color: var(--fg);
  transition: background-color 0.15s ease;
}

#history-list button:hover {
  background: var(--border);
}

@media (max-width: 700px) {
  .page-header {
    padding-top: 1rem;
  }

  .workspace__panes .zone__body {
    height: 20rem;
  }

  .zone--raw .zone__body {
    height: 10rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .zone:hover,
  [data-role="analysis-red-flags"] li:hover,
  #download-link:hover {
    transform: none;
  }
}
