/*
 * cserver.cmeta.install - page styling.
 *
 * Everything is scoped under #cxi, because this page renders inside two very
 * different documents: the engine's internal cserver ships no CSS whatsoever
 * (a bare white page), while the cPlatform loads Bootstrap 5.3 and puts a
 * `dark-theme` class on <body>. Scoping keeps this file from leaking into the
 * platform's chrome, and the variables below let the same rules serve both
 * themes.
 *
 * Two selectors switch to the dark palette, and BOTH are needed:
 *
 *   #cxi.dark            install.js, from the theme the server sent for a
 *                        signed-in user.
 *   body.dark-theme #cxi the platform's own class, for an anonymous visitor
 *                        the server tells us nothing about.
 *
 * The second is not a nicety. This file is pulled in from inside
 * {% block content %}, so install.js registers its DOMContentLoaded handler
 * BEFORE the platform's own handler further down base.html - the one that adds
 * `dark-theme`. Handlers run in registration order, so when install.js looked
 * for the class it was not there yet and every anonymous visitor got the light
 * palette painted onto the platform's dark page: #1c2024 text on #0b0e14,
 * a contrast ratio of 1.18. CSS has no such ordering problem - the moment the
 * class lands the palette follows.
 *
 * It also outranks the light class: `body.dark-theme #cxi` is (0,1,1,1)
 * against `#cxi.light`'s (0,1,1,0), so a stale `.light` from that race cannot
 * win. The platform removes `dark-theme` for a user who chose light, so the
 * two never contradict each other.
 */

#cxi {
  --bg:        #ffffff;
  --fg:        #1c2024;
  --muted:     #5b6570;
  --line:      #dfe3e8;
  --panel:     #f7f8fa;
  --panel-2:   #eef1f4;
  --accent:    #b8442a;
  --accent-fg: #ffffff;
  --code-bg:   #23262b;
  --code-fg:   #eceff3;
  --code-com:  #8b98a5;
  --chip-bg:   #ffffff;
  /* Links sitting ON the terminal background. That background is dark in both
     themes, so this stays the same in both - unlike --accent, whose light-theme
     value (#b8442a) scored 2.82 against it and was the one genuinely hard-to-read
     thing on the page. #f0785a clears 4.5 on both #23262b and #0e1013. */
  --code-link: #f0785a;

  /* 1120 rather than 1000: at 1000 the nine OS chips wrap onto three lines and
     the ten compute chips onto two, leaving a single orphan on each. Past
     ~1060 both settle (2 lines and 1), and the prose still stops well short of
     a full-bleed line length on a wide monitor. */
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 16px 60px;
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  box-sizing: border-box;
}

#cxi.dark,
body.dark-theme #cxi {
  --bg:        #14161a;
  --fg:        #e6e9ed;
  --muted:     #9aa4b0;
  --line:      #333941;
  --panel:     #1c1f24;
  --panel-2:   #23272e;
  --accent:    #e2603f;
  --accent-fg: #14161a;
  --code-bg:   #0e1013;
  --code-fg:   #e6e9ed;
  --code-com:  #79838f;
  --chip-bg:   #22262c;
}

#cxi *, #cxi *::before, #cxi *::after { box-sizing: inherit; }

/* The `hidden` attribute is only a UA-level `display: none`, so ANY author
   rule that sets display beats it - and `.cxi-row { display: flex }` does
   exactly that. Without this, simple mode set hidden on every advanced row and
   every one of them still rendered. Needs !important because the rules it has
   to outrank are equally specific author rules. */
#cxi [hidden] { display: none !important; }

/* ---------- header ----------
   Everything in the page shares one left and right edge with the picker below
   it. Prose used to be clamped to 70ch, which on a wide screen left the intro
   ending less than halfway across while the matrix under it ran the full
   width - the two read as misaligned rather than as one column. */

#cxi-head {
  margin: 0 0 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

#cxi-h1 {
  margin: 0 0 10px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#cxi-lede {
  margin: 0 0 14px;
  font-size: 15.5px;
  line-height: 1.6;
}
#cxi-lede b { font-weight: 600; }

#cxi-sub {
  margin: 14px 0 0;
  color: var(--muted);
}

#cxi-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}

/* One card per destination: the name people scan for, and a few words saying
   what they would find there. */
.cxi-link {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  text-decoration: none;
  line-height: 1.35;
  transition: border-color .12s, background .12s;
}
.cxi-link:hover { border-color: var(--accent); background: var(--panel-2); }
.cxi-link b { font-size: 13.5px; font-weight: 600; color: var(--accent); }
.cxi-link span { font-size: 12px; color: var(--muted); }

.cxi-badge {
  align-self: center;
  padding: 4px 10px;
  border: 1px dashed var(--line);
  border-radius: 20px;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- the picker ---------- */

#cxi-matrix {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.cxi-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
}
.cxi-row:last-child { border-bottom: 0; }

.cxi-key {
  flex: 0 0 190px;
  padding: 12px 14px;
  background: var(--panel-2);
  border-right: 1px solid var(--line);
  font-weight: 600;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.cxi-hint {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  margin-top: 2px;
}

.cxi-opts {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  align-items: center;
}

/* A single option: a real <button> so it is keyboard-reachable, styled as a
   chip. `aria-pressed` carries the state for screen readers; `.on` paints it. */
.cxi-opt {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--chip-bg);
  color: var(--fg);
  border-radius: 6px;
  padding: 7px 14px;
  font: inherit;
  font-size: 14px;
  line-height: 1.25;
  cursor: pointer;
  text-align: center;
  transition: background .12s, border-color .12s, color .12s;
}
.cxi-opt:hover { border-color: var(--accent); }
.cxi-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cxi-opt.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.cxi-opt.on .cxi-sub { color: var(--accent-fg); opacity: .82; }

