/* ============================================================
   Design system — Painel da Clínica
   Clean/saúde: azul-petróleo + teal, cards rounded-xl, shadow-sm.
   Sem framework: variáveis CSS + dark mode via [data-theme].
   ============================================================ */

:root {
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --border: #E2E8F0;
  --text: #0F172A;
  --muted: #64748B;
  --primary: #0891B2;        /* azul-médico (cyan-600) */
  --primary-strong: #0E7490;
  --primary-soft: #ECFEFF;
  --accent: #0D9488;         /* teal */
  --ok: #059669;  --ok-soft: #ECFDF5;
  --warn: #D97706; --warn-soft: #FFFBEB;
  --err: #DC2626;  --err-soft: #FEF2F2;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #0B1220;
  --card: #111A2C;
  --border: #1E293B;
  --text: #E2E8F0;
  --muted: #94A3B8;
  --primary: #22D3EE;
  --primary-strong: #06B6D4;
  --primary-soft: #113344;
  --ok-soft: #062E23; --warn-soft: #33230A; --err-soft: #3A1214;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.55 -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .87rem; }
.error { color: var(--err); font-size: .87rem; min-height: 1em; }
h1 { font-size: 1.25rem; margin: 0 0 .75rem; }
h2 { font-size: 1.02rem; margin: 0 0 .8rem; font-weight: 650; }
a { color: var(--primary); }
ul { padding-left: 1.2rem; margin: .4rem 0; }
li { margin-bottom: .25rem; }

/* ------------------------------------------------------------ login */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--bg) 55%, var(--primary-soft));
}
.login .card { width: 350px; text-align: center; padding: 2rem 1.6rem; }
.login .logo {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto .8rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
}
.login input { width: 100%; margin-bottom: .7rem; }
.login button { width: 100%; margin-top: .3rem; }

/* ------------------------------------------------------------ shell */
#app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--card); border-right: 1px solid var(--border);
  padding: 1.1rem .8rem .8rem; display: flex; flex-direction: column; gap: .15rem;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; padding: 0 .5rem .9rem; font-size: 1.02rem; }
.brand .dot {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.nav-label { font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: .8rem .6rem .3rem; }
button.nav {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  background: none; border: 0; text-align: left; cursor: pointer;
  padding: .55rem .65rem; border-radius: 10px; color: var(--muted);
  font: inherit; font-weight: 500;
}
button.nav:hover { background: var(--bg); color: var(--text); }
button.nav.active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 650; }
[data-theme="dark"] button.nav.active { color: var(--primary); }
button.nav svg { width: 17px; height: 17px; flex: none; }
.sidebar .spacer { flex: 1; }
.userchip {
  display: flex; align-items: center; gap: .55rem; padding: .7rem .6rem 0;
  border-top: 1px solid var(--border); margin-top: .5rem;
}
.userchip .avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--primary-soft); color: var(--primary-strong);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .8rem;
}
.userchip .info { line-height: 1.2; overflow: hidden; flex: 1; }
.userchip .info b { font-size: .85rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userchip .info span { font-size: .72rem; color: var(--muted); }
.iconbtn { background: none; border: 0; cursor: pointer; color: var(--muted); padding: .3rem; border-radius: 8px; font-size: .95rem; }
.iconbtn:hover { background: var(--bg); color: var(--text); }

/* header */
.topbar {
  display: flex; align-items: center; gap: .55rem; flex-wrap: wrap;
  padding: .9rem 1.6rem; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) 85%, transparent);
  backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 1.1rem; flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: .38rem;
  font-size: .76rem; font-weight: 600; padding: .28rem .65rem;
  border-radius: 999px; border: 1px solid var(--border); background: var(--card);
  color: var(--muted);
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.ok { color: var(--ok); } .pill.ok .dot { background: var(--ok); }
.pill.warn { color: var(--warn); } .pill.warn .dot { background: var(--warn); }
.pill.err { color: var(--err); } .pill.err .dot { background: var(--err); }

main { padding: 1.4rem 1.6rem 5rem; max-width: 1060px; width: 100%; }

/* ------------------------------------------------------------ cards */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem; margin-bottom: 1.1rem;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; align-items: start; }
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav-label, .userchip { display: none; }
  button.nav { width: auto; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------ forms */
label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin: .65rem 0 .25rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: .5rem .7rem;
  outline: none; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
textarea { width: 100%; min-height: 130px; resize: vertical; line-height: 1.5; }
.charcount { text-align: right; font-size: .72rem; color: var(--muted); margin-top: .2rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-top: .5rem; }
.row input, .row select { flex: 1; min-width: 120px; }
.row > div { display: flex; flex-direction: column; min-width: 140px; }
.row > div label { margin: 0 0 .25rem; }

button.primary, button.small {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent;
  transition: filter .12s, background .12s;
}
button.primary {
  background: var(--primary); color: #fff; font-weight: 650;
  padding: .55rem 1.2rem; margin-top: .8rem;
}
button.primary:hover { background: var(--primary-strong); }
button.small {
  background: var(--primary-soft); color: var(--primary-strong);
  font-size: .82rem; font-weight: 600; padding: .42rem .8rem;
}
[data-theme="dark"] button.small { color: var(--primary); }
button.small:hover { filter: brightness(.96); }
button.small.danger, button.danger { background: var(--err-soft); color: var(--err); }

/* ------------------------------------------------------------ tables */
table { width: 100%; border-collapse: collapse; margin-top: .5rem; font-size: .88rem; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .45rem .6rem; border-bottom: 1px solid var(--border); }
td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; text-align: left; }
tbody tr:hover { background: color-mix(in srgb, var(--primary-soft) 40%, transparent); }
tbody tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-flex; align-items: center; gap: .32rem;
  font-size: .74rem; font-weight: 650; padding: .18rem .6rem; border-radius: 999px;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }

