/*
 * edu_chat.css  —  Education Assistant Chat Widget Styles
 *
 * Structure:
 *   1. Host container & layout
 *   2. nlux theme overrides   (scoped to #edu-chat-container)
 *   3. Disclaimer banner
 *   4. Source badges
 *   5. Freshness warning
 *   6. Escalation button (inline, inside message)
 *   7. Choice buttons (clarification)
 *   8. Counselor footer (appears after the second answer)
 *   9. Responsive
 *
 * Color tokens use the Nexus palette from the architecture document.
 * Override via CSS custom properties on #edu-chat-container.
 */

/* ─── § 1. Host container ───────────────────────────────────────────────── */

#edu-chat-container {
  --edu-primary:       #01696F;
  --edu-primary-dark:  #0C4E54;
  --edu-bg:            #F7F6F2;
  --edu-surface:       #F9F8F5;
  --edu-border:        #D4D1CA;
  --edu-text:          #28251D;
  --edu-text-muted:    #7A7974;
  --edu-text-faint:    #BAB9B4;
  --edu-warning-bg:    #FFF7ED;
  --edu-warning-text:  #964219;
  --edu-warning-border:#F3A96A;
  --edu-radius:        8px;
  --edu-radius-sm:     4px;
  --edu-font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  display:        flex;
  flex-direction: column;
  height:         100%;
  font-family:    var(--edu-font);
  background:     var(--edu-bg);
  border:         1px solid var(--edu-border);
  border-radius:  var(--edu-radius);
  overflow:       hidden;
}


/* ─── § 2. nlux theme overrides ─────────────────────────────────────────── */
/*
 * nlux renders with the "nova" theme. These overrides blend it into the
 * Nexus palette without fighting the library's layout logic.
 *
 * TODO: Inspect the actual nlux DOM classes in DevTools and refine these.
 *   The class names below are targets for nlux 2.x nova theme.
 *   Common approach: set --nlux-* CSS variables if the theme exposes them,
 *   otherwise override specific classes.
 */

#edu-chat-container .nlux-AiChat-root {
  background: var(--edu-bg);
  flex:        1;
  overflow-y:  auto;

  /* Edu owl avatar — 36px, full-image (no crop), matches white_bg in the source PNG. */
  --nlux-WelcomeMessage-Avatar--Width: 36px;
  --nlux-ChatItem-Avatar--Width:       36px;
  --nlux-ChatItem-Avatar--BorderRadius: 4px;
}

/* Render the owl avatar background fully, not cropped — nlux uses background-image,
   so default 'cover' crops the ears. 'contain' keeps the whole owl visible. */
#edu-chat-container .nlux-comp-avatar,
#edu-chat-container .nlux-comp-avatarContainer {
  background-size:     contain;
  background-repeat:   no-repeat;
  background-position: center;
  background-color:    #fff;
}

/* Bot message bubbles */
#edu-chat-container .nlux_msg_received {
  background:    var(--edu-surface);
  border:        1px solid var(--edu-border);
  border-radius: var(--edu-radius);
  color:         var(--edu-text);
  font-size:     0.9375rem;    /* 15px */
  line-height:   1.6;
}

/* Inline images inside assistant messages (school logos in program cards) */
#edu-chat-container .nlux_msg_received img {
  height:         24px;
  width:          auto;
  max-width:      48px;
  vertical-align: middle;
  margin-right:   0.4em;
  object-fit:     contain;
}

/* Links inside assistant messages — underline so they read as clickable */
#edu-chat-container .nlux_msg_received a {
  color:            var(--edu-primary);
  text-decoration:  underline;
}
#edu-chat-container .nlux_msg_received a:hover {
  text-decoration:  none;
}

/* User message bubbles */
#edu-chat-container .nlux_msg_sent {
  background:    var(--edu-primary);
  color:         #fff;
  border-radius: var(--edu-radius);
}

/* Composer / input area */
#edu-chat-container .nlux-composer-root {
  border-top:  1px solid var(--edu-border);
  background:  var(--edu-surface);
  padding:     8px;
}

#edu-chat-container .nlux-composer-input {
  font-family: var(--edu-font);
  font-size:   0.9375rem;
  color:       var(--edu-text);
  background:  #fff;
  border:      1px solid var(--edu-border);
  border-radius: var(--edu-radius-sm);
}

#edu-chat-container .nlux-composer-input:focus {
  outline:       none;
  border-color:  var(--edu-primary);
  box-shadow:    0 0 0 2px rgba(1, 105, 111, 0.15);
}

