:root {
  --bg: #0f1216;
  --bg-2: #161a20;
  --bg-3: #1e242c;
  --line: #262d36;
  --line-2: #303843;
  --text: #e3e8ee;
  --muted: #7c8794;
  --brand: #6b8db8;
  --brand-2: #88a6cc;
  --brand-soft: #1a2330;
  --accent: #67b27c;
  --warn: #d4a44a;
  --danger: #c97070;
  --radius: 10px;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); min-height: 100vh; font-size: 14.5px; -webkit-font-smoothing: antialiased; }
body { background-image: url("/assets/bg-medical.svg"); background-repeat: repeat; background-size: 320px 320px; background-attachment: fixed; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px; }
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.card.narrow { width: 100%; max-width: 400px; }

.logo { font-weight: 600; font-size: 16px; letter-spacing: -.01em; }
.logo .dot { color: var(--brand); }

h1 { font-size: 22px; margin: 0 0 6px; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 10px; font-weight: 600; }
h3 { font-size: 14px; margin: 0; font-weight: 600; }
p.muted, .muted { color: var(--muted); margin: 0; }

label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], textarea, select {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-3); color: var(--text);
  outline: none; font: inherit; font-size: 14px; transition: border-color .12s;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); }
textarea { resize: vertical; min-height: 70px; font-family: inherit; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-2); background: transparent; color: var(--text); font-weight: 500; font-size: 13.5px; transition: background .12s, border-color .12s; text-decoration: none; }
.btn:hover { background: var(--bg-3); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: white; }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.danger { border-color: rgba(201,112,112,.4); color: var(--danger); }
.btn.danger:hover { background: rgba(201,112,112,.08); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg-3); color: var(--text); }
.btn.block { width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn svg { width: 14px; height: 14px; }

.form-actions { margin-top: 18px; display: flex; gap: 8px; justify-content: flex-end; }
.form-actions.between { justify-content: space-between; }

.flash { padding: 9px 12px; border-radius: 8px; margin: 10px 0; font-size: 13px; }
.flash.error { background: rgba(201,112,112,.1); border: 1px solid rgba(201,112,112,.3); color: #e3a4a4; }
.flash.ok { background: rgba(103,178,124,.08); border: 1px solid rgba(103,178,124,.3); color: #a7d4b5; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--bg-2); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(8px); }
.topbar .right { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-2); display: grid; place-items: center; font-weight: 600; font-size: 13px; border: 1px solid var(--line-2); }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }

/* stats */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 18px 0; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .lbl { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 500; }
.stat .val { font-size: 22px; font-weight: 600; margin-top: 4px; letter-spacing: -.01em; }
.stat .val.muted { color: var(--muted); }
.stat .sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* cards de consulta */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.cons-card {
  position: relative;
  background: linear-gradient(180deg, #1d242d 0%, #161a20 100%);
  border: 1px solid var(--line);
  border-top-color: #303843;
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.04),
    0 1px 2px rgba(0,0,0,.25),
    0 4px 10px rgba(0,0,0,.18),
    0 12px 24px rgba(0,0,0,.10);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.cons-card::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: linear-gradient(180deg, rgba(107,141,184,.06) 0%, transparent 40%);
  opacity: .8;
}
.cons-card:hover {
  transform: translateY(-2px);
  border-color: #3a4654;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.05),
    0 2px 3px rgba(0,0,0,.30),
    0 8px 16px rgba(0,0,0,.22),
    0 20px 40px rgba(0,0,0,.15);
}
.cons-card > * { position: relative; }
.cons-card .codigo { font-family: ui-monospace, 'JetBrains Mono', monospace; font-size: 15px; color: var(--brand-2); letter-spacing: .06em; }
.cons-card .meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.cons-card .row { display: flex; gap: 5px; margin-top: 12px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid rgba(48,56,67,.5); }
.cons-card .titulo { font-weight: 500; margin-top: 6px; font-size: 13.5px; }
.cons-card .paciente { margin-top: 8px; font-size: 13px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 7px; border-radius: 4px; font-size: 10.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; border: 1px solid; }
.badge.aberta { border-color: rgba(107,141,184,.4); color: var(--brand-2); background: rgba(107,141,184,.08); }
.badge.resolvida { border-color: var(--line-2); color: var(--muted); }
.badge.online { border-color: rgba(103,178,124,.4); color: var(--accent); background: rgba(103,178,124,.08); }
.badge.offline { border-color: var(--line-2); color: var(--muted); }
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.panel { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 16px; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 4px 14px 0; border-bottom: 1px solid var(--line); }
.panel-tabs { display: flex; gap: 2px; }
.panel-tabs button { background: transparent; border: 0; color: var(--muted); padding: 12px 14px; font-weight: 500; font-size: 13px; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; transition: color .12s; }
.panel-tabs button.active { color: var(--text); border-bottom-color: var(--brand); }
.panel-tabs button:hover { color: var(--text); }

.panel-tools { display: flex; gap: 8px; align-items: center; padding: 8px 0; flex-wrap: wrap; }
.panel-tools .search { position: relative; }
.panel-tools .search svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 13px; height: 13px; pointer-events: none; }
.panel-tools .search input { width: 220px; padding: 6px 10px 6px 28px; font-size: 13px; border-radius: 6px; }
.panel-tools select { width: auto; padding: 6px 26px 6px 10px; font-size: 13px; border-radius: 6px; appearance: none; -webkit-appearance: none; -moz-appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%237c8794' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>"); background-repeat: no-repeat; background-position: right 9px center; background-size: 10px; cursor: pointer; }
.panel-tools .count { font-size: 12px; color: var(--muted); margin-left: auto; padding-left: 8px; white-space: nowrap; }

.panel-body { padding: 14px; }
.panel-body .empty { padding: 40px 20px; border: none; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin: 0 0 4px; }

/* CHAT */
.chat-shell { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }
.chat-header { display: flex; align-items: center; gap: 12px; padding: 11px 18px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.chat-header .avatar { width: 40px; height: 40px; font-size: 15px; }
.chat-header .info { flex: 1; min-width: 0; }
.chat-header .info .name { font-weight: 600; font-size: 15px; }
.chat-header .info .sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.chat-header .presenca { display: flex; align-items: center; gap: 8px; }

.chat-body { flex: 1; overflow-y: auto; padding: 22px 18px; display: flex; flex-direction: column; gap: 10px; }
.day-sep { text-align: center; font-size: 10.5px; color: var(--muted); padding: 8px 0; text-transform: uppercase; letter-spacing: .08em; }

.msg-row { display: flex; gap: 8px; align-items: flex-end; max-width: 78%; animation: slideIn .12s ease-out; }
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.theirs { align-self: flex-start; }
.msg-avatar { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; border: 1px solid var(--line); margin-bottom: 14px; }
.msg-avatar.psicologo { background: var(--brand-soft); color: var(--brand-2); border-color: rgba(107,141,184,.35); }
.msg-avatar.paciente { background: rgba(103,178,124,.08); color: var(--accent); border-color: rgba(103,178,124,.3); }
.msg-avatar svg { width: 16px; height: 16px; }
.msg-stack { display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.msg-row.mine .msg-stack { align-items: flex-end; }
.msg-bubble { padding: 8px 12px 6px; border-radius: 12px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; font-size: 14px; }
.msg-row.mine .msg-bubble { background: var(--brand); color: white; border-bottom-right-radius: 3px; }
.msg-row.theirs .msg-bubble { background: var(--bg-2); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.msg-bubble .time { font-size: 9.5px; margin-top: 3px; text-align: right; color: var(--muted); }
.msg-row.mine .msg-bubble .time { color: rgba(255,255,255,.7); }
.msg-name { font-size: 10px; color: var(--muted); margin-top: 3px; padding: 0 4px; }
.msg.sys { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 4px 10px; }

@keyframes slideIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

.typing { align-self: flex-start; color: var(--muted); font-size: 11.5px; padding: 3px 12px 3px 46px; font-style: italic; }
.typing .dots { display: inline-flex; gap: 3px; margin-left: 4px; }
.typing .dots span { width: 4px; height: 4px; background: var(--muted); border-radius: 50%; animation: bounce 1.2s infinite; }
.typing .dots span:nth-child(2) { animation-delay: .15s; }
.typing .dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-3px); opacity: 1; } }

.chat-foot { background: var(--bg-2); border-top: 1px solid var(--line); padding: 10px 14px; }
.composer { display: flex; gap: 9px; align-items: flex-end; max-width: 1100px; margin: 0 auto; }
.composer textarea { flex: 1; min-height: 40px; max-height: 180px; padding: 10px 12px; border-radius: 12px; resize: none; line-height: 1.4; font-size: 14px; }
.composer .send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--brand); color: white; display: grid; place-items: center; transition: background .12s; }
.composer .send:hover { background: var(--brand-2); }
.composer .send:disabled { background: var(--bg-3); color: var(--muted); cursor: not-allowed; }

