/**
 * AJAIA design tokens and shared primitives.
 * workwithjefrie.com visual language: paper-light default, dark via
 * <html data-theme="dark">. Load this BEFORE page CSS on every page.
 * Rule: no hard-coded colors in page CSS. Only these variables.
 */

:root {
  --paper:      #F2F3F5;   /* page background */
  --surface:    #FFFFFF;   /* cards, sidebar, panels */
  --surface-2:  #F8F9FB;   /* subtle wells, toolbars */
  --ink:        #0D1017;   /* primary text */
  --ink-soft:   #333B49;   /* body text */
  --muted:      #656E7E;   /* secondary text, labels */
  --faint:      #656F81;   /* placeholders */
  --line:       #E2E5EA;   /* hairlines */
  --line-str:   #818DA3;   /* stronger borders, inputs */
  --accent:     #1F42E5;   /* THE blue - buttons, active states */
  --accent-ink: #16309F;   /* accent text on light */
  --accent-sft: #EFF2FF;   /* accent tint fills */
  --accent-brd: #D8DEFC;   /* accent tint borders */
  --ok:         #107E4F;  --ok-sft:  #E4F5EC;
  --warn:       #98641A;  --warn-sft:#FBF3E4;
  --danger:     #C2372E;  --danger-sft:#FBEAE8;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --font-display: 'Archivo', sans-serif;
  --font-body: 'IBM Plex Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

/* Dark theme = same variables remapped. Toggle via <html data-theme="dark"> */
[data-theme="dark"] {
  --paper:      #0D1017;
  --surface:    #161B24;
  --surface-2:  #10141C;
  --ink:        #FFFFFF;
  --ink-soft:   #DDE2EC;
  --muted:      #8892A4;
  --faint:      #7A8398;
  --line:       #262D3A;
  --line-str:   #586782;
  --accent:     #1F42E5;      /* filled buttons stay the same blue */
  --accent-ink: #8FA1FF;      /* accent text on dark */
  --accent-sft: #141A2E;
  --accent-brd: #2A3450;
  --ok:         #6EDCA8;  --ok-sft:  rgba(18,144,90,0.18);
  --warn:       #E0B25C;  --warn-sft:rgba(183,121,31,0.18);
  --danger:     #F08A80;  --danger-sft:rgba(194,55,46,0.18);
}

/* ---------- Base ---------- */

html {
  background: var(--paper);
}

body {
  background: var(--paper);
  color: var(--ink-soft);
  font-family: var(--font-body);
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

/* ---------- Shared primitives ---------- */

/* Eyebrow: mono uppercase label preceded by an accent bar */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.eyebrow::before {
  content: '';
  width: 18px;
  height: 2px;
  background: var(--accent);
}

/* Brand mark: two squares side by side */
.brand-mark {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}
.brand-mark::before,
.brand-mark::after {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 2px;
}
.brand-mark::before { background: var(--accent); }
.brand-mark::after { background: var(--accent-ink); }

/* Square nav marker */
.sq-marker {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--line-str);
  flex-shrink: 0;
  transition: background 0.2s var(--ease);
}
.active > .sq-marker,
.sq-marker.active { background: var(--accent); }

/* Status dot */
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}
.status-dot.pulse { animation: ajaia-pulse 2s infinite; }
@keyframes ajaia-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* Buttons */
.btn-accent {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #FFFFFF;
  border: none;
  border-radius: 8px;
  padding: 12px 22px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease);
}
.btn-accent:hover {
  background: var(--accent-ink);
  transform: translateY(-1px);
}
.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--line-str);
  border-radius: 8px;
  padding: 11px 20px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
}
.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
  transform: translateY(-1px);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.card-hero {
  box-shadow: 0 1px 0 var(--line), 0 24px 48px -30px rgba(13, 16, 23, 0.35);
}

