/*
 * 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.
 */

/* KB article prose — mirrors the Starlight content area (SC-13009). Scoped to .kb-prose. */

.kb-prose {
  max-width: 52rem;
  font-size: 1rem;
  line-height: 1.75;
  color: #1e293b;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Headings */

.kb-prose h1,
.kb-prose h2,
.kb-prose h3,
.kb-prose h4,
.kb-prose h5,
.kb-prose h6 {
  font-weight: 700;
  line-height: 1.3;
  margin-top: 1.75em;
  margin-bottom: 0.5em;
  color: #0f172a;
}

.kb-prose h1:first-child,
.kb-prose h2:first-child,
.kb-prose h3:first-child,
.kb-prose h4:first-child,
.kb-prose h5:first-child,
.kb-prose h6:first-child {
  margin-top: 0;
}

.kb-prose h1 { font-size: 2em; }
.kb-prose h2 { font-size: 1.5em; }
.kb-prose h3 { font-size: 1.25em; }
.kb-prose h4 { font-size: 1.1em; }
.kb-prose h5 { font-size: 1em; font-weight: 600; }
.kb-prose h6 { font-size: 0.9em; font-weight: 600; }

/* Paragraphs */

.kb-prose p {
  margin-top: 0;
  margin-bottom: 1.1em;
}

.kb-prose p:last-child {
  margin-bottom: 0;
}

/* Lists — restore what Tailwind preflight strips */

.kb-prose ul,
.kb-prose ol {
  margin-top: 0;
  margin-bottom: 1.1em;
  padding-left: 1.75em;
}

.kb-prose ul {
  list-style: disc;
}

.kb-prose ol {
  list-style: decimal;
}

.kb-prose li {
  margin-top: 0.3em;
  margin-bottom: 0.3em;
}

.kb-prose li > ul,
.kb-prose li > ol {
  margin-top: 0.3em;
  margin-bottom: 0.3em;
}

/* Links */

.kb-prose a {
  color: var(--color-blue-700);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.kb-prose a:hover {
  color: var(--color-blue-700);
}

/* Strong / em */

.kb-prose strong { font-weight: 700; }
.kb-prose em     { font-style: italic; }
.kb-prose del    { text-decoration: line-through; }

/* Horizontal rule */

.kb-prose hr {
  border: 0;
  border-top: 1px solid #e2e8f0;
  margin: 2em 0;
}

/* Blockquote */

.kb-prose blockquote {
  border-left: 4px solid #94a3b8;
  margin: 1.25em 0;
  padding: 0.5em 1em;
  color: #475569;
  background-color: #f8fafc;
  border-radius: 0 0.25rem 0.25rem 0;
}

.kb-prose blockquote p:last-child {
  margin-bottom: 0;
}

/* Inline code */

.kb-prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.875em;
  background-color: #f1f5f9;
  color: #0f172a;
  padding: 0.15em 0.35em;
  border-radius: 0.25rem;
  border: 1px solid #e2e8f0;
}

/* Block code — pre > code resets the inline treatment */

.kb-prose pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.875em;
  background-color: #1e293b;
  color: #e2e8f0;
  border-radius: 0.375rem;
  padding: 1em 1.25em;
  overflow-x: auto;
  margin: 1.25em 0;
  line-height: 1.6;
}

.kb-prose pre code {
  background-color: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
  border: 0;
  font-size: 1em;
}

/* Tables */

.kb-prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25em 0;
  font-size: 0.9375em;
}

.kb-prose thead {
  background-color: #f1f5f9;
}

.kb-prose th {
  font-weight: 700;
  text-align: left;
  padding: 0.6em 0.85em;
  border: 1px solid #e2e8f0;
  color: #0f172a;
}

.kb-prose td {
  padding: 0.6em 0.85em;
  border: 1px solid #e2e8f0;
  vertical-align: top;
}

.kb-prose tbody tr:nth-child(even) {
  background-color: #f8fafc;
}

/* Images */

.kb-prose img {
  max-width: 100%;
  height: auto;
  border-radius: 0.375rem;
  display: block;
  margin: 1.25em 0;
}

/* Admonitions */