#edu-chat-container .nlux-composer-sendButton {
  background:    var(--edu-primary);
  color:         #fff;
  border-radius: var(--edu-radius-sm);
  border:        none;
  transition:    background 0.15s;
}

#edu-chat-container .nlux-composer-sendButton:hover {
  background: var(--edu-primary-dark);
}

/* Conversation starters */
#edu-chat-container .nlux-conversationStarter-root {
  border:        1px solid var(--edu-border);
  border-radius: var(--edu-radius-sm);
  background:    var(--edu-surface);
  color:         var(--edu-primary);
  font-size:     0.875rem;
  transition:    border-color 0.15s, background 0.15s;
}

#edu-chat-container .nlux-conversationStarter-root:hover {
  border-color: var(--edu-primary);
  background:   #E8F4F4;
}

/* Let the card grow to accommodate up to 3 wrapped lines (nova.css clamp = 3). */
#edu-chat-container .nlux-comp-conversationStarter {
  height:     auto;
  min-height: 101px;   /* matches nova.css default --nlux-cvStrt--hg */
}


/* ─── § 3. Disclaimer banner ─────────────────────────────────────────────── */

.edu-disclaimer {
  display:          flex;
  align-items:      flex-start;
  gap:              8px;
  padding:          10px 14px;
  background:       #EFF8F8;
  border-bottom:    1px solid var(--edu-border);
  font-size:        0.8125rem;   /* 13px */
  color:            var(--edu-text-muted);
  line-height:      1.5;
}

.edu-disclaimer__icon {
  font-size:   1rem;
  color:       var(--edu-primary);
  flex-shrink: 0;
  margin-top:  1px;
}

.edu-disclaimer__text {
  margin: 0;
}


/* ─── § 4. Source badges ─────────────────────────────────────────────────── */

.edu-message-enhancer {
  margin-top: 10px;
}

.edu-sources {
  display:   flex;
  flex-wrap: wrap;
  gap:       6px;
  margin-top: 8px;
}

.edu-sources__label {
  font-size:   0.75rem;
  font-weight: 600;
  color:       var(--edu-text-muted);
  align-self:  center;
  margin-right: 2px;
}

.edu-source-badge {
  display:         inline-flex;
  align-items:     center;
  gap:             4px;
  padding:         3px 9px;
  background:      var(--edu-surface);
  border:          1px solid var(--edu-border);
  border-radius:   100px;   /* pill */
  font-size:       0.75rem;
  color:           var(--edu-primary);
  text-decoration: none;
  transition:      border-color 0.15s, background 0.15s;
  max-width:       220px;
  overflow:        hidden;
  white-space:     nowrap;
  text-overflow:   ellipsis;
}

.edu-source-badge:hover {
  border-color: var(--edu-primary);
  background:   #E8F4F4;
}

.edu-source-date {
  font-size:  0.6875rem;
  color:      var(--edu-text-faint);
  flex-shrink: 0;
}


/* ─── § 5. Freshness warning ─────────────────────────────────────────────── */

.edu-freshness-warning {
  display:       flex;
  align-items:   flex-start;
  gap:           6px;
  margin-top:    8px;
  padding:       8px 10px;
  background:    var(--edu-warning-bg);
  border:        1px solid var(--edu-warning-border);
  border-radius: var(--edu-radius-sm);
  font-size:     0.8125rem;
  color:         var(--edu-warning-text);
  line-height:   1.5;
}

.edu-freshness-warning__icon {
  flex-shrink: 0;
  font-style:  normal;
}


/* ─── § 6. Escalation button (inline, inside a message bubble) ───────────── */

.edu-escalation {
  margin-top: 12px;
}

.edu-escalation__btn {
  display:         inline-block;
  padding:         8px 16px;
  background:      var(--edu-primary);
  color:           #fff;
  border-radius:   var(--edu-radius-sm);
  text-decoration: none;
  font-size:       0.875rem;
  font-weight:     600;
  transition:      background 0.15s;
}

.edu-escalation__btn:hover {
  background: var(--edu-primary-dark);
}


/* ─── § 7. Choice buttons (clarification) ───────────────────────────────── */

.edu-choices {
  display:   flex;
  flex-wrap: wrap;
  gap:       8px;
  margin-top: 12px;
}

.edu-choice-btn {
  padding:          7px 14px;
  background:       var(--edu-surface);
  color:            var(--edu-primary);
  border:           1px solid var(--edu-primary);
  border-radius:    var(--edu-radius-sm);
  font-family:      var(--edu-font);
  font-size:        0.875rem;
  cursor:           pointer;
  transition:       background 0.15s, color 0.15s;
}

