/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-0:     #0e1117;
  --bg-1:     #161b22;
  --bg-2:     #1c2330;
  --bg-3:     #232a36;
  --bg-4:     #2a3244;
  --border:   #2d3748;
  --border-2: #3d4f6e;

  --teal:     #1abc9c;
  --teal-dim: #14896f;
  --teal-glow:rgba(26,188,156,0.15);

  --text-0:   #e8edf3;
  --text-1:   #a8b4c4;
  --text-2:   #68788e;

  --red:      #e74c3c;
  --red-dim:  rgba(231,76,60,0.15);
  --yellow:   #f1c40f;
  --yellow-dim:rgba(241,196,15,0.12);
  --blue:     #3498db;
  --purple:   #9b59b6;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  --sidebar-w: 220px;
  --font-mono: 'JetBrains Mono', monospace;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-0);
  color: var(--text-0);
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
}

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

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 24px; }
.logo-title { font-size: 14px; font-weight: 700; color: var(--teal); letter-spacing: .3px; }
.logo-sub   { font-size: 11px; color: var(--text-2); }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1px;
  color: var(--text-2); text-transform: uppercase;
  padding: 8px 8px 6px;
}

.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 12px;
  background: transparent; border: none;
  color: var(--text-1); font-size: 13px; font-weight: 500;
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all .15s;
}
.nav-btn:hover { background: var(--bg-3); color: var(--text-0); }
.nav-btn.active {
  background: var(--teal-glow);
  color: var(--teal);
  border: 1px solid rgba(26,188,156,.3);
}
.nav-icon { font-size: 15px; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.status-indicator { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-ok      { background: var(--teal); box-shadow: 0 0 6px var(--teal); }
.dot-error   { background: var(--red); }
.dot-loading { background: var(--yellow); animation: pulse 1s infinite; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── Main ─────────────────────────────────────────────────── */
.main {
  flex: 1; display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
  background: var(--bg-0);
}

.view { display: none; flex-direction: column; height: 100%; overflow: hidden; }
.view.active { display: flex; }

/* ── View Header ──────────────────────────────────────────── */
.view-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.view-title { font-size: 20px; font-weight: 700; color: var(--text-0); }
.view-desc  { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.header-actions { display: flex; gap: 8px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all .15s;
  text-decoration: none;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-teal   { background: var(--teal); color: #0e1117; border-color: var(--teal); }
.btn-teal:hover { background: #22d4b0; }
.btn-ghost  { background: transparent; color: var(--text-1); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-3); color: var(--text-0); }
.btn-red    { background: var(--red-dim); color: var(--red); border-color: var(--red); }

/* ── Mode Bar ─────────────────────────────────────────────── */
.mode-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.mode-label { font-size: 12px; color: var(--text-2); font-weight: 600; flex-shrink: 0; }
.mode-tabs  { display: flex; gap: 4px; }

.mode-tab {
  padding: 5px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 500;
  background: var(--bg-3); color: var(--text-1);
  border: 1px solid var(--border);
  cursor: pointer; transition: all .15s;
}
.mode-tab.active {
  background: var(--teal-glow); color: var(--teal);
  border-color: rgba(26,188,156,.4);
}
.mode-info  { font-size: 11px; color: var(--text-2); margin-left: auto; }

/* ── Quick Actions ────────────────────────────────────────── */
.quick-actions {
  padding: 10px 24px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.qa-label { font-size: 11px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .8px; margin-bottom: 8px; }
.qa-buttons { display: flex; flex-wrap: wrap; gap: 6px; }

.qa-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 20px;
  font-size: 12px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border-2);
  background: var(--bg-2); color: var(--text-1);
  transition: all .15s; white-space: nowrap;
}
.qa-btn:hover { background: var(--bg-4); color: var(--text-0); border-color: var(--teal-dim); }
.qa-btn.qa-alert  { border-color: rgba(231,76,60,.4); color: var(--red); }
.qa-btn.qa-alert:hover { background: var(--red-dim); }
.qa-btn.qa-doc    { border-color: rgba(52,152,219,.4); color: var(--blue); }
.qa-btn.qa-doc:hover { background: rgba(52,152,219,.1); }

/* ── Patient Panel ────────────────────────────────────────── */
.patient-panel {
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  flex-shrink: 0;
}
.patient-panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 24px; cursor: pointer; font-size: 13px;
  color: var(--text-1); font-weight: 500;
}
.patient-panel-header:hover { color: var(--text-0); }
.panel-toggle { font-size: 10px; transition: transform .2s; }
.panel-toggle.open { transform: rotate(180deg); }

.patient-panel-body { padding: 0 24px 12px; display: none; }
.patient-panel-body.open { display: block; }

.patient-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.patient-fields .field-group:last-child { grid-column: 1/-1; }

.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-group label { font-size: 11px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .6px; }
.field-group input,
.field-group textarea,
.field-group select {
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-0); border-radius: var(--radius-sm);
  padding: 7px 10px; font-size: 13px; font-family: inherit;
  transition: border-color .15s; resize: vertical;
}
.field-group input:focus,
.field-group textarea:focus,
.field-group select:focus {
  outline: none; border-color: var(--teal);
}

/* ── Chat Area ────────────────────────────────────────────── */
.chat-area {
  flex: 1; overflow-y: auto; padding: 0;
  display: flex; flex-direction: column;
}
.chat-area::-webkit-scrollbar { width: 6px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 3px; }

.messages { padding: 16px 24px; display: flex; flex-direction: column; gap: 16px; }

/* Welcome screen */
.chat-welcome {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 24px; text-align: center; gap: 12px;
}
.welcome-icon { font-size: 48px; }
.chat-welcome h2 { font-size: 22px; font-weight: 700; color: var(--text-0); }
.chat-welcome p  { color: var(--text-1); line-height: 1.6; }
.welcome-modes { display: flex; gap: 16px; margin-top: 8px; }
.wm-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 24px;
  cursor: pointer; transition: all .2s; width: 200px;
  text-align: center;
}
.wm-card:hover { background: var(--bg-3); border-color: var(--teal); transform: translateY(-2px); }
.wm-icon  { font-size: 28px; margin-bottom: 8px; }
.wm-title { font-size: 14px; font-weight: 600; color: var(--text-0); margin-bottom: 4px; }
.wm-desc  { font-size: 12px; color: var(--text-2); line-height: 1.5; }

/* Messages */
.message {
  display: flex; flex-direction: column; gap: 6px;
  max-width: 90%;
}
.message.user   { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.msg-label {
  font-size: 11px; font-weight: 600; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-2);
}
.message.user .msg-label { color: var(--teal); }

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px; line-height: 1.65;
  max-width: 100%;
}
.message.user .msg-bubble {
  background: var(--teal-glow);
  border: 1px solid rgba(26,188,156,.25);
  color: var(--text-0);
  border-radius: var(--radius) var(--radius-sm) var(--radius) var(--radius);
}
.message.assistant .msg-bubble {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-0);
  border-radius: var(--radius-sm) var(--radius) var(--radius) var(--radius);
}

