/* ============================================================
   MedChat — Design tokens
   Paleta: clínica, fria, confiável (não é o azul padrão do Bootstrap)
   ============================================================ */
:root {
  --ink:          #0B2B36; /* texto principal */
  --ink-soft:     #4A6570; /* texto secundário */
  --teal:         #0E5C6B; /* cor primária */
  --teal-deep:    #083C47; /* primária escura (hover/active) */
  --teal-pale:    #E5F1F0; /* fundo de destaque suave */
  --mint:         #3FBFA0; /* acento — vitals / sucesso */
  --paper:        #F3F8F7; /* fundo geral */
  --surface:      #FFFFFF; /* cartões / bolhas */
  --line:         #DCE7E6; /* bordas */
  --amber:        #C97A1A; /* avisos / disclaimer */
  --coral:        #C43D3D; /* erros */
  --mono:         #6C8288; /* texto de metadados (mono) */

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --font-display: "Source Serif 4", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
}

/* ============================================================
   Shell geral
   ============================================================ */
.app-shell {
  height: 100dvh;
  display: flex;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lang-switch { flex-shrink: 0; }

.lang-btn {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-family: var(--font-mono);
  padding: 5px 9px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: border-color .12s ease, color .12s ease;
}
.lang-btn:hover { border-color: var(--teal); color: var(--teal-deep); }

.lang-option.active {
  background: var(--teal-pale);
  color: var(--teal-deep);
  font-weight: 600;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.28rem;
  font-weight: 600;
  color: var(--teal-deep);
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.btn-new-chat {
  width: 100%;
  margin-top: 14px;
  background: var(--teal);
  border: none;
  color: #fff;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  transition: background .15s ease;
}
.btn-new-chat:hover { background: var(--teal-deep); color: #fff; }

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 16px;
}

.history-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 4px;
  position: relative;
  border: 1px solid transparent;
}
.history-item:hover { background: var(--teal-pale); }
.history-item.active {
  background: var(--teal-pale);
  border-color: var(--line);
}
.history-item .title {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 22px;
}
.history-item .meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--mono);
  margin-top: 2px;
}
.history-item .del-btn {
  position: absolute;
  right: 6px;
  top: 8px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity .12s ease;
  font-size: 0.8rem;
}
.history-item:hover .del-btn { opacity: 1; }
.history-item .del-btn:hover { color: var(--coral); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 0.72rem;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ============================================================
   Coluna principal do chat
   ============================================================ */
.main-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
}

/* ---------- Topbar com traçado ECG (elemento-assinatura) ---------- */
.topbar {
  background: linear-gradient(180deg, var(--teal-deep) 0%, var(--teal) 100%);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
}

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

.topbar-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar-subtitle {
  font-size: 0.74rem;
  opacity: 0.85;
  font-family: var(--font-mono);
}

.ecg-wrap {
  width: 150px;
  height: 34px;
  flex-shrink: 0;
  opacity: 0.9;
}
.ecg-line {
  stroke: var(--mint);
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 340;
  stroke-dashoffset: 340;
  animation: ecg-draw 2.4s linear infinite;
}
@keyframes ecg-draw {
  0%   { stroke-dashoffset: 340; }
  60%  { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -20; }
}

.btn-sidebar-toggle {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: none;
  align-items: center;
  justify-content: center;
}

.disclaimer-strip {
  background: #FCF3E3;
  border-bottom: 1px solid #F0DFB8;
  color: var(--amber);
  font-size: 0.76rem;
  padding: 7px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Área de mensagens ---------- */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 5% 12px;
  scroll-behavior: smooth;
}

.messages-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  max-width: 560px;
  margin: 8vh auto 0;
  text-align: center;
  color: var(--ink-soft);
}
.empty-state .icon {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  color: var(--teal);
}
.empty-state h2 {
  font-family: var(--font-display);
  color: var(--teal-deep);
  font-size: 1.4rem;
  margin-bottom: 8px;
}
.suggestion-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
  text-align: left;
}
.suggestion-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
  font-size: 0.84rem;
  color: var(--ink);
  transition: border-color .15s ease, transform .1s ease;
}
.suggestion-card:hover {
  border-color: var(--teal);
  transform: translateY(-1px);
}

/* ---------- Bolhas de mensagem ---------- */
.msg-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.msg-row.user { flex-direction: row-reverse; }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
}
.avatar.assistant { background: var(--teal); }
.avatar.user { background: var(--ink-soft); }