.edu-choice-btn:hover {
  background: var(--edu-primary);
  color:      #fff;
}

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


/* ─── § 8. Counselor footer (appears after the second answer) ───────────── */

.edu-counselor-footer {
  display:          flex;
  justify-content:  center;
  padding:          8px 14px;
  border-top:       1px solid var(--edu-border);
  background:       var(--edu-surface);
  font-size:        0.8125rem;
}

.edu-counselor-footer__link {
  color:           var(--edu-primary);
  text-decoration: none;
  font-weight:     500;
}

.edu-counselor-footer__link:hover {
  text-decoration: underline;
}


/* ─── § 9. Responsive ────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .edu-choices {
    flex-direction: column;
  }

  .edu-choice-btn {
    width: 100%;
    text-align: left;
  }

  .edu-sources {
    flex-direction: column;
  }
}


/* ─── § 10. Compact state (empty, pre-engagement) ────────────────────────── */

#edu-chat-container.edu-compact {
  max-height: 160px;
  transition: max-height 250ms ease-out;
}

#edu-chat-container.edu-expanded {
  max-height: 100vh;
  transition: max-height 250ms ease-out;
}

.edu-compact-card {
  display:        flex;
  flex-direction: column;
  height:         100%;
  padding:        16px;
  background:     var(--edu-surface);
  cursor:         text;
  border-radius:  var(--edu-radius);
  box-sizing:     border-box;
}

.edu-compact-card:focus-within {
  outline: 2px solid var(--edu-primary);
  outline-offset: -2px;
}

.edu-compact-card__header {
  display:     flex;
  align-items: center;
  gap:         10px;
  margin-bottom: 4px;
}

.edu-compact-card__owl {
  width:  24px;
  height: 24px;
  flex-shrink: 0;
}

.edu-compact-card__heading {
  font-size:   1rem;       /* 16px */
  font-weight: 600;
  color:       var(--edu-text);
  margin:      0;
  line-height: 1.3;
}

.edu-compact-card__subtitle {
  font-size:    0.8125rem;  /* 13px */
  color:        var(--edu-text-muted);
  margin:       0 0 12px 34px;    /* align with heading text (owl 24 + gap 10) */
  line-height:  1.4;
}

.edu-compact-card__input {
  font-family:   var(--edu-font);
  font-size:     0.9375rem;   /* 15px — matches nlux composer */
  color:         var(--edu-text);
  background:    #fff;
  border:        1px solid var(--edu-border);
  border-radius: var(--edu-radius-sm);
  padding:       10px 12px;
  width:         100%;
  box-sizing:    border-box;
  cursor:        text;
}

.edu-compact-card__input:focus {
  outline:      none;
  border-color: var(--edu-primary);
  box-shadow:   0 0 0 2px rgba(1, 105, 111, 0.15);
}

/* Mobile: slightly smaller font to keep the card compact on narrow widths */
@media (max-width: 480px) {
  .edu-compact-card__heading { font-size: 0.9375rem; }
  .edu-compact-card__subtitle { font-size: 0.75rem; margin-left: 32px; }
}


/* ─── § 11. Search indicator (rotating during MCP tool calls) ───────────── */

.edu-search-indicator {
  display:        inline-block;
  margin-top:     8px;
  padding:        4px 10px;
  background:     var(--edu-bg);
  border:         1px solid var(--edu-border);
  border-radius:  100px;
  font-size:      0.8125rem;     /* 13px */
  color:          var(--edu-text-muted);
  font-style:     italic;
  animation:      edu-pulse 1.6s ease-in-out infinite;
}

@keyframes edu-pulse {
  0%, 100% { opacity: 0.65; }
  50%      { opacity: 1.0;  }
}


/* ─── § 12. Program cards (rendered from SSE 'cards' event) ─────────────── */

/* Force the bot bubble's content area into a flex column so .edu-cards-grid
   can sit above the prose via order: -1 regardless of insertion timing. */
.nlux-comp-message.nlux_msg_streaming,
.nlux-comp-message.nlux_msg_received {
  display:        flex;
  flex-direction: column;
}

/* ─── § 12a. Tables the model writes into a bubble ─────────────────────────
   A city's departments with their bases, or an institution's bases, come as
   a markdown table with the department names linked. nova.css zeroes table
   margins and draws no borders, so four columns of long linked names in a
   narrow bubble ran together (seen 2026-09-07). The model marks its number
   columns right-aligned (`---:`), which nlux renders as align="right". */