.kb-admonition {
  border-left: 4px solid;
  border-radius: 0.375rem;
  padding: 0.85em 1em;
  margin: 1.25em 0;
}

.kb-admonition-title {
  font-weight: 700;
  font-size: 0.9em;
  margin: 0 0 0.5em 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kb-admonition-content > *:first-child { margin-top: 0; }
.kb-admonition-content > *:last-child  { margin-bottom: 0; }

/* note — blue */
.kb-admonition-note {
  background-color: var(--color-blue-100);
  border-color: var(--color-blue-700);
}
.kb-admonition-note .kb-admonition-title {
  color: var(--color-blue-700);
}

/* tip — green */
.kb-admonition-tip {
  background-color: var(--color-green-100);
  border-color: var(--color-green-700);
}
.kb-admonition-tip .kb-admonition-title {
  color: var(--color-green-700);
}

/* caution — amber */
.kb-admonition-caution {
  background-color: var(--color-orange-100);
  border-color: var(--color-orange-700);
}
.kb-admonition-caution .kb-admonition-title {
  color: var(--color-orange-700);
}

/* danger — red */
.kb-admonition-danger {
  background-color: var(--color-red-100);
  border-color: var(--color-red-700);
}
.kb-admonition-danger .kb-admonition-title {
  color: var(--color-red-700);
}

/* Roomier horizontal gutter for article content inside the preview drawer.
   Applies to both the .kb-prose (draft-show inline surface, SC-13009) and
   the .lexxy-content (article-preview drawer, PR2). The DS drawer body's
   default padding (~14px) is tight for a 600px reading column; this widens
   it toward the Starlight content column. Scoped to the drawer, so inline
   padded-card surfaces are unaffected. */
.tw-drawer-body .kb-prose,
.tw-drawer-body .lexxy-content {
  padding-inline: 0.75rem;
}

/* Top-nav active state (EPIC E Gap 2). The DS .tw-btn-tertiary nav links are
   transparent with primary text and carry no current-page treatment, so the
   active section was indistinguishable. nav_link_to adds .kb-nav-link to every
   link and aria-current="page" to the current one; this gives that one a subtle
   filled pill built from DS color tokens. */
.kb-nav-link[aria-current="page"] {
  background-color: var(--tw-color-blue-100, #dfebfe);
  color: var(--tw-color-blue-700, #0948cf);
  font-weight: 600;
}

/* Mobile-responsive top-nav (EPIC E Gap 3). Pure-CSS disclosure: a visually
   hidden checkbox toggled by the hamburger <label>. The links are siblings of
   the checkbox (not inside a collapsing element), so desktop paints them inline
   and the hamburger is hidden; below 768px the links hide and drop down below
   the topbar when the box is checked.

   NOTE: every display rule is scoped under .kb-nav (raising specificity to
   0-2-0) because design-system.css loads AFTER application.css, so the DS
   single-class rules .tw-btn (on the label) and tw:flex (on the nav) would
   otherwise win on source order and defeat the collapse. */
.kb-nav { position: relative; }
.kb-nav .kb-nav-checkbox {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.kb-nav .kb-nav-toggle { display: none; }
.kb-nav .kb-nav-links { display: flex; }

@media (max-width: 767px) {
  .kb-nav .kb-nav-toggle {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
  }
  .kb-nav .kb-nav-links { display: none; }
  .kb-nav .kb-nav-checkbox:checked ~ .kb-nav-links {
    display: flex;
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    z-index: 50;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    min-width: 12rem;
    padding: 0.5rem;
    background-color: var(--tw-color-white, #fff);
    border: 1px solid var(--tw-color-neutral-200);
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgb(0 0 0 / 0.08);
  }
}

/* Video embeds — responsive 16:9 */

.kb-embed {
  position: relative;
  padding-top: 56.25%;
  width: 100%;
  border-radius: 0.375rem;
  overflow: hidden;
  margin: 1.25em 0;
}

.kb-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Tom Select theming — align the section/subsection typeahead with the DS
   form-select look (border, radius, focus ring, active option). Scoped to
   .ts-* so it only touches the enhanced control. */

.ts-wrapper {
  width: 100%;
}

.ts-control {
  min-height: 2.5rem;
  padding: 0.4rem 0.625rem;
  border: 1px solid var(--color-neutral-300, #d4d4d4);
  border-radius: 0.375rem;
  background-color: var(--color-white, #fff);
  font-size: 0.95rem;
  line-height: 1.4;
  box-shadow: none;
}

.ts-wrapper.focus .ts-control,
.ts-control:focus-within {
  border-color: var(--color-blue-700, #1d4ed8);
  outline: 2px solid color-mix(in oklab, var(--color-blue-700, #1d4ed8) 30%, transparent);
  outline-offset: 1px;
}

.ts-dropdown {
  border: 1px solid var(--color-neutral-200, #e5e5e5);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.08);
  font-size: 0.95rem;
}

.ts-dropdown .optgroup-header {
  font-weight: 600;
  color: var(--color-neutral-500, #737373);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.ts-dropdown .option.active,
.ts-dropdown .option:hover {
  background-color: var(--color-blue-100, #dbeafe);
  color: var(--color-blue-700, #1d4ed8);
}

/* ══════════════════════════════════════════════════════════════════════════
   DARK THEME — internal Knowledge app (ENG-1354)
   ══════════════════════════════════════════════════════════════════════════
   Additive only, same invariant as the block at the end of public_kb.css: a
   `:root[data-theme="dark"]` token remap plus existing light selectors prefixed
   with `[data-theme="dark"]`. No light declaration is edited, no `!important`.

   Why the token remap wins: the vendored design-system.css declares its 133
   `--tw-color-*` tokens on an UNLAYERED `:root,:host` (0-1-0), so
   `:root[data-theme="dark"]` (0-2-0) beats it on specificity — which matters
   because design-system.css loads AFTER this file.

   The page background and body colour come from public_kb.css's `body` rule
   (that file is glob-loaded here too), so the neutral/background hexes in the
   two files are deliberately identical.

   Hex literals appear only as TOKEN VALUES — defining a theme's palette is not
   the ad-hoc colour use docs/design-system.md rule 7 prohibits, and every
   non-token rule below reads a var().
   ────────────────────────────────────────────────────────────────────────── */

:root[data-theme="dark"] {
  --tw-color-background: #0d1119;

  --tw-color-neutral-0:   #171b25;   /* raised surface — cards, topbar        */
  --tw-color-neutral-50:  #12161f;
  --tw-color-neutral-100: #12161f;   /* sunk surface                          */
  --tw-color-neutral-200: #343c4f;   /* subtle border                         */
  --tw-color-neutral-300: #707b91;   /* strong border — interactive edges     */
  --tw-color-neutral-400: #7d8798;
  --tw-color-neutral-500: #9aa3b4;
  --tw-color-neutral-600: #b3bbc9;
  --tw-color-neutral-700: #c6cdd9;
  --tw-color-neutral-800: #dbe1ec;
  --tw-color-neutral-900: #eef0f6;   /* .tw-app's text colour                 */

  --tw-color-neutral-translucent-100: rgba(220, 228, 245, 0.08);
  --tw-color-neutral-translucent-200: rgba(220, 228, 245, 0.14);

  --tw-color-table-header: #22293a;

  /* The ALIAS only, never --tw-color-primary-500. The alias gives
     .tw-btn-tertiary, tw:text-primary, .tw-page-header-title and .tw-page-link
     a legible #a8bdf0 accent (9.3:1) while .tw-btn-primary keeps its navy
     -500 fill with white text. The two places the alias is used as a
     BACKGROUND are guarded further down. */
  --tw-color-primary: #a8bdf0;

  --tw-color-blue-100: #1b2740;
  --tw-color-blue-700: #a8c6ff;

  /* The near-white *-50 tints are only ever used as backgrounds, and red-900
     only ever as the paired foreground. Remapping them by token fixes both the
     .tw-btn-outline-danger/-warning surfaces AND the live
     `tw:bg-green-50 / tw:bg-red-50 / tw:text-red-900` utilities on the draft
     review page in one place. (The paired `tw:text-green-900` needs no token:
     the DS bundle stops at text-green-800, so that class is inert and the added
     row simply inherits .tw-app's foreground.) */
  --tw-color-red-50:    #2b1416;
  --tw-color-orange-50: #2b1f0e;
  --tw-color-green-50:  #122a1c;
  --tw-color-red-900:   #ff9bb3;

  /* DELIBERATELY NOT REMAPPED, each a trap:
     - --tw-color-white: it is simultaneously the TEXT of ~20 filled
       button/badge rules and the SURFACE of .tw-card. Remapping it makes every
       primary button's label vanish; the surfaces get explicit rules instead.
     - the hue ramps at -500/-600/-700: -700 doubles as a filled-button
       background, -600 fills .tw-badge-info. The tinted variants that need
       fixing are enumerated below instead.
     - --tw-color-primary-100/-200/-500/-700: -500 fills .tw-btn-primary, -700
       its :active, -200 the .tw-btn-tertiary focus ring. */
}

/* ── Surfaces whose light background is --tw-color-white ────────────────────
   (which we cannot remap — see above). */
[data-theme="dark"] .tw-card,
[data-theme="dark"] .tw-card-header-sticky,
[data-theme="dark"] .tw-page-header-container {
  background-color: var(--tw-color-neutral-0);
}

/* ── Interaction states the token remap alone would break (AC-3) ──────────── */

/* .tw-btn-secondary paints primary-500 navy text on a translucent chip: ~1.5:1
   once the chip is dark. Used on the dashboard, API tokens, sections and
   article pages. */
[data-theme="dark"] .tw-btn-secondary { color: var(--tw-color-primary); }

/* neutral-600/-700 are used as BACKGROUNDS here, with white text — inverting
   the ramp turns the hover into a bright panel with invisible text. */
[data-theme="dark"] .tw-btn-outline-secondary:hover,
[data-theme="dark"] .tw-btn-outline-secondary:active {
  background-color: #343c4f;
  border-color: #707b91;
  color: var(--tw-color-neutral-900);
}

/* blue-600 (#0d5af4) on the dark topbar is 3.1:1 — and this is the top nav and
   Sign out. The token itself must stay put (it fills .tw-badge-info). */
[data-theme="dark"] .tw-btn-tertiary:hover { color: var(--tw-color-neutral-900); }

/* Where --tw-color-primary is a BACKGROUND rather than a foreground. */
[data-theme="dark"] .tw-page-item.tw-active .tw-page-link {
  background-color: #2f4aa8;
  color: #fff;                       /* 7.9:1 */
}
[data-theme="dark"] .tw-page-link:hover {
  background-color: #22293a;
  color: var(--tw-color-neutral-900);
}

/* An explicit focus ring so AC-6 does not depend on the UA default. This is
   0-3-0, so it also wins over .tw-btn-tertiary:focus (0-2-0), which sets
   `outline-style: none` and paints a box-shadow ring instead. */
[data-theme="dark"] .tw-btn:focus-visible {
  outline: 2px solid #c4d2f7;        /* 11.2:1 */
  outline-offset: 2px;
}

/* ── Tinted badges / tags / notifications ───────────────────────────────────
   The hue ramps are not inverted, so these cannot be fixed by tokens. Each
   needs BOTH a tinted surface and an accent foreground: the DS sets the
   title/icon colour separately and it survives the background override
   (green-700 on the tint is 4.4:1 and red-600 is 4.2:1 — both fail). */
[data-theme="dark"] .tw-badge-primary-subtle,
[data-theme="dark"] .tw-badge-primary-soft,
[data-theme="dark"] .tw-tag-primary-subtle {
  background-color: #1c2438;
  border-color: #232d45;
  color: #a8bdf0;                    /* 8.2:1 */
}
[data-theme="dark"] .tw-badge-success-subtle,
[data-theme="dark"] .tw-tag-success-subtle,
[data-theme="dark"] .tw-inline-notification-success {
  background-color: #122a1c;
  border-color: rgba(125, 220, 154, 0.40);
  color: #7ddc9a;
}
[data-theme="dark"] .tw-badge-warning-subtle,
[data-theme="dark"] .tw-tag-warning-subtle,
[data-theme="dark"] .tw-inline-notification-warning {
  background-color: #2b1f0e;
  border-color: rgba(240, 179, 102, 0.42);
  color: #f0b366;
}
[data-theme="dark"] .tw-badge-danger-subtle,
[data-theme="dark"] .tw-tag-danger-subtle,
[data-theme="dark"] .tw-inline-notification-error {
  background-color: #2b1416;
  border-color: rgba(255, 155, 179, 0.42);
  color: #ff9bb3;
}
/* The notification body text must stay readable on those tints — the accent
   above is for the icon/title. */
[data-theme="dark"] .tw-inline-notification-message { color: #dbe1ec; }

/* ── Form select chevron ────────────────────────────────────────────────────
   The DS paints it as a hardcoded data-URI stroked in #505b72, which is
   invisible on a dark field. Same documented component background, restroked. */
[data-theme="dark"] .tw-form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%239aa3b4' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
}

/* ── Theme toggle icon state ────────────────────────────────────────────────
   Driven by the pre-paint attribute so the right glyph is on the first frame. */
.kb-theme-icon { line-height: 1; }
[data-theme="light"] .kb-theme-icon--dark  { display: none; }
[data-theme="dark"]  .kb-theme-icon--light { display: none; }

/* ── Top nav ────────────────────────────────────────────────────────────────
   SCOPED under .kb-nav because public_kb.css defines a same-named
   .kb-nav-link[aria-current="page"] for the public sidebar and is glob-loaded
   here too; .kb-nav is internal-only. */
[data-theme="dark"] .kb-nav .kb-nav-link[aria-current="page"] {
  background-color: var(--tw-color-blue-100);
  color: var(--tw-color-blue-700);
}

/* The mobile nav dropdown — the most conspicuous "unintended light panel"
   candidate on the whole internal surface (its light background is
   --tw-color-white, which stays #fff).

   MUST stay inside the same @media as the light rule it mirrors: the checkbox
   is only visually hidden (still focusable/checkable), so `:checked` survives a
   resize past 768px, and an unmediated version would paint a bordered, shadowed
   box around the inline DESKTOP nav — an artifact light mode does not have. */
@media (max-width: 767px) {
  [data-theme="dark"] .kb-nav .kb-nav-checkbox:checked ~ .kb-nav-links {
    background-color: var(--tw-color-neutral-0);
    border-color: var(--tw-color-neutral-200);
    box-shadow: 0 4px 12px rgb(0 0 0 / 0.55);
  }
}

/* ── Tom Select (the section/subsection typeahead on the article form) ──────
   public/vendor/tom-select/tom-select.css is hardcoded light (#fff, #f2f2f2,
   #303030, #f5fafd, #495c68) and is vendored third-party — never edited. These
   targeted overrides are the whole dark treatment for it. */
[data-theme="dark"] .ts-wrapper .ts-control {
  background-color: var(--tw-color-neutral-0);
  border-color: var(--tw-color-neutral-300);
  color: var(--tw-color-neutral-900);
}
/* .full .ts-control and .disabled .ts-control in the vendored bundle are both
   0-2-0 AND load after this file, so a plain [data-theme="dark"] .ts-control
   would tie and lose on source order. The .ts-wrapper ancestor takes these to
   0-3-0, which wins outright. */
[data-theme="dark"] .ts-wrapper.disabled .ts-control {
  background-color: var(--tw-color-neutral-100);
}
[data-theme="dark"] .ts-wrapper .ts-control input,
[data-theme="dark"] .ts-wrapper .ts-control .item {
  color: var(--tw-color-neutral-900);
}
[data-theme="dark"] .ts-wrapper .ts-control input::placeholder { color: var(--tw-color-neutral-500); }
[data-theme="dark"] .ts-dropdown {
  background-color: var(--tw-color-neutral-0);
  border-color: var(--tw-color-neutral-200);
  color: var(--tw-color-neutral-900);
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.55);
}
[data-theme="dark"] .ts-dropdown .option { color: var(--tw-color-neutral-800); }
[data-theme="dark"] .ts-dropdown .optgroup-header {
  background-color: var(--tw-color-neutral-100);
  color: var(--tw-color-neutral-500);
}
[data-theme="dark"] .ts-dropdown .option.active,
[data-theme="dark"] .ts-dropdown .option:hover {
  background-color: var(--tw-color-blue-100);
  color: var(--tw-color-blue-700);
}
