/* SanMarcSoft Comms Hub — AI Chat Sidebar
   Uses design-system.css tokens. */

/* ---- Toggle button ---- */
.agent-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-md);
  background: none;
  border: none;
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: color var(--duration-instant), background-color var(--duration-instant);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.agent-toggle:hover {
  color: var(--color-text-secondary);
  background-color: var(--color-surface-hover-subtle);
}

/* ---- Sidebar shell ---- */
.agent-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 22rem;
  background-color: var(--color-surface-1);
  border-left: 1px solid var(--color-border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transform: translateX(100%);
  transition: transform var(--duration-normal) var(--ease-out);
  box-shadow: var(--shadow-lg);
}

body.agent-open .agent-sidebar {
  transform: translateX(0);
}

/* ---- Header ---- */
.agent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
  background-color: var(--color-surface-2);
  flex-shrink: 0;
}

.agent-header h3 {
  font-family: var(--font-heading);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
  margin: 0;
}

/* ---- Messages area ---- */
.agent-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.agent-messages::-webkit-scrollbar { width: 4px; }
.agent-messages::-webkit-scrollbar-track { background: transparent; }
.agent-messages::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: 2px;
}

/* ---- Message bubbles ---- */
.agent-msg {
  max-width: 92%;
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  word-break: break-word;
}

.agent-msg-user {
  align-self: flex-end;
  background-color: var(--color-brand);
  color: oklch(0.15 0 0);
  border-radius: var(--radius-lg) var(--radius-lg) var(--space-1) var(--radius-lg);
}

.agent-msg-agent {
  align-self: flex-start;
  background-color: var(--color-surface-2);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--space-1);
}

/* Markdown in agent messages */
.agent-msg-agent p { margin: 0 0 var(--space-2); }
.agent-msg-agent p:last-child { margin-bottom: 0; }
.agent-msg-agent ul, .agent-msg-agent ol {
  margin: var(--space-1) 0 var(--space-2) var(--space-6);
  padding: 0;
}
.agent-msg-agent li { margin-bottom: var(--space-1); }
.agent-msg-agent a { color: var(--color-brand-bright); text-decoration: underline; }
.agent-msg-agent a:hover { color: var(--color-brand); }
.agent-msg-agent code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background-color: var(--color-surface-0);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.35em;
}
.agent-msg-agent pre {
  background-color: var(--color-surface-0);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  overflow-x: auto;
  margin: var(--space-2) 0;
}
.agent-msg-agent pre code {
  background: none;
  border: none;
  padding: 0;
}
.agent-msg-agent h1, .agent-msg-agent h2, .agent-msg-agent h3 {
  color: var(--color-text-primary);
  font-weight: var(--weight-semibold);
  margin: var(--space-2) 0 var(--space-1);
}
.agent-msg-agent blockquote {
  border-left: 3px solid var(--color-border);
  margin: var(--space-1) 0;
  padding-left: var(--space-3);
  color: var(--color-text-secondary);
}
.agent-msg-agent strong { color: var(--color-text-primary); }

/* ---- Typing indicator ---- */
.agent-typing {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-3);
}

.agent-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--color-text-tertiary);
  animation: agent-pulse 1.2s infinite ease-in-out;
}

.agent-typing span:nth-child(1) { animation-delay: 0s; }
.agent-typing span:nth-child(2) { animation-delay: 0.2s; }
.agent-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes agent-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ---- Error message ---- */
.agent-msg-error {
  align-self: flex-start;
  background-color: oklch(0.20 0.05 25);
  border: 1px solid oklch(0.35 0.1 25);
  color: oklch(0.80 0.12 25);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  font-size: var(--text-sm);
  max-width: 92%;
}

/* ---- Source links ---- */
.agent-sources {
  align-self: flex-start;
  max-width: 92%;
  margin-top: calc(var(--space-1) * -1);
}

.agent-sources-title {
  font-size: 0.6875rem;
  font-weight: var(--weight-medium);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-1);
}

.agent-source-link {
  display: inline-block;
  font-size: var(--text-xs);
  color: var(--color-brand);
  text-decoration: none;
  background-color: var(--color-brand-subtle);
  border: 1px solid oklch(0.40 0.06 70);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  margin: var(--space-1) var(--space-1) var(--space-1) 0;
  transition: background-color var(--duration-instant);
}

.agent-source-link:hover {
  background-color: oklch(0.35 0.06 70);
  color: var(--color-brand-bright);
}

