/*
  Document Shelf - shared UI stylesheet.

  Reading room, not admin panel: quiet neutrals, one accent, generous
  whitespace, a serif reserved for the wordmark and long-form document
  reading. Everything else stays in the system sans stack so the tool
  feels fast and gets out of the way. No external requests: system fonts
  only, no icon font, no framework.

  Palette: this is Steelray's actual brand system, "Daybreak" (light) and
  "Nightshift" (dark), copied from steelray-cloud/platform/web/spa/src/
  styles.css (--sr-* tokens there), which is itself the schema-validated
  source also used for the Cognito Managed Login branding
  (steelray-cloud/infra/modules/auth/branding/managed-login-daybreak.json).
  Reusing it means Document Shelf, the cloud SPA, and the sign-in pages all
  read as the same product family. A couple of tokens (border-strong,
  ink-faint) aren't part of that set; they're interpolated from the same
  hue family and noted below.
*/

:root {
  color-scheme: light dark;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", "URW Palladio L", P052, Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;

  /* Daybreak (light) */
  --bg: #f6f1e8;
  --bg-raised: #fbf8f2;
  --bg-sunken: #f1ead9;
  --ink: #11140f;
  --ink-soft: #63665b;
  --ink-faint: #8d8f82; /* interpolated: not a brand token, between --ink-soft and --bg */
  --border: #e2dacb;
  --border-strong: #63665b; /* brand secondaryButton hover border */
  --accent: #655dc6;
  --accent-ink: #fbf8f2;
  --accent-soft: rgba(101, 93, 198, 0.16);
  --accent-on-soft: #40389f;
  --danger: #d91515; /* brand alert border */
  --danger-soft: #fff7f7; /* brand alert background */
  --focus-ring: #655dc6;
  --shadow: 0 1px 2px rgba(17, 20, 15, 0.06), 0 6px 20px rgba(17, 20, 15, 0.06);
  --radius: 8px;
  --radius-lg: 14px;
  --measure: 40rem;

  --code-bg: #f1ead9;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Nightshift (dark) */
    --bg: #0e1014;
    --bg-raised: #161a21;
    --bg-sunken: #1d222b;
    --ink: #ece7da;
    --ink-soft: #8a8e96;
    --ink-faint: #61646b; /* interpolated: not a brand token, between --ink-soft and --bg */
    --border: #232831;
    --border-strong: #8a8e96; /* brand secondaryButton hover border */
    --accent: #8a84d6;
    --accent-ink: #11140f;
    --accent-soft: rgba(138, 132, 214, 0.18);
    --accent-on-soft: #a7a4df;
    --danger: #eb6f6f; /* brand alert border */
    --danger-soft: #1a0000; /* brand alert background */
    --focus-ring: #8a84d6;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 24px rgba(0, 0, 0, 0.35);
    --code-bg: #1d222b;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1014;
  --bg-raised: #161a21;
  --bg-sunken: #1d222b;
  --ink: #ece7da;
  --ink-soft: #8a8e96;
  --ink-faint: #61646b;
  --border: #232831;
  --border-strong: #8a8e96;
  --accent: #8a84d6;
  --accent-ink: #11140f;
  --accent-soft: rgba(138, 132, 214, 0.18);
  --accent-on-soft: #a7a4df;
  --danger: #eb6f6f;
  --danger-soft: #1a0000;
  --focus-ring: #8a84d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 24px rgba(0, 0, 0, 0.35);
  --code-bg: #1d222b;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 3px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.6rem 1rem;
  z-index: 100;
  border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
  left: 0;
}

button {
  font: inherit;
  color: inherit;
}

img {
  max-width: 100%;
}

/* Layout shell */

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}