/* ------------------------------------------------------------ dropzone */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 1.6rem 1rem; text-align: center; color: var(--muted);
  cursor: pointer; transition: border-color .15s, background .15s; margin-top: .6rem;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary-soft) 55%, transparent);
  color: var(--primary-strong);
}
.dropzone svg { width: 34px; height: 34px; opacity: .75; margin-bottom: .35rem; }
.dropzone .hint { font-size: .78rem; }
.dropzone.uploading { pointer-events: none; opacity: .7; }
.progress { height: 5px; border-radius: 4px; background: var(--border); overflow: hidden; margin-top: .7rem; }
.progress > i { display: block; height: 100%; width: 40%; background: var(--primary); border-radius: 4px; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

/* --------------------------------------------------- chat / playground */
.chat { max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: .45rem; padding: .3rem 0; }
.msg { max-width: 84%; padding: .5rem .8rem; border-radius: 14px; font-size: .88rem; white-space: pre-wrap; }
.msg .muted { display: block; font-size: .68rem; margin-top: .15rem; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.user .muted { color: rgba(255,255,255,.75); }
.msg.assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.drawer {
  position: fixed; top: 0; right: -430px; width: 400px; max-width: 96vw; height: 100vh;
  background: var(--card); border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(15,23,42,.12);
  display: flex; flex-direction: column; transition: right .25s ease; z-index: 40;
}
.drawer.open { right: 0; }
.drawer header { display: flex; align-items: center; gap: .6rem; padding: .9rem 1rem; border-bottom: 1px solid var(--border); }
.drawer header h2 { margin: 0; flex: 1; }
.drawer .chat { flex: 1; max-height: none; padding: 1rem; }
.drawer footer { display: flex; gap: .5rem; padding: .8rem 1rem; border-top: 1px solid var(--border); }
.drawer footer input { flex: 1; }
.typing { display: inline-flex; gap: 4px; padding: .6rem .8rem; align-self: flex-start; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.fab {
  position: fixed; right: 1.4rem; bottom: 1.4rem; z-index: 30;
  display: flex; align-items: center; gap: .5rem;
  background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff;
  border: 0; border-radius: 999px; padding: .7rem 1.15rem; font: inherit; font-weight: 650;
  cursor: pointer; box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 40%, transparent);
}
.fab:hover { filter: brightness(1.06); }

/* ------------------------------------------------------------- avisos */
#toasts {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: .5rem; align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--text); color: var(--card); border-radius: 999px;
  padding: .55rem 1.1rem; font-size: .87rem; font-weight: 550;
  box-shadow: 0 6px 20px rgba(15,23,42,.25); animation: sobe .25s ease;
  max-width: 90vw;
}
.toast.erro { background: var(--err); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes sobe { from { opacity: 0; transform: translateY(10px); } }

/* ------------------------------------ linhas editáveis (serviços etc.) */
.linha {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .2rem; border-bottom: 1px solid var(--border);
}
.linha:last-child { border-bottom: 0; }
.linha .nome { flex: 1; min-width: 0; font-weight: 550; }
.linha .nome small { display: block; font-weight: 400; color: var(--muted); font-size: .76rem; }
.linha .acoes { display: flex; gap: .3rem; flex: none; }
.linha.inativa .nome { opacity: .5; text-decoration: line-through; }
.linha .valor-preco { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .87rem; }

.editor-linha { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; padding: .6rem .2rem; background: var(--bg); border-radius: 10px; margin: .3rem 0; }
.editor-linha label { margin: 0 0 .2rem; }
.editor-linha .campo { display: flex; flex-direction: column; }
.editor-linha input[type=text] { min-width: 200px; }
.editor-linha input[type=number] { width: 92px; }

/* seletor de dias da semana */
.dias { display: flex; gap: .3rem; flex-wrap: wrap; }
.dias label {
  margin: 0; cursor: pointer; user-select: none;
  border: 1px solid var(--border); border-radius: 8px; padding: .32rem .55rem;
  font-size: .78rem; font-weight: 600; color: var(--muted); background: var(--card);
}
.dias input { display: none; }
.dias input:checked + span { color: var(--primary-strong); }
.dias label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
[data-theme="dark"] .dias input:checked + span { color: var(--primary); }

.horario-grupo {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .6rem; background: var(--bg); border-radius: 8px; margin-bottom: .35rem;
}
.horario-grupo .dias-txt { flex: 1; font-size: .87rem; }
.horario-grupo .hora { font-variant-numeric: tabular-nums; font-weight: 600; }

.prof-bloco { padding: .9rem 0; border-bottom: 1px solid var(--border); }
.prof-bloco:last-child { border-bottom: 0; }
.prof-bloco > .cabecalho { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.prof-bloco > .cabecalho strong { font-size: .98rem; }

/* --------------------------------------------------- métricas do topo */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .8rem; margin-bottom: 1.1rem; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .85rem 1rem; box-shadow: var(--shadow);
}
.stat .valor { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat .rotulo { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: .15rem; }
.stat.destaque .valor { color: var(--primary-strong); }
[data-theme="dark"] .stat.destaque .valor { color: var(--primary); }
.stat.alerta .valor { color: var(--warn); }

/* estado vazio */
.vazio { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.vazio .icone { font-size: 2rem; opacity: .5; display: block; margin-bottom: .4rem; }
.vazio b { display: block; color: var(--text); margin-bottom: .2rem; font-size: .95rem; }

/* seções agrupadas (conversas por profissional) */
.grupo-titulo {
  display: flex; align-items: center; gap: .5rem; margin: 1.2rem 0 .4rem;
  font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
}
.grupo-titulo::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.grupo-titulo .contagem {
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  padding: .05rem .5rem; font-size: .7rem; letter-spacing: 0; text-transform: none;
}

/* lista de conversas (mestre-detalhe) */
.conversas { display: grid; grid-template-columns: 320px 1fr; gap: 1.1rem; align-items: start; }
@media (max-width: 900px) { .conversas { grid-template-columns: 1fr; } }
.conv-lista { max-height: 560px; overflow-y: auto; padding-right: .2rem; }
.conv-item {
  display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left;
  background: none; border: 1px solid transparent; border-radius: 10px;
  padding: .5rem .6rem; cursor: pointer; font: inherit; color: inherit;
}
.conv-item:hover { background: var(--bg); }
.conv-item.ativo { background: var(--primary-soft); border-color: var(--primary); }
.conv-item .avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; font-size: .78rem; font-weight: 700;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
.conv-item.ativo .avatar { background: var(--card); color: var(--primary-strong); border-color: var(--primary); }
.conv-item .info { flex: 1; min-width: 0; line-height: 1.25; }
.conv-item .info b { display: block; font-size: .87rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .info span { font-size: .72rem; color: var(--muted); }
.conv-item .pausado { font-size: .65rem; color: var(--warn); font-weight: 700; }

.conv-detalhe { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.conv-detalhe header {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .7rem .9rem; border-bottom: 1px solid var(--border); background: var(--bg);
}
.conv-detalhe header .titulo { font-weight: 650; }
.conv-detalhe header .spacer { flex: 1; }
.conv-detalhe .chat { padding: .9rem; max-height: 460px; }

.busca { position: relative; margin-bottom: .6rem; }
.busca input { width: 100%; padding-left: 2rem; }
.busca::before { content: "🔍"; position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); font-size: .8rem; opacity: .6; }

/* ------------------------------------------------- calendário semanal */
.cal-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem; flex-wrap: wrap; }
.cal-head .spacer { flex: 1; }
.toggle-view { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.toggle-view button {
  background: var(--card); border: 0; padding: .4rem .9rem; cursor: pointer;
  font: inherit; font-size: .85rem; color: var(--muted);
}
.toggle-view button.active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 650; }
[data-theme="dark"] .toggle-view button.active { color: var(--primary); }

.calendario { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .5rem; }
.cal-dia {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: .5rem; min-height: 110px; display: flex; flex-direction: column; gap: .3rem;
}
.cal-dia.hoje { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 18%, transparent); }
.cal-dia .dia-nome { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.cal-dia .dia-num { font-weight: 700; font-size: 1rem; margin-bottom: .2rem; }
.cal-item {
  background: var(--primary-soft); color: var(--primary-strong);
  border-radius: 6px; padding: .25rem .4rem; font-size: .72rem; line-height: 1.25;
  cursor: default;
}
[data-theme="dark"] .cal-item { color: var(--primary); }
.cal-item.pendente { background: var(--warn-soft); color: var(--warn); }
.cal-item b { display: block; font-size: .74rem; }
.cal-vazio { color: var(--muted); font-size: .72rem; }
@media (max-width: 900px) {
  .calendario { grid-template-columns: 1fr; }
  .cal-dia { min-height: auto; flex-direction: row; align-items: baseline; flex-wrap: wrap; }
  .cal-dia .dia-num { margin: 0 .4rem 0 0; }
}

/* prompt preview */
pre.prompt {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: .9rem 1rem; white-space: pre-wrap; font-size: .8rem; line-height: 1.5;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  max-height: 420px; overflow-y: auto;
}
.qr { text-align: center; padding: .6rem; }
.qr img { width: 240px; height: 240px; border: 1px solid var(--border); border-radius: 10px; }
