/* ==========================================================================
   turnstone — ui-base.css
   Cross-page UI baseline shared between the coordinator page, per-node
   server UI, and the console dashboard.  Tokens (colors, typography,
   glows) live in base.css; this file holds form controls, buttons, the
   appbar chrome, and a few small primitives.

   Namespace rubric:
     .ui-*   — original "Instrument Panel" controls (.ui-btn, .ui-input,
               .ui-pill, .ui-panel) used by the admin dashboard.
     .appbar* .btn .ghost .risk
             — bare-class primitives used by coordinator + ui surfaces.
     .dash-* — legacy dashboard-row vocabulary (base.css).
     .ts-*   — chat-view vocabulary (chat.css).
     page-local classes stay unprefixed within their own stylesheet.

   The .ui-* and bare-class families coexist deliberately: admin renders
   the .ui-* family; coord + ui render the bare-class family.  No
   collisions across families.
   ========================================================================== */

/* ==========================================================================
   Form controls — flat, monospace, 1px border, accent :focus-visible ring
   ========================================================================== */
.ui-input,
.ui-textarea,
.ui-select {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.ui-input::placeholder,
.ui-textarea::placeholder {
  color: var(--fg-dim);
  opacity: 0.7;
}
.ui-input:focus-visible,
.ui-textarea:focus-visible,
.ui-select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
.ui-input:disabled,
.ui-textarea:disabled,
.ui-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ui-textarea {
  resize: vertical;
  min-height: 32px;
}

/* ==========================================================================
   Buttons — flat 1px border; accent-filled "primary" variant
   ========================================================================== */
.ui-btn {
  font: inherit;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
  letter-spacing: 0.01em;
}
.ui-btn:hover {
  background: var(--bg-highlight);
  border-color: var(--accent-dim);
  color: var(--fg-bright);
}
.ui-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.ui-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ui-btn--primary {
  background: var(--accent);
  color: var(--on-color);
  border-color: var(--accent);
  font-weight: 600;
}
.ui-btn--primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
  color: var(--on-color);
}

.ui-btn--danger {
  border-color: var(--red);
  color: var(--red);
}
.ui-btn--danger:hover {
  background: var(--red-glow);
  color: var(--red);
  border-color: var(--red);
}

/* Compact "refresh" / icon button — inline affordance in sidebars and
   section headings. */
.ui-btn--icon {
  font-size: 11px;
  padding: 1px 5px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--fg);
}
.ui-btn--icon:hover {
  background: var(--bg-elevated);
}
/* Match .ui-btn's focus-visible pattern so the compact variant gets
   the same accent-ring treatment instead of falling back to the
   browser-default outline (phase-4 designer review: focus-ring
   consistency). */
.ui-btn--icon:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ==========================================================================
   State glyphs — unified vocabulary (● running / ◐ thinking / ⚠ attention /
   ✗ error / ○ idle).  Pages that render tree rows use these directly; the
   existing LED-dot .dash-state-dot (base.css) remains for tabular views.
   ========================================================================== */
.ui-glyph {
  width: 14px;
  text-align: center;
  flex-shrink: 0;
  font-family: var(--font-mono);
}
.ui-glyph-running {
  color: var(--green);
}
.ui-glyph-thinking {
  color: var(--cyan);
}
.ui-glyph-attention {
  color: var(--yellow);
  font-weight: 700;
}
.ui-glyph-error {
  color: var(--red);
}
.ui-glyph-idle {
  color: var(--fg-dim);
}

/* ==========================================================================
   Status pills — reusable chip for enum states (task status, run state)
   ========================================================================== */
.ui-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  font-family: var(--font-mono);
}
.ui-pill--pending {
  color: var(--fg-dim);
}
.ui-pill--in-progress {
  color: var(--yellow);
  border-color: var(--yellow);
}
.ui-pill--done {
  color: var(--green);
  border-color: var(--green);
}
.ui-pill--blocked {
  color: var(--red);
  border-color: var(--red);
}
.ui-pill--running {
  color: var(--green);
  border-color: var(--green);
}
.ui-pill--thinking {
  color: var(--cyan);
  border-color: var(--cyan);
}
.ui-pill--attention {
  color: var(--yellow);
  border-color: var(--yellow);
}
.ui-pill--error {
  color: var(--red);
  border-color: var(--red);
}

/* ==========================================================================
   Section heading — used on tree/list sidebars.
   ========================================================================== */
.ui-section-heading {
  margin: 0;
  padding: 6px 10px 4px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ==========================================================================
   Panel surfaces — flat, 1px border, subtle elevation
   ========================================================================== */
.ui-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.ui-panel--flush {
  border-radius: 0;
  border-left: none;
  border-right: none;
}

/* ==========================================================================
   Typography helpers — explicit tiers so the utility actually conveys size.
   Opt-in overrides for headings / captions; do not redefine the shared
   body typography defaults from base.css (var(--font-ui), 14px / 1.45).
   ========================================================================== */
.ui-heading {
  font-family: var(--font-ui);
  font-weight: 600;
  color: var(--fg-bright);
}
.ui-heading--sm {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
}
.ui-heading--md {
  font-size: 13px;
}
.ui-heading--lg {
  font-size: 15px;
}
.ui-dim {
  color: var(--fg-dim);
}

/* ==========================================================================
   Reduced-motion — any animation declared in this file stays disabled.
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .ui-input,
  .ui-textarea,
  .ui-select,
  .ui-btn {
    transition: none;
  }
}

/* ==========================================================================
   Appbar — chat-app header variant.  Distinct from .topbar (admin-style
   with brand mark + nav + env metadata) — the appbar is for per-session
   chat surfaces that need a back-link, title, session metadata, and a
   right-cluster of action buttons (end / cancel / theme-toggle).

   Shape:
     [back]  title [subtitle/chip]              [status] [btn] [btn]
     ←────┘  ├─ 14px 600                        └── --ink-3 11px mono
             └─ optional 12px --ink-3 subtitle

   Used in ui/static (server chat) and console coordinator.
   ========================================================================== */
.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--hair);
}

