/* ─────────────────────────────────────────────
   SamAlgo Chat — Utility Classes (chat-utils.css)
   Shared atomic classes for buttons, cards, badges,
   inputs, icons, flex helpers, and text utilities.
   ───────────────────────────────────────────── */

/* ── Reset & Base ── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* ── Focus ring (global) ── */

:focus-visible {
  outline: 2px solid var(--chat-focus-ring, rgba(96, 165, 250, 0.45));
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ── Selection ── */

::selection {
  background: rgba(96, 165, 250, 0.28);
  color: var(--chat-text);
}

/* ── Scrollbar (Firefox + Webkit) ── */

.chat-sidebar-body,
.chat-messages-scroll,
.tool-code,
.message-content pre {
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.22) transparent;
}

.chat-sidebar-body::-webkit-scrollbar,
.chat-messages-scroll::-webkit-scrollbar,
.tool-code::-webkit-scrollbar,
.message-content pre::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.chat-sidebar-body::-webkit-scrollbar-track,
.chat-messages-scroll::-webkit-scrollbar-track,
.tool-code::-webkit-scrollbar-track,
.message-content pre::-webkit-scrollbar-track {
  background: transparent;
}

.chat-sidebar-body::-webkit-scrollbar-thumb,
.chat-messages-scroll::-webkit-scrollbar-thumb,
.tool-code::-webkit-scrollbar-thumb,
.message-content pre::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.22);
  border-radius: 999px;
}

.chat-sidebar-body::-webkit-scrollbar-thumb:hover,
.chat-messages-scroll::-webkit-scrollbar-thumb:hover,
.tool-code::-webkit-scrollbar-thumb:hover,
.message-content pre::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.38);
}

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--chat-border-strong, rgba(148, 163, 184, 0.28));
  border-radius: var(--chat-radius, 8px);
  padding: 10px 14px;
  color: var(--chat-text, #f8fafc);
  background: rgba(15, 23, 42, 0.78);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(96, 165, 250, 0.48);
  background: rgba(30, 41, 59, 0.78);
}

.btn:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18);
}

/* Button modifiers */

.btn--primary {
  border-color: rgba(96, 165, 250, 0.38);
  color: #93c5fd;
  background: rgba(30, 41, 59, 0.88);
}

.btn--primary:hover:not(:disabled) {
  border-color: rgba(96, 165, 250, 0.68);
  background: rgba(37, 99, 235, 0.28);
  box-shadow: 0 4px 18px rgba(59, 130, 246, 0.18);
}

.btn--danger {
  border-color: rgba(248, 113, 113, 0.38);
  color: #fca5a5;
  background: rgba(30, 20, 20, 0.55);
}

.btn--danger:hover:not(:disabled) {
  border-color: rgba(248, 113, 113, 0.68);
  background: rgba(127, 29, 29, 0.38);
  box-shadow: 0 4px 18px rgba(248, 113, 133, 0.14);
}

.btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--chat-text-muted, #94a3b8);
  padding: 8px;
  min-width: 32px;
  min-height: 32px;
}

.btn--ghost:hover:not(:disabled) {
  border-color: rgba(96, 165, 250, 0.32);
  color: var(--chat-text, #f8fafc);
  background: rgba(59, 130, 246, 0.1);
}

.btn--ghost.btn--danger:hover:not(:disabled) {
  border-color: rgba(251, 113, 133, 0.32);
  color: #fecaca;
  background: rgba(251, 113, 133, 0.1);
}

.btn--sm {
  padding: 6px 10px;
  font-size: 0.78rem;
  min-height: 28px;
  gap: 4px;
}

.btn--sm.btn--ghost {
  min-width: 28px;
  min-height: 28px;
  padding: 6px;
}

.btn--full {
  width: 100%;
  justify-content: center;
}

/* ── Cards / Panels ── */

.card {
  border: 1px solid var(--chat-border, rgba(148, 163, 184, 0.18));
  border-radius: var(--chat-radius, 8px);
  background: rgba(15, 23, 42, 0.78);
  padding: 1.1rem;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.18);
}

.card--flat {
  box-shadow: none;
  background: rgba(15, 23, 42, 0.55);
}

