/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 *
 * This file is unlayered CSS, so it wins over the Tailwind build's layered
 * rules (theme/base/utilities) regardless of load order — the app-wide state
 * rules below rely on that. Design tokens (--color-*) come from the Tailwind
 * @theme and are readable here as plain custom properties.
 */

/* Form field groups — invalid-field treatment. Rails wraps a field (and its
   label) that failed validation in <div class="field_with_errors">; the
   wrapper gets display:contents so it never disturbs the form's layout,
   while the control inside gets the err border + soft err ring and the
   label turns err so "fix the highlighted fields" actually highlights. */
.field_with_errors {
  display: contents;
}

.field_with_errors :is(input, select, textarea) {
  border-color: var(--color-err);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-err) 14%, transparent);
}

.field_with_errors label {
  color: var(--color-err);
}

/* Keyboard focus discipline: one accent focus-visible ring app-wide, so
   tabbing looks deliberate against indigo surfaces instead of the browser
   default. Text controls opt out — they already carry their own accent
   border + soft ring focus treatment (and it fires on any focus, not just
   keyboard). Checkboxes/radios keep the outline. */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

:is(input:not([type="checkbox"]):not([type="radio"]), textarea, select):focus-visible {
  outline: none;
}

/* ------------------------------------------------------------------------
   Knowledge Center article body (.article-body wraps Knowledge::Markdown
   output on the article page). Report tables + mermaid charts in the
   indigo/gold vocabulary. Selectors are compounded with .md so they win
   over the generic .md prose rules at equal load order. */

.md.article-body table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.25em 0;
  font-size: 0.95em;
  border: 1px solid var(--color-line);
  border-radius: 0.75rem;
  background: var(--color-surface);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.md.article-body th,
.md.article-body td {
  border: 0;
  padding: 0.6em 0.9em;
  text-align: left;
  vertical-align: top;
}

/* Header row: eyebrow treatment on a soft indigo tint, underscored in gold */
.md.article-body thead th {
  background: var(--color-accent-soft);
  border-bottom: 2px solid var(--color-star);
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-ink);
}

.md.article-body tbody td {
  border-bottom: 1px solid var(--color-line-subtle);
  color: var(--color-ink-2);
}

.md.article-body tbody tr:last-child td {
  border-bottom: 0;
}

/* Zebra: barely-there periwinkle wash on even rows */
.md.article-body tbody tr:nth-child(even) td {
  background: color-mix(in oklab, var(--color-surface-2) 45%, transparent);
}

/* Rounded corners survive border-collapse: separate via the corner cells */
.md.article-body thead th:first-child { border-top-left-radius: 0.7rem; }
.md.article-body thead th:last-child { border-top-right-radius: 0.7rem; }
.md.article-body tbody tr:last-child td:first-child { border-bottom-left-radius: 0.7rem; }
.md.article-body tbody tr:last-child td:last-child { border-bottom-right-radius: 0.7rem; }

/* Mermaid chart blocks: source arrives as an escaped code block and stays
   one if the chart is invalid; a rendered chart sits centered on a card. */
.md.article-body pre.mermaid {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: 0.75rem;
  padding: 1.15em;
  margin: 1.25em 0;
  overflow-x: auto;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.85em;
  color: var(--color-ink-2);
}

.md.article-body pre.mermaid[data-knowledge-chart="rendered"] {
  text-align: center;
  box-shadow: var(--shadow-soft);
}

.md.article-body pre.mermaid svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}

