/* ═══════════════════════════════════════════════════════════════
   AVCB.AI — Shared design tokens (UI v2.10)

   One source of truth for brand color, status colors, typography,
   shape, motion, z-index, and the small utility/component
   primitives (Badge, Card, Tabs, focus-ring) used across the chat,
   admin, share, and auth surfaces.

   Replaces the three parallel --accent definitions that previously
   lived in style.css, admin.css, and auth.css. Those files still
   own surface-specific tokens (bg/surface/text per theme); only
   the shared brand layer lives here.

   Load order: this file FIRST, then the surface-specific file
   (style.css / admin.css / auth.css). Legacy aliases at the bottom
   keep existing var() calls working unchanged.
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* ── Brand ──────────────────────────────────────────────────── */
  --brand-primary:        #ea6a2b;
  --brand-primary-hover:  #d45a1e;
  --brand-primary-soft:   rgba(234, 106, 43, 0.08);
  --brand-primary-ring:   rgba(234, 106, 43, 0.18);
  --brand-primary-border: rgba(234, 106, 43, 0.22);

  /* ── Status (semantic) ──────────────────────────────────────── */
  --status-success: #059669;
  --status-warning: #d97706;
  --status-error:   #dc2626;
  --status-info:    #2563eb;

  /* Soft surfaces for status pills/cards (work on both themes
     because they're rgba over whatever background exists). */
  --status-success-soft: rgba(5, 150, 105, 0.10);
  --status-warning-soft: rgba(217, 119, 6, 0.10);
  --status-error-soft:   rgba(220, 38, 38, 0.10);
  --status-info-soft:    rgba(37, 99, 235, 0.10);

  /* ── Typography ─────────────────────────────────────────────── */
  --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* ── Shape ──────────────────────────────────────────────────── */
  --radius-sm:   6px;
  --radius:     10px;
  --radius-lg:  14px;
  --radius-full: 999px;

  /* ── Motion ─────────────────────────────────────────────────── */
  --duration-fast:   120ms;
  --duration-medium: 200ms;
  --duration-slow:   300ms;
  --easing-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* ── Elevation (light by default; dark overridden below) ────── */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.22);

  /* ── Z-index scale ──────────────────────────────────────────── */
  --z-sidebar: 90;
  --z-overlay: 100;
  --z-modal:   200;
  --z-toast:   9999;

  /* ── Disclaimer/amber band tokens (used in chat + share) ────── */
  --amber-fg:     #6b4f00;
  --amber-bg:     #fff7e0;
  --amber-border: #f0c040;

  /* ── LEGACY ALIASES — kept so existing var(--accent) etc. work
     unchanged. New code should use --brand-primary / --status-*. */
  --accent:       var(--brand-primary);
  --accent-hover: var(--brand-primary-hover);
  --accent-light: var(--brand-primary-soft);

  --auth-accent:        var(--brand-primary);
  --auth-accent-hover:  var(--brand-primary-hover);
  --auth-accent-soft:   var(--brand-primary-ring);

  --green: var(--status-success);
  --red:   var(--status-error);
  --blue:  var(--status-info);

  --font: var(--font-sans);
  --mono: var(--font-mono);
}

body.dark {
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.5);

  --amber-fg:     #ffd97a;
  --amber-bg:     #3a2e10;
  --amber-border: #6b4f00;
}

/* ═══════════════════════════════════════════════════════════════
   FOCUS-VISIBLE (a11y) — one source of truth, was duplicated
   across style.css, admin.css, auth.css.
   ═══════════════════════════════════════════════════════════════ */

:where(button, a, input, textarea, select, [role="button"], [tabindex]):focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  box-shadow: 0 0 0 3px var(--brand-primary-ring);
}

/* ═══════════════════════════════════════════════════════════════
   UTILITY LAYER — small, named flex primitives that replace
   the ~80 inline style="display:flex;..." attributes peppered
   through admin.html and elsewhere.

   Prefixed `u-` to make their utility nature explicit at a glance
   and to keep them out of the way of component classes.
   ═══════════════════════════════════════════════════════════════ */

