/* ==========================================================================
   agent-panel.css — Agency Agent main-view layout (v2.18 polish).
   Lives in #mn as a .view, activated by the sidebar "Agent" tab handler.
   Card container → left portfolio sidebar + right chat column.
   CSS/layout only — DOM + JS (ap-* ids/classes) unchanged.
   ========================================================================== */

/* Base shape. Hidden by default (inherits .view { display: none }); the
   `#agent-panel.view.active` rule below uses id specificity to beat the
   `.view.active { display: block }` rule from layout.css. */
.agent-panel {
  flex: 1;
  min-height: 0;
  padding: 0;
  background: var(--bg);
}

/* FIX 1 — outer card wrapping the sidebar + chat. */
#agent-panel.view.active {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
  margin: 24px;
  height: calc(100vh - 120px);
}

@media (max-width: 900px) {
  #agent-panel.view.active {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 120px);
  }
}

/* ── FIX 2 — Left sidebar ──────────────────────────────────── */
.ap-left {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  padding: 0;
  min-width: 0;
}

@media (max-width: 900px) {
  .ap-left {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 50vh;
  }
}

/* "YOUR PORTFOLIO" header */
.ap-left-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ap-left-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  text-transform: uppercase;
}

/* Portfolio stats block */
.ap-context {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  flex-shrink: 0;
}

.ap-context-loading,
.ap-context-error {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 12px;
  padding: 2px 0;
}
.ap-context-error { color: #dc2626; font-style: normal; }

.ap-context-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.ap-context-label { color: var(--text-secondary); }

.ap-context-value {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* "Need attention" row value reads red. */
.ap-context-stat--warn .ap-context-value { color: #dc2626; }

/* Divider between stats and the client list (rendered by JS). */
.ap-context-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0 0;
}

/* Client list — the rows after the divider. The JS keeps these inside
   #ap-context, so style them as compact rows with hover affordance. */
.ap-context-client {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  gap: 8px;
  min-width: 0;
}
.ap-context-client:hover { background: var(--surface); }

.ap-context-client-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

/* Score badge. JS assigns good/ok/bad; map to spec's red/amber/green. */
.ap-context-client-score {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.ap-score--good { color: #059669; } /* >= threshold (healthy) */
.ap-score--ok   { color: #d97706; } /* mid */
.ap-score--bad  { color: #dc2626; } /* low */

/* Shortcut buttons */
.ap-shortcuts {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.ap-shortcut {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.ap-shortcut:hover {
  background: var(--accent-light);
  border-color: #6D28D9;
  color: #6D28D9;
}

/* ── FIX 3 — Chat column ───────────────────────────────────── */
.ap-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
}

.ap-chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.ap-chat-title-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ap-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.ap-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

.ap-clear {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.ap-clear:hover {
  border-color: #dc2626;
  color: #dc2626;
}

/* Messages area. Bottom border doubles as the divider above the input
   region (no extra markup needed). */
.ap-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  border-bottom: 1px solid var(--border);
}

/* Text alignment — ALL message content left-aligned, no exceptions.
   Bubble POSITION (left/right) is controlled by flex align-self below,
   so forcing text-align:left here only affects inner text, not the
   bubble's side of the row. */
.ap-msg,
.ap-msg *,
.ap-msg-content,
.ap-msg-content *,
.ap-bubble,
.ap-bubble *,
.ap-welcome,
.ap-welcome * {
  text-align: left !important;
}

.ap-welcome,
.ap-msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.ap-msg--user  { flex-direction: row-reverse; }

/* Avatar circle */
.ap-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #6D28D9;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ap-avatar--user {
  background: var(--border);
  color: var(--text);
}

.ap-msg-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.ap-msg--agent .ap-msg-content { align-items: flex-start; max-width: 85%; }
.ap-msg--user  .ap-msg-content { align-items: flex-end;   max-width: 75%; }

.ap-bubble {
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.ap-bubble--agent {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 4px;
  color: var(--text);
  align-self: flex-start;
  max-width: 85%;
}

.ap-bubble--user {
  background: #6D28D9;
  border-radius: 12px 12px 4px 12px;
  color: #ffffff;
  line-height: 1.5;
  align-self: flex-end;
  max-width: 75%;
}

.ap-bubble p { margin: 0 0 6px; }
.ap-bubble p:last-child { margin: 0; }
.ap-bubble ul { margin: 4px 0; padding-left: 18px; }
.ap-bubble li { margin-bottom: 3px; }
.ap-bubble strong { font-weight: 600; }
.ap-bubble em { font-style: italic; }

.ap-msg-time {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 4px;
  padding: 0 4px;
}

/* Typing indicator */
.ap-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 4px;
}
.ap-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  display: inline-block;
  animation: apTyping 1.2s infinite;
}
.ap-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ap-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes apTyping {
  0%, 60%, 100% { opacity: 0.3; transform: scale(1); }
  30%           { opacity: 1;   transform: scale(1.2); }
}

/* Input area — the bordered pill (min-height keeps the JS textarea
   auto-grow working past the 48px baseline). */
.ap-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 8px 0 16px;
  min-height: 48px;
  margin: 16px 20px 0;
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}
.ap-input-wrap:focus-within {
  border-color: #6D28D9;
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.08);
}

/* Descendant selector (.ap-input-wrap .ap-textarea, specificity 0,2,0)
   so border/outline/box-shadow removal beats the global
   [data-theme="light"] textarea rule (0,1,1) in inputs.css that would
   otherwise paint a second border inside the wrapper's pill. The
   wrapper (.ap-input-wrap) owns the border + focus ring; the textarea
   itself must stay borderless. */
.ap-input-wrap .ap-textarea {
  flex: 1;
  border: none;
  outline: none;
  box-shadow: none;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  padding: 12px 0;
  line-height: 1.5;
  font-family: var(--font);
}
.ap-input-wrap .ap-textarea:focus {
  border: none;
  outline: none;
  box-shadow: none;
}
.ap-textarea::placeholder { color: var(--text-secondary); }
.ap-textarea:disabled     { opacity: 0.6; cursor: not-allowed; }

.ap-send {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #6D28D9;
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.ap-send:hover:not(:disabled) { background: #5b21b6; }
.ap-send:disabled             { opacity: 0.4; cursor: not-allowed; }

.ap-hint {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 8px;
  padding: 0 20px 16px;
  flex-shrink: 0;
}