/* Badges */
.badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 4px;
  padding: 3px 8px;
}
.badge-epic { background: var(--accent-sft); color: var(--accent-ink); }
.badge-story { background: var(--ok-sft); color: var(--ok); }
.badge-task { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.badge-bug { background: var(--danger-sft); color: var(--danger); }

/* Callout ("rope") */
.callout {
  border-left: 3px solid var(--accent);
  background: var(--accent-sft);
  border-radius: 0 10px 10px 0;
  padding: 14px 18px;
}

/* Avatar: initials in a circle */
.avatar-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-sft);
  color: var(--accent-ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

/* Theme toggle: segmented Light/Dark pill */
.theme-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.theme-toggle button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.theme-toggle button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(13, 16, 23, 0.12);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   Mobile bottom tab bar (frames 11a-11g) — injected by mobile-tabbar.js.
   Hidden on tablet+; shown on phones. All colors are tokens.
   ============================================================ */
.mobile-tabbar { display: none; }

/* Phones only: 768px itself (tablet portrait) keeps the hamburger drawer and
   no tab bar. Page CSS that must clear the bar uses the same breakpoint and
   var(--mobile-tabbar-h). */
@media (max-width: 767.98px) {
  :root {
    --mobile-tabbar-h: calc(57px + env(safe-area-inset-bottom, 0px));
  }
  .mobile-tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 250;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .mobile-tabbar .mtab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 44px;
    padding: 6px 0;
    text-decoration: none;
    color: var(--muted);
    font-family: var(--font-mono, 'IBM Plex Mono', monospace);
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .mobile-tabbar .mtab-ic {
    width: 18px;
    height: 18px;
    flex: none;
  }
  .mobile-tabbar .mtab.active { color: var(--accent-ink); }
  .mobile-tabbar .mtab.active .mtab-ic { color: var(--accent); }

  /* Keep page content clear of the fixed bar (specificity beats .main-content). */
  body:has(.mobile-tabbar) .main-content {
    padding-bottom: calc(var(--mobile-tabbar-h) + 23px);
  }
}

/* ============================================================
   Chat markdown (AjaiaFormat.renderChatMarkdown output)
   ============================================================ */
.md-h { font-weight: 700; margin: 12px 0 4px; line-height: 1.3; }
.md-h1 { font-size: 1.08em; }
.md-h2 { font-size: 1.02em; }
.md-h3, .md-h4 { font-size: 0.95em; opacity: 0.92; }
.md-hr { border: 0; border-top: 1px solid var(--border, rgba(120, 120, 120, 0.25)); margin: 10px 0; }
.md-table-wrap { overflow-x: auto; margin: 8px 0; max-width: 100%; }
.md-table { border-collapse: collapse; font-size: 0.86em; width: 100%; }
.md-table th, .md-table td {
    border: 1px solid var(--border, rgba(120, 120, 120, 0.28));
    padding: 4px 8px;
    text-align: left;
    vertical-align: top;
}
.md-table th { background: rgba(120, 120, 120, 0.09); font-weight: 600; }
.message-content p, .chatbot-messages .message p { margin: 6px 0; }
.message-content p:first-child, .chatbot-messages .message p:first-child { margin-top: 0; }
.message-content p:last-child, .chatbot-messages .message p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol,
.chatbot-messages .message ul, .chatbot-messages .message ol {
    margin: 6px 0 6px 20px;
    padding: 0;
}
.message-content li, .chatbot-messages .message li { margin: 3px 0; }
.message-content pre, .chatbot-messages .message pre {
    overflow-x: auto;
    background: rgba(120, 120, 120, 0.08);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 0.85em;
}
/* ============================================================
   AJAIA answer-first card (frame 6a) — token-based, dark-safe
   ============================================================ */
.aa-card { display: flex; flex-direction: column; gap: 14px; }
.aa-context {
    font-family: var(--font-mono, 'IBM Plex Mono', monospace);
    font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--faint); display: flex; align-items: center; gap: 7px;
}
.aa-context-bar { width: 14px; height: 2px; background: var(--line-str); flex: none; }