.appbar-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--ink-3);
  text-decoration: none;
  border-radius: var(--r-sm);
  cursor: pointer;
}

.appbar-back:hover {
  background: var(--hair-2);
  color: var(--ink);
}

.appbar-back:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.appbar-back-arrow {
  font-family: var(--font-mono);
  font-size: 14px;
}

/* Title block — bold title + optional secondary label on the same line.
   min-width: 0 is required for .dim's ellipsis to fire under a narrow
   appbar — without it the flex container refuses to shrink below its
   content's intrinsic width. */
.appbar-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex-shrink: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.appbar-title .dim {
  font-weight: 400;
  font-size: 13px;
  color: var(--ink-3);
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Spacer pushes the right cluster to the edge. Use as a flex filler
   between the title and the action row. */
.appbar-spacer {
  flex: 1;
}

/* Status text (SSE connection state, streaming indicator). Polite
   aria-live lives on this span; the typography here intentionally
   doesn't pulse so screen readers don't see layout churn. */
.appbar-status {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}

/* Right cluster of action buttons. Match .btn sizing (28px / 12px) but
   the pill shape optionally squares off when grouped tightly. */
.appbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ==========================================================================
   Ghost button — low-emphasis tool button; lives inline in section
   headings (e.g. coord sidebar refresh) or anywhere a tertiary action
   needs to disappear into the surface.
   ========================================================================== */
.ghost {
  height: 22px;
  padding: 0 8px;
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
}

.ghost:hover {
  background: var(--hair-2);
  color: var(--ink);
}

.ghost:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Darker accent on accent-soft — raw --accent on pale --accent-soft in
   light mode falls below WCAG AA at 12px; mix 60% accent + 40% ink to
   land comfortably above 4.5:1 in both themes. */
.ghost.on {
  background: var(--accent-soft);
  color: color-mix(in srgb, var(--accent) 60%, var(--ink));
}

/* ==========================================================================
   Button primitive — default shape is pill (999px) per the prototype;
   approval-dock buttons get a 6px-radius squared shape in
   console/static/style.css.

   Variants:
     .btn           neutral (hair border, panel bg)
     .btn.primary   accent-tinted (used for key ok/continue actions)
     .btn.deny      err-tinted (destructive secondary)
     .btn.approve   ok-tinted (approval actions — green per existing
                    turnstone chat.css convention, deliberately breaking
                    the Claude Design spec which preferred amber. Amber
                    remains the "needs attention" surface for k-badges
                    and .pill.attn / .risk.med).
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--panel);
  border: 1px solid var(--hair);
  border-radius: 999px;
  cursor: pointer;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}

.btn:hover {
  background: var(--panel-2);
  color: var(--ink);
  border-color: color-mix(in srgb, var(--ink-3) 30%, var(--hair));
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--accent-soft);
  /* Raw --accent on pale --accent-soft is borderline AA at 12px; darken
     with ink to push contrast > 4.5:1 in both themes. */
  color: color-mix(in srgb, var(--accent) 60%, var(--ink));
  border-color: color-mix(in srgb, var(--accent) 35%, var(--hair));
}

.btn.primary:hover {
  background: color-mix(in srgb, var(--accent-soft) 70%, var(--panel));
  border-color: var(--accent);
  color: var(--ink);
}

.btn.deny {
  color: var(--err);
  border-color: color-mix(in srgb, var(--err) 28%, var(--hair));
}

.btn.deny:hover {
  background: var(--err-soft);
  border-color: var(--err);
}

.btn.approve {
  /* Green-on-green-tinted — greens don't mud through cool panels the way
     warm colours do, so runtime color-mix is safe here. 28% fill gives
     the button visible body against the panel without washing out the
     text contrast. --ok-text is theme-aware (dark forest in light,
     bright mint in dark) for ≥7:1 against the tinted bg in both. */
  background: color-mix(in srgb, var(--ok) 28%, var(--panel));
  color: var(--ok-text);
  border-color: color-mix(in srgb, var(--ok) 65%, var(--hair));
  font-weight: 600;
}

.btn.approve:hover {
  background: color-mix(in srgb, var(--ok) 40%, var(--panel));
  color: var(--ink);
  border-color: var(--ok);
}

.btn .kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  padding: 1px 4px;
  border: 1px solid var(--hair);
  border-radius: 3px;
}

/* ==========================================================================
   Risk severity tag — uppercase-mono tier indicator (low/med/high/crit).
   Used by coordinator.js when surfacing approval risk. The ts-pulse
   keyframe below is referenced by ui/static/style.css's verdict-judge
   spinner.
   ========================================================================== */
@keyframes ts-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.risk {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 3px;
}

.risk.low {
  background: var(--ok-soft);
  color: var(--ok);
}
.risk.med {
  background: var(--warn-soft);
  color: var(--warn);
}
.risk.high {
  background: var(--err-soft);
  color: var(--err);
}
/* .risk.crit — darker filled red via --err-fill (bright --err as a fill
   reads as alarm-loud). White text in both themes for max contrast. */
.risk.crit {
  background: var(--err-fill);
  color: #fff;
}
