/* =====================================================================
   liaescreve — sistema visual "Editorial / Foco"
   Paleta papel-quente + tinta, tipografia serifada nos titulos,
   topo enxuto (sem rail/sidebar globais) e workspace de coluna unica.
   Distinto de EHRs SaaS: menos cromo, mais leitura.
   ===================================================================== */
:root {
  /* marca LIA — teal-esmeralda + coral (o "ia") */
  --primary: #0e6b60;          /* teal-esmeralda */
  --primary-600: #0c5c53;
  --primary-700: #0a4a43;
  --primary-050: #e7f4f1;
  --accent: #e2543c;           /* coral (o "ia") */
  --accent-600: #cf4930;
  --gold: #b8901f;
  --maroon: #8b2635;

  /* base limpa: off-white frio + tinta */
  --bg: #f4f7f5;               /* fundo suave */
  --paper: #ffffff;            /* cards */
  --panel: #ffffff;
  --ink: #16302c;              /* tinta quase-preta */
  --muted: #5d6f6a;            /* tinta suave */
  --line: #e4ece9;             /* hairline */
  --line-soft: #eef4f1;

  --danger: #b23b2b;
  --ok: #0e9f6e;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(14,74,67,.05), 0 10px 30px rgba(14,74,67,.08);
  --shadow-soft: 0 1px 2px rgba(14,74,67,.05);
  --ai-grad: linear-gradient(92deg, #0e6b60 0%, #e2543c 100%);

  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 15.5px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-700); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.center { text-align: center; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; }

/* ---------------------------------------------------------------- SHELL (rail + sidebar) */
.shell-root { min-height: 100vh; display: flex; }

/* rail de módulos à esquerda */
.rail {
  width: 68px; flex: none; background: var(--primary-700);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 0 12px; gap: 6px; position: sticky; top: 0; height: 100vh; z-index: 30;
}
.rail-logo { margin-bottom: 10px; }
.rail-logo img { width: 38px; height: 38px; border-radius: 11px; object-fit: cover; display: block; }
.rail-logo:hover { text-decoration: none; }
.rail-btn, .rail-new {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  color: #bfe0da; position: relative; transition: .15s;
}
.rail-btn:hover, .rail-new:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.rail-btn.on { background: rgba(255,255,255,.16); color: #fff; }
.rail-btn.on::before {
  content: ""; position: absolute; left: -11px; top: 12px; bottom: 12px;
  width: 4px; border-radius: 0 4px 4px 0; background: var(--accent);
}
.rail-new { background: var(--accent); color: #fff; margin-bottom: 6px; }
.rail-new:hover { background: var(--accent-600); color: #fff; }
.rail .tip {
  position: absolute; left: 56px; white-space: nowrap; background: var(--ink); color: #fff;
  font-size: 12px; font-weight: 500; padding: 5px 9px; border-radius: 7px;
  opacity: 0; pointer-events: none; transition: .12s; z-index: 40;
}
.rail-btn:hover .tip, .rail-new:hover .tip { opacity: 1; }
.rail-sp { flex: 1; }
.rail-plano {
  font-size: 10.5px; font-weight: 700; color: #cdeae4; background: rgba(255,255,255,.12);
  border-radius: 20px; padding: 3px 8px; margin-bottom: 8px; max-width: 56px;
  overflow: hidden; text-overflow: ellipsis; text-align: center;
}
.rail-plano:hover { text-decoration: none; color: #fff; background: rgba(255,255,255,.2); }

.acct-menu { position: relative; }
.acct-menu summary { list-style: none; cursor: pointer; }
.acct-menu summary::-webkit-details-marker { display: none; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.acct-pop {
  position: absolute; left: 52px; bottom: 0; width: 220px; z-index: 40;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 10px; overflow: hidden;
}
.acct-who { padding: 6px 8px 10px; border-bottom: 1px solid var(--line-soft); margin-bottom: 6px; }
.acct-who b { display: block; }
.acct-who span { color: var(--muted); font-size: 12.5px; }
.acct-pop a { display: block; padding: 8px; border-radius: 8px; color: var(--ink); font-size: 14px; }
.acct-pop a:hover { background: var(--bg); text-decoration: none; }

.main { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; height: 100vh; }
.shell { display: flex; gap: 34px; max-width: 1180px; margin: 0 auto; padding: 30px 34px 64px; }
.context { width: 250px; flex: none; }
.context:empty { display: none; }
.content { flex: 1; min-width: 0; }

/* coluna de contexto (chat/pacientes/modelos) — visual editorial */
.side-cta {
  width: 100%; border: 0; border-radius: 10px; background: var(--primary); color: #fff;
  font-weight: 600; padding: 10px 12px; cursor: pointer; display: flex; align-items: center;
  gap: 8px; font-size: 14px; margin-bottom: 6px;
}
.side-cta:hover { background: var(--primary-700); text-decoration: none; color: #fff; }
.side-link { display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 9px; color: var(--ink); font-size: 14px; margin-top: 2px; }
.side-link:hover { background: color-mix(in srgb, var(--bg) 55%, #fff); text-decoration: none; }
.side-link.active { background: var(--primary-050); color: var(--primary-700); font-weight: 600; }
.side-group { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .5px; margin: 16px 6px 6px; text-transform: uppercase; }
.side-empty { color: var(--muted); font-size: 13px; padding: 6px; line-height: 1.5; }
.side-item { display: block; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.side-item:hover { background: color-mix(in srgb, var(--bg) 55%, #fff); text-decoration: none; }
.side-item.active { background: var(--primary-050); color: var(--primary-700); font-weight: 600; }
.side-item .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------------------------------------------------------------- BUTTONS */
.btn-primary, .btn-ghost, .btn-danger, .btn-ai {
  border: 0; border-radius: 9px; padding: .55rem .95rem; cursor: pointer;
  font-weight: 600; font-size: .92rem; font-family: inherit; display: inline-block;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-700); text-decoration: none; color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { background: color-mix(in srgb, var(--bg) 55%, #fff); text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { text-decoration: none; color: #fff; filter: brightness(.95); }
.btn-ai { color: #fff; background: var(--ai-grad); }
.btn-ai:hover { text-decoration: none; color: #fff; opacity: .94; }
.block { display: block; width: 100%; text-align: center; }
button:disabled { opacity: .55; cursor: default; }

/* ---------------------------------------------------------------- AUTH */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; background:
  radial-gradient(1200px 600px at 50% -10%, #fff 0%, var(--bg) 60%); }
.auth-card { max-width: 400px; width: 100%; background: var(--paper); border: 1px solid var(--line);
  border-radius: 18px; padding: 2.2rem; box-shadow: var(--shadow); }
.auth-card .lia-logo { width: 76px; height: 76px; border-radius: 50%; object-fit: cover; display: block; margin: 0 auto .8rem; }
.auth-card h1 { margin: 0 0 .2rem; text-align: center; font-size: 1.7rem; }
.auth-card h1 .ac, .auth-card .ac { color: var(--accent); }
.auth-card .tag { text-align: center; margin-top: 0; color: var(--muted); }
form label { display: block; margin: .85rem 0; font-size: .84rem; color: var(--muted); font-weight: 600; }
form input, form select, form textarea {
  width: 100%; padding: .62rem .72rem; margin-top: .3rem; border: 1px solid var(--line);
  border-radius: 9px; font-size: .95rem; color: var(--ink); background: #fff; font-family: inherit;
}
form input:focus, form select:focus, form textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(58,81,96,.14);
}
.alert-erro { background: #fbe7e2; color: var(--danger); padding: .6rem .8rem; border-radius: 9px; font-size: .9rem; }
.alert-ok { background: #e6f2ea; color: var(--ok); padding: .6rem .8rem; border-radius: 9px; font-size: .9rem; }

/* ---------------------------------------------------------------- PAGE / LISTAS */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.4rem; gap: 1rem; }
.page-head h1 { margin: 0; font-size: 2rem; }
.page-head p { margin: .2rem 0 0; }

.lista { width: 100%; border-collapse: collapse; background: var(--paper); border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow-soft); }
.lista th, .lista td { text-align: left; padding: .85rem 1rem; border-bottom: 1px solid var(--line-soft); font-size: .92rem; }
.lista th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.lista tr:last-child td { border-bottom: 0; }
.lista tbody tr:hover td { background: color-mix(in srgb, var(--bg) 45%, #fff); }
.badge { padding: .15rem .55rem; border-radius: 20px; font-size: .76rem; font-weight: 600; }
.badge-em_andamento { background: #e6f2ea; color: var(--ok); }
.badge-pausada { background: #f6ecd6; color: var(--gold); }
.badge-finalizada { background: #ece7dc; color: var(--muted); }
.empty { text-align: center; padding: 3.4rem; background: var(--paper); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { font-family: var(--serif); font-size: 1.15rem; }

.pill { background: var(--primary-050); color: var(--primary-700); border-radius: 20px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.linkbtn { border: 0; background: transparent; color: var(--danger); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* ---------------------------------------------------------------- ATENDIMENTO (foco, coluna unica) */
.consulta-grid { display: block; max-width: 860px; margin: 0 auto; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.3rem; box-shadow: var(--shadow-soft); margin-bottom: 1.2rem; }
.panel h2 { margin: 0 0 .9rem; font-family: var(--sans); font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; }
.panel label { display: block; margin: .75rem 0; font-size: .82rem; color: var(--muted); font-weight: 600; }
.field .lbl { font-size: .82rem; color: var(--muted); font-weight: 600; }
.segmented { display: flex; gap: .5rem; margin-top: .35rem; }
.segmented label { flex: 1; border: 1px solid var(--line); border-radius: 9px; padding: .5rem; text-align: center; font-weight: 500; color: var(--ink); cursor: pointer; }
.mic-level { display: flex; align-items: center; gap: .5rem; height: 26px; background: var(--bg); border-radius: 8px; padding: 0 .6rem; margin: .5rem 0; overflow: hidden; }
.mic-level span { display: block; height: 8px; width: 0%; background: var(--accent); border-radius: 4px; transition: width .1s; }
.mic-level em { font-size: .72rem; color: var(--muted); white-space: nowrap; font-style: normal; }
.rec-controls { margin-top: 1rem; display: flex; flex-direction: column; gap: .5rem; }

.transcricao-col { display: flex; flex-direction: column; min-height: 46vh; }
.transcricao-head { display: flex; align-items: baseline; gap: 1rem; padding-bottom: .8rem; border-bottom: 1px solid var(--line-soft); }
.timer { font-variant-numeric: tabular-nums; font-size: 2rem; font-weight: 400; font-family: var(--serif); color: var(--ink); }
.transcricao-head .titulo { font-weight: 600; }
.transcricao-head .titulo em { color: var(--muted); font-style: normal; font-weight: 400; margin-left: .3rem; }
.estado { margin-left: auto; font-size: .85rem; color: var(--muted); }
.estado.rec { color: var(--accent); }
.estado.pause { color: var(--gold); }
.estado.done { color: var(--ok); }
.transcricao-body { flex: 1; overflow-y: auto; padding: 1.1rem .2rem; }
.transcricao-body { font-size: 1.06rem; line-height: 1.7; }
.placeholder { text-align: center; color: var(--muted); margin-top: 3rem; }
.placeholder .mic-ico { font-size: 2.6rem; }
.frase { padding: .4rem 0; border-bottom: 1px solid var(--line-soft); }
.frase .ts { color: var(--accent); font-size: .74rem; font-variant-numeric: tabular-nums; margin-right: .5rem; font-weight: 600; }

/* documentos (1:N em abas) */
.atend-right { display: flex; flex-direction: column; gap: 1.2rem; min-width: 0; }
.doc-block { display: flex; flex-direction: column; }
.doc-tabbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--line-soft); margin-bottom: .9rem; }
.doc-tab { border: 0; background: transparent; padding: 8px 12px; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; font-weight: 600; color: var(--muted); font-size: .9rem; border-radius: 6px 6px 0 0; }
.doc-tab:hover { color: var(--primary); background: var(--bg); }
.doc-tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.doc-tab-add { border: 1px dashed var(--line); background: transparent; color: var(--muted); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: .85rem; font-weight: 600; }
.doc-tab-add:hover { border-color: var(--primary); color: var(--primary); }
.doc-gen { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.doc-controls { display: flex; gap: .5rem; margin: .6rem 0; }
.doc-controls select { flex: 1; }
.doc-nome { width: 100%; font-family: var(--serif); font-weight: 600; font-size: 1.15rem; border: 1px solid transparent; border-radius: 6px; padding: .35rem .45rem; margin-bottom: .5rem; color: var(--ink); background: transparent; }
.doc-nome:hover { border-color: var(--line); }
.doc-nome:focus { outline: none; border-color: var(--primary); background: #fff; }
.documento { width: 100%; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: .88rem; line-height: 1.6; border: 1px solid var(--line); border-radius: 10px; padding: .8rem; background: #fff; }
.doc-view .documento { min-height: 320px; }
.doc-actions { display: flex; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }
.assinar-tog { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); margin: .3rem 0 .8rem; font-weight: 600; }
.assinar-tog input { width: auto; margin: 0; }

/* ---------------------------------------------------------------- CHAT (copiloto Lia) */
#lia-chat { display: flex; flex-direction: column; min-height: calc(100vh - 160px); }
.chat-log { flex: 1; overflow-y: auto; padding: .5rem 0 1rem; display: flex; flex-direction: column; gap: .7rem; }
.chat-hero { text-align: center; margin: auto; max-width: 640px; padding: 2rem 1rem; }
.chat-hero-logo { width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--line); }
.chat-hero h1 { font-size: 2rem; margin: .8rem 0 1.2rem; }
.chat-hero h1 .ac { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; }
.chip { border: 1px solid var(--line); background: var(--paper); border-radius: 20px; padding: 8px 14px; cursor: pointer; font-size: .9rem; color: var(--ink); }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chat-disc { margin-top: 1.4rem; font-size: .8rem; }
.msg { max-width: 76%; padding: .7rem 1rem; border-radius: 14px; white-space: pre-wrap; line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--paper); color: var(--ink); border-bottom-left-radius: 4px; border: 1px solid var(--line); }
.msg.pending { color: var(--muted); font-style: italic; }
.chat-input { display: flex; gap: .6rem; align-items: flex-end; border: 1px solid var(--line); border-radius: 14px; padding: .5rem .6rem; background: #fff; box-shadow: var(--shadow-soft); }
.chat-input textarea { flex: 1; border: 0; resize: none; font: inherit; padding: .4rem .3rem; max-height: 160px; background: transparent; }
.chat-input textarea:focus { outline: none; }
.chat-foot { text-align: center; font-size: .75rem; margin: .5rem 0 0; }

/* ---------------------------------------------------------------- PLANOS */
.planos-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.2rem; }
.plano-card { position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow-soft); display: flex; flex-direction: column; }
.plano-card.destaque { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(58,81,96,.14), var(--shadow); }
.plano-card.atual { outline: 2px solid var(--ok); outline-offset: -2px; }
.plano-tag { position: absolute; top: -11px; left: 1.5rem; background: var(--ai-grad); color: #fff; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; }
.plano-card h2 { margin: 0 0 .3rem; font-size: 1.4rem; }
.plano-preco { margin-bottom: 1rem; }
.plano-preco b { font-size: 2rem; font-family: var(--serif); }
.plano-preco span { color: var(--muted); }
.plano-feats { list-style: none; padding: 0; margin: 0 0 1.2rem; flex: 1; }
.plano-feats li { padding: .38rem 0; border-bottom: 1px solid var(--line-soft); font-size: .9rem; }
.plano-feats li:before { content: "✓ "; color: var(--ok); font-weight: 700; }

/* ---------------------------------------------------------------- VERIFICACAO CLINICA (fidelidade + escalas) */
.clinico-panel h2 { margin-bottom: .6rem; }
.clinico-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.clinico-out { margin-top: .8rem; }
.fid-score { font-size: .95rem; margin-bottom: .6rem; }
.fid-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.fid-item { display: flex; align-items: baseline; gap: 8px; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; background: #fff; }
.fid-item:hover { border-color: var(--primary); }
.fid-tag { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 20px; flex: none; }
.fid-relatado .fid-tag { background: #e6f2ea; color: var(--ok); }
.fid-conduta .fid-tag { background: var(--primary-050); color: var(--primary-700); }
.fid-inferido .fid-tag { background: #f6ecd6; color: var(--gold); }
.fid-inferido { border-style: dashed; }
.fid-txt { flex: 1; }
.fid-src { font-size: .72rem; color: var(--muted); flex: none; }
.fid-lac { margin-top: .8rem; background: #fbf1ea; border: 1px solid #efd9c9; border-radius: 10px; padding: .6rem .8rem; }
.fid-lac ul { margin: .3rem 0 0; padding-left: 1.1rem; }
.esc-card { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; margin-bottom: .7rem; background: #fff; }
.esc-head { display: flex; align-items: center; gap: 8px; margin-bottom: .4rem; }
.esc-ev { margin: .2rem 0 .5rem; padding-left: 1.1rem; font-size: .88rem; }
.esc-ev li { cursor: pointer; }
.esc-ev li:hover { color: var(--primary); }
.esc-reg { display: flex; gap: .5rem; align-items: center; }
.esc-reg .esc-score { width: 90px; }
.frase.frase-fonte { background: #fdf3d6; border-radius: 6px; box-shadow: 0 0 0 2px #f0d98a inset; transition: background .2s; }

/* ---------------------------------------------------------------- TOAST */
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 10px; font-size: .9rem; box-shadow: 0 6px 18px rgba(38,34,27,.25); z-index: 50; }
.toast.erro { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------------------------------------------------------------- RESPONSIVO */
@media (max-width: 860px) {
  .shell-root { flex-direction: column; }
  .rail {
    width: 100%; height: auto; flex-direction: row; position: sticky; top: 0;
    padding: 8px 12px; gap: 4px;
  }
  .rail-logo { margin-bottom: 0; margin-right: 4px; }
  .rail-sp { flex: 1; }
  .rail .tip { display: none; }
  .acct-pop { left: auto; right: 0; bottom: auto; top: 52px; }
  .main { height: auto; overflow: visible; }
  .shell { flex-direction: column; padding: 20px 16px 48px; }
  .context { width: auto; }
  .consulta-grid { max-width: none; }
  .page-head h1 { font-size: 1.6rem; }
}
