/* ==========================================================================
   BASIC CHAOS — extended UI components
   Everything a working tool needs beyond the core primitives.
   Requires tokens.css. Works in web pages and packaged apps alike.

   Icon law (amended): words first. An icon appears only where a word does
   not fit — top-bar corners, row affordances, dense toolbars — and it is
   always one of the house glyphs (icons.svg / icons.html), drawn chunky,
   filled, in currentColor, with an aria-label. Never decorative.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Icons — sizing wrappers for the sprite glyphs.
   <svg class="bc-icon"><use href="#i-gear"/></svg>
   -------------------------------------------------------------------------- */
.bc-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex: none;
  vertical-align: -4px;
}
.bc-icon--sm { width: 16px; height: 16px; vertical-align: -3px; }
.bc-icon--lg { width: 24px; height: 24px; vertical-align: -5px; }

/* Icon button: 44px hit area, wash on hover, pill per house shape. */
.bc-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box; /* keep 44x44 a true circle even if a host app pads buttons */
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: var(--r-btn);
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--bc-speed) var(--bc-ease), color var(--bc-speed) var(--bc-ease);
}
.bc-icon-btn:hover { background: var(--wash); color: var(--text); }
/* Pressed: the wash goes deep — instant down, eased release. */
.bc-icon-btn:active { background: var(--press); color: var(--accent); transition-duration: 0ms; }
.bc-icon-btn--solid { background: var(--deep); color: var(--text); }
.bc-header .bc-icon-btn, .bca-topbar .bc-icon-btn { color: rgba(245, 246, 245, 0.7); }
.bc-header .bc-icon-btn:hover, .bca-topbar .bc-icon-btn:hover { background: rgba(245, 246, 245, 0.12); color: var(--bc-sky); }

/* --------------------------------------------------------------------------
   Action — the nebenote text action: lowercase, underlined, quiet until
   hovered. "sort→"  "new +"  "esc"  "edit"  "cancel"  "create"
   -------------------------------------------------------------------------- */
.bc-action {
  background: none;
  border: none;
  padding: var(--bc-space-2);
  font-family: var(--bc-font);
  font-size: var(--bc-text-small);
  font-weight: var(--bc-weight-medium);
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--line);
  cursor: pointer;
}
.bc-action:hover { text-decoration-color: var(--accent); color: var(--accent); }
.bc-action--primary { font-weight: var(--bc-weight-bold); text-decoration-color: var(--accent); }
.bc-action--danger { color: var(--danger); text-decoration-color: var(--danger); }
.bc-action--muted { color: var(--muted); }

/* Action row: cancel/create pairs, right-aligned like the nebenote form. */
.bc-action-row {
  display: flex;
  justify-content: flex-end;
  gap: var(--bc-space-4);
  align-items: center;
}

/* --------------------------------------------------------------------------
   Avatar — round (a control you tap), deep plane, holds initials or a glyph.
   -------------------------------------------------------------------------- */
.bc-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--deep);
  color: var(--text);
  font-size: var(--bc-text-small);
  font-weight: var(--bc-weight-bold);
  text-transform: uppercase;
  flex: none;
  overflow: hidden;
}
.bc-avatar--sm { width: 28px; height: 28px; font-size: var(--bc-text-micro); }
.bc-avatar--lg { width: 56px; height: 56px; }
.bc-avatar > img { width: 100%; height: 100%; object-fit: cover; }

/* --------------------------------------------------------------------------
   Search row — input plane + escape action, like the nebenote picker.
   -------------------------------------------------------------------------- */
.bc-search {
  display: flex;
  align-items: center;
  gap: var(--bc-space-3);
}
.bc-search > .bc-input { flex: 1; }

/* --------------------------------------------------------------------------
   Filter row — view openers, not tabs. Each one opens its own view (a date
   picker, a topic index, a group list); none is selected by default.
   Dressed like section labels, not links. Active only while its view is
   open: set aria-expanded="true" or .is-active.
   -------------------------------------------------------------------------- */