.nlux-comp-message .nlux-markdown-container table {
  display:         block;          /* scrolls sideways instead of squeezing */
  max-width:       100%;
  overflow-x:      auto;
  border-collapse: collapse;
  margin:          8px 0 12px;
  font-size:       0.8125rem;      /* 13px */
  line-height:     1.35;
}

.nlux-comp-message .nlux-markdown-container th,
.nlux-comp-message .nlux-markdown-container td {
  padding:        5px 12px 5px 0;
  border-bottom:  1px solid var(--edu-border);
  text-align:     left;
  vertical-align: top;
}

.nlux-comp-message .nlux-markdown-container th {
  font-size:      0.75rem;
  font-weight:    600;
  color:          var(--edu-text-muted);
  letter-spacing: 0.02em;
  white-space:    nowrap;
}

.nlux-comp-message .nlux-markdown-container th[align="right"],
.nlux-comp-message .nlux-markdown-container td[align="right"] {
  text-align:           right;
  white-space:          nowrap;
  font-variant-numeric: tabular-nums;
}

.nlux-comp-message .nlux-markdown-container tbody tr:last-child td {
  border-bottom: 0;
}

.nlux-comp-message .nlux-markdown-container td a {
  color:                 var(--edu-primary);
  text-decoration:       underline;
  text-underline-offset: 2px;
}

/* ─── § 12b. The table the agent draws in place of the cards ───────────────
   The 'table' event (columns + rows, a cell with a url is a link) is built
   into the bubble by edu_chat.js the way the cards are, and sits in the
   same slot above the prose. Same look as § 12a; number columns come
   marked by the agent (align "right"). */
.edu-table-wrap {
  order:      -1;              /* pin above the prose, like the cards */
  max-width:  100%;
  overflow-x: auto;            /* scrolls sideways instead of squeezing */
  margin:     0 0 12px;
}

.edu-table {
  border-collapse: collapse;
  font-size:       0.8125rem;  /* 13px */
  line-height:     1.35;
}

.edu-table th,
.edu-table td {
  padding:        5px 12px 5px 0;
  border-bottom:  1px solid var(--edu-border);
  text-align:     left;
  vertical-align: top;
}

.edu-table th {
  font-size:      0.75rem;
  font-weight:    600;
  color:          var(--edu-text-muted);
  letter-spacing: 0.02em;
  white-space:    nowrap;
}

.edu-table .edu-table-num {
  text-align:           right;
  white-space:          nowrap;
  font-variant-numeric: tabular-nums;
}

.edu-table tbody tr:last-child td {
  border-bottom: 0;
}

.edu-table td a {
  color:                 var(--edu-primary);
  text-decoration:       underline;
  text-underline-offset: 2px;
}

.edu-cards-grid {
  order:          -1;          /* pin above the prose */
  display:        flex;
  flex-direction: column;
  gap:            8px;
  margin-bottom:  12px;
}

/* Hedge fades in first; each card cascades in 50ms after the previous,
   sliding from above. `backwards` fill mode keeps each child invisible
   until its turn so the cascade is visible. */
.edu-cards-hedge {
  animation: edu-cards-fadein 280ms ease-out backwards;
}

.edu-card {
  animation: edu-card-slidein 320ms cubic-bezier(0.2, 0.7, 0.3, 1) backwards;
}

/* hedge is the grid's 1st child; cards are 2nd onward */
.edu-card:nth-child(2)  { animation-delay:  80ms; }
.edu-card:nth-child(3)  { animation-delay: 130ms; }
.edu-card:nth-child(4)  { animation-delay: 180ms; }
.edu-card:nth-child(5)  { animation-delay: 230ms; }
.edu-card:nth-child(6)  { animation-delay: 280ms; }
.edu-card:nth-child(7)  { animation-delay: 330ms; }
.edu-card:nth-child(8)  { animation-delay: 380ms; }
.edu-card:nth-child(9)  { animation-delay: 430ms; }
.edu-card:nth-child(10) { animation-delay: 480ms; }
.edu-card:nth-child(11) { animation-delay: 530ms; }

.edu-cards-actions {
  animation: edu-cards-fadein 280ms ease-out 600ms backwards;
}

