/* =============================================================
   sow-chat.css  –  SOW Builder chat interface
   All class names are prefixed  sow-  to avoid collisions
   with the existing Bootstrap / style.css rules.
   ============================================================= */

/* ── Section wrapper ──────────────────────────────────────────────────────── */
.sow-chat-section {
  background: #f4f5f7;
  padding: 0;
  /* Grow to at least full viewport height below the nav */
  min-height: calc(100vh - 65px);
  /* Establish a stacking context for sticky children */
  position: relative;
}

/* ── Connection status bar ───────────────────────────────────────────────── */
.sow-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 24px;
  font-size: 12px;
  color: #555;
  background: #eaecef;
  border-bottom: 1px solid #d6d9de;
  width: 100%;
  box-sizing: border-box;
  /* Stick to top of section when scrolling */
  position: fixed;
  top: 0;
  z-index: 1000;
  left: 0;
  right: 0;
  box-sizing: border-box;
}

.sow-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #bbb;
  flex-shrink: 0;
  transition: background 0.3s;
}
.sow-status-dot.connected    { background: #43a047; }
.sow-status-dot.connecting   { background: #fb8c00; animation: sow-pulse 1s infinite; }
.sow-status-dot.disconnected { background: #e53935; }

@keyframes sow-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.25; }
}

/* ── Outer container ──────────────────────────────────────────────────────── */
.sow-chat-outer {
  display: flex;
  flex-direction: column;
  width: 100%;
  /* Tall enough to always show meaningful content above the input */
  min-height: calc(100vh - 65px - 32px);
}

/* ── Panel header ────────────────────────────────────────────────────────── */
.sow-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 28px 14px;
  background: #fff;
  border-bottom: 1px solid #e2e4e8;
  flex-shrink: 0;
}

.sow-chat-header-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #1a3a6b;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sow-chat-header-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sow-chat-header-text h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #1a1a2e;
  letter-spacing: 0.01em;
}

.sow-chat-header-text p {
  margin: 0;
  font-size: 12px;
  color: #777;
}

/* ── Chat window ─────────────────────────────────────────────────────────── */
/*
 * Grows to fill available space.  No fixed height — it just expands
 * naturally as messages are added.  The sticky input bar below it
 * always stays visible at the bottom of the viewport.
 */
.sow-chat-window {
  flex: 1;
  padding: 24px 28px 110px;
  background: #f4f5f7;
  /* Enough min-height so the window is visible before content arrives */
  min-height: 300px;
}

/* ── Message rows ────────────────────────────────────────────────────────── */
/* Constrain messages to 950px centered — header spans full width */
.sow-message {
  max-width: 950px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  margin-bottom: 18px;
  animation: sow-fadein 0.22s ease;
}

