/* Parlax stylesheet. Hand-written, no framework or build step.
   Colors, spacing, type and radii are the variables below; see specs/ui.md
   ("Colors", "Typography", "Layout") before adding or changing one. */

:root {
  /* Palette (specs/ui.md, "Colors"); contrast ratios are checked there. */
  --bg: #ffffff;
  --surface: #f5f6f8;
  --text: #1f2328;
  --text-muted: #5b6470;
  --border: #7d858f;
  --divider: #e6e9ec;
  --accent: #f86666;
  --accent-strong: #c62a2a;
  --accent-strong-hover: #a02222;
  --on-accent: #ffffff;
  --accent-tint: #fef0f0;
  --error: #a02222;
  --success: #1e7a3c;
  --success-tint: #eef7f1;

  /* Typography */
  --font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-size-base: 1rem;
  --font-size-small: 0.875rem;
  --font-size-h1: 2rem;
  --font-size-h2: 1.5rem;
  --font-size-h3: 1.25rem;
  --line-height: 1.5;
  --line-height-heading: 1.25;
  --measure: 70ch;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;

  /* Layout and shapes */
  --content-width: 60rem;
  --page-padding: var(--space-4);
  --radius: 4px;
  --focus-width: 3px;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1d2127;
    --text: #e8eaed;
    --text-muted: #a7afb9;
    --border: #7d858f;
    --divider: #3a414a;
    --accent: #f86666;
    --accent-strong: #fa9494;
    --accent-strong-hover: #fbbbbb;
    --on-accent: #14171c;
    --accent-tint: #3a1f22;
    --error: #fa9494;
    --success: #6fcf8f;
    --success-tint: #1a2a20;
  }
}

@media (max-width: 30rem) {
  :root {
    --page-padding: var(--space-3);
  }
}

/* Base */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  overflow-wrap: break-word;
}

main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-5) var(--page-padding) var(--space-6);
}

h1,
h2,
h3 {
  line-height: var(--line-height-heading);
  margin: var(--space-5) 0 var(--space-3);
}

h1 {
  font-size: var(--font-size-h1);
  margin-top: 0;
}

h2 {
  font-size: var(--font-size-h2);
}

h3 {
  font-size: var(--font-size-h3);
}

p,
ul,
ol {
  max-width: var(--measure);
  margin: 0 0 var(--space-3);
}

a {
  color: var(--accent-strong);
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--accent-strong-hover);
}

/* Focus: always visible, never removed (specs/ui.md, "Accessibility"). */

:focus-visible {
  outline: var(--focus-width) solid var(--accent-strong);
  outline-offset: 2px;
}

/* Shared header (specs/ui.md, "Layout"): app name left, navigation and
   logout right; on narrow screens the navigation wraps below the name. */

.site-header {
  background: var(--surface);
  border-bottom: 2px solid var(--accent);
}

.site-header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-3) var(--page-padding);
}

.site-name {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  font-size: var(--font-size-h3);
  font-weight: 700;
  text-decoration: none;
}

.site-name:hover {
  color: var(--text);
  text-decoration: underline;
}

/* Logo (specs/ui.md, "Logo"): height set here, width follows the aspect
   ratio of the img's width/height attributes. */
.site-logo {
  height: 2.5rem;
  width: auto;
}

.login-logo {
  display: block;
  height: 6rem;
  width: auto;
  margin: 0 auto var(--space-3);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-nav a {
  display: inline-block;
  padding: var(--space-2) 0;
  text-decoration: none;
}

.site-nav a:hover {
  text-decoration: underline;
}

/* Current page: bold and underlined, not color alone. */
.site-nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: var(--accent-strong);
  text-decoration-thickness: 3px;
  text-underline-offset: 0.4em;
}

.logout {
  margin: 0;
}

/* Forms (specs/ui.md, "Components"): labels above their fields, fields fill
   the column width except date inputs. */

.field label {
  display: block;
  margin-bottom: var(--space-1);
  font-weight: 600;
}

input,
textarea,
select,
button {
  font: inherit;
}

input:not([type]),
input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
input[type="file"],
select,
textarea {
  min-height: 44px;
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

.field input,
.field textarea {
  width: 100%;
}

/* Title fields in the upload table fill their cell. */
td input:not([type]) {
  width: 100%;
  min-width: 12rem;
}

textarea {
  resize: vertical;
}

input[type="date"] {
  width: auto;
}

input[type="file"] {
  max-width: 100%;
}

/* Browser validation: only marked invalid after the user has edited the
   field, so an empty required form doesn't start out red. */
input:user-invalid,
textarea:user-invalid {
  border-color: var(--error);
  border-width: 2px;
}

.hint {
  color: var(--text-muted);
  font-size: var(--font-size-small);
}

td .hint {
  display: block;
  margin-top: var(--space-1);
}

/* A new API token, shown once: long, so it may break anywhere. */
.token-secret {
  overflow-wrap: anywhere;
  user-select: all;
}

/* Buttons: one primary (accent background) per page, secondary outline for
   the others. At least 44px high. */

.button-primary,
.button-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border: 2px solid var(--accent-strong);
  border-radius: var(--radius);
  font-weight: 600;
  line-height: var(--line-height-heading);
  cursor: pointer;
}

.button-primary {
  background: var(--accent-strong);
  color: var(--on-accent);
}

.button-primary:hover {
  background: var(--accent-strong-hover);
  border-color: var(--accent-strong-hover);
}

.button-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.button-secondary:hover {
  border-color: var(--text);
}

/* Disabled while its form is submitted (loading feedback in app.js). */
.button-primary:disabled {
  cursor: progress;
}

/* Tables: header row set apart, row separators, no vertical lines. Wide
   tables scroll inside their container, never the page. */

.table-scroll {
  overflow-x: auto;
  margin: 0 0 var(--space-4);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

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

thead th {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
}

/* Alerts: a box with border and tint, not just red text, so errors don't
   look like links (specs/ui.md, "Colors"). */

.alert {
  padding: var(--space-3);
  border: 1px solid var(--error);
  border-left-width: 4px;
  border-radius: var(--radius);
  background: var(--accent-tint);
  color: var(--text);
}

/* Upload result status: color plus the catalog text, never color alone. */

.status {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  border-left: 4px solid;
  border-radius: var(--radius);
  color: var(--text);
}

.status-stored {
  border-color: var(--success);
  background: var(--success-tint);
}

.status-rejected {
  border-color: var(--error);
  background: var(--accent-tint);
}

.status-duplicate {
  border-color: var(--border);
  background: var(--surface);
}

/* Answer and sources: the answer is set apart from the form by a top line;
   sources are a compact list below it. Answer text keeps the model's line
   breaks. */

.answer {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--divider);
}

.answer h2 {
  margin-top: 0;
}

.answer-text {
  white-space: pre-line;
}

.sources {
  padding-left: var(--space-4);
  font-size: var(--font-size-small);
}

.sources li {
  margin-bottom: var(--space-1);
}

/* Login page: logo, app name and a narrow, centered form. */

.login {
  max-width: 22rem;
  margin: var(--space-5) auto 0;
}

.login h1 {
  text-align: center;
}

.login .button-primary {
  width: 100%;
}

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

/* Feedback block below the answer (specs/feedback.md): closed by default;
   the question and answer that are sent are shown read-only. */

.feedback {
  margin-top: var(--space-4);
}

.feedback summary {
  cursor: pointer;
}

.feedback-sent dd {
  margin-left: 0;
  margin-bottom: var(--space-2);
  font-size: var(--font-size-small);
}