@keyframes edu-cards-fadein {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes edu-card-slidein {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.edu-cards-hedge {
  margin:         0 0 4px 0;
  font-size:      0.8125rem;   /* 13px */
  color:          var(--edu-text-muted);
  font-style:     italic;
  line-height:    1.4;
}

/* Closing "see the full table" line of canonical bubbles */
.edu-cards-footer {
  margin:         8px 0 0 0;
  font-size:      0.8125rem;
  color:          var(--edu-text-muted);
  font-style:     italic;
  line-height:    1.4;
  animation:      edu-cards-fadein 280ms ease-out 600ms backwards;
}

.edu-cards-footer a {
  color:          var(--edu-primary);
  text-decoration: underline;
}

.edu-card {
  display:                grid;
  grid-template-columns:  96px 1fr;
  grid-template-rows:     auto auto auto;
  gap:                    4px 14px;
  padding:                12px 14px;
  border:                 1px solid var(--edu-border);
  border-radius:          var(--edu-radius);
  text-decoration:        none;
  color:                  var(--edu-text);
  background:             var(--edu-surface);
  transition:             border-color .12s ease, background .12s ease, transform .12s ease;
}

.edu-card:hover,
.edu-card:focus {
  border-color:   var(--edu-primary);
  background:     #fff;
  outline:        none;
}

/* Override surrounding theme's anchor styling — the whole card is an <a>.
   The widget's existing `#edu-chat-container .nlux_msg_received a` rule
   (specificity 1,1,1) sets link blue + underline for inline markdown
   links in bot replies; we need higher specificity to beat it on cards. */
#edu-chat-container .nlux_msg_received a.edu-card,
#edu-chat-container .nlux_msg_received a.edu-card:hover,
#edu-chat-container .nlux_msg_received a.edu-card:focus {
  color:           var(--edu-text);
  text-decoration: none;
}

.edu-cards-grid .edu-card .edu-card-logo,
img.edu-card-logo {
  grid-column:    1;
  grid-row:       1 / span 3;
  width:          96px !important;
  height:         68px !important;
  max-width:      96px;
  max-height:     68px;
  min-width:      96px;
  object-fit:     contain;
  align-self:     start;
  margin:         0;
}

.edu-card-title {
  grid-column:    2;
  font-weight:    600;
  font-size:      0.9375rem;   /* 15px */
  line-height:    1.3;
  color:          var(--edu-text);
  text-decoration: none;
}

.edu-card-school {
  grid-column:    2;
  font-size:      0.8125rem;   /* 13px */
  color:          var(--edu-text);
  text-decoration: none;
}

.edu-card-status {
  grid-column:    2;
  font-size:      0.75rem;     /* 12px */
  color:          var(--edu-text-muted);
  text-decoration: none;
}

.edu-cards-actions {
  display:         flex;
  flex-direction:  column;
  gap:             8px;
  margin-top:      12px;
  padding-top:     12px;
  border-top:      1px solid var(--edu-border);
}

.edu-cards-action-button {
  display:        block;
  width:          100%;
  min-height:     44px;
  padding:        12px 16px;
  font-family:    inherit;
  font-size:      0.9375rem;   /* 15px */
  font-weight:    500;
  color:          #fff;
  background:     var(--edu-primary);
  border:         none;
  border-radius:  var(--edu-radius);
  cursor:         pointer;
  text-align:     center;
  transition:     background-color 0.15s ease, transform 0.05s ease;
}

.edu-cards-action-button:hover {
  background:     var(--edu-primary-dark);
}

.edu-cards-action-button:active {
  transform:      scale(0.98);
}

.edu-cards-action-button:disabled {
  opacity:        0.5;
  cursor:         wait;
}

/* Phase 1.5 — canonical sectioned bubble */
.edu-cards-section-head {
  display:        flex;
  gap:            6px;
  align-items:    baseline;
  font-weight:    600;
  font-size:      0.9375rem;   /* 15px */
  color:          var(--edu-text);
  padding:        12px 0 6px;
  margin:         8px 0 6px;
  border-bottom:  1px solid var(--edu-border);
}
.edu-cards-section-head .count {
  font-weight:    400;
  font-size:      0.8125rem;   /* 13px */
  color:          var(--edu-text-muted, #6b7280);
}
.edu-cards-grid--canonical .edu-cards-section-head:first-of-type {
  margin-top:     0;
  padding-top:    0;
}

/* Phase 1.5 — multi-match choice buttons (vertical column) */
.edu-cards-actions--column {
  flex-direction: column;
}
.edu-cards-choice-button {
  /* Inherits .edu-cards-action-button base; nothing extra needed for now. */
}