.card--hover {
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.card--hover:hover {
  border-color: var(--chat-border-strong, rgba(148, 163, 184, 0.28));
  background: rgba(20, 30, 50, 0.72);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
}

/* ── Badges ── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.32em 0.7em;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  white-space: nowrap;
  vertical-align: baseline;
  border-radius: 999px;
  border: 1px solid transparent;
}

.badge--success {
  background: rgba(52, 211, 153, 0.16);
  color: var(--chat-green, #34d399);
  border-color: rgba(52, 211, 153, 0.36);
}

.badge--warning {
  background: rgba(251, 191, 36, 0.16);
  color: var(--chat-amber, #fbbf24);
  border-color: rgba(251, 191, 36, 0.36);
}

.badge--info {
  background: rgba(34, 211, 238, 0.16);
  color: var(--chat-cyan, #22d3ee);
  border-color: rgba(34, 211, 238, 0.36);
}

.badge--error {
  background: rgba(251, 113, 133, 0.16);
  color: var(--chat-red, #fb7185);
  border-color: rgba(251, 113, 133, 0.36);
}

.badge--sm {
  font-size: 0.68rem;
  padding: 0.22em 0.55em;
}

/* ── Inputs ── */

.input {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: var(--chat-radius, 8px);
  background: rgba(2, 6, 23, 0.55);
  color: var(--chat-text, #f8fafc);
  padding: 0.62rem 0.8rem;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.5;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.input::placeholder {
  color: var(--chat-text-dim, #64748b);
}

.input:focus-visible {
  border-color: rgba(56, 189, 248, 0.72);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}

.input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

textarea.input {
  resize: vertical;
  min-height: 80px;
  line-height: 1.6;
}

/* ── Icon buttons ── */

.icon-btn {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--chat-border, rgba(148, 163, 184, 0.18));
  border-radius: 7px;
  color: var(--chat-text-muted, #94a3b8);
  background: rgba(8, 12, 22, 0.65);
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}

.icon-btn:hover:not(:disabled) {
  color: var(--chat-text, #f8fafc);
  border-color: rgba(96, 165, 250, 0.42);
}

.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.icon-btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18);
}

.icon-btn--sm {
  width: 28px;
  height: 28px;
}

.icon-btn--md {
  width: 34px;
  height: 34px;
}

.icon-btn--danger:hover:not(:disabled) {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.48);
  background: rgba(127, 29, 29, 0.36);
}

/* ── Flex helpers ── */

.flex-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.flex-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.flex-1 {
  flex: 1;
  min-width: 0;
}

.flex-wrap {
  flex-wrap: wrap;
}

/* ── Text helpers ── */

.text-muted {
  color: var(--chat-text-muted, #94a3b8);
}

.text-soft {
  color: var(--chat-text-soft, #cbd5e1);
}

.text-dim {
  color: var(--chat-text-dim, #64748b);
}

.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Semantic helpers ── */

.sidebar-nav-link {
  text-decoration: none;
  color: inherit;
}

.sidebar-nav-link + .sidebar-nav-link {
  margin-top: 0.5rem;
}

.sidebar-section-spacer {
  margin-top: 10px;
}

.relative {
  position: relative;
}

.section-title {
  margin: 0 0 14px;
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--chat-text, #f8fafc);
  letter-spacing: 0;
}

.empty-state {
  border: 1px solid var(--chat-border, rgba(148, 163, 184, 0.18));
  border-radius: var(--chat-radius, 8px);
  padding: 14px;
  color: var(--chat-text-muted, #94a3b8);
  background: rgba(148, 163, 184, 0.04);
  font-size: 0.86rem;
  text-align: center;
}

.status-pill {
  border: 1px solid var(--chat-border, rgba(148, 163, 184, 0.18));
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--chat-text-muted, #94a3b8);
  font-size: 0.74rem;
  white-space: nowrap;
}

/* ── Expandable pattern ── */

.expandable-chevron {
  color: var(--chat-text-dim, #64748b);
  transition: transform 160ms ease;
}

.expandable[aria-expanded="true"] .expandable-chevron,
.expandable.expanded .expandable-chevron {
  transform: rotate(90deg);
}

/* ── Alert / Banner ── */

.alert {
  border-radius: var(--chat-radius, 8px);
  padding: 10px 12px;
  font-size: 0.84rem;
  line-height: 1.45;
}

.alert-error {
  border: 1px solid rgba(251, 113, 133, 0.32);
  color: #ffe4e6;
  background: rgba(251, 113, 133, 0.1);
}

.alert-success {
  border: 1px solid rgba(52, 211, 153, 0.32);
  color: #d1fae5;
  background: rgba(52, 211, 153, 0.1);
}

.alert-info {
  border: 1px solid rgba(34, 211, 238, 0.32);
  color: #cffafe;
  background: rgba(34, 211, 238, 0.1);
}

.alert-warning {
  border: 1px solid rgba(251, 191, 36, 0.32);
  color: #fde68a;
  background: rgba(251, 191, 36, 0.1);
}

/* ── Glassmorphism helpers ── */

.glass {
  background: rgba(30, 41, 59, 0.82);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
}

.glass--strong {
  background: rgba(30, 41, 59, 0.92);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

/* ── Animation helpers ── */

.animate-in {
  animation: message-in 180ms ease-out both;
}

.animate-pulse {
  animation: pulse-glow 2s ease-in-out infinite;
}

/* ── Section headers with accent border ── */

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--chat-text);
}

.section-header::before {
  content: "";
  width: 3px;
  height: 18px;
  border-radius: 999px;
  background: var(--chat-blue);
  flex-shrink: 0;
}

/* ── Status indicators ── */

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.status-dot--success {
  background: var(--chat-green);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}

.status-dot--warning {
  background: var(--chat-amber);
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
  animation: pulse-glow 2s ease-in-out infinite;
}

.status-dot--error {
  background: var(--chat-red);
  box-shadow: 0 0 8px rgba(251, 113, 133, 0.5);
}

.status-dot--info {
  background: var(--chat-cyan);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.5);
}
