:root {
  --bg: #0e1014;
  --bg-2: #16191f;
  --bg-3: #1d2129;
  --linha: #2a2f39;
  --texto: #e7e9ee;
  --texto-2: #9aa2b1;
  --texto-3: #6b7382;
  --acento: #6ea8fe;
  --acento-forte: #4d8ef7;
  --ok: #4ade80;
  --alerta: #fbbf24;
  --erro: #f87171;
  --raio: 10px;
  --sombra: 0 8px 24px rgba(0, 0, 0, .35);
  --fonte: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "Cascadia Mono", "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --bg-2: #ffffff;
    --bg-3: #f0f2f5;
    --linha: #dfe3e8;
    --texto: #1a1d23;
    --texto-2: #5b6472;
    --texto-3: #8a93a1;
    --acento: #2563eb;
    --acento-forte: #1d4ed8;
    --ok: #16a34a;
    --alerta: #b45309;
    --erro: #dc2626;
    --sombra: 0 6px 20px rgba(20, 25, 40, .10);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--texto);
  font-family: var(--fonte);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

code, pre, .mono { font-family: var(--mono); font-size: .88em; }
h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -.01em; }
a { color: inherit; text-decoration: none; }

/* ---------------------------------------------------------------- topo */

.topo {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; height: 56px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--linha);
}
.marca { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.marca-icone { font-size: 19px; }
.topo-agente {
  display: flex; align-items: center; gap: 8px;
  padding-left: 16px; margin-left: 2px;
  border-left: 1px solid var(--linha);
  color: var(--texto-2); font-size: 14px;
}

/* ------------------------------------------------------------- listagem */

.container { max-width: 900px; margin: 0 auto; padding: 40px 24px 80px; }
.cabecalho-pagina { margin-bottom: 28px; }
.cabecalho-pagina h1 { font-size: 26px; }
.sub { color: var(--texto-2); margin: 8px 0 0; max-width: 62ch; }
.sub code, .campo-destino {
  background: var(--bg-3); padding: 1px 5px; border-radius: 5px;
}

.grade { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.cartao {
  display: flex; flex-direction: column; justify-content: space-between; gap: 16px;
  background: var(--bg-2); border: 1px solid var(--linha);
  border-radius: var(--raio); padding: 18px;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.cartao:hover {
  border-color: var(--acento); transform: translateY(-2px); box-shadow: var(--sombra);
}
.cartao-topo { display: flex; gap: 14px; }
.cartao-icone { font-size: 26px; line-height: 1.2; }
.cartao h2 { font-size: 16px; }
.cartao-resumo { margin: 5px 0 0; color: var(--texto-2); font-size: 13.5px; }
.cartao-rodape { display: flex; gap: 8px; flex-wrap: wrap; }

.selo {
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
  padding: 3px 9px; border-radius: 20px; border: 1px solid transparent;
}
.selo-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.selo-alerta { color: var(--alerta); border-color: color-mix(in srgb, var(--alerta) 40%, transparent); }
.selo-neutro { color: var(--texto-2); border-color: var(--linha); }
/* O selo de agendamento so ganha texto depois do fetch; vazio, nao ocupa espaco. */
.selo:empty { display: none; }
.vazio { color: var(--texto-2); }

/* --------------------------------------------------------------- layout */

.layout {
  display: grid; grid-template-columns: 210px minmax(0, 1fr);
  gap: 36px; max-width: 1060px; margin: 0 auto; padding: 32px 24px 120px;
}
@media (max-width: 780px) { .layout { grid-template-columns: 1fr; gap: 12px; } .rail { display: none; } }

.rail { position: sticky; top: 84px; align-self: start; display: flex; flex-direction: column; gap: 1px; }
.rail a {
  padding: 7px 11px; border-radius: 7px; font-size: 13.5px; color: var(--texto-2);
  border-left: 2px solid transparent; transition: background .12s, color .12s;
}
.rail a:hover { background: var(--bg-2); color: var(--texto); }
.rail a.ativo { color: var(--acento); border-left-color: var(--acento); background: var(--bg-2); }

.painel { min-width: 0; display: flex; flex-direction: column; gap: 22px; }

.secao {
  background: var(--bg-2); border: 1px solid var(--linha);
  border-radius: var(--raio); padding: 22px 24px; scroll-margin-top: 76px;
}
.secao h2 { font-size: 16.5px; }
.secao-desc { margin: 6px 0 18px; color: var(--texto-2); font-size: 13.5px; max-width: 68ch; }
.carregando { color: var(--texto-3); font-size: 14px; padding: 6px 0; }

/* --------------------------------------------------------------- campos */

.campo { padding: 15px 0; border-top: 1px solid var(--linha); }
.campo:first-child { border-top: none; padding-top: 0; }
.campo-cabeca { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.campo-label { font-weight: 560; font-size: 14px; }
.campo-obrig { color: var(--acento); font-size: 12px; }
.campo-destino { font-size: 11px; color: var(--texto-3); margin-left: auto; }
.campo-ajuda { margin: 4px 0 9px; color: var(--texto-2); font-size: 13px; max-width: 68ch; }
.campo-erro { color: var(--erro); font-size: 12.5px; margin-top: 6px; }
.campo.tem-erro input, .campo.tem-erro textarea, .campo.tem-erro select { border-color: var(--erro); }

input[type="text"], input[type="number"], input[type="password"], input[type="time"],
textarea, select {
  width: 100%; max-width: 460px; padding: 8px 11px;
  background: var(--bg-3); color: var(--texto);
  border: 1px solid var(--linha); border-radius: 8px;
  font-family: inherit; font-size: 14px; transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--acento);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--acento) 20%, transparent);
}
input[type="number"] { max-width: 150px; }
input[type="time"] { max-width: 130px; }
textarea { min-height: 84px; resize: vertical; font-family: var(--mono); }
select { max-width: 260px; cursor: pointer; }

/* interruptor sim/nao */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-trilho {
  width: 40px; height: 23px; border-radius: 20px;
  background: var(--bg-3); border: 1px solid var(--linha);
  position: relative; transition: background .15s, border-color .15s;
}
.switch-trilho::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--texto-3); transition: transform .15s, background .15s;
}
.switch input:checked + .switch-trilho { background: var(--acento); border-color: var(--acento); }
.switch input:checked + .switch-trilho::after { transform: translateX(17px); background: #fff; }
.switch-texto { font-size: 13.5px; color: var(--texto-2); }

.caixas { display: flex; gap: 16px; flex-wrap: wrap; }
.caixa { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; cursor: pointer; }
.caixa input { accent-color: var(--acento); width: 15px; height: 15px; }

/* seletor de pasta do Drive */
.pasta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pasta-atual {
  display: flex; align-items: center; gap: 8px; min-width: 240px; max-width: 420px;
  padding: 8px 11px; background: var(--bg-3);
  border: 1px solid var(--linha); border-radius: 8px; font-size: 13.5px;
}
.pasta-nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pasta-id { color: var(--texto-3); font-size: 11px; font-family: var(--mono); }
.pasta-vazia { color: var(--texto-3); }

/* --------------------------------------------------------------- botoes */

.btn {
  padding: 8px 15px; border-radius: 8px; border: 1px solid transparent;
  font-family: inherit; font-size: 13.5px; font-weight: 560; cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primario { background: var(--acento-forte); color: #fff; }
.btn-primario:not(:disabled):hover { background: var(--acento); }
.btn-secundario { background: var(--bg-3); color: var(--texto); border-color: var(--linha); }
.btn-secundario:not(:disabled):hover { border-color: var(--acento); }
.btn-fantasma { background: transparent; color: var(--texto-2); }
.btn-fantasma:not(:disabled):hover { color: var(--texto); background: var(--bg-3); }
.btn-perigo { background: transparent; color: var(--erro); border-color: color-mix(in srgb, var(--erro) 35%, transparent); }
.btn-perigo:not(:disabled):hover { background: color-mix(in srgb, var(--erro) 12%, transparent); }
.btn-mini { padding: 5px 10px; font-size: 12.5px; }

/* --------------------------------------------------------- barra salvar */

.barra-salvar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--linha);
  transform: translateY(100%); transition: transform .2s ease;
}
.barra-salvar.visivel { transform: translateY(0); }
.salvar-status { margin-right: auto; font-size: 13px; color: var(--texto-2); }
.salvar-status.ok { color: var(--ok); }
.salvar-status.erro { color: var(--erro); }

/* -------------------------------------------------- agendamento/doctor */

.agenda-linha { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.agenda-info { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 16px;
  padding-top: 16px; border-top: 1px solid var(--linha); }
.agenda-item { font-size: 13px; }
.agenda-item span { display: block; color: var(--texto-3); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em; }
.aviso { color: var(--texto-2); font-size: 13.5px; }

.terminal {
  margin: 16px 0 0; padding: 14px 16px; max-height: 380px; overflow: auto;
  background: var(--bg-3); border: 1px solid var(--linha); border-radius: 8px;
  font-size: 12.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}
.oculto { display: none !important; }

/* ---------------------------------------------------------------- login */

.login-tela {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - 56px); padding: 24px;
}
.login-caixa {
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 18px;
  background: var(--bg-2); border: 1px solid var(--linha);
  border-radius: 12px; padding: 30px 28px; box-shadow: var(--sombra);
}
.login-marca { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.login-icone { font-size: 34px; }
.login-marca h1 { font-size: 17px; }
.login-campo { display: flex; flex-direction: column; gap: 6px; }
.login-campo span { font-size: 13px; color: var(--texto-2); }
.login-campo input { max-width: none; }
.login-erro {
  margin: 0; padding: 9px 12px; border-radius: 8px; font-size: 13px;
  color: var(--erro); background: color-mix(in srgb, var(--erro) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--erro) 30%, transparent);
}
.login-botao { width: 100%; padding: 10px; }

/* ---------------------------------------------------------------- modal */

.modal {
  position: fixed; inset: 0; z-index: 50; display: flex;
  align-items: center; justify-content: center; padding: 24px;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px);
}
.modal-caixa {
  width: min(560px, 100%); max-height: 78vh; display: flex; flex-direction: column;
  background: var(--bg-2); border: 1px solid var(--linha);
  border-radius: 12px; box-shadow: var(--sombra); overflow: hidden;
}
.modal-topo {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--linha);
}
.modal-topo h3 { font-size: 15px; }
.btn-fechar {
  background: none; border: none; color: var(--texto-2);
  font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.btn-fechar:hover { color: var(--texto); }
.trilha {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 10px 18px; border-bottom: 1px solid var(--linha);
  font-size: 12.5px; color: var(--texto-2);
}
.trilha button {
  background: none; border: none; color: var(--acento);
  font: inherit; cursor: pointer; padding: 2px 4px; border-radius: 5px;
}
.trilha button:hover { background: var(--bg-3); }
.trilha .sep { color: var(--texto-3); }
.trilha .atual { color: var(--texto); padding: 2px 4px; }

.lista-drive { overflow-y: auto; flex: 1; padding: 8px; min-height: 180px; }
.item-drive {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border-radius: 8px;
  background: none; border: 1px solid transparent; color: var(--texto);
  font: inherit; text-align: left; cursor: pointer;
}
.item-drive:hover { background: var(--bg-3); }
.item-drive.selecionado { background: color-mix(in srgb, var(--acento) 15%, transparent);
  border-color: var(--acento); }
.item-icone { font-size: 15px; }
.item-nome { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-entrar { color: var(--texto-3); font-size: 16px; padding: 0 4px; }
.item-drive:hover .item-entrar { color: var(--acento); }
.lista-msg { padding: 24px 14px; color: var(--texto-2); font-size: 13.5px; text-align: center; }
.lista-msg.erro { color: var(--erro); text-align: left; }

.modal-rodape {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-top: 1px solid var(--linha);
}
.modal-dica { font-size: 12.5px; color: var(--texto-3); }