@keyframes sow-fadein {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.sow-message.user      { justify-content: flex-start; }
.sow-message.assistant { justify-content: flex-start; }

/* ── Message bubbles ─────────────────────────────────────────────────────── */
.sow-bubble {
  max-width: 94%;
  padding: 11px 16px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
  border-radius: 18px;
}

.sow-message.user .sow-bubble {
  background: #1a3a6b;
  color: #fff;
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 18px;
}

.sow-message.assistant .sow-bubble {
  background: #fff;
  color: #1a1a2e;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* Status / tool-activity messages */
.sow-message.status {
  justify-content: center;
}
.sow-message.status .sow-bubble {
  background: #fff8e1;
  color: #7a4f00;
  font-size: 12.5px;
  font-style: italic;
  padding: 7px 14px;
  border-radius: 12px;
  max-width: 86%;
  text-align: center;
  box-shadow: none;
}

/* ── Inline markdown styles inside bubbles ───────────────────────────────── */
.sow-bubble strong,
.sow-bubble b { font-weight: 700; }

.sow-bubble em { font-style: italic; }

.sow-bubble code {
  font-family: 'Courier New', monospace;
  font-size: 0.88em;
  background: rgba(0,0,0,0.07);
  padding: 1px 5px;
  border-radius: 4px;
}

.sow-bubble .sow-h2 {
  display: block;
  font-size: 15px;
  font-weight: 800;
  color: #1a3a6b;
  margin: 14px 0 6px;
  letter-spacing: 0.02em;
}

.sow-bubble .sow-h3 {
  display: block;
  font-size: 13.5px;
  font-weight: 700;
  color: #1a1a2e;
  margin: 12px 0 4px;
}

/* Main bullet list */
/* Main bullet list
 * Use ::before pseudo-elements for bullets so Bootstrap's list-style:none
 * reset cannot override them.
 */
.sow-bubble ul.sow-ul {
  margin: 6px 0 8px 0;
  padding: 0;
  list-style: none !important;
}
.sow-bubble ul.sow-ul > li {
  margin-bottom: 6px;
  list-style: none !important;
  padding-left: 20px;
  position: relative;
}
.sow-bubble ul.sow-ul > li::before {
  content: "•";   /* • */
  position: absolute;
  left: 4px;
  color: #1a3a6b;
  font-weight: 700;
}

/* Sub-bullet list */
.sow-bubble ul.sow-ul-sub {
  margin: 4px 0 4px 8px;
  padding: 0;
  list-style: none !important;
}
.sow-bubble ul.sow-ul-sub > li {
  margin-bottom: 3px;
  font-size: 0.96em;
  list-style: none !important;
  padding-left: 18px;
  position: relative;
}
.sow-bubble ul.sow-ul-sub > li::before {
  content: "–";   /* – en-dash as sub-bullet */
  position: absolute;
  left: 4px;
  color: #666;
}

/* Confidence badges */
.sow-match-strong   { color: #2e7d32; font-weight: 600; }
.sow-match-moderate { color: #e65100; font-weight: 600; }
.sow-match-weak     { color: #9e9e9e; }

/* ── Typing indicator ────────────────────────────────────────────────────── */
.sow-typing-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 11px 16px;
  background: #fff;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  width: fit-content;
}

.sow-typing-wrap span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #aaa;
  animation: sow-bounce 1.1s infinite;
}
.sow-typing-wrap span:nth-child(2) { animation-delay: 0.18s; }
.sow-typing-wrap span:nth-child(3) { animation-delay: 0.36s; }

@keyframes sow-bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.45; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* ── Input area — sticky at bottom of viewport ───────────────────────────── */
/*
 * position:sticky + bottom:0 means it travels down with content
 * until it would go off-screen, then it locks to the bottom edge.
 * This works regardless of the outer page structure.
 */
.sow-chat-input-area {
  position: fixed;
  bottom: 0;
  z-index: 1000;
  left: 0;
  right: 0;
  box-sizing: border-box;
  background: #fff;
  border-top: 2px solid #e2e4e8;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.07);
  padding: 14px 28px 20px;
}

/* Inner wrapper keeps input aligned with the chat content column */
.sow-chat-input-area > * {
  max-width: 950px;
  margin-left: auto;
  margin-right: auto;
}

.sow-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #f0f2f5;
  border: 2px solid #e2e4e8;
  border-radius: 26px;
  padding: 7px 7px 7px 18px;
  transition: border-color 0.2s;
}

.sow-input-row:focus-within {
  border-color: #1a3a6b;
  background: #fff;
}

.sow-chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14.5px;
  font-family: 'Work Sans', 'Segoe UI', sans-serif;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  color: #1a1a2e;
}
.sow-chat-input::placeholder { color: #aaa; }
.sow-chat-input:disabled     { cursor: not-allowed; }

/* Send button */
.sow-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #1a3a6b;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}
.sow-send-btn:hover    { background: #0d2a55; }
.sow-send-btn:active   { transform: scale(0.9); }
.sow-send-btn:disabled { background: #ccc; cursor: not-allowed; transform: none; }
.sow-send-btn svg      { width: 17px; height: 17px; }

.sow-chat-hint {
  margin-top: 7px;
  font-size: 11.5px;
  color: #bbb;
  text-align: center;
  user-select: none;
}

/* ── File upload button ──────────────────────────────────────────────────── */
.sow-file-label {
  display: inline-block;
  cursor: pointer;
  background: #1a3a6b;
  color: #fff;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.2s;
  user-select: none;
}
.sow-file-label:hover { background: #0d2a55; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sow-chat-header     { padding: 14px 16px 10px; }
  .sow-chat-window     { padding: 16px 14px 8px; }
  .sow-chat-input-area {
    padding: 10px 14px 16px;
    margin-left: -14px;
    margin-right: -14px;
    padding-left: 14px;
    padding-right: 14px;
  }
  .sow-bubble          { max-width: 90%; font-size: 13.5px; }
  .sow-status-bar      { padding: 5px 14px; }
}