/* Markdown in assistant bubble */
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 {
  color: var(--teal); margin: 14px 0 6px; font-size: 14px;
}
.msg-bubble h1 { font-size: 16px; }
.msg-bubble strong { color: var(--text-0); font-weight: 600; }
.msg-bubble em { color: var(--text-1); }
.msg-bubble code {
  font-family: var(--font-mono); font-size: 12px;
  background: var(--bg-3); padding: 2px 6px;
  border-radius: 4px; color: var(--teal);
}
.msg-bubble pre {
  background: var(--bg-0); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px;
  overflow-x: auto; margin: 8px 0;
}
.msg-bubble pre code { background: none; padding: 0; color: var(--text-1); }
.msg-bubble ul,.msg-bubble ol { padding-left: 20px; margin: 6px 0; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 12.5px; }
.msg-bubble th {
  background: var(--bg-3); color: var(--teal);
  padding: 6px 10px; text-align: left; border: 1px solid var(--border);
}
.msg-bubble td { padding: 6px 10px; border: 1px solid var(--border); }
.msg-bubble tr:nth-child(even) td { background: var(--bg-1); }
.msg-bubble blockquote {
  border-left: 3px solid var(--teal); padding-left: 12px;
  color: var(--text-1); margin: 8px 0; font-style: italic;
}

/* Alert bubble */
.msg-bubble.alert-critical {
  border-color: var(--red) !important;
  background: var(--red-dim) !important;
}
.msg-bubble.alert-urgent {
  border-color: var(--yellow) !important;
  background: var(--yellow-dim) !important;
}

/* Typing indicator */
.typing-indicator {
  display: flex; gap: 5px; padding: 14px 16px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm) var(--radius) var(--radius) var(--radius);
  align-self: flex-start;
}
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--teal); animation: typing .8s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typing { 0%,100%{opacity:.3;transform:scale(.8)} 50%{opacity:1;transform:scale(1)} }

/* ── Chat Input ───────────────────────────────────────────── */
.chat-input-area {
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  flex-shrink: 0;
}
.input-wrapper {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px;
  transition: border-color .15s;
}
.input-wrapper:focus-within { border-color: var(--teal); }

.chat-input {
  flex: 1; background: transparent; border: none;
  color: var(--text-0); font-family: inherit; font-size: 14px;
  line-height: 1.5; resize: none; max-height: 160px;
  overflow-y: auto;
}
.chat-input:focus { outline: none; }
.chat-input::placeholder { color: var(--text-2); }

