/* ============================================================
   PLIXY — TOKENS.CSS
   ------------------------------------------------------------
   Theme-agnostic structural rules. ALL appearance decisions
   (colour, typography, sizes, weights, paddings, borders,
   radii) live in the theme files. This file owns:
     • reset
     • layout grid + responsive breakpoints
     • view-switching (display rules)
     • default visibility for theme-conditional elements
   ============================================================ */

/* ---------- reset ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-feature-settings: "kern", "liga", "tnum";
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }
hr { box-sizing: content-box; height: 0; }

/* ---------- view switching ---------- */
.view { display: none; }
.view.view-active { display: block; }

/* ---------- masthead layout ---------- */
.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.brand { display: flex; align-items: baseline; }
.topnav { display: flex; align-items: baseline; }
/* The brand name is a link home for signed-in users. It must keep
   looking like the name, not like a link. `:where()` adds no weight,
   so a theme that gives .brand-mark its own colour still wins. */
.brand-mark:where(a) { color: inherit; text-decoration: none; }

/* Default visibility for theme-conditional elements.
   Each theme can override these with display: <whatever>. */
.brand-sub      { display: none; }   /* notebook only */
.brand-meta     { display: none; }   /* technical, admin */
.topnav-user-label { display: none; } /* admin only */

.pane-subtitle  { display: none; }   /* admin only */
.title-rule     { display: none; border: 0; margin: 0; }   /* admin only */
.edit-attrs-label { display: none; } /* technical, admin */

/* ---------- main two-pane layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(420px, 560px) 1fr;
}
.layout:has(.pane-left, .pane-right) {
  min-height: calc(100vh - 80px);
}
.pane-left  { position: relative; }
.pane-right { position: relative; }

/* ---------- independent pane scrolling (v1.3.0, Task B3) ----------
   Wide screens: the page itself does not scroll on the two-pane
   view; each pane is its own scroll area and the top bar stays in
   place (R3). The body.page-two-pane prefix (set by issue_list.html)
   does two jobs: it limits these rules to the list/detail page, so
   every other page keeps ordinary page scrolling, and it outranks the
   .layout:has(.pane-left, .pane-right) min-height rule above and its
   per-theme variant in theme-lean.css, which would otherwise keep the
   layout taller than the window.

   How the height is passed down: body is a column exactly one window
   tall; <main> takes what the top bar leaves; .layout fills <main>;
   the two panes fill .layout and scroll inside it. min-height: 0 at
   each level is what allows a flex or grid child to be shorter than
   its content, without which nothing would ever scroll.

   The side rail (.meta-rail) is positioned inside .pane-right, so it
   scrolls with the issue, as before. Phones (max-width: 960px) are
   not affected: there the page scrolls as a whole. */