.banner-fim { text-align: center; padding: 12px; background: var(--bg-2); color: var(--muted); border-top: 1px solid var(--line); font-size: 13px; }
.banner-fim.danger { color: var(--danger); }

/* paciente entrada */
.paciente-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.paciente-card { width: 100%; max-width: 420px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.paciente-card .psic-info { display: flex; align-items: center; gap: 12px; padding-bottom: 16px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.paciente-card .psic-info .avatar { width: 48px; height: 48px; font-size: 16px; }
.paciente-card .psic-info .name { font-weight: 600; font-size: 15px; }
.paciente-card .psic-info .crp { font-size: 11.5px; color: var(--muted); margin-top: 1px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-bg.open { display: flex; }
.modal { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; max-width: 460px; width: 100%; max-height: 90vh; overflow-y: auto; }
.modal.lg { max-width: 600px; }
.modal h2 { display: flex; justify-content: space-between; align-items: center; }
.modal .close-x { background: transparent; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; padding: 0 4px; line-height: 1; }
.modal .close-x:hover { color: var(--text); }

.copy-row { display: flex; gap: 6px; margin-top: 8px; }
.copy-row input { font-family: ui-monospace, monospace; font-size: 13px; }

/* profile dropdown */
.profile-trigger { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer; transition: background .12s; }
.profile-trigger:hover { background: var(--bg-3); }
.profile-trigger .nome-small { font-size: 13px; }
.profile-trigger svg { width: 12px; height: 12px; color: var(--muted); }
.profile-pop { position: absolute; top: 54px; right: 24px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); min-width: 200px; padding: 6px; display: none; z-index: 20; }
.profile-pop.open { display: block; }
.profile-pop button, .profile-pop a { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border-radius: 6px; border: 0; background: transparent; color: var(--text); text-align: left; font-size: 13.5px; cursor: pointer; }
.profile-pop button:hover, .profile-pop a:hover { background: var(--bg-3); text-decoration: none; }
.profile-pop button svg, .profile-pop a svg { width: 14px; height: 14px; color: var(--muted); }
.profile-pop .sep { height: 1px; background: var(--line); margin: 4px 0; }

/* detalhes consulta */
.det-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 14px 0 8px; }
.det-grid .field .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.det-grid .field .val { font-size: 14px; margin-top: 2px; }
.det-grid .field.full { grid-column: 1/-1; }

/* TOUR / onboarding */
.tour-spotlight {
  position: fixed; z-index: 80; border-radius: 10px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(8, 11, 15, .78), 0 0 0 2px rgba(107, 141, 184, .6), 0 0 24px rgba(107, 141, 184, .4);
  transition: top .28s ease, left .28s ease, width .28s ease, height .28s ease, opacity .2s ease;
}
.tour-spotlight.full { box-shadow: 0 0 0 9999px rgba(8, 11, 15, .82); }
.tour-tooltip {
  position: fixed; z-index: 82; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 16px 18px 14px; max-width: 340px; width: max-content; min-width: 260px;
  box-shadow: 0 14px 36px rgba(0,0,0,.5), 0 4px 10px rgba(0,0,0,.3);
  transition: top .28s ease, left .28s ease, opacity .2s ease;
  animation: tourIn .25s ease-out;
}
.tour-tooltip.centro { left: 50% !important; top: 50% !important; transform: translate(-50%, -50%); max-width: 380px; }
@keyframes tourIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.tour-tooltip.centro { animation: tourCentroIn .25s ease-out; }
@keyframes tourCentroIn { from { opacity: 0; transform: translate(-50%, -48%); } to { opacity: 1; transform: translate(-50%, -50%); } }

.tour-tooltip .step-label { font-size: 10.5px; color: var(--brand-2); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; }
.tour-tooltip h3 { font-size: 15.5px; margin: 4px 0 8px; font-weight: 600; }
.tour-tooltip p { font-size: 13.5px; color: var(--muted); margin: 0; line-height: 1.5; }
.tour-tooltip .actions { display: flex; justify-content: space-between; margin-top: 16px; gap: 10px; align-items: center; }
.tour-tooltip .actions .right { display: flex; gap: 8px; align-items: center; }
.tour-tooltip .skip { font-size: 12px; color: var(--muted); background: transparent; border: 0; cursor: pointer; padding: 4px 2px; }
.tour-tooltip .skip:hover { color: var(--text); text-decoration: underline; }
.tour-progress { display: flex; gap: 4px; }
.tour-progress span { width: 16px; height: 3px; background: var(--line); border-radius: 2px; transition: background .2s; }
.tour-progress span.done { background: var(--brand); }
.tour-progress span.current { background: var(--brand-2); }

.tour-tooltip::before {
  content: ''; position: absolute; width: 12px; height: 12px; background: var(--bg-2);
  border: 1px solid var(--line-2); transform: rotate(45deg);
}
.tour-tooltip.seta-top::before { top: -7px; left: 30px; border-right: 0; border-bottom: 0; }
.tour-tooltip.seta-top.seta-direita::before { left: auto; right: 30px; }
.tour-tooltip.seta-bottom::before { bottom: -7px; left: 30px; border-left: 0; border-top: 0; }
.tour-tooltip.seta-bottom.seta-direita::before { left: auto; right: 30px; }
.tour-tooltip.seta-left::before { left: -7px; top: 24px; border-top: 0; border-right: 0; }
.tour-tooltip.seta-right::before { right: -7px; top: 24px; border-bottom: 0; border-left: 0; }
.tour-tooltip.centro::before { display: none; }

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .container { padding: 14px; }
  .card { padding: 18px; }
  .msg-row { max-width: 92%; }
  .profile-pop { right: 14px; }
  .panel-head { padding: 4px 10px 0; }
  .panel-body { padding: 10px; }
  .panel-tools .search input { width: 160px; }
}