.bc-filter-row {
  display: flex;
  align-items: center;
  gap: var(--bc-space-3);
  flex-wrap: wrap;
  margin-left: -10px;
}
.bc-filter {
  display: inline-flex;
  align-items: center;
  border: none;
  border-radius: var(--r-el);
  background: none;
  color: var(--muted);
  font-family: var(--bc-font);
  font-size: var(--bc-text-label);
  font-weight: var(--bc-weight-bold);
  letter-spacing: var(--bc-tracking-label);
  text-transform: uppercase;
  min-height: 28px;
  padding: 2px 10px;
  cursor: pointer;
  transition: background var(--bc-speed) var(--bc-ease), color var(--bc-speed) var(--bc-ease);
}
.bc-filter:hover { background: var(--wash); color: var(--text); }
.bc-filter[aria-expanded="true"], .bc-filter.is-active { background: var(--wash); color: var(--text); }

/* --------------------------------------------------------------------------
   List section head — label left, action right. RECENT · FAVORITES · edit
   -------------------------------------------------------------------------- */
.bc-list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--bc-space-3);
  margin: var(--bc-space-6) 0 var(--bc-space-2);
}

/* Count — a number in a small deep field, for group rows. */
.bc-count {
  display: inline-block;
  min-width: 24px;
  text-align: center;
  background: var(--deep);
  color: var(--muted);
  font-size: var(--bc-text-label);
  font-weight: var(--bc-weight-bold);
  border-radius: var(--r-el);
  padding: 3px 8px;
}

/* --------------------------------------------------------------------------
   Checkbox and radio — planes with a checked wash. No 1px boxes.
   -------------------------------------------------------------------------- */
.bc-check,
.bc-radio {
  appearance: none;
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin: 0;
  background: var(--deep);
  border: none;
  border-radius: var(--r-el);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  flex: none;
  transition: background var(--bc-speed) var(--bc-ease);
}
.bc-radio { border-radius: 50%; }
.bc-check::before,
.bc-radio::before {
  content: "";
  width: 12px;
  height: 12px;
  transform: scale(0);
  transition: transform var(--bc-speed) var(--bc-ease);
}
.bc-check::before {
  clip-path: polygon(43% 78%, 9% 47%, 21% 34%, 42% 53%, 79% 15%, 92% 28%);
  background: var(--bc-ink);
}
.bc-radio::before { border-radius: 50%; background: var(--bc-ink); }
.bc-check:checked, .bc-radio:checked { background: var(--bc-sky); }
.bc-check:checked::before, .bc-radio:checked::before { transform: scale(1.15); }
.bc-choice {
  display: flex;
  align-items: center;
  gap: var(--bc-space-3);
  min-height: 36px;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Slider — a plane track, sky fill via accent thumb. No ticks.
   -------------------------------------------------------------------------- */
.bc-range {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 8px;
  background: var(--deep);
  border-radius: var(--r-el);
  outline: none;
  cursor: pointer;
}
.bc-range::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}
.bc-range::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}

/* --------------------------------------------------------------------------
   Stepper — minus · value · plus. Controls are pills, the value is type.
   -------------------------------------------------------------------------- */
.bc-stepper {
  display: inline-flex;
  align-items: center;
  gap: var(--bc-space-2);
}
.bc-stepper > .bc-icon-btn { background: var(--deep); color: var(--text); }
.bc-stepper-value {
  min-width: 48px;
  text-align: center;
  font-weight: var(--bc-weight-bold);
  font-size: var(--bc-text-title);
}

/* --------------------------------------------------------------------------
   Disclosure — native details/summary, chevron rotates, no marker triangle.
   -------------------------------------------------------------------------- */
.bc-disclosure { background: var(--surface); border-radius: var(--r-field); }
.bc-disclosure > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bc-space-3);
  padding: var(--bc-space-3) var(--bc-space-4);
  min-height: 44px;
  box-sizing: border-box;
  font-weight: var(--bc-weight-medium);
  cursor: pointer;
}
.bc-disclosure > summary::-webkit-details-marker { display: none; }
.bc-disclosure > summary .bc-icon { transition: transform var(--bc-speed) var(--bc-ease); color: var(--muted); }
.bc-disclosure[open] > summary .bc-icon { transform: rotate(180deg); }
.bc-disclosure-body { padding: 0 var(--bc-space-4) var(--bc-space-4); }

/* --------------------------------------------------------------------------
   Menu — a floating plane of actions. Rows wash on hover.
   -------------------------------------------------------------------------- */