/* ---- Action card ---- */
.agent-action-card {
  align-self: flex-start;
  max-width: 96%;
  background-color: var(--color-surface-2);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.agent-action-card-header {
  padding: var(--space-3);
  background-color: var(--color-brand-subtle);
  border-bottom: 1px solid var(--color-border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.agent-action-card-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-brand);
  flex: 1;
}

.agent-action-card-body {
  padding: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
}

.agent-action-card-body dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-1) var(--space-3);
  margin: 0;
}

.agent-action-card-body dt {
  color: var(--color-text-tertiary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.agent-action-card-body dd {
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--text-xs);
}

.agent-action-card-footer {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border-subtle);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

.agent-btn-confirm {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background-color: var(--color-brand);
  color: oklch(0.15 0 0);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  min-height: var(--touch-target);
  transition: background-color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.agent-btn-confirm:hover { background-color: var(--color-brand-bright); }
.agent-btn-confirm:disabled { opacity: 0.5; cursor: not-allowed; }

.agent-btn-dismiss {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--color-text-tertiary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  border: 1px solid var(--color-border);
  cursor: pointer;
  font-family: var(--font-body);
  min-height: var(--touch-target);
  transition: color var(--duration-instant), background-color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.agent-btn-dismiss:hover {
  background-color: var(--color-surface-hover-subtle);
  color: var(--color-text-secondary);
}

.agent-action-executing {
  font-size: var(--text-xs);
  color: var(--color-brand);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border-subtle);
  text-align: right;
}

.agent-action-done {
  font-size: var(--text-xs);
  color: var(--color-success);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border-subtle);
  text-align: right;
}

.agent-action-failed {
  font-size: var(--text-xs);
  color: var(--color-error);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border-subtle);
  text-align: right;
}

/* ---- Social post card ---- */
.agent-social-card {
  align-self: flex-start;
  max-width: 96%;
  background-color: var(--color-surface-2);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.agent-social-card-header {
  padding: var(--space-2) var(--space-3);
  background-color: var(--color-brand-subtle);
  border-bottom: 1px solid var(--color-border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.agent-social-card-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-brand);
}

.agent-social-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border-subtle);
  overflow-x: auto;
}

.agent-social-tab {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-tertiary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: var(--font-body);
  white-space: nowrap;
  min-height: var(--touch-target);
  transition: color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.agent-social-tab:hover { color: var(--color-text-secondary); }
.agent-social-tab.active {
  color: var(--color-brand);
  border-bottom-color: var(--color-brand);
}

.agent-social-content { padding: var(--space-3); }
.agent-social-panel { display: none; }
.agent-social-panel.active { display: block; }

.agent-social-text {
  font-size: var(--text-sm);
  color: var(--color-text-primary);
  line-height: var(--leading-relaxed);
  white-space: pre-wrap;
  word-break: break-word;
  background-color: var(--color-surface-0);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}

.agent-social-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.agent-char-count {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
}

.agent-char-count.over-limit { color: var(--color-error); }

.agent-copy-btn {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-tertiary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  font-family: var(--font-body);
  min-height: var(--touch-target);
  transition: color var(--duration-instant), background-color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.agent-copy-btn:hover {
  background-color: var(--color-surface-hover-subtle);
  color: var(--color-text-secondary);
}

/* ---- Input area ---- */
.agent-input-area {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border-subtle);
  background-color: var(--color-surface-2);
  flex-shrink: 0;
}

.agent-input {
  flex: 1;
  background-color: var(--color-surface-0);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  color: var(--color-text-primary);
  font-size: var(--text-base); /* prevent iOS zoom */
  font-family: var(--font-body);
  resize: none;
  max-height: 7.5rem;
  overflow-y: auto;
  line-height: var(--leading-normal);
  transition: border-color var(--duration-instant);
}

.agent-input:focus {
  outline: none;
  border-color: var(--color-brand);
}

.agent-input::placeholder { color: var(--color-text-tertiary); }

.agent-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-md);
  background-color: var(--color-brand);
  border: none;
  color: oklch(0.15 0 0);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--duration-instant);
  -webkit-tap-highlight-color: transparent;
}

.agent-send:hover { background-color: var(--color-brand-bright); }
.agent-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Mobile (full width) ---- */
@media (max-width: 767px) {
  .agent-sidebar {
    width: 100%;
    border-left: none;
  }
}