.send-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: var(--teal); color: #0e1117;
  border: none; cursor: pointer; font-size: 18px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all .15s;
}
.send-btn:hover { background: #22d4b0; transform: scale(1.05); }
.send-btn:disabled { background: var(--bg-4); color: var(--text-2); cursor: default; transform: none; }

.input-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 6px; padding: 0 4px;
}
.token-info  { font-size: 11px; color: var(--text-2); font-family: var(--font-mono); }
.input-hint  { font-size: 11px; color: var(--text-2); }

/* ── Reports Grid ─────────────────────────────────────────── */
.reports-grid, .patients-grid {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px,1fr));
  gap: 14px; align-content: start;
}

.report-card, .patient-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  cursor: pointer; transition: all .15s;
}
.report-card:hover, .patient-card:hover {
  border-color: var(--teal); background: var(--bg-3);
}

.rc-type {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .6px; padding: 3px 8px;
  border-radius: 4px; margin-bottom: 8px;
}
.rc-type.primeira { background: rgba(26,188,156,.15); color: var(--teal); }
.rc-type.recorrente { background: rgba(52,152,219,.15); color: var(--blue); }

.rc-name { font-size: 14px; font-weight: 600; color: var(--text-0); margin-bottom: 4px; }
.rc-summary { font-size: 12px; color: var(--text-2); line-height: 1.5; margin-bottom: 10px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rc-date { font-size: 11px; color: var(--text-2); font-family: var(--font-mono); }

/* ── Status Cards ─────────────────────────────────────────── */
.status-cards {
  padding: 20px 24px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px,1fr));
  gap: 14px; align-content: start;
}
.stat-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-card-title { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .7px; margin-bottom: 10px; }
.stat-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 13px; }
.stat-key   { color: var(--text-1); }
.stat-val   { color: var(--text-0); font-weight: 500; font-family: var(--font-mono); font-size: 12px; }
.stat-ok    { color: var(--teal); }
.stat-err   { color: var(--red); }

.env-guide { padding: 0 24px 24px; }
.env-guide h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text-1); }
.code-block {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  font-family: var(--font-mono); font-size: 12.5px;
  color: var(--text-1); line-height: 1.7; overflow-x: auto;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  z-index: 1000; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-2); border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); width: 480px; max-width: 95vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--text-2);
  font-size: 18px; cursor: pointer; padding: 2px 6px;
}
.modal-close:hover { color: var(--text-0); }
.modal-body   { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border); }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-3); border: 1px solid var(--border-2);
  color: var(--text-0); padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  transform: translateY(80px); opacity: 0;
  transition: all .3s; z-index: 9999; max-width: 320px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: var(--teal); }
.toast.error   { border-color: var(--red); }

/* ── Empty State ──────────────────────────────────────────── */
.empty-state {
  grid-column: 1/-1; text-align: center;
  padding: 60px 20px; color: var(--text-2); font-size: 14px;
}

/* ── Scrollbars ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

/* ── Report Viewer ─────────────────────────────────────────── */
.report-viewer {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; background: var(--bg-0);
}

.rv-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.rv-title {
  font-size: 15px; font-weight: 600; color: var(--teal);
}

.rv-content {
  flex: 1; overflow-y: auto;
  padding: 24px;
  font-size: 13.5px; line-height: 1.7;
  color: var(--text-0);
}

.rv-content h1,.rv-content h2,.rv-content h3 { color: var(--teal); margin: 16px 0 8px; }
.rv-content h1 { font-size: 18px; }
.rv-content h2 { font-size: 15px; }
.rv-content h3 { font-size: 13px; }
.rv-content strong { color: var(--text-0); font-weight: 600; }
.rv-content table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 12.5px; }
.rv-content th { background: var(--bg-3); color: var(--teal); padding: 8px 12px; text-align: left; border: 1px solid var(--border); }
.rv-content td { padding: 7px 12px; border: 1px solid var(--border); }
.rv-content tr:nth-child(even) td { background: var(--bg-1); }
.rv-content ul,.rv-content ol { padding-left: 22px; margin: 8px 0; }
.rv-content li { margin-bottom: 4px; }
.rv-content code { font-family: var(--font-mono); font-size: 12px; background: var(--bg-3); padding: 2px 6px; border-radius: 4px; color: var(--teal); }
.rv-content blockquote { border-left: 3px solid var(--teal); padding-left: 14px; color: var(--text-1); margin: 10px 0; }
.rv-content hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* Botão ativo nas ações rápidas */
.qa-btn.qa-active {
  background: var(--teal-glow) !important;
  border-color: var(--teal) !important;
  color: var(--teal) !important;
}