.bubble-col {
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg-row.user .bubble-col { align-items: flex-end; }

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.92rem;
  line-height: 1.55;
  word-wrap: break-word;
}
.msg-row.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
  color: var(--ink);
}
.msg-row.user .bubble {
  background: var(--teal);
  color: #fff;
  border-top-right-radius: 4px;
}

.bubble img.attached-img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  display: block;
}

/* Markdown dentro das bolhas do assistente */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 {
  font-family: var(--font-display);
  color: var(--teal-deep);
  margin: 14px 0 8px;
}
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child { margin-top: 0; }
.bubble ul, .bubble ol { padding-left: 20px; margin: 0 0 8px; }
.bubble code {
  background: var(--teal-pale);
  color: var(--teal-deep);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.bubble pre {
  background: var(--teal-deep);
  color: #EAF7F5;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0 0 8px;
}
.bubble pre code { background: none; color: inherit; padding: 0; }
.bubble blockquote {
  border-left: 3px solid var(--mint);
  margin: 0 0 8px;
  padding: 2px 12px;
  color: var(--ink-soft);
}
.bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 6px 0 10px;
  font-size: 0.86rem;
}
.bubble th, .bubble td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}
.bubble th {
  background: var(--teal-pale);
  color: var(--teal-deep);
  font-weight: 600;
}
.bubble strong { color: inherit; }
.bubble hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }

/* ---------- Barra de "vitais" (metadados por mensagem) ---------- */
.vitals-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--mono);
}
.vitals-bar .pill {
  background: var(--teal-pale);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.vitals-bar .pill.cache { background: #EAF7EF; color: #1E7A46; border-color: #CFEBD9; }
.vitals-bar .pill.guard { background: #FCF3E3; color: #A9660F; border-color: #F0DFB8; }

.msg-actions {
  display: flex;
  gap: 6px;
}
.msg-actions button {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.72rem;
  padding: 2px 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.msg-actions button:hover { color: var(--teal); }

.typing-dots span {
  width: 6px; height: 6px;
  background: var(--teal);
  border-radius: 50%;
  display: inline-block;
  margin-right: 3px;
  animation: blink 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ============================================================
   Composer (caixa de digitação)
   ============================================================ */
.composer-wrap {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 14px 5% 18px;
}

.composer-inner {
  max-width: 860px;
  margin: 0 auto;
}

.image-preview-strip {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.image-preview-item {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
}
.image-preview-item img {
  width: 100%; height: 100%; object-fit: cover;
}
.image-preview-item .remove-img {
  position: absolute;
  top: 2px; right: 2px;
  background: rgba(11,43,54,0.75);
  color: #fff;
  border: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 0.65rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.composer-box:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(14,92,107,0.12);
}

#messageInput {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  max-height: 200px;
  font-size: 0.94rem;
  font-family: var(--font-body);
  color: var(--ink);
  padding: 8px 0;
  line-height: 1.5;
}
#messageInput:focus { outline: none; box-shadow: none; }

.composer-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--teal-pale); color: var(--teal-deep); }

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--teal);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s ease, transform .08s ease;
}
.btn-send:hover { background: var(--teal-deep); }
.btn-send:disabled { background: var(--line); color: var(--ink-soft); cursor: not-allowed; }
.btn-send:active:not(:disabled) { transform: scale(0.94); }

.composer-hint {
  font-size: 0.7rem;
  color: var(--ink-soft);
  margin-top: 6px;
  padding-left: 6px;
  font-family: var(--font-mono);
}

/* ============================================================
   Toasts / feedback
   ============================================================ */
.mc-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--teal-deep);
  color: #fff;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 0.82rem;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.mc-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

/* ============================================================
   Responsivo
   ============================================================ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 24px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(11,43,54,0.35);
    z-index: 1040;
  }
  .sidebar-backdrop.show { display: block; }

  .btn-sidebar-toggle { display: flex; }
  .ecg-wrap { width: 90px; }
  .bubble-col { max-width: 88%; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .messages-area { padding: 18px 4% 8px; }
  .composer-wrap { padding: 10px 3% 14px; }
}

@media (max-width: 480px) {
  .topbar-subtitle { display: none; }
  .disclaimer-strip span.full-text { display: none; }
}