/* Knowledge center: document discovery and an uninterrupted writing canvas. */
.kc-library { max-width: 1120px; margin: auto; padding: 48px 32px; }
.kc-library-header, .kc-canvas-header, .kc-actions, .kc-list-summary, .kc-pagination { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.kc-library-header h1 { margin: 6px 0 10px; font-size: 36px; font-weight: 700; letter-spacing: -.04em; }
.kc-eyebrow { color: var(--color-accent); font-size: 12px; font-weight: 600; }
.kc-muted { color: var(--color-ink-3); font-size: 14px; line-height: 1.6; }
.kc-button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 16px; border: 1px solid var(--color-line); border-radius: 8px; background: var(--color-surface); color: var(--color-ink-2); font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.kc-button:hover { border-color: var(--color-accent); }
.kc-primary { background: var(--color-accent); color: var(--color-on-accent); border-color: var(--color-accent); }
.kc-text-link { color: var(--color-ink-2); font-size: 14px; font-weight: 500; }
.kc-text-link:hover { color: var(--color-accent); }
.kc-filters { display: flex; flex-wrap: wrap; gap: 10px; margin: 32px 0 20px; }
.kc-filters input[type=search] { flex: 1 1 260px; min-width: 180px; }
.kc-filters input[type=search], .kc-filters select, .kc-metadata input { height: 44px; border: 1px solid var(--color-line); border-radius: 8px; background-color: var(--color-surface); color: var(--color-ink); padding: 10px 12px; font-size: 14px; }
.kc-filters select { appearance: none; padding-right: 36px; max-width: 220px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23787980' stroke-width='1.5'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); background-position: right 12px center; background-repeat: no-repeat; }
.kc-library :focus-visible, .kc-canvas :focus-visible { outline: 2px solid var(--color-accent); outline-offset: 3px; }
.kc-list-summary { font-size: 13px; color: var(--color-ink-3); padding-bottom: 14px; }
.kc-review-inbox { margin: 32px 0 8px; border-top: 2px solid var(--color-accent); }
.kc-review-header { padding: 18px 12px 14px; }
.kc-review-header h2 { margin: 4px 0 5px; color: var(--color-ink); font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.kc-review-list { list-style: none; margin: 0; padding: 0; }
.kc-review-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 15px 12px; border-top: 1px solid var(--color-line); }
.kc-review-link { min-width: 0; }
.kc-review-title { display: block; color: var(--color-ink); font-size: 15px; font-weight: 600; }
.kc-review-meta, .kc-review-more { display: block; margin-top: 4px; color: var(--color-ink-3); font-size: 12px; }
.kc-review-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.kc-review-actions .kc-button { min-height: 36px; padding: 7px 11px; font-size: 12px; }
.kc-review-form { margin: 0; }
.kc-review-more { padding: 12px; border-top: 1px solid var(--color-line); }
.kc-document-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--color-line); }
.kc-document-row { border-bottom: 1px solid var(--color-line); }
.kc-document-link { display: block; padding: 20px 12px; border-radius: 6px; }
.kc-document-link:hover { background: var(--color-surface); }
.kc-document-heading { display: flex; align-items: center; gap: 10px; color: var(--color-ink); }
.kc-document-heading strong { font-size: 16px; font-weight: 600; }
.kc-excerpt { margin: 6px 0 10px; color: var(--color-ink-2); font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.kc-document-meta { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--color-ink-3); }
.kc-pagination { justify-content: center; margin-top: 24px; font-size: 14px; }
.kc-empty { padding: 64px 20px; text-align: center; color: var(--color-ink-3); }
.kc-empty h2 { font-size: 24px; color: var(--color-ink); }
.kc-empty p { margin: 12px 0 24px; }
.kc-canvas { min-height: calc(100vh - 72px); background: var(--color-surface); }
.kc-canvas-header { padding: 20px 32px; border-bottom: 1px solid var(--color-line); }
.kc-writing-column { max-width: 824px; margin: auto; padding: 48px 32px 100px; }
.kc-title { display: block; width: 100%; padding: 0; margin-bottom: 24px; border: 0; background: transparent; color: var(--color-ink); font-family: inherit; font-size: 36px; font-weight: 700; letter-spacing: -.04em; }
.kc-title::placeholder { color: var(--color-ink-3); }
.kc-editor { border: 0; background: transparent; }
.kc-editor [data-editor-chrome] { background: transparent; padding: 8px 0; border-color: var(--color-line); }
.kc-editor textarea { padding: 24px 0; min-height: 440px; font-family: inherit; font-size: 16px; line-height: 1.85; resize: vertical; }
.kc-editor [data-editor-preview] { padding: 24px 0; max-height: none; min-height: 440px; }
.kc-details { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--color-line); }
.kc-details summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--color-ink-2); }
.kc-details .kc-muted { margin: 16px 0; }
.kc-metadata { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-top: 20px; }
.kc-metadata label { display: block; font-size: 13px; color: var(--color-ink-2); margin-bottom: 8px; }
.kc-metadata input { width: 100%; }
.kc-file { display: block; width: 100%; font-size: 14px; }
.kc-draft-recovery { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 32px; padding: 4px 0 4px 16px; border-left: 3px solid var(--color-star); }
.kc-draft-recovery[hidden] { display: none; }
.kc-draft-recovery strong { color: var(--color-ink); }
.kc-draft-recovery p { margin: 4px 0 0; color: var(--color-ink-3); font-size: 14px; line-height: 1.5; }
.kc-draft-recovery [data-kc-draft-warning] { color: var(--color-ink-2); }
.kc-errors { border-left: 3px solid var(--color-err); padding: 16px; margin-bottom: 24px; color: var(--color-err); background: var(--color-err-surface); }
.kc-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@media (max-width: 640px) {
  .kc-library { padding: 28px 20px; }
  .kc-library-header { align-items: flex-start; flex-direction: column; }
  .kc-review-row { align-items: flex-start; flex-direction: column; gap: 10px; }
  .kc-review-actions { width: 100%; justify-content: space-between; }
  .kc-filters select { flex: 1 1 140px; max-width: none; }
  .kc-canvas-header { padding: 16px 20px; }
  .kc-writing-column { padding: 32px 20px 64px; }
  .kc-title { font-size: 28px; }
  .kc-metadata { grid-template-columns: 1fr; }
  .kc-draft-recovery { flex-direction: column; }
}