.u-row          { display: flex; align-items: center; gap: 0.5rem; }
.u-row-tight    { display: flex; align-items: center; gap: 0.35rem; }
.u-row-loose    { display: flex; align-items: center; gap: 0.75rem; }
.u-row-between  { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.u-row-end      { display: flex; align-items: center; justify-content: flex-end; gap: 0.45rem; }
.u-row-wrap     { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.u-stack        { display: flex; flex-direction: column; gap: 0.5rem; }
.u-stack-tight  { display: flex; flex-direction: column; gap: 0.18rem; }
.u-card-pad     { padding: 1rem 1.25rem; }
.u-section-pad  { padding: 0.75rem 1.25rem; }
.u-pad-y        { padding-top: 0.5rem; padding-bottom: 0.5rem; }
/* !important is needed so .u-hidden beats component rules like
   .modal-overlay { display: flex } that live later in the cascade.
   Callers that flip elements visible should remove the class
   (classList.remove('u-hidden')) instead of setting inline display. */
.u-hidden       { display: none !important; }
.u-grow         { flex: 1; min-width: 0; }
.u-shrink-0     { flex-shrink: 0; }
.u-ml-auto      { margin-left: auto; }
.u-mt-1         { margin-top: 1rem; }
.u-mono         { font-family: var(--font-mono); }
.u-text-xs      { font-size: 0.72rem; }
.u-text-sm      { font-size: 0.78rem; }
.u-text-muted   { color: var(--text-tertiary, #9ca3af); }

/* ═══════════════════════════════════════════════════════════════
   BADGE — unified pill used for status, mode, role, regulation,
   source, verification, etc. Replaces five near-duplicate patterns
   (.regulation-badge, .badge-mode, .badge-status, .badge-role,
   .user-tag).
   ═══════════════════════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.25;
}

.badge--neutral {
  background: rgba(0,0,0,0.04);
  color: var(--text-tertiary, #6b7280);
  border-color: rgba(0,0,0,0.06);
}
.badge--primary {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
  border-color: var(--brand-primary-border);
}
.badge--success {
  background: var(--status-success-soft);
  color: var(--status-success);
  border-color: rgba(5,150,105,0.22);
}
.badge--warning {
  background: var(--status-warning-soft);
  color: var(--status-warning);
  border-color: rgba(217,119,6,0.28);
}
.badge--error {
  background: var(--status-error-soft);
  color: var(--status-error);
  border-color: rgba(220,38,38,0.22);
}
.badge--info {
  background: var(--status-info-soft);
  color: var(--status-info);
  border-color: rgba(37,99,235,0.22);
}

body.dark .badge--neutral {
  background: rgba(255,255,255,0.06);
  color: #cbd5e1;
  border-color: rgba(255,255,255,0.08);
}

.badge--dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
   UNIFIED TABS (underline pattern) — replaces three near-identical
   blocks (auth-tabs, admin-tabs, state-tabs).
   ═══════════════════════════════════════════════════════════════ */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border, #e2e5ea);
}
.tab {
  padding: 0.7rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-tertiary, #9ca3af);
  cursor: pointer;
  transition: color var(--duration-fast), border-color var(--duration-fast);
  white-space: nowrap;
}
.tab:hover { color: var(--text-secondary, #4b5563); }
.tab[aria-selected="true"],
.tab--active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
}

/* ═══════════════════════════════════════════════════════════════
   STATE-AWARE CONTEXT STRIP — pinned above the chat so users
   always see which UF/regulation they're querying against.
   ═══════════════════════════════════════════════════════════════ */

.context-strip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.5rem 1.25rem;
  background: var(--bg-sidebar, #fff);
  border-bottom: 1px solid var(--border, #e2e5ea);
  font-size: 0.78rem;
  color: var(--text-secondary, #4b5563);
  flex-shrink: 0;
}
.context-strip-icon {
  color: var(--brand-primary);
  flex-shrink: 0;
  display: inline-flex;
}
.context-strip-state {
  font-weight: 700;
  color: var(--text-primary, #111827);
}
.context-strip-sep {
  color: var(--text-tertiary, #9ca3af);
  opacity: 0.6;
}
.context-strip-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-tertiary, #9ca3af);
  font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════════
   PER-ANSWER "RASCUNHO TÉCNICO" TAG — replaces (visually defangs)
   the shouty amber disclaimer bar. Renders as a small muted pill
   next to each assistant message footer, so the caveat appears
   exactly where the answer it qualifies appears.
   ═══════════════════════════════════════════════════════════════ */

.draft-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.14rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--amber-fg);
  background: var(--amber-bg);
  border: 1px solid var(--amber-border);
  cursor: help;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════
   COMMAND PALETTE (Cmd/Ctrl+K) — shadcn Command pattern.
   Markup is built dynamically by ui.js: window.openPalette().
   ═══════════════════════════════════════════════════════════════ */

.cmdk-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: var(--z-modal);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 18vh 1rem 1rem;
  animation: cmdkFadeIn var(--duration-fast) var(--easing-out);
}
.cmdk-overlay.open { display: flex; }
@keyframes cmdkFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.cmdk-box {
  width: 100%;
  max-width: 560px;
  background: var(--bg-sidebar, #fff);
  border: 1px solid var(--border, #e2e5ea);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: cmdkZoomIn var(--duration-medium) var(--easing-out);
}
@keyframes cmdkZoomIn {
  from { opacity: 0; transform: scale(0.97) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.cmdk-search {
  width: 100%;
  padding: 0.95rem 1.1rem;
  border: none;
  border-bottom: 1px solid var(--border, #e2e5ea);
  background: transparent;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--text-primary, #111827);
  outline: none;
}
.cmdk-search::placeholder { color: var(--text-tertiary, #9ca3af); }

.cmdk-list {
  max-height: 60vh;
  overflow-y: auto;
  padding: 0.4rem;
}
.cmdk-group-label {
  padding: 0.45rem 0.65rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary, #9ca3af);
}
.cmdk-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.86rem;
  color: var(--text-secondary, #4b5563);
  transition: background var(--duration-fast), color var(--duration-fast);
  user-select: none;
}
.cmdk-item[aria-selected="true"],
.cmdk-item:hover {
  background: var(--bg-hover, rgba(0,0,0,0.04));
  color: var(--text-primary, #111827);
}
.cmdk-item-icon {
  flex-shrink: 0;
  color: var(--text-tertiary, #9ca3af);
  display: inline-flex;
}
.cmdk-item[aria-selected="true"] .cmdk-item-icon,
.cmdk-item:hover .cmdk-item-icon { color: var(--brand-primary); }
.cmdk-item-label  { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item-hint   { font-size: 0.7rem; color: var(--text-tertiary, #9ca3af); font-family: var(--font-mono); flex-shrink: 0; }
.cmdk-empty       { padding: 1.5rem 1rem; text-align: center; color: var(--text-tertiary, #9ca3af); font-size: 0.85rem; }

/* ═══════════════════════════════════════════════════════════════
   GROUNDING / VERIFICATION CARD — promotes the verification chip
   from 11px pill at right edge to a result card at the top of the
   assistant message. This is the "make grounding the headline"
   change. The legacy .verification-chip rules in style.css still
   work for the inline-pill mode used in admin/history rendering.
   ═══════════════════════════════════════════════════════════════ */

.grounding-card {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  margin-bottom: 0.65rem;
  font-size: 0.8rem;
  line-height: 1.4;
  border: 1px solid transparent;
}
.grounding-card--ok {
  background: var(--status-success-soft);
  color: var(--status-success);
  border-color: rgba(5,150,105,0.22);
}
.grounding-card--warn {
  background: var(--status-warning-soft);
  color: var(--status-warning);
  border-color: rgba(217,119,6,0.28);
  cursor: help;
}
.grounding-card-icon {
  flex-shrink: 0;
  margin-top: 1px;
  display: inline-flex;
}
.grounding-card-body { flex: 1; min-width: 0; }
.grounding-card-title {
  font-weight: 700;
  margin-bottom: 0.1rem;
}
.grounding-card-detail {
  font-size: 0.74rem;
  font-weight: 500;
  opacity: 0.9;
}

/* ═══════════════════════════════════════════════════════════════
   SOURCES PANEL — collapsible details/summary that expands the
   sources row into a list with file + (when available) section +
   page + quoted excerpt. Pure CSS; JS only toggles open state.
   ═══════════════════════════════════════════════════════════════ */

.sources-panel {
  margin-top: 0.5rem;
  border-top: 1px solid var(--border, #e2e5ea);
  padding-top: 0.5rem;
}
.sources-panel-summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0;
  cursor: pointer;
  user-select: none;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-tertiary, #9ca3af);
  list-style: none;
}
.sources-panel-summary::-webkit-details-marker { display: none; }
.sources-panel-summary::before {
  content: '▸';
  font-size: 0.6rem;
  transition: transform var(--duration-fast);
  opacity: 0.6;
}
.sources-panel[open] .sources-panel-summary::before { transform: rotate(90deg); }

.sources-panel-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.4rem 0 0.2rem;
}
.sources-panel-item {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--bg-hover, rgba(0,0,0,0.03));
  font-size: 0.78rem;
  color: var(--text-secondary, #4b5563);
  text-decoration: none;
  transition: background var(--duration-fast), color var(--duration-fast);
}
.sources-panel-item:hover {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
}
.sources-panel-item-icon { flex-shrink: 0; opacity: 0.7; margin-top: 2px; }
.sources-panel-item-body { flex: 1; min-width: 0; }
.sources-panel-item-name { font-weight: 600; }
.sources-panel-item-meta {
  font-size: 0.7rem;
  color: var(--text-tertiary, #9ca3af);
  margin-top: 0.1rem;
  font-family: var(--font-mono);
}