/* Verdict hero */
.aa-hero {
    border: 1.5px solid var(--accent);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 14px 30px -20px color-mix(in srgb, var(--accent) 55%, transparent);
}
.aa-hero-top { background: var(--accent); color: #fff; padding: 16px 16px 15px; }
.aa-hero-eyebrow {
    font-family: var(--font-mono, monospace);
    font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em;
    color: color-mix(in srgb, #fff 78%, var(--accent)); margin-bottom: 8px;
}
.aa-hero-verdict {
    font-family: var(--font-display, 'Archivo', sans-serif);
    font-weight: 900; font-size: 26px; letter-spacing: -0.02em; line-height: 1;
}
.aa-hero-sub { font-size: 13px; color: color-mix(in srgb, #fff 88%, var(--accent)); line-height: 1.45; margin-top: 9px; }
.aa-hero-foot { display: flex; background: var(--accent-sft); }
.aa-hero-cell { flex: 1; padding: 9px 14px; }
.aa-hero-cell + .aa-hero-cell { border-left: 1px solid var(--accent-brd); }
.aa-hero-cell-label {
    font-family: var(--font-mono, monospace);
    font-size: 8.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
}
.aa-hero-cell-value { font-family: var(--font-display, 'Archivo', sans-serif); font-weight: 800; font-size: 15px; color: var(--accent-ink); }

/* Sections */
.aa-section-label {
    font-family: var(--font-mono, monospace);
    font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 8px;
}
.aa-why { display: flex; flex-direction: column; gap: 9px; }
.aa-why-row { display: flex; gap: 10px; align-items: flex-start; }
.aa-check {
    width: 17px; height: 17px; border-radius: 50%; background: var(--ok-sft);
    flex: none; margin-top: 1px; position: relative;
}
.aa-check::after {
    content: ""; position: absolute; left: 5.5px; top: 5px;
    width: 6px; height: 3px;
    border-left: 1.5px solid var(--ok); border-bottom: 1.5px solid var(--ok);
    transform: rotate(-45deg);
}
.aa-why-row span:last-child { font-size: 13px; color: var(--ink-soft); line-height: 1.4; }

.aa-alts { display: flex; flex-direction: column; gap: 7px; }
.aa-alt {
    display: flex; gap: 11px; align-items: baseline;
    background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 10px 13px;
}
.aa-alt-name { font-family: var(--font-display, 'Archivo', sans-serif); font-weight: 700; font-size: 12.5px; min-width: 86px; flex: none; color: var(--ink); }
.aa-alt-note { font-size: 12px; color: var(--muted); line-height: 1.4; }
.aa-skip { color: var(--danger); font-weight: 600; }

.aa-risk {
    display: flex; gap: 9px; align-items: flex-start;
    background: var(--danger-sft); border-radius: 9px; padding: 11px 13px;
}
.aa-risk-tag {
    font-family: var(--font-mono, monospace);
    font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
    color: #fff; background: var(--danger); border-radius: 4px; padding: 3px 6px; flex: none;
}
.aa-risk span:last-child { font-size: 12px; color: var(--danger); line-height: 1.45; }

.aa-details { display: flex; flex-direction: column; }
.aa-detail + .aa-detail { border-top: 1px solid var(--line); }
.aa-detail-head {
    width: 100%; display: flex; justify-content: space-between; align-items: center;
    background: none; border: none; cursor: pointer;
    font-size: 12.5px; color: var(--ink-soft); font-weight: 500; padding: 8px 2px;
    font-family: var(--font-body, sans-serif); text-align: left;
}
.aa-detail-count { font-family: var(--font-mono, monospace); font-size: 9px; color: var(--faint); }
.aa-detail-toggle { color: var(--faint); font-size: 15px; }
.aa-detail-body { font-size: 12.5px; color: var(--muted); line-height: 1.55; padding: 0 2px 10px; }

.aa-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.aa-action {
    flex: 1; min-width: 84px; text-align: center;
    background: var(--surface); border: 1px solid var(--line-str); border-radius: 8px;
    padding: 10px; font-size: 11.5px; font-weight: 600; color: var(--ink-soft); cursor: pointer;
    font-family: var(--font-body, sans-serif);
}
.aa-action:hover { border-color: var(--accent); color: var(--accent-ink); }
.aa-action.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.aa-action.primary:hover { background: var(--accent-ink); }

/* Answer-card fit on narrow surfaces: in the assistant widget (and small
   screens) the side-by-side name/note alternative rows crush the note into
   a sliver and overflow the card - stack them vertically instead. */
.aa-alt-note { flex: 1; min-width: 0; }
.chatbot-window .aa-alt { flex-direction: column; align-items: stretch; gap: 4px; }
.chatbot-window .aa-alt-name { min-width: 0; }
.chatbot-window .aa-hero-verdict { font-size: 1.35rem; }
@media (max-width: 480px) {
    .aa-alt { flex-direction: column; align-items: stretch; gap: 4px; }
    .aa-alt-name { min-width: 0; }
}

/* ---- Brand logo (replaces the two-square brand-mark in the shell) ---- */
.brand-logo {
  width: 26px;
  height: 26px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
}

/* ---- Ask AJAIA icon button: the logo, tooltip carries the words ---- */
.ask-ajaia-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--accent-brd);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.2s var(--ease), transform 0.2s var(--ease);
}
.ask-ajaia-icon-btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.ask-ajaia-logo {
  width: 20px;
  height: 20px;
  object-fit: contain;
  border-radius: 4px;
  display: block;
}

/* chatbot-widget.css ships .ask-ai-btn { opacity: 0 } (hover-reveal on
   work-item cards). The logo icon variant is always visible - the old
   text buttons carried inline opacity overrides for the same reason. */
.ask-ai-btn.ask-ajaia-icon-btn {
  opacity: 1;
  visibility: visible;
  transform: none;
  background: var(--surface);
  border: 1px solid var(--accent-brd);
  padding: 0;
}
.ask-ai-btn.ask-ajaia-icon-btn:hover {
  background: var(--accent-sft);
  border-color: var(--accent);
  color: inherit;
}

/* ---------------- keyboard accessibility ----------------
   Focus styling used to be ad-hoc per page stylesheet, so whether a keyboard
   user could see where they were depended on which page they were on, and
   several rules removed the outline entirely. This is the floor: one visible
   ring on every focusable element, app-wide.

   :focus-visible rather than :focus so it appears for keyboard and
   programmatic focus but not on mouse clicks. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Dark theme: the filled accent is too dark against a dark background to read
   as a focus ring, so use the lighter accent reserved for text on dark. */
[data-theme="dark"] :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline-color: var(--accent-ink);
}

/* Skip link: injected by shell.js as the first focusable element so a keyboard
   user can jump past the sidebar instead of tabbing the whole nav on every
   page. Off-screen until focused. */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 10001;
    padding: 10px 16px;
    background: var(--surface);
    color: var(--ink);
    border: 2px solid var(--accent);
    border-radius: 0 0 8px 0;
    font-weight: 600;
    text-decoration: none;
}

.skip-link:focus {
    left: 0;
}