/* Visual editing remains part of the continuous KC canvas. */
.kc-editor [hidden] { display: none !important; }
.kc-editor-modes { display: flex; gap: 4px; padding-bottom: 12px; }
.kc-editor-modes button, .kc-visual-toolbar button, .kc-visual-toolbar select, .kc-link-panel summary { min-height: 36px; padding: 6px 10px; border-radius: 6px; font-size: 13px; color: var(--color-ink-2); cursor: pointer; }
.kc-editor-modes button[aria-pressed=true], .kc-visual-toolbar button[aria-pressed=true] { background: var(--color-accent-soft); color: var(--color-accent); }
.kc-visual-toolbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 8px 0; border-top: 1px solid var(--color-line); border-bottom: 1px solid var(--color-line); }
.kc-visual-toolbar button:hover:not(:disabled), .kc-link-panel summary:hover { background: var(--color-surface-2); }
.kc-visual-toolbar :disabled { opacity: .4; cursor: default; }
.kc-visual-toolbar select { border: 1px solid var(--color-line); background: var(--color-surface); max-width: 160px; }
.kc-visual-body { min-height: 440px; padding: 24px 0; font-size: 16px; line-height: 1.85; outline: none; overflow-wrap: anywhere; }
.kc-visual-body:focus-visible { outline: none; }
.kc-visual-body pre { white-space: pre-wrap; }
.kc-visual-body table { table-layout: fixed; }
.kc-visual-body td, .kc-visual-body th { min-width: 80px; position: relative; }
.kc-visual-body .selectedCell { background: var(--color-accent-soft); }
.kc-visual-body img { max-width: 100%; height: auto; }
.kc-visual-body ul[data-type=taskList] { list-style: none; padding-left: 0; }
.kc-visual-body ul[data-type=taskList] li { display: flex; gap: 10px; }
.kc-visual-body ul[data-type=taskList] li > div { flex: 1; }
.kc-editor .kc-markdown-source { display: block; width: 100%; font-family: ui-monospace, monospace; font-size: 14px; background: transparent; border: 0; }
.kc-editor [data-kc-preview] { min-height: 440px; padding: 24px 0; }
.kc-editor-notice { padding: 12px 0; font-size: 14px; color: var(--color-ink-3); }
.kc-link-panel { position: relative; }
.kc-link-panel summary { list-style: none; }
.kc-link-popover { position: absolute; top: 42px; left: 0; width: min(300px, 75vw); z-index: 20; padding: 16px; border: 1px solid var(--color-line); border-radius: 8px; background: var(--color-surface); box-shadow: var(--shadow-card); }
.kc-link-popover label { display: block; font-size: 13px; margin-bottom: 8px; }
.kc-link-popover input { width: 100%; border: 1px solid var(--color-line); border-radius: 6px; padding: 8px; margin-bottom: 12px; }

.kc-table-controls { display: inline-flex; gap: 4px; flex-wrap: wrap; }