.cxi-opt .cxi-sub {
  display: block;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--muted);
  margin-top: 1px;
}

/* Checkbox-style options (extras, automation repos) sit in the same chip
   shape, so the whole matrix reads as one control surface. */
.cxi-checks .cxi-opt { display: inline-flex; align-items: center; gap: 8px; text-align: left; }
.cxi-checks .cxi-box {
  width: 15px; height: 15px;
  flex: 0 0 15px;
  border: 1px solid var(--muted);
  border-radius: 3px;
  display: inline-block;
  position: relative;
  background: var(--bg);
}
.cxi-checks .cxi-opt.on .cxi-box {
  background: var(--accent-fg);
  border-color: var(--accent-fg);
}
.cxi-checks .cxi-opt.on .cxi-box::after {
  content: "";
  position: absolute;
  left: 4px; top: 0.5px;
  width: 4px; height: 9px;
  border: solid var(--accent);
  border-width: 0 2px 2px 0;
  transform: rotate(42deg);
}

/* The compute row is a placeholder until workloads can be driven from here. */
.cxi-row.cxi-disabled .cxi-opt {
  opacity: .55;
  cursor: not-allowed;
  border-style: dashed;
}
.cxi-row.cxi-disabled .cxi-opt:hover { border-color: var(--line); }
/* Targets with no `task/target--<id>` yet: dimmer again, so the row does not
   quietly promise the same level of support for all of them. */
.cxi-row.cxi-disabled .cxi-opt.cxi-planned {
  opacity: .3;
  font-style: italic;
}

/* ---------- the generated command ---------- */

.cxi-cmd-row .cxi-key { background: var(--panel-2); }

.cxi-cmd-wrap {
  flex: 1 1 auto;
  position: relative;
  background: var(--code-bg);
  min-width: 0;
}

#cxi-cmd {
  margin: 0;
  padding: 14px 76px 14px 16px;
  overflow-x: auto;
  color: var(--code-fg);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre;
  tab-size: 2;
}
#cxi-cmd .c { color: var(--code-com); }

#cxi-copy {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  border: 1px solid #4a525c;
  background: #2c3138;
  color: #e6e9ed;
  border-radius: 5px;
  padding: 4px 11px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
#cxi-copy:hover { background: #3a4048; }
#cxi-copy.done { background: #2f6b46; border-color: #2f6b46; color: #fff; }

#cxi-why {
  margin: 14px 2px 0;
  color: var(--muted);
  font-size: 13.5px;
}

/* ---------- per-choice notes ---------- */

#cxi-notes {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.cxi-note {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--panel);
  padding: 10px 13px;
  font-size: 13.5px;
}
.cxi-note b { display: block; margin-bottom: 2px; font-size: 13px; }
.cxi-note p { margin: 0; color: var(--muted); }

/* ---------- reference sections ---------- */

.cxi-sec { margin-top: 40px; }

.cxi-sec h2 {
  margin: 0 0 10px;
  font-size: 19px;
  font-weight: 600;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
}
.cxi-sec p { margin: 0 0 12px; }
.cxi-sub { color: var(--muted); font-size: 13.5px; }

.cxi-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 14px;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
}
.cxi-table th, .cxi-table td {
  border: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
.cxi-table td:last-child, .cxi-table th:last-child { white-space: normal; }
.cxi-table thead th { background: var(--panel-2); font-weight: 600; }
.cxi-table td:first-child { color: var(--muted); text-align: right; width: 1%; }

pre.cxi-static {
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 6px;
  padding: 12px 16px;
  margin: 0 0 14px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.65;
}
pre.cxi-static .c { color: var(--code-com); }

#cxi code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;
  font-size: .92em;
  /* Bootstrap - which the cPlatform loads and the internal cserver does not -
     paints bare <code> pink. Without this the identical page shows pink inline
     code on one host and body-coloured code on the other. `inherit` also does
     the right thing inside <pre>, where the surrounding rule already sets the
     terminal foreground. */
  color: inherit;
}
#cxi p code, #cxi dd code, #cxi td code, #cxi li code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.5px 4px;
}
#cxi pre code { background: none; border: 0; padding: 0; }

.cxi-dl { margin: 0; }
.cxi-dl dt { font-weight: 600; margin-top: 12px; }
.cxi-dl dd { margin: 3px 0 0; color: var(--muted); }

#cxi a { color: var(--accent); }

/* ...except on the terminal background, which does not follow the theme. */
#cxi-cmd a,
.cxi-cmd-wrap a,
pre.cxi-static a { color: var(--code-link); }

#cxi-foot {
  margin-top: 34px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

/* ---------- narrow screens ---------- */

@media (max-width: 720px) {
  .cxi-row { flex-direction: column; }
  .cxi-key {
    flex: 0 0 auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 12px;
  }
  .cxi-key .cxi-hint { display: inline; margin-left: 6px; }
  #cxi-cmd { padding-right: 16px; padding-top: 42px; }
}

/* ---------- simple / advanced ----------
   Sits above the picker rather than inside it: it decides which rows the
   picker even has, so it is not one of them. */

#cxi-modebar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
}
#cxi-modebar .cxi-opts {
  padding: 0;
  background: none;
  gap: 6px;
}
#cxi-modebar .cxi-opt { padding: 6px 14px; }

#cxi-modenote {
  color: var(--muted);
  font-size: 13px;
  flex: 1 1 260px;
  min-width: 0;
}

/* The "(the engine)" / "(the automations)" hints beside each star link -
   quiet enough that the repo names stay the thing you read. */
#cxi-foot span { color: var(--muted); font-size: 12.5px; }