.site-header__bar {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.wordmark:hover {
  text-decoration: none;
  color: var(--accent);
}

/* The Steelray ray mark: brand purples, fixed in both themes (see
   web/static/favicon.svg and its header comment for provenance). */
.wordmark-mark {
  flex: none;
  width: 1.42rem;
  height: 1.1rem;
}

.auth-card .wordmark-mark {
  width: 1.7rem;
  height: 1.32rem;
}

.site-nav {
  display: flex;
  gap: 1.25rem;
  flex: 1;
  font-size: 0.92rem;
}

.site-nav a {
  color: var(--ink-soft);
  padding: 0.3rem 0.1rem;
  border-bottom: 2px solid transparent;
}

.site-nav a:hover {
  color: var(--ink);
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.site-user {
  font-size: 0.85rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

.site-main {
  flex: 1;
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem;
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  .site-header__bar {
    flex-wrap: wrap;
    gap: 0.6rem 1rem;
  }
  .site-nav {
    order: 3;
    width: 100%;
    gap: 1rem;
  }
  .site-user {
    order: 2;
    margin-left: auto;
  }
  .site-main {
    padding: 1.5rem 1rem 3rem;
  }
}

/* Page heading */

.page-heading {
  margin-bottom: 1.5rem;
}

.page-heading h1 {
  font-family: var(--font-serif);
  font-size: 1.9rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
}

.page-heading p {
  color: var(--ink-soft);
  margin: 0;
  max-width: var(--measure);
}

/* Search */

.search-form {
  position: relative;
  margin-bottom: 1.75rem;
}

.search-form input[type="search"] {
  width: 100%;
  padding: 0.85rem 1rem 0.85rem 2.6rem;
  font-size: 1.05rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--ink);
}

.search-form input[type="search"]::placeholder {
  color: var(--ink-faint);
}

.search-form input[type="search"]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.search-form__icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.1rem;
  height: 1.1rem;
  color: var(--ink-faint);
  pointer-events: none;
}

.search-status {
  min-height: 1.4rem;
  font-size: 0.85rem;
  color: var(--ink-faint);
  margin-top: 0.5rem;
}

/* Tag filter row: a compact horizontal strip of pills between the search
   box and the document list. Wraps onto a second row for a long tag list,
   then scrolls vertically within a capped height rather than growing
   forever and pushing matches further down the page. */

.tag-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  max-height: 4.75rem;
  overflow-y: auto;
  margin: 0 0 1.5rem;
  padding-bottom: 0.1rem;
}

/* Shared pill look for the tag-filter row and the tag pills on document
   cards and search results (.tag-chips a). Both are plain <a> elements so
   they work without JS and share one visual language. */
.tag-pill,
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  line-height: 1.2;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--bg-sunken);
  color: var(--ink-soft);
  border: 1px solid transparent;
  white-space: nowrap;
}

.tag-pill:hover,
.tag-chip:hover {
  background: var(--accent-soft);
  color: var(--ink);
  text-decoration: none;
}

.tag-pill .count {
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.tag-pill[aria-current="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.tag-pill[aria-current="true"] .count {
  color: var(--accent-ink);
  opacity: 0.85;
}

/* Day groups + document list */

.day-heading {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  font-weight: 600;
  margin: 2rem 0 0.75rem;
}

.day-heading:first-of-type {
  margin-top: 0;
}

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

.document-card {
  padding: 1.1rem 0;
  border-top: 1px solid var(--border);
}

.document-list > .document-card:first-child,
.document-list > li:first-child > .document-card {
  border-top: none;
}

.document-card__title {
  font-size: 1.08rem;
  font-weight: 600;
  margin: 0 0 0.3rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.document-card__title a {
  color: var(--ink);
}

.document-card__title a:hover {
  color: var(--accent);
}

.kind-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.45rem;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--ink-soft);
  text-transform: uppercase;
  vertical-align: middle;
}

.document-card__summary {
  color: var(--ink-soft);
  margin: 0 0 0.5rem;
  max-width: var(--measure);
}

.document-card__summary mark {
  background: var(--accent-soft);
  color: var(--ink);
  border-radius: 3px;
  padding: 0 0.1em;
}

.document-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--ink-faint);
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.copy-link-btn {
  border: 1px solid transparent;
  background: none;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  font-size: 0.85rem;
}

.copy-link-btn:hover {
  color: var(--ink);
  background: var(--bg-sunken);
}

.copy-link-btn[data-copied="true"] {
  color: var(--accent);
}

/* Empty state */