.bc-menu {
  background: var(--surface);
  border-radius: var(--r-field);
  padding: var(--bc-space-2);
  min-width: 200px;
  display: inline-block;
}
.bc-night .bc-menu, .bc-quiet .bc-menu { background: var(--bc-char-lift); }
.bc-menu-item {
  display: flex;
  align-items: center;
  gap: var(--bc-space-3);
  width: 100%;
  border: none;
  background: none;
  border-radius: var(--r-el);
  padding: var(--bc-space-3);
  min-height: 40px;
  box-sizing: border-box;
  font-family: var(--bc-font);
  font-size: var(--bc-text-body);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.bc-menu-item:hover { background: var(--wash); }
.bc-menu-item .bc-icon { color: var(--muted); }
.bc-menu-item--danger, .bc-menu-item--danger .bc-icon { color: var(--danger); }
.bc-menu-gap { height: var(--bc-space-2); }

/* --------------------------------------------------------------------------
   Dialog — a centered plane over an ink scrim. Title, body, action row.
   -------------------------------------------------------------------------- */
.bc-scrim {
  position: fixed;
  inset: 0;
  background: rgba(29, 31, 33, 0.55);
  display: grid;
  place-items: center;
  padding: var(--bc-space-5);
  z-index: 100;
}
.bc-dialog {
  background: var(--bg);
  color: var(--text);
  border-radius: var(--r-field);
  padding: var(--bc-space-5);
  max-width: 440px;
  width: 100%;
}
.bc-dialog > .bc-head { font-size: 18px; margin-bottom: var(--bc-space-3); }
.bc-dialog .bc-action-row { margin-top: var(--bc-space-5); }

/* --------------------------------------------------------------------------
   Toast — a brief ink plane, bottom of screen. One line, one action, gone.
   -------------------------------------------------------------------------- */
.bc-toast {
  display: inline-flex;
  align-items: center;
  gap: var(--bc-space-4);
  background: var(--bc-ink);
  color: var(--bc-chalk-lift);
  border-radius: var(--r-field);
  padding: var(--bc-space-3) var(--bc-space-4);
  font-size: var(--bc-text-small);
}
.bc-toast .bc-action { color: var(--bc-sky); text-decoration-color: var(--bc-sky); padding: 0; }
.bc-toast-dock {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--bc-space-5) + env(safe-area-inset-bottom, 0px));
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 110;
}
.bc-toast-dock .bc-toast { pointer-events: auto; }

/* --------------------------------------------------------------------------
   Chip — a removable mark. The color field with its own remove control.
   -------------------------------------------------------------------------- */
.bc-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--bc-space-1);
  background: var(--deep);
  color: var(--text);
  border-radius: var(--r-btn);
  padding: 4px 6px 4px 12px;
  font-size: var(--bc-text-small);
  font-weight: var(--bc-weight-medium);
}
.bc-chip .bc-icon-btn { width: 28px; height: 28px; color: var(--muted); }
.bc-chip--sky { background: var(--bc-sky); color: var(--bc-ink); }
.bc-chip--sky .bc-icon-btn { color: rgba(51, 51, 51, 0.6); }

/* --------------------------------------------------------------------------
   Key — a keycap for shortcuts: esc, ⌘K. Mono, deep plane.
   -------------------------------------------------------------------------- */
.bc-key {
  display: inline-block;
  font-family: var(--bc-font-mono);
  font-size: 11px;
  background: var(--deep);
  color: var(--muted);
  border-radius: var(--r-el);
  padding: 3px 7px;
  vertical-align: 1px;
}

/* --------------------------------------------------------------------------
   Loading — an indeterminate bar. Motion is a state change; this is the
   one legal moving element. No spinners, nothing circular.
   -------------------------------------------------------------------------- */
.bc-loading {
  height: 6px;
  background: var(--deep);
  border-radius: var(--r-el);
  overflow: hidden;
  position: relative;
}
.bc-loading::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 35%;
  background: var(--accent);
  border-radius: var(--r-el);
  animation: bc-loading-slide 1.1s var(--bc-ease) infinite;
}
@keyframes bc-loading-slide {
  0%   { left: -35%; }
  100% { left: 100%; }
}

/* --------------------------------------------------------------------------
   Empty state — a quiet plane with a glyph and one next step.
   -------------------------------------------------------------------------- */