@media (min-width: 961px) {
  body.page-two-pane {
    height: 100vh;
    height: 100dvh;   /* where supported: excludes retractable browser bars */
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  body.page-two-pane > main {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  body.page-two-pane .layout {
    flex: 1 1 auto;
    min-height: 0;
  }
  body.page-two-pane .pane-left,
  body.page-two-pane .pane-right {
    overflow-y: auto;
    min-height: 0;
  }
}

/* ---------- one pane at a time on phones (v1.3.0, Task B5) ----------
   On a phone the list and the issue do not fit side by side, and
   stacked they made the issue hard to find. body.page-two-pane gains
   has-selection while an issue is open (set by issue_list.html on a
   full page load, kept in step with the address bar by indexNav() in
   _list_pane.html). With it the list is hidden; without it the issue
   pane is. Both panes stay in the page, so going back needs no reload
   and the list keeps its state. Wide screens are unaffected. */
.detail-back { display: none; }
@media (max-width: 960px) {
  body.page-two-pane.has-selection .pane-left { display: none; }
  body.page-two-pane:not(.has-selection) .pane-right { display: none; }
  /* Appearance (font, colour) is per theme; this is structure only.
     The padding makes the link a comfortable touch target. */
  .detail-back { display: inline-block; padding: 6px 0; margin-bottom: 14px; }
}

/* ---------- index entries ---------- */
.index-list { list-style: none; padding: 0; margin: 0; }
.index-entry {
  cursor: pointer;
  position: relative;
}
.index-entry { display: grid; grid-template-columns: 1fr; gap: 0; }

/* ---------- reading view ---------- */
.issue-eyebrow { display: flex; align-items: baseline; flex-wrap: wrap; }
.issue-by-line { /* prose flow */ }

/* ---------- meta rail ---------- */
.meta-rail { position: absolute; }
.rail-list { margin: 0; padding: 0; }
.rail-row {
  display: flex; justify-content: space-between; align-items: baseline;
}
.rail-actions { display: flex; flex-direction: column; }
.rail-action {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  font-family: inherit;
}

/* ---------- section break ---------- */
.section-break { display: flex; align-items: center; }
.section-break-rule { flex: 1; }

/* ---------- comments ---------- */
.comment { position: relative; }
.comment-head { display: flex; align-items: baseline; }
.comment-actions {
  margin-left: auto;
  display: flex;
  opacity: 0;
  transition: opacity 100ms ease;
}
.comment:hover .comment-actions { opacity: 1; }
.comment-action {
  background: transparent;
  border: 0;
  font-family: inherit;
}
.comment-attach {
  display: inline-flex;
  align-items: center;
}

/* ---------- reply composer ---------- */
.reply-composer { /* container */ }
.reply-textarea { width: 100%; font-family: inherit; resize: vertical; }
.reply-toolbar { display: flex; align-items: center; }
.reply-submit { margin-left: auto; }

/* ---------- edit shell ---------- */
.edit-shell { /* container */ }
.edit-eyebrow { display: flex; align-items: center; }
.edit-back { cursor: pointer; }
.edit-title-input { width: 100%; font-family: inherit; }
.edit-description { width: 100%; font-family: inherit; resize: vertical; }
.edit-attach-row { display: flex; align-items: center; }
.edit-attrs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}
.edit-attr { display: flex; flex-direction: column; }
.edit-attr-input { font-family: inherit; }
.edit-actions { display: flex; align-items: center; }
.edit-action--delete { margin-left: auto; }

/* ---------- forms reset ---------- */
.filter-input,
.filter-summary,
.edit-attr-input,
.edit-title-input,
.edit-description,
.reply-textarea {
  outline: none;
}
.filter-grid { display: grid; }

.chips { display: flex; flex-wrap: wrap; }
.chip { font-family: inherit; cursor: pointer; user-select: none; }

/* ---------- demo controls (always present) ---------- */
.demo-controls {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 999;
  font-family: -apple-system, BlinkMacSystemFont, "Inter Tight", system-ui, sans-serif;
  font-size: 11px;
}
.theme-switch,
.view-switch {
  background: rgba(20,20,20,0.92);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 4px;
  gap: 2px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.18);
  border-radius: 4px;
  backdrop-filter: blur(10px);
}
.theme-switch-label {
  padding: 0 8px 0 6px;
  color: rgba(255,255,255,0.55);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.theme-switch-button,
.view-switch-button {
  background: transparent;
  border: 0;
  padding: 5px 11px;
  color: rgba(255,255,255,0.6);
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.04em;
  border-radius: 3px;
  font-weight: 500;
}
.theme-switch-button:hover,
.view-switch-button:hover {
  color: rgba(255,255,255,0.95);
}
.theme-switch-button--active,
.view-switch-button--active {
  background: rgba(255,255,255,0.95);
  color: #1a1a1a;
}

/* ---------- width containment (v1.3.0, Task B1) ----------
   No page may be wider than the screen (R1). These rules remove the
   causes instead of hiding the symptom: `overflow-x: hidden` on html
   or body is deliberately NOT used, because it would hide content and
   break sticky positioning. */

/* Grid and flex children refuse to shrink below their content's
   natural width unless told they may; one long word in a pane would
   otherwise widen the whole page. */
.pane-left, .pane-right { min-width: 0; }
/* Long unbroken words (a pasted URL, a file name) wrap instead of
   widening the page. The last two selectors were found by measuring
   the pages in a browser: an attachment chip with a long file name on
   the edit page, and the issue title quoted on the delete
   confirmation. */
.issue-title, .issue-body, .comment-body, .ix-title,
.rail-row-value, .comment-attach, .edit-confirm-prompt { overflow-wrap: anywhere; }
/* Form controls have an intrinsic width (a <select> is as wide as its
   longest option); cap them at their container. */
input, select, textarea { max-width: 100%; }
/* A wide table scrolls inside its own box; the page itself does not. */
.staff-table-scroll { overflow-x: auto; }

/* ---------- responsive (single-column) ---------- */
@media (max-width: 960px) {
  /* minmax(0, 1fr), not 1fr: a bare 1fr column has an automatic
     minimum of its content's width and stretches past the screen. */
  .layout { grid-template-columns: minmax(0, 1fr); }
  .meta-rail { position: static; width: auto; }
  /* `body` prefix: the lean theme sets its own two-column grid on
     .edit-attrs with bare 1fr columns, and a theme rule wins at equal
     specificity because theme files load after this one. */
  body .edit-attrs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .demo-controls { flex-direction: column; align-items: center; gap: 6px; }
  /* The top bar may take a second line instead of pushing its last
     items off the screen. */
  .masthead { flex-wrap: wrap; row-gap: 8px; }
  .topnav { flex-wrap: wrap; }
  .share-link-row { flex-wrap: wrap; }
  /* Found by measuring at 320px: a comment's heading row (author,
     date, edit/delete) and the edit page's button row (Save, Cancel,
     Delete) were one line too long for the narrowest phones. */
  .comment-head { flex-wrap: wrap; }
  .edit-actions { flex-wrap: wrap; row-gap: 8px; }
  /* v1.3.0 (Task B2): the staff review page has no theme styling at
     all (see expired_review.html), so no theme gives it a side margin
     and its text touched the screen edge. Same 20px as the issue
     panel (decision D-30). Written here once because no theme file
     sets this page's padding. */
  .staff-page { padding-left: 20px; padding-right: 20px; }
}

/* ---------- entrance animation ---------- */
@keyframes plixyFadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.view-active .pane-right > *,
.view-active .edit-shell > * {
  animation: plixyFadeUp 380ms ease both;
}
.view-active .pane-right > *:nth-child(1) { animation-delay: 30ms; }
.view-active .pane-right > *:nth-child(2) { animation-delay: 70ms; }
.view-active .pane-right > *:nth-child(3) { animation-delay: 110ms; }
.view-active .pane-right > *:nth-child(4) { animation-delay: 150ms; }
.view-active .pane-right > *:nth-child(5) { animation-delay: 190ms; }
.view-active .pane-right > *:nth-child(6) { animation-delay: 230ms; }

/* ---------- form errors (v1.1) ----------
   Theme-agnostic baseline. Themes may override colours/border to
   match their palette; the defaults here render readably against
   any of the four theme backgrounds.

   Used by:
     - <p class="form-errors"> sibling to a form field's widget
       (per-field error rendering in issue_form.html,
       comment_edit_form.html, login.html, _share_section.html)
     - <div class="form-errors form-errors--top"> for
       top-of-form non_field_errors blocks. */
.form-errors {
  color: #b91c1c;            /* a red dark enough to read on white */
  font-size: 12px;
  margin: 6px 0 0;
  line-height: 1.4;
}
.form-errors--top {
  margin: 0 0 14px;
  padding: 8px 12px;
  border: 1px solid #fecaca;  /* light red border */
  background: #fef2f2;        /* very light red wash */
  border-radius: 4px;
  font-size: 13px;
}
.form-errors ul { margin: 0; padding-left: 18px; }

/* ---------- form notice (v1.3.0, Task A7) ----------
   The neutral counterpart of .form-errors--top: a confirmation
   ("Your password has been changed.") or a hint (the password rules).
   Theme-agnostic like the error block above. Text colour is inherited
   from the theme; border and wash are a translucent mid-grey, which
   stays visible on all four theme backgrounds (light paper or dark)
   without a per-theme rule. */
.form-notice {
  margin: 0 0 14px;
  padding: 8px 12px;
  border: 1px solid rgba(128, 128, 128, 0.45);
  background: rgba(128, 128, 128, 0.08);
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.4;
}
.form-notice p { margin: 0; }
.form-notice ul { margin: 0; padding-left: 18px; }
.edit-field-group > .form-notice { margin: 8px 0 0; }

/* ---------- tags (v1.3.0, Part C) ----------
   Theme-neutral baseline for tag chips and the tag editor. Everything
   draws with currentColor, so the chips take the text colour of
   wherever they sit and read in all four themes without a per-theme
   rule. A personal tag (visible to its owner only) has a dashed
   border; a global tag a solid one. */
.tag {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1.5;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.tag--personal { border-style: dashed; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-none { margin: 0; opacity: 0.7; font-size: 12px; }

/* Chips under the title of the public share page (Task C6). */
.public-tags { margin: 10px 0 0; }

/* Chips under a list entry (Task C3). The element is always present
   so there is a target for the update after a save; it takes no
   space while it has no chips. */
.ix-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.ix-tags:empty { display: none; }

/* The editor: a disclosure under the chips. Checkbox rows are full
   width so each is an easy touch target on a phone. */
.tag-editor { margin-top: 8px; }
.tag-editor > summary { cursor: pointer; }
.tag-form { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.tag-options { display: flex; flex-direction: column; gap: 6px; }
.tag-option { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 28px; }
.tag-option input { margin: 0; flex: none; }
.tag-new-input { width: 100%; font-family: inherit; font-size: inherit; padding: 4px 6px; }
.tag-form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Sharing form on the issue panel (Task D3). It reuses the tag
   editor's form and checkbox-row classes (.tag-form, .tag-options,
   .tag-option); only what differs is here. A long list of users
   scrolls inside its own box so the panel keeps a sane height. */
.sharing-section { margin: 10px 0 14px; }
.sharing-note { margin: 0 0 10px; font-size: 12px; line-height: 1.4; opacity: 0.8; }
.sharing-group-title { font-size: 11px; opacity: 0.7; margin-bottom: 4px; }
.sharing-options { max-height: 220px; overflow-y: auto; }
.rail-row[hidden] { display: none; }

/* "Send by email…" section on the issue panel (Task E3). Reuses the
   tag editor's and the sharing form's classes; only what differs is
   here. The record of past sends is a compact list: date, recipient
   and result on one wrapping line, the error text (if any) below. */
.email-section { margin: 10px 0 14px; }
.email-addresses, .email-message {
  width: 100%; box-sizing: border-box;
  font-family: inherit; font-size: inherit; padding: 4px 6px;
  resize: vertical;
}
.email-form .share-section-input { width: 100%; box-sizing: border-box; }
.email-log { margin-top: 14px; }
.email-log-list { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.email-log-row {
  display: flex; flex-wrap: wrap; gap: 2px 8px;
  padding: 4px 0; border-top: 1px solid rgba(128, 128, 128, 0.25);
}
.email-log-when { opacity: 0.7; }
.email-log-who { overflow-wrap: anywhere; }
.email-log-status { margin-left: auto; }
.email-log-row--failed .email-log-status { font-weight: 600; }
.email-log-error { flex-basis: 100%; opacity: 0.8; overflow-wrap: anywhere; }

/* Tag filter in the list (Task C5). The field spans the filter
   grid's full width because the number of tags is open-ended; the
   chips wrap. The label and the all/any switch share one line and
   wrap on a narrow screen. A personal tag's chip is dashed. */
.filter-field--tags { grid-column: 1 / -1; }
.filter-tags-head {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 6px 12px;
  margin-bottom: 6px;
}
.filter-tags-head .filter-label { margin: 0; }
/* Two classes, so this outranks each theme's own `.chip { border: … }`
   rule, which loads later and would otherwise reset the style. */
.chips .chip--personal { border-style: dashed; }

/* "My tags" page (Task C4). Rows wrap so the page fits a phone: the
   name box takes the free width, the buttons keep their size, and a
   message takes a full line under its row. */
.my-tags-lede { margin: 0 0 18px; font-size: 13px; line-height: 1.5; opacity: 0.8; }
.my-tags-list { list-style: none; margin: 18px 0 0; padding: 0; }
.my-tag-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 8px 0;
}
.my-tags-list .my-tag-row { border-top: 1px solid rgba(128, 128, 128, 0.25); }
.my-tag-rename { display: flex; align-items: center; gap: 8px; flex: 1 1 240px; min-width: 0; }
.my-tag-name { flex: 1 1 auto; min-width: 0; }
.my-tag-count { font-size: 12px; opacity: 0.7; white-space: nowrap; }
.my-tag-delete { margin-left: auto; }
/* Inside a row the buttons sit in a line of their own making; the
   edit page's rule that pushes Delete to the far right of a button
   bar does not apply here. */
.my-tag-row .edit-action--delete { margin-left: 0; }
.my-tag-error { flex-basis: 100%; margin: 0; }
.my-tags-empty { margin: 18px 0 0; opacity: 0.7; }

/* ---------- order direction toggle (UX-2, v1.2.0) ----------
   Structural baseline for the .order-dir segmented control in the
   list-pane filter region. Per-theme `--on` accent rules live in
   each theme-*.css. The control is two server-rendered <label>s
   wrapping hidden radio inputs that share name="dir"; visual state
   is round-tripped on filter submit (Option A in the plan). */
.order-dir {
  display: inline-flex;
  gap: 0;
  border: 1px solid currentColor;
  border-radius: 3px;
  overflow: hidden;
}
.order-dir-option {
  cursor: pointer;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.4;
  user-select: none;
}
.order-dir-option + .order-dir-option {
  border-left: 1px solid currentColor;
}