.empty-state {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  text-align: left;
}

.empty-state h2 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
}

.empty-state p {
  color: var(--ink-soft);
  max-width: var(--measure);
}

.empty-state pre {
  background: var(--bg-sunken);
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
}

.no-results {
  padding: 2rem 0;
  color: var(--ink-soft);
}

/* Skeleton loaders */

.skeleton-line {
  height: 0.9rem;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border) 37%, var(--bg-sunken) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-line {
    animation: none;
  }
}

/* Load more */

.load-more-row {
  margin-top: 1.75rem;
  text-align: center;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--ink-faint);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  filter: brightness(0.94);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* Forms */

.form-grid {
  display: grid;
  gap: 1.1rem;
  max-width: 32rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.88rem;
  font-weight: 600;
}

.field .hint {
  font-size: 0.8rem;
  color: var(--ink-faint);
}

.field input[type="text"],
.field input[type="email"],
.field textarea {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--ink);
  font: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 4.5rem;
}

.field .error-text {
  font-size: 0.82rem;
  color: var(--danger);
  min-height: 1.1em;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.92rem;
}

.toggle-row input {
  width: 1.05rem;
  height: 1.05rem;
}

/* Publish drop zone */

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 2.75rem 2rem;
  text-align: center;
  cursor: pointer;
  background: var(--bg-raised);
  margin-bottom: 1.75rem;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone[data-active="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.dropzone p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.dropzone .file-chosen {
  margin-top: 0.75rem;
  font-weight: 600;
  color: var(--ink);
}

.progress-track {
  height: 0.4rem;
  background: var(--bg-sunken);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 1rem;
}

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

.upload-banner {
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
}

.upload-banner.is-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.upload-banner.is-success {
  background: var(--accent-soft);
  color: var(--ink);
}

.success-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.success-card .url-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.success-card .url-row code {
  flex: 1;
  padding: 0.5rem 0.7rem;
  background: var(--bg-sunken);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  overflow-x: auto;
  white-space: nowrap;
}

.success-card .actions {
  display: flex;
  gap: 0.6rem;
}

/* API docs */

.api-doc-section {
  margin-bottom: 2.5rem;
}

.api-doc-section h2 {
  font-size: 1.25rem;
  margin-bottom: 0.4rem;
}

.api-doc-section h3 {
  font-size: 1rem;
  margin: 1.25rem 0 0.5rem;
}

.api-doc-section p {
  color: var(--ink-soft);
  max-width: var(--measure);
}

.method-path {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  background: var(--bg-sunken);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  display: inline-block;
}

.method-path .method {
  font-weight: 700;
  color: var(--accent);
  margin-right: 0.5rem;
}

pre.code-block {
  position: relative;
  background: var(--code-bg);
  color: var(--ink);
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.55;
}

.copy-code-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--ink-soft);
  cursor: pointer;
}

.copy-code-btn:hover {
  color: var(--ink);
}

.field-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 0.75rem 0 1.25rem;
}

.field-table th,
.field-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.field-table th {
  color: var(--ink-faint);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.field-table code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* Minimal auth-style pages: login, preview */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 26rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-card .wordmark {
  justify-content: center;
  margin-bottom: 1.5rem;
  font-size: 1.4rem;
}

.auth-card p.lede {
  color: var(--ink-soft);
  margin: 0 0 1.5rem;
}

.auth-card .btn {
  width: 100%;
}

.auth-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
  text-align: left;
}

.preview-meta {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0 1.5rem;
  font-size: 0.85rem;
  color: var(--ink-faint);
}

.preview-card h1 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  margin: 0 0 0.25rem;
}

.preview-card .tag-chips {
  justify-content: center;
  margin-bottom: 1.5rem;
}

/* Error page */

.error-card {
  text-align: center;
  padding: 3rem 1rem;
}

.error-card .status {
  font-family: var(--font-mono);
  color: var(--ink-faint);
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.error-card h1 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  margin: 0 0 0.75rem;
}

.error-card p {
  color: var(--ink-soft);
  max-width: 30rem;
  margin: 0 auto 1.5rem;
}

/* Utility */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