.bc-empty {
  background: var(--surface);
  border-radius: var(--r-field);
  padding: var(--bc-space-7) var(--bc-space-5);
  text-align: center;
  color: var(--muted);
}
.bc-empty .bc-icon { width: 32px; height: 32px; margin-bottom: var(--bc-space-3); }
.bc-empty .bc-head { font-size: 16px; color: var(--text); margin-bottom: var(--bc-space-2); }

/* --------------------------------------------------------------------------
   LOG — publishing surfaces, from basicchaos.com.
   A section head with a heavy rule, an index of display-type rows,
   and a card grid for entries. Mode-aware: same markup in day, night, loud.
   -------------------------------------------------------------------------- */

/* Section head — baseline-aligned title + action over the heavy rule. */
.bc-section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--bc-space-5);
  margin-bottom: var(--bc-space-5);
  padding-bottom: var(--bc-space-3);
  border-bottom: var(--bc-rule-heavy) solid currentColor;
}
.bc-section-head a {
  color: inherit;
  font-weight: var(--bc-weight-bold);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

/* Index — display-type rows for projects, chapters, anything listable. */
.bc-index { display: grid; border-top: var(--bc-rule-hair) solid var(--line); }
.bc-index-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 320px) auto;
  align-items: center;
  gap: var(--bc-space-5);
  min-height: 100px;
  padding: var(--bc-space-4) 0;
  border-bottom: var(--bc-rule-hair) solid var(--line);
  color: inherit;
  text-decoration: none;
  transition: color var(--bc-speed) var(--bc-ease), padding var(--bc-speed) var(--bc-ease);
}
.bc-index-row:hover { color: var(--accent); padding-inline: var(--bc-space-3); }
.bc-index-row strong {
  font-family: var(--bc-font-display);
  font-size: clamp(28px, 4vw, 52px);
  font-weight: var(--bc-weight-display);
  letter-spacing: var(--bc-tracking-display);
  line-height: 1;
  text-transform: uppercase;
}
.bc-index-row span { color: var(--muted); }
.bc-index-row b { font-size: 22px; font-weight: var(--bc-weight-body); }

/* Entry grid — 12 columns; cards span 4, a featured card spans 8. */
.bc-entry-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--bc-space-4);
}
.bc-entry-card {
  grid-column: span 4;
  display: flex;
  flex-direction: column;
  min-height: 330px;
  background: var(--surface);
  border: 2px solid var(--rule);
  border-radius: var(--r-plane);
  overflow: hidden;
}
.bc-entry-card--large { grid-column: span 8; }
.bc-entry-card > img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-bottom: 2px solid var(--rule);
}
.bc-entry-card__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: clamp(20px, 3vw, 34px);
}
.bc-entry-card h3 {
  margin: var(--bc-space-5) 0 var(--bc-space-3);
  font-family: var(--bc-font-display);
  font-size: clamp(25px, 3vw, 42px);
  font-weight: var(--bc-weight-display);
  letter-spacing: var(--bc-tracking-display);
  line-height: 1.02;
}
.bc-entry-card h3 a { color: inherit; text-decoration: none; }
.bc-entry-card h3 a:hover { color: var(--accent); }
.bc-entry-card p { margin: 0 0 var(--bc-space-5); color: var(--muted); }
@media (max-width: 850px) {
  .bc-entry-card, .bc-entry-card--large { grid-column: span 6; }
  .bc-index-row { grid-template-columns: minmax(0, 1fr) auto; }
  .bc-index-row span { display: none; }
}
@media (max-width: 560px) {
  .bc-entry-card, .bc-entry-card--large { grid-column: 1 / -1; min-height: 280px; }
}

/* Entry meta — the label line above a card title: kind + date. */
.bc-entry-meta {
  display: flex;
  justify-content: space-between;
  gap: var(--bc-space-3);
  color: var(--muted);
  font-size: var(--bc-text-label);
  font-weight: var(--bc-weight-display);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

/* Tag — a small pill naming the project an entry belongs to. */
.bc-tag {
  display: inline-flex;
  align-items: center;
  min-height: 29px;
  padding: 4px 11px;
  background: var(--deep);
  color: inherit;
  border-radius: var(--r-btn);
  font-size: var(--bc-text-micro);
  font-weight: var(--bc-weight-display);
  letter-spacing: 0.07em;
  text-decoration: none;
  text-transform: uppercase;
}
.bc-tag:hover { background: var(--bc-sky); color: var(--bc-ink); }
.bc-tag-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: auto; }
