/* =====================================================================
   Agenda LSPR — Loja de Saúde de Prado
   ===================================================================== */

@font-face {
    font-family: "Inter";
    src: url("fonts/inter.woff2") format("woff2");
    font-weight: 100 900;
    font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Inter";
    src: url("fonts/inter-ext.woff2") format("woff2");
    font-weight: 100 900;
    font-display: swap;
    unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
    --primaria: #0a9cb8;
    --primaria-escura: #077f96;
    --primaria-suave: #e7f6f9;
    --primaria-anel: rgba(10, 156, 184, .22);
    --verde: #7ab648;
    --verde-escuro: #4f8a26;
    --verde-suave: #eef7e7;
    --perigo: #d0342c;
    --perigo-suave: #fdeeed;
    --aviso: #b7791f;
    --aviso-suave: #fdf6e7;

    --texto: #15232b;
    --texto-2: #52636b;
    --texto-3: #87969d;
    --borda: #e4e9ec;
    --borda-forte: #d2dbdf;
    --fundo: #f4f6f8;
    --superficie: #ffffff;
    --superficie-2: #f9fbfb;

    --raio: 12px;
    --raio-p: 8px;
    --sombra-1: 0 1px 2px rgba(15, 35, 45, .06);
    --sombra-2: 0 1px 3px rgba(15, 35, 45, .06), 0 6px 20px rgba(15, 35, 45, .06);
    --sombra-3: 0 12px 40px rgba(15, 35, 45, .18);
    --topbar: 64px;
    --nav-inferior: 0px;
    --seguro-baixo: env(safe-area-inset-bottom, 0px);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body {
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    color: var(--texto);
    background: var(--fundo);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    font-feature-settings: "cv11", "ss01";
}
body.com-modal { overflow: hidden; }
a { color: var(--primaria-escura); }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 4px; }
h1 small { color: var(--texto-3); font-weight: 500; font-size: 15px; }
h2 { font-size: 16px; font-weight: 650; letter-spacing: -.01em; margin: 0 0 14px; }
h3 { font-size: 12px; font-weight: 650; margin: 22px 0 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--texto-3); }
small { color: var(--texto-3); }
code { background: var(--fundo); padding: 1px 6px; border-radius: 5px; font-size: 12px; }
.ico { width: 18px; height: 18px; flex-shrink: 0; vertical-align: middle; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

/* ---------- Topbar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 50;
    height: var(--topbar);
    display: flex; align-items: center; gap: 28px;
    padding: 0 20px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    background: rgba(255, 255, 255, .92);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--borda);
}
.topbar::before {
    content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px;
    background: linear-gradient(90deg, var(--primaria), var(--verde));
}
.topbar-logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--texto); flex-shrink: 0; }
.topbar-logo img { height: 38px; width: auto; display: block; }
.topbar-marca { display: flex; flex-direction: column; line-height: 1.15; }
.topbar-marca strong { font-size: 14px; font-weight: 650; color: var(--texto); white-space: nowrap; }
.topbar-marca small { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .12em; color: var(--verde-escuro); }
.topbar-nav { display: flex; gap: 2px; height: 100%; }
.topbar-nav a {
    position: relative; display: flex; align-items: center; gap: 8px;
    padding: 0 14px; color: var(--texto-2); text-decoration: none; font-weight: 550;
    transition: color .15s;
}
.topbar-nav a:hover { color: var(--texto); }
.topbar-nav a.ativo { color: var(--primaria-escura); }
.topbar-nav a.ativo::after {
    content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px;
    background: var(--primaria); border-radius: 2px 2px 0 0;
}
.topbar-direita { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-data {
    display: flex; align-items: center; gap: 8px;
    color: var(--texto-2); font-weight: 550; white-space: nowrap;
    padding: 8px 12px; background: var(--fundo); border-radius: 999px; font-size: 13px;
}
.topbar-data .ico { width: 16px; height: 16px; color: var(--primaria); }
.data-curta { display: none; }
.btn-icone {
    width: 40px; height: 40px; border-radius: 50%;
    border: 1px solid var(--borda); background: var(--superficie); cursor: pointer;
    display: grid; place-items: center; color: var(--texto-2);
    transition: all .15s;
}
.btn-icone:hover { color: var(--primaria-escura); border-color: var(--primaria); background: var(--primaria-suave); }

.menu-utilizador { position: relative; }
.btn-utilizador {
    display: flex; align-items: center; gap: 8px; padding: 3px 12px 3px 3px;
    border: 1px solid var(--borda); background: var(--superficie); border-radius: 999px; cursor: pointer;
    font-weight: 550; transition: border-color .15s;
}
.btn-utilizador:hover { border-color: var(--borda-forte); }
.avatar {
    width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primaria), var(--verde)); color: #fff; font-weight: 700; font-size: 13px;
}
.menu-dropdown {
    position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px;
    background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); box-shadow: var(--sombra-3);
    padding: 6px; z-index: 60;
    opacity: 0; visibility: hidden; transform: translateY(-4px); transition: all .15s;
}
.menu-dropdown.aberto { opacity: 1; visibility: visible; transform: none; }
.menu-cabecalho { padding: 10px 12px; border-bottom: 1px solid var(--borda); margin-bottom: 4px; }
.menu-cabecalho strong, .menu-cabecalho small { display: block; }
.menu-dropdown a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--raio-p); text-decoration: none; color: var(--texto); }
.menu-dropdown a .ico { color: var(--texto-3); }
.menu-dropdown a:hover { background: var(--fundo); }

/* Navegação inferior (telemóvel) */
.nav-inferior { display: none; }

/* ---------- Conteúdo ---------- */
.conteudo { padding: 24px; max-width: 1440px; margin: 0 auto; }
.cartao {
    background: var(--superficie); border-radius: var(--raio); box-shadow: var(--sombra-1);
    border: 1px solid var(--borda); padding: 22px; margin-bottom: 20px;
}
.cartao > h2:first-child { margin-top: 0; }
.cartao-estreito { max-width: 560px; }
.cabecalho-pagina { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.cabecalho-pagina h1, .cabecalho-pagina h2 { margin: 0; margin-right: auto; }
.subtitulo { color: var(--texto-2); margin: 2px 0 0; }
.migalhas { margin: 0 0 14px; }
.migalhas a { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; color: var(--texto-2); font-weight: 550; }
.migalhas a:hover { color: var(--primaria-escura); }
.meta { color: var(--texto-3); margin: 0 0 18px; font-size: 13px; }
.vazio { color: var(--texto-3); text-align: center; padding: 28px 16px; }
.ajuda { color: var(--texto-2); font-size: 13px; line-height: 1.55; }
.pre { white-space: pre-wrap; }
.espaco { flex: 1; }
.grelha-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grelha-2 > .cartao { margin-bottom: 0; }
.grelha-ficha { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; margin-bottom: 20px; }
.grelha-ficha > .cartao { margin-bottom: 0; }

/* ---------- Formulários ---------- */
label, .campo { display: block; margin-bottom: 14px; font-weight: 550; font-size: 13px; color: var(--texto); }
.rotulo { display: block; font-weight: 550; font-size: 13px; margin-bottom: 6px; }
label em, .rotulo em { color: var(--perigo); font-style: normal; }
label small, .rotulo small { font-weight: 450; margin-left: 2px; }
input[type=text], input[type=password], input[type=tel], input[type=search], input[type=date],
input[type=time], input[type=number], input[type=email], select, textarea {
    display: block; width: 100%; margin-top: 6px; min-height: 42px;
    padding: 9px 12px; font: inherit; font-size: 14px; font-weight: 450; color: var(--texto);
    border: 1px solid var(--borda-forte); border-radius: var(--raio-p); background: var(--superficie);
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none; appearance: none;
}
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2352636b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; background-size: 18px; padding-right: 36px;
}
input::placeholder, textarea::placeholder { color: var(--texto-3); }
input:hover, select:hover, textarea:hover { border-color: #b9c6cc; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primaria); box-shadow: 0 0 0 3px var(--primaria-anel); }
textarea { resize: vertical; min-height: 64px; }
input[readonly] { background: var(--superficie-2); }
.linha-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.data-hora { display: grid; grid-template-columns: minmax(0, 1fr) 104px; gap: 6px; }
.data-hora input { margin-top: 0; }
.caixa-verificacao { display: flex; align-items: center; gap: 10px; font-weight: 450; font-size: 14px; cursor: pointer; }
.caixa-verificacao input { width: 18px; height: 18px; accent-color: var(--primaria); flex-shrink: 0; margin: 0; }
.acoes { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.form-apagar { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--borda); }
.copiar { display: flex; gap: 6px; margin-top: 6px; }
.copiar input { margin-top: 0; font-family: Consolas, "SF Mono", monospace; font-size: 13px; }
.input-icone { position: relative; display: block; }
.input-icone .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); margin-top: 3px; color: var(--texto-3); pointer-events: none; width: 17px; height: 17px; }
.input-icone input { padding-left: 38px; }

/* ---------- Botões ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: 40px; padding: 8px 16px; font-weight: 600; font-size: 14px;
    border: 1px solid var(--borda-forte); background: var(--superficie); color: var(--texto);
    border-radius: var(--raio-p); cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
    box-shadow: var(--sombra-1);
}
.btn .ico { width: 17px; height: 17px; }
.btn:hover { background: var(--fundo); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primaria-anel); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-primario { background: var(--primaria); border-color: var(--primaria); color: #fff; box-shadow: 0 1px 2px rgba(7, 127, 150, .3); }
.btn-primario:hover { background: var(--primaria-escura); border-color: var(--primaria-escura); }
.btn-perigo { color: var(--perigo); border-color: #f1c9c6; }
.btn-perigo:hover { background: var(--perigo-suave); }
.btn-pequeno { min-height: 32px; padding: 5px 11px; font-size: 13px; }
.btn-bloco { width: 100%; }

/* ---------- Alertas e etiquetas ---------- */
.alerta {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px; border-radius: var(--raio-p); margin-bottom: 16px; white-space: pre-line;
    border: 1px solid; font-weight: 500; transition: opacity .4s, transform .4s;
}
.alerta .ico { margin-top: 1px; }
.alerta.a-sair { opacity: 0; transform: translateY(-6px); pointer-events: none; }
.alerta-sucesso { background: var(--verde-suave); border-color: #cfe5bd; color: #3d6d1c; }
.alerta-erro { background: var(--perigo-suave); border-color: #f4c7c3; color: #a32720; }
.alerta-aviso { background: var(--aviso-suave); border-color: #efd9a6; color: #85570b; }
.etiqueta { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef2f4; color: var(--texto-2); white-space: nowrap; }
.etiqueta-verde, .sms-enviada { background: #e5f3da; color: #3d6d1c; }
.etiqueta-azul, .sms-pendente, .sms-a_enviar { background: #dff2f6; color: #06677b; }
.sms-falhada { background: var(--perigo-suave); color: #a32720; }
.etiqueta-cinza, .sms-cancelada { background: #eef2f4; color: #6b7a80; }
.bolinha { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: 0; flex-shrink: 0; }

.toast {
    position: fixed; left: 50%; bottom: calc(24px + var(--nav-inferior) + var(--seguro-baixo)); z-index: 200;
    transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
    background: #15232b; color: #fff; padding: 11px 18px; border-radius: 999px; font-weight: 550;
    box-shadow: var(--sombra-3); transition: all .25s;
}
.toast.visivel { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Tabelas ---------- */
.tabela-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
.tabela { width: 100%; border-collapse: collapse; }
.tabela th, .tabela td { padding: 12px 12px; text-align: left; border-bottom: 1px solid var(--borda); vertical-align: middle; }
.tabela th { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--texto-3); background: var(--superficie-2); border-top: 1px solid var(--borda); }
.tabela th:first-child { border-top-left-radius: var(--raio-p); }
.tabela th:last-child { border-top-right-radius: var(--raio-p); }
.tabela tbody tr:last-child td { border-bottom: 0; }
.tabela .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabela tr.clicavel { cursor: pointer; }
.tabela tbody tr { transition: background .1s; }
.tabela tbody tr:hover { background: var(--superficie-2); }
.tabela tr.inativo td { color: var(--texto-3); }
.tabela a { text-decoration: none; font-weight: 600; color: var(--texto); }
.tabela a:hover { color: var(--primaria-escura); }
.acoes-linha { text-align: right; white-space: nowrap; }
.acoes-linha form { display: inline; margin: 0; }
.sem-quebra { white-space: nowrap; }
.nome-com-avatar { display: flex; align-items: center; gap: 10px; }
.mini-avatar {
    width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
    background: var(--primaria-suave); color: var(--primaria-escura); font-weight: 700; font-size: 12px;
}
.pesquisa { display: flex; gap: 8px; flex: 1; max-width: 460px; }
.pesquisa .input-icone { flex: 1; }
.pesquisa input { margin: 0; }
.pesquisa .input-icone .ico { margin-top: 0; }
.paginacao { display: flex; gap: 4px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.paginacao a { min-width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--raio-p); border: 1px solid var(--borda); text-decoration: none; color: var(--texto); font-weight: 550; }
.paginacao a.ativo { background: var(--primaria); border-color: var(--primaria); color: #fff; }

.separadores { display: flex; gap: 4px; border-bottom: 1px solid var(--borda); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.separadores::-webkit-scrollbar { display: none; }
.separadores a { display: flex; align-items: center; gap: 8px; padding: 12px 14px; text-decoration: none; color: var(--texto-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.separadores a .ico { width: 17px; height: 17px; }
.separadores a:hover { color: var(--texto); }
.separadores a.ativo { color: var(--primaria-escura); border-color: var(--primaria); }
.filtros { display: flex; gap: 6px; flex-wrap: wrap; }
.filtros a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--texto-2); background: var(--fundo); font-size: 13px; font-weight: 550; border: 1px solid transparent; }
.filtros a.ativo { background: var(--primaria-suave); color: var(--primaria-escura); border-color: #bfe5ed; }

/* ---------- Ficha do utente ---------- */
.perfil-topo { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.perfil-avatar {
    width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primaria), var(--verde)); color: #fff; font-weight: 700; font-size: 22px;
}
.perfil-topo h1 { margin: 0; }
.perfil-topo .meta { margin: 2px 0 0; }
.perfil-acoes { display: flex; gap: 8px; margin-left: auto; }
.resumo-utente { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.resumo-utente .numero { background: var(--superficie-2); border: 1px solid var(--borda); border-radius: var(--raio-p); padding: 16px; }
.resumo-utente strong { display: block; font-size: 26px; font-weight: 700; color: var(--texto); letter-spacing: -.02em; }
.resumo-utente span { color: var(--texto-2); font-size: 13px; font-weight: 500; }
.resumo-utente .numero:first-child strong { color: var(--primaria-escura); }

/* ---------- Admin SMS ---------- */
.estado-telemovel { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; padding: 14px; border-radius: var(--raio-p); margin-bottom: 8px; }
.estado-telemovel .ponto { width: 10px; height: 10px; border-radius: 50%; background: #b0bcc0; flex-shrink: 0; }
.estado-telemovel.ligado { color: var(--verde-escuro); background: var(--verde-suave); }
.estado-telemovel.ligado .ponto { background: var(--verde); box-shadow: 0 0 0 4px rgba(122, 182, 72, .25); animation: pulsar 2s infinite; }
.estado-telemovel.desligado { color: var(--perigo); background: var(--perigo-suave); }
.estado-telemovel.desligado .ponto { background: var(--perigo); }
@keyframes pulsar { 50% { box-shadow: 0 0 0 7px rgba(122, 182, 72, .1); } }
.variavel { border: 1px dashed #9fd6e1; background: var(--primaria-suave); color: var(--primaria-escura); border-radius: 6px; padding: 3px 8px; margin: 2px; cursor: pointer; font-family: Consolas, monospace; font-size: 12px; }
.variavel:hover { border-style: solid; }
.pre-visualizacao { background: var(--fundo); border-radius: var(--raio-p); padding: 14px; margin-bottom: 14px; }
#smsPrevia { background: #dcf3c8; border-radius: 14px 14px 14px 4px; padding: 10px 13px; margin: 8px 0; white-space: pre-wrap; max-width: 420px; font-weight: 450; }

/* ---------- Modais ---------- */
.modal {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(12, 28, 36, .5);
    backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center;
    padding: 24px 16px;
    animation: fundo-entrar .15s ease-out;
}
@keyframes fundo-entrar { from { opacity: 0; } }
.modal-caixa {
    background: var(--superficie); border-radius: 16px; width: 100%; max-width: 620px;
    max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px);
    display: flex; flex-direction: column;
    box-shadow: var(--sombra-3); animation: caixa-entrar .2s cubic-bezier(.2, .9, .3, 1.1);
    overflow: hidden;
}
.modal-pequena { max-width: 440px; }
@keyframes caixa-entrar { from { transform: translateY(12px) scale(.98); opacity: 0; } }
.modal-topo { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--borda); flex-shrink: 0; }
.modal-topo h2 { margin: 0; font-size: 17px; flex: 1; }
.modal-icone { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--primaria-suave); color: var(--primaria-escura); flex-shrink: 0; }
.modal-fechar {
    width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; cursor: pointer;
    display: grid; place-items: center; color: inherit; opacity: .65; flex-shrink: 0; transition: all .15s;
}
.modal-fechar:hover { opacity: 1; background: rgba(0, 0, 0, .06); }
.modal-caixa > form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal-corpo { padding: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; flex: 1; min-height: 0; }
.modal-rodape {
    display: flex; gap: 8px; justify-content: flex-end; align-items: center;
    padding: 14px 20px; border-top: 1px solid var(--borda); background: var(--superficie-2); flex-shrink: 0;
}

/* Formulário de marcação */
.secao { margin-bottom: 8px; padding-bottom: 6px; }
.secao + .secao { border-top: 1px solid var(--borda); padding-top: 16px; }
.secao-titulo { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--texto-3); margin-bottom: 12px; }
.seletor-tipo { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 18px; background: var(--fundo); border-radius: 10px; }
.seletor-tipo label { margin: 0; }
.seletor-tipo input { position: absolute; opacity: 0; pointer-events: none; }
.seletor-tipo span {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--texto-2); border-radius: 7px; transition: all .15s;
}
.seletor-tipo input:checked + span { background: var(--superficie); color: var(--primaria-escura); box-shadow: var(--sombra-2); }
.seletor-tipo input:focus-visible + span { box-shadow: 0 0 0 3px var(--primaria-anel); }
#formMarcacao .so-consulta, #formMarcacao .so-outros { display: none; }
#formMarcacao.tipo-consulta .so-consulta, #formMarcacao.tipo-outros .so-outros { display: block; }
.duracao { display: flex; align-items: center; gap: 6px; margin: -4px 0 6px; color: var(--texto-2); font-size: 13px; font-weight: 500; }
.duracao .ico { width: 15px; height: 15px; color: var(--primaria); }
.duracao.invalida { color: var(--perigo); }

.campo-autocomplete { position: relative; }
.autocomplete-lista {
    position: absolute; left: 0; right: 0; top: 100%; z-index: 10; margin-top: 4px;
    background: var(--superficie); border: 1px solid var(--borda); border-radius: 10px; box-shadow: var(--sombra-3);
    max-height: 280px; overflow-y: auto; font-weight: 400; padding: 4px;
}
.ac-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer; border-radius: var(--raio-p); }
.ac-item strong { display: block; font-weight: 600; }
.ac-item small { display: block; }
.ac-item:hover, .ac-item.ativo { background: var(--primaria-suave); }
.ac-avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--primaria-suave); color: var(--primaria-escura); font-weight: 700; font-size: 12px; flex-shrink: 0; }
.ac-item:hover .ac-avatar, .ac-item.ativo .ac-avatar { background: var(--primaria); color: #fff; }
.ac-vazio { display: flex; align-items: center; gap: 8px; padding: 12px; color: var(--texto-2); font-size: 13px; }
.utente-estado { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 550; margin: -6px 0 12px; }
.utente-estado:empty { display: none; }
.utente-estado .ico { width: 16px; height: 16px; }
.utente-estado a { margin-left: auto; font-weight: 600; text-decoration: none; }
.utente-estado.existente { color: var(--verde-escuro); }
.utente-estado.novo { color: var(--primaria-escura); }

.cores { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cor { margin: 0; cursor: pointer; text-align: center; }
.cor input { position: absolute; opacity: 0; pointer-events: none; }
.cor span {
    display: grid; place-items: center; aspect-ratio: 1; max-width: 46px; margin: 0 auto;
    border-radius: 50%; background: var(--c); color: #fff;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); transition: transform .12s, box-shadow .12s;
}
.cor span .ico { width: 20px; height: 20px; opacity: 0; transform: scale(.5); transition: all .15s; stroke-width: 3; }
.cor:hover span { transform: scale(1.06); }
.cor small { display: block; font-size: 11px; margin-top: 5px; line-height: 1.2; font-weight: 500; }
.cor input:checked + span { box-shadow: 0 0 0 3px var(--superficie), 0 0 0 5px var(--c); }
.cor input:checked + span .ico { opacity: 1; transform: none; }
.cor input:checked ~ small { color: var(--texto); font-weight: 650; }
.cor input:focus-visible + span { box-shadow: 0 0 0 3px var(--superficie), 0 0 0 5px var(--primaria); }

/* Detalhes */
.detalhes-topo {
    position: relative; padding: 22px 22px 20px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 78%, #000));
    background-color: var(--c);
}
.detalhes-topo .modal-fechar { position: absolute; right: 12px; top: 12px; opacity: .85; }
.detalhes-topo .modal-fechar:hover { background: rgba(255, 255, 255, .2); }
.detalhes-tipo { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding: 3px 9px; border-radius: 999px; background: rgba(255, 255, 255, .22); }
.detalhes-topo h2 { font-size: 21px; margin: 10px 40px 6px 0; line-height: 1.25; }
.detalhes-topo p { margin: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-weight: 550; opacity: .95; }
.detalhes-topo p .ico { width: 16px; height: 16px; }
.detalhes { margin: 0; }
.det-linha { display: flex; align-items: center; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--borda); }
.det-linha:first-child { padding-top: 0; }
.det-ico { width: 36px; height: 36px; border-radius: 10px; background: var(--fundo); color: var(--texto-2); display: grid; place-items: center; flex-shrink: 0; }
.det-texto { flex: 1; min-width: 0; }
.det-linha dt { color: var(--texto-3); font-size: 12px; font-weight: 550; }
.det-linha dd { margin: 1px 0 0; font-weight: 550; word-wrap: break-word; }
.det-linha dd a { text-decoration: none; }
.det-acao { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--primaria-escura); background: var(--primaria-suave); flex-shrink: 0; }
.det-acao:hover { background: var(--primaria); color: #fff; }
.det-registo { display: flex; gap: 10px; margin-top: 14px; padding: 12px; background: var(--superficie-2); border-radius: var(--raio-p); font-size: 12px; color: var(--texto-2); line-height: 1.6; }
.det-registo .ico { width: 16px; height: 16px; margin-top: 2px; color: var(--texto-3); }

/* =====================================================================
   Agenda
   ===================================================================== */
.pagina-agenda .conteudo {
    max-width: none; padding: 16px;
    height: calc(100vh - var(--topbar)); height: calc(100dvh - var(--topbar));
}
.agenda-layout { display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 16px; height: 100%; }
.agenda-lateral {
    display: flex; flex-direction: column; gap: 18px; min-height: 0; overflow-y: auto;
    background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); padding: 16px; box-shadow: var(--sombra-1);
}
.btn-nova { min-height: 46px; font-size: 15px; border-radius: 10px; box-shadow: 0 4px 14px rgba(10, 156, 184, .28); }
.btn-nova .ico { width: 20px; height: 20px; }

/* Mini-calendário */
.mini-topo { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.mini-topo strong { font-size: 14px; font-weight: 650; }
.mini-topo button { width: 30px; height: 30px; border-radius: 50%; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--texto-2); }
.mini-topo button:hover { background: var(--fundo); color: var(--texto); }
.mini-grelha { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px 0; text-align: center; }
.mini-sem { font-size: 11px; font-weight: 650; color: var(--texto-3); padding: 4px 0; }
.mini-dia {
    position: relative; height: 32px; border: 0; background: transparent; cursor: pointer;
    font-size: 13px; font-weight: 500; color: var(--texto); font-variant-numeric: tabular-nums;
    border-radius: 0;
}
.mini-dia:hover { background: var(--fundo); border-radius: 8px; }
.mini-dia.fora { color: #b7c2c7; }
.mini-dia.na-vista { background: var(--primaria-suave); color: var(--primaria-escura); font-weight: 650; }
.mini-dia.na-vista:hover { border-radius: 0; }
.mini-grelha > .mini-dia.na-vista:not(.na-vista + .na-vista) { border-top-left-radius: 8px; border-bottom-left-radius: 8px; }
.mini-dia.hoje::before {
    content: ""; position: absolute; inset: 2px; margin: auto; width: 28px; height: 28px;
    border-radius: 50%; background: var(--primaria); z-index: 0;
}
.mini-dia.hoje { color: #fff; font-weight: 700; isolation: isolate; }
.mini-dia.hoje::before { z-index: -1; }
.mini-dia.com-marcacoes::after {
    content: ""; position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%);
    width: 4px; height: 4px; border-radius: 50%; background: var(--verde);
}
.mini-dia.hoje.com-marcacoes::after { background: #fff; bottom: 4px; }

/* Painel do dia */
.painel-hoje { border-top: 1px solid var(--borda); padding-top: 16px; min-height: 0; }
.painel-titulo { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.painel-titulo h3 { margin: 0; font-size: 12px; }
.contador { min-width: 24px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--primaria-suave); color: var(--primaria-escura); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.lista-dia { display: flex; flex-direction: column; gap: 6px; }
.item-dia {
    display: flex; gap: 10px; align-items: stretch; width: 100%; text-align: left; cursor: pointer;
    border: 1px solid var(--borda); background: var(--superficie); border-radius: 10px; padding: 8px 10px 8px 0; overflow: hidden;
    transition: border-color .15s, box-shadow .15s;
}
.item-dia::before { content: ""; width: 3px; border-radius: 0 3px 3px 0; background: var(--c); flex-shrink: 0; }
.item-dia:hover { border-color: var(--borda-forte); box-shadow: var(--sombra-2); }
.item-hora { display: flex; flex-direction: column; font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; min-width: 40px; }
.item-hora small { font-weight: 500; font-size: 11px; }
.item-info { min-width: 0; display: flex; flex-direction: column; }
.item-info strong { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-info small { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lista-vazia { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 8px; color: var(--texto-3); font-size: 13px; text-align: center; }
.lista-vazia .ico { width: 26px; height: 26px; opacity: .6; }

/* Área principal */
.agenda-principal {
    display: flex; flex-direction: column; min-width: 0; min-height: 0;
    background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); box-shadow: var(--sombra-1); overflow: hidden;
}
.agenda-toolbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--borda); flex-wrap: wrap; }
.toolbar-navegacao { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.btn-hoje { min-height: 36px; padding: 6px 14px; }
.grupo-setas { display: flex; }
.btn-seta {
    width: 36px; height: 36px; border: 0; background: transparent; border-radius: 50%; cursor: pointer;
    display: grid; place-items: center; color: var(--texto-2); transition: background .15s;
}
.btn-seta:hover { background: var(--fundo); color: var(--texto); }
.toolbar-titulo { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-ajustar { min-height: 36px; padding: 6px 12px; color: var(--texto-2); box-shadow: none; }
.btn-ajustar.ativo { background: var(--primaria-suave); border-color: #bfe5ed; color: var(--primaria-escura); }
.btn-ajustar:disabled { opacity: .4; }
/* Modo "dia todo": a altura de cada intervalo é calculada para caber no ecrã */
/* Altura mínima pequena: o FullCalendar (expandRows) estica as linhas até ocuparem o espaço todo */
.agenda-calendario.modo-ajustar .fc .fc-timegrid-slot { height: 8px !important; }
/* As etiquetas das horas não podem impor altura mínima às linhas */
.agenda-calendario.modo-ajustar .fc .fc-timegrid-slot { line-height: 0; font-size: 0; }
.agenda-calendario.modo-ajustar .fc .fc-timegrid-slot-label-frame { height: 0; overflow: visible; }
.agenda-calendario.modo-ajustar .fc .fc-timegrid-slot-label-cushion { top: -6px; font-size: 10.5px; line-height: 1; }
.agenda-calendario.modo-ajustar .ev { padding: 1px 5px; line-height: 1.2; }
.agenda-calendario.modo-ajustar .ev-titulo { font-size: 11.5px; }
.agenda-calendario.modo-ajustar .ev-hora, .agenda-calendario.modo-ajustar .ev-sub { font-size: 10.5px; }
.segmentado { display: inline-flex; padding: 3px; background: var(--fundo); border-radius: 10px; gap: 2px; }
.segmentado button {
    border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; cursor: pointer;
    font-weight: 600; font-size: 13px; color: var(--texto-2); transition: all .15s;
}
.segmentado button:hover { color: var(--texto); }
.segmentado button.ativo { background: var(--superficie); color: var(--texto); box-shadow: var(--sombra-2); }
.so-compacto { display: none; }
.agenda-calendario { flex: 1; min-height: 0; position: relative; }
.agenda-calendario.desliza-esq #calendario { animation: deslizar-esq .25s ease-out; }
.agenda-calendario.desliza-dir #calendario { animation: deslizar-dir .25s ease-out; }
@keyframes deslizar-esq { from { transform: translateX(24px); opacity: .4; } }
@keyframes deslizar-dir { from { transform: translateX(-24px); opacity: .4; } }
#calendario { height: 100%; }
.fab { display: none; }

/* FullCalendar */
.fc {
    --fc-border-color: #edf1f3;
    --fc-today-bg-color: rgba(10, 156, 184, .035);
    --fc-now-indicator-color: #e5483f;
    --fc-highlight-color: rgba(10, 156, 184, .12);
    --fc-neutral-bg-color: var(--superficie-2);
    --fc-page-bg-color: var(--superficie);
    font-size: 13px;
}
.fc .fc-scrollgrid { border: 0; }
.fc .fc-scrollgrid-section-header > th, .fc .fc-scrollgrid-section > td { border-right: 0; }
.fc-theme-standard .fc-scrollgrid { border-left: 0; }
.fc .fc-col-header-cell { border-left-color: transparent; border-right-color: transparent; background: var(--superficie); }
.fc .fc-col-header-cell-cushion { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; color: var(--texto-2); text-decoration: none; }
.fc .cab-dia { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; }
.fc .cab-num { font-size: 20px; font-weight: 600; color: var(--texto); width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; line-height: 1; letter-spacing: -.02em; }
.fc .fc-day-today .cab-dia { color: var(--primaria-escura); }
.fc .fc-day-today .cab-num { background: var(--primaria); color: #fff; }
.fc .fc-day-sat, .fc .fc-day-sun { background: rgba(244, 246, 248, .55); }
.fc .fc-timegrid-slot { height: 22px; border-bottom: 0; }
.fc .fc-timegrid-slot-minor { border-top-color: transparent; }
.fc .fc-timegrid-slot-lane:not(.fc-timegrid-slot-minor) { border-top-color: #e6ebee; }
.fc .fc-timegrid-slot-label { border-color: transparent !important; vertical-align: top; }
.fc .fc-timegrid-slot-label-cushion { color: var(--texto-3); font-size: 11px; font-weight: 550; padding: 0 10px 0 6px; position: relative; top: -8px; font-variant-numeric: tabular-nums; }
.fc .fc-timegrid-axis { border-color: transparent !important; }
.fc .fc-timegrid-col { border-left-color: #edf1f3; }
.fc-media-screen .fc-timegrid-slot-lane { cursor: pointer; }
.fc .fc-timegrid-slot-lane:hover { background: rgba(10, 156, 184, .04); }
.fc .fc-timegrid-now-indicator-line { border-width: 2px 0 0; }
.fc .fc-timegrid-now-indicator-arrow { border-width: 6px 0 6px 7px; border-top-color: transparent; border-bottom-color: transparent; }
.fc .fc-timegrid-col-events { margin: 0 4px 0 2px; }
.fc .fc-highlight { border-radius: 6px; }

/* Cards das marcações: fundo suave com barra na cor escolhida */
.fc .fc-event.ev-card {
    background: color-mix(in srgb, var(--c) 15%, #fff) !important;
    border: 0 !important; border-left: 3px solid var(--c) !important;
    border-radius: 6px !important; box-shadow: 0 0 0 1px rgba(255, 255, 255, .9);
    cursor: pointer; transition: background .15s, box-shadow .15s;
}
.fc .fc-event.ev-card:hover { background: color-mix(in srgb, var(--c) 24%, #fff) !important; box-shadow: 0 0 0 1px #fff, 0 4px 12px rgba(15, 35, 45, .12); z-index: 5 !important; }
.fc .fc-event.ev-card .fc-event-main { color: color-mix(in srgb, var(--c) 52%, #000) !important; padding: 0; }
.fc .fc-event.ev-outros { background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgba(255, 255, 255, .45) 6px 12px) !important; }
.fc .fc-event-mirror { background: var(--primaria) !important; border: 0 !important; opacity: .85; }
.ev { padding: 3px 6px; overflow: hidden; line-height: 1.3; height: 100%; }
.ev-titulo { font-weight: 650; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-hora { font-size: 11px; font-weight: 550; opacity: .85; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-sub { font-size: 11px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.ev-curto { display: flex; gap: 6px; align-items: baseline; }
.ev-curto .ev-sub { display: none; }
.ev-curto .ev-hora { order: -1; }
.fc-daygrid-event .ev { display: flex; gap: 6px; align-items: baseline; padding: 2px 6px; }
.fc-daygrid-event .ev-hora { order: -1; }
.fc-daygrid-event .ev-sub { display: none; }

/* Vista de mês */
.fc .fc-daygrid-day-top { flex-direction: row; padding: 4px; }
.fc .fc-daygrid-day-number { font-size: 13px; font-weight: 600; color: var(--texto-2); text-decoration: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; padding: 0; }
.fc .fc-day-today .fc-daygrid-day-number { background: var(--primaria); color: #fff; }
.fc .fc-day-other .fc-daygrid-day-number { color: #b7c2c7; }
.fc .fc-col-header-cell.fc-day { padding: 8px 0; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--texto-2); }
.fc .fc-daygrid-more-link { font-weight: 600; color: var(--primaria-escura); font-size: 12px; }
.fc .fc-popover { border-radius: var(--raio); box-shadow: var(--sombra-3); border-color: var(--borda); overflow: hidden; }
.fc .fc-popover-header { background: var(--superficie-2); padding: 8px 10px; font-weight: 600; }
.fc-media-screen .fc-daygrid-day { cursor: pointer; }

/* ---------- Login ---------- */
.pagina-login {
    min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1.1fr 1fr;
    background: var(--superficie);
}
.login-marca {
    position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between;
    padding: 48px; color: #fff;
    background: radial-gradient(circle at 15% 20%, rgba(255, 255, 255, .14), transparent 40%),
                linear-gradient(140deg, #0a9cb8 0%, #0b8ea7 45%, #5e9f37 100%);
}
.login-marca::after {
    content: ""; position: absolute; right: -120px; bottom: -120px; width: 420px; height: 420px; border-radius: 50%;
    border: 70px solid rgba(255, 255, 255, .07);
}
.login-marca-logo { background: #fff; border-radius: 18px; padding: 12px 18px; display: inline-flex; align-self: flex-start; box-shadow: 0 10px 30px rgba(0, 0, 0, .12); }
.login-marca-logo img { height: 52px; display: block; }
.login-marca h2 { font-size: 34px; line-height: 1.15; letter-spacing: -.03em; margin: 0 0 12px; max-width: 440px; font-weight: 700; }
.login-marca p { font-size: 16px; opacity: .9; max-width: 420px; margin: 0; line-height: 1.6; }
.login-marca-rodape { font-size: 13px; opacity: .75; position: relative; z-index: 1; }
.login-form-area { display: grid; place-items: center; padding: 32px 24px; padding-bottom: calc(32px + var(--seguro-baixo)); }
.login-caixa { width: 100%; max-width: 380px; }
.login-logo-mobile { display: none; }
.login-caixa h1 { font-size: 26px; margin: 0 0 6px; }
.login-caixa .subtitulo { margin: 0 0 28px; }
.login-caixa input { min-height: 48px; font-size: 15px; }
.login-caixa .btn { min-height: 48px; font-size: 15px; margin-top: 6px; }

/* ---------- Impressão ---------- */
.pagina-impressao { background: #e9eef0; }
.barra-impressao {
    display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
    padding: 12px 20px; background: var(--superficie); border-bottom: 1px solid var(--borda);
    position: sticky; top: 0; z-index: 5; box-shadow: var(--sombra-1);
}
.barra-impressao label { margin: 0; }
.barra-impressao input { margin-top: 4px; }
/* No ecrã, a folha tem as proporções de um A4 vertical */
.folha { background: #fff; width: 210mm; max-width: 100%; min-height: 297mm; margin: 24px auto; padding: 12mm; box-shadow: var(--sombra-2); border-radius: 2px; }
.tabela-impressao { table-layout: fixed; }
.tabela-impressao .col-hora { width: 22mm; }
.tabela-impressao .td-hora { white-space: nowrap; }
.tabela-impressao .td-hora strong { font-size: 13.5px; }
.tabela-impressao .td-hora small { display: block; padding-left: 16px; }
.tabela-impressao .td-hora .bolinha { margin-right: 4px; }
.tabela-impressao .col-utente { width: 52mm; }
.tabela-impressao .col-consulta { width: 42mm; }
.tabela-impressao td { word-wrap: break-word; }
.folha-topo { display: flex; align-items: center; gap: 22px; border-bottom: 2px solid var(--verde); padding-bottom: 16px; margin-bottom: 18px; }
.folha-topo img { height: 60px; }
.folha-topo h1 { margin: 0; color: var(--primaria-escura); font-size: 24px; }
.folha-topo p { margin: 3px 0 0; color: var(--texto-2); }
.folha-topo .folha-data { font-size: 16px; color: var(--texto); font-weight: 650; }
.tabela-impressao td, .tabela-impressao th { padding: 9px 8px; font-size: 12.5px; vertical-align: top; }
.tabela-impressao tbody tr:last-child td { border-bottom: 1px solid var(--borda); }
.folha-rodape { margin-top: 22px; font-size: 11px; color: var(--texto-3); text-align: right; }

@media print {
    @page { size: A4 portrait; margin: 12mm 12mm 14mm; }
    .nao-imprimir { display: none !important; }
    .pagina-impressao { background: #fff; }
    .folha { box-shadow: none; margin: 0; padding: 0; width: auto; min-height: 0; max-width: none; }
    .tabela-impressao thead { display: table-header-group; }
    .tabela-impressao tr { page-break-inside: avoid; }
    .tabela th { background: #f2f4f5 !important; }
    .tabela, .bolinha, .folha-topo { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* =====================================================================
   Responsivo
   ===================================================================== */

/* Portátil pequeno */
@media (max-width: 1280px) {
    .topbar { gap: 18px; }
    .topbar-marca { display: none; }
    .agenda-layout { grid-template-columns: 248px minmax(0, 1fr); }
}

/* Tablet (horizontal e vertical) */
@media (max-width: 1024px) {
    :root { --topbar: 60px; }
    .conteudo { padding: 18px; }
    .data-longa { display: none; }
    .data-curta { display: inline; }
    .nome-utilizador { display: none; }
    .btn-utilizador { padding: 3px; }
    .agenda-layout { grid-template-columns: minmax(0, 1fr); }
    .agenda-lateral { display: none; }
    .pagina-agenda .conteudo { padding: 12px; }
    .so-compacto { display: inline-block; }
    .grelha-2 { grid-template-columns: 1fr; }
    .grelha-ficha { grid-template-columns: 1fr; }
    .resumo-utente { grid-template-columns: repeat(4, 1fr); }
    .fab {
        display: grid; place-items: center; position: fixed; z-index: 40;
        right: calc(20px + env(safe-area-inset-right)); bottom: calc(24px + var(--nav-inferior) + var(--seguro-baixo));
        width: 60px; height: 60px; border-radius: 18px; border: 0; cursor: pointer;
        background: var(--primaria); color: #fff; box-shadow: 0 8px 24px rgba(10, 156, 184, .45);
        transition: transform .15s;
    }
    .fab .ico { width: 28px; height: 28px; }
    .fab:active { transform: scale(.94); }
    .pagina-login { grid-template-columns: 1fr; }
    .login-marca { display: none; }
    .login-logo-mobile { display: block; height: 72px; margin: 0 auto 18px; }
    .login-caixa { text-align: center; }
    .login-caixa form { text-align: left; }
    /* Alvos de toque maiores */
    .fc .fc-timegrid-slot { height: 26px; }
}

/* Telemóvel */
@media (max-width: 640px) {
    :root { --topbar: 56px; --nav-inferior: 64px; }
    body { font-size: 15px; padding-bottom: calc(var(--nav-inferior) + var(--seguro-baixo)); }
    /* 16px evita o zoom automático do iOS ao tocar nos campos */
    input[type=text], input[type=password], input[type=tel], input[type=search], input[type=date],
    input[type=time], input[type=number], input[type=email], select, textarea { font-size: 16px; min-height: 46px; }
    .btn { min-height: 44px; }
    .btn-pequeno { min-height: 36px; }

    .topbar { gap: 10px; padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
    .topbar-logo img { height: 32px; }
    .topbar-nav { display: none; }
    .topbar-data { padding: 6px 10px; font-size: 13px; }
    #btnImprimir { display: none; }
    .avatar { width: 34px; height: 34px; }

    .nav-inferior {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
        height: calc(var(--nav-inferior) + var(--seguro-baixo)); padding-bottom: var(--seguro-baixo);
        background: rgba(255, 255, 255, .96); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid var(--borda);
    }
    .nav-inferior a, .nav-inferior button {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        text-decoration: none; color: var(--texto-3); font-size: 11px; font-weight: 600; border: 0; background: none; cursor: pointer;
    }
    .nav-inferior .ico { width: 23px; height: 23px; }
    .nav-inferior a.ativo { color: var(--primaria-escura); }
    .nav-inferior a.ativo .ico { stroke-width: 2.4; }

    .conteudo { padding: 14px; padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
    .cartao { padding: 16px; border-radius: 14px; }
    .tabela-wrap { margin: 0 -16px; padding: 0 16px; }
    h1 { font-size: 20px; }
    .linha-2 { grid-template-columns: 1fr; gap: 0; }
    .linha-2.linha-2-fixa { grid-template-columns: 1fr 1fr; gap: 10px; }
    .cabecalho-pagina { gap: 10px; }
    .cabecalho-pagina .btn-primario { order: 2; }
    .pesquisa { order: 3; max-width: none; flex-basis: 100%; }
    .nao-telemovel { display: none !important; }

    /* Agenda em ecrã inteiro */
    .pagina-agenda .conteudo {
        padding: 0; height: calc(100vh - var(--topbar) - var(--nav-inferior) - var(--seguro-baixo));
        height: calc(100dvh - var(--topbar) - var(--nav-inferior) - var(--seguro-baixo));
    }
    .agenda-principal { border: 0; border-radius: 0; box-shadow: none; }
    .agenda-toolbar { display: grid; grid-template-columns: 1fr auto auto; gap: 10px 6px; padding: 10px 12px; }
    .toolbar-navegacao { display: contents; }
    .toolbar-titulo { grid-column: 1; grid-row: 1; font-size: 17px; align-self: center; }
    .btn-ajustar { grid-column: 2; grid-row: 1; padding: 6px 9px; }
    .btn-ajustar span { display: none; }
    .grupo-setas { grid-column: 3; grid-row: 1; }
    .btn-hoje { grid-column: 2 / 4; grid-row: 2; min-height: 36px; }
    .segmentado { grid-column: 1; grid-row: 2; width: 100%; }
    .segmentado button { flex: 1; padding: 7px 6px; }
    .fc .cab-num { font-size: 17px; width: 32px; height: 32px; }
    .fc .fc-timegrid-slot-label-cushion { padding: 0 6px 0 2px; font-size: 10.5px; }
    .fc .fc-timegrid-slot { height: 28px; }
    .ev-titulo { font-size: 12.5px; }

    /* Modais como folha a deslizar de baixo */
    .modal { padding: 0; align-items: flex-end; }
    .modal-caixa, .modal-pequena {
        max-width: none; border-radius: 18px 18px 0 0;
        max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
        animation: folha-subir .28s cubic-bezier(.2, .9, .3, 1);
    }
    #modalMarcacao .modal-caixa { height: calc(100dvh - 24px); }
    .modal-caixa::before { content: ""; position: absolute; left: 50%; transform: translateX(-50%); margin-top: 6px; width: 38px; height: 4px; border-radius: 4px; background: rgba(0, 0, 0, .18); z-index: 2; }
    .modal-caixa { position: relative; }
    .modal-topo { padding: 18px 16px 14px; }
    .modal-corpo { padding: 16px; }
    .modal-rodape { padding: 12px 16px calc(12px + var(--seguro-baixo)); }
    .modal-rodape .btn { flex: 1; }
    .modal-rodape .espaco { display: none; }
    #btnDesmarcar { flex: 0 0 auto; }
    #btnDesmarcar span { display: none; }
    .detalhes-topo { padding: 26px 18px 18px; }
    .detalhes-topo h2 { font-size: 20px; }
    @keyframes folha-subir { from { transform: translateY(100%); } }
    .cores { grid-template-columns: repeat(4, 1fr); row-gap: 12px; }
    .data-hora { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }

    /* Tabelas transformadas em cartões */
    .tabela-cartoes thead { display: none; }
    .tabela-cartoes, .tabela-cartoes tbody { display: block; }
    .tabela-cartoes tr {
        display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px;
        padding: 14px 0; border-bottom: 1px solid var(--borda);
    }
    .tabela-cartoes tbody tr:hover { background: none; }
    .tabela-cartoes td { display: block; padding: 0; border: 0; min-width: 0; font-size: 14px; }
    .tabela-cartoes td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; color: var(--texto-3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 1px; }
    .tabela-cartoes td:empty, .tabela-cartoes td.vazio-movel { display: none; }
    .tabela-cartoes td.td-principal, .tabela-cartoes td.td-largo, .tabela-cartoes td.acoes-linha { grid-column: 1 / -1; }
    .tabela-cartoes td.td-principal { font-size: 15px; }
    .tabela-cartoes td.acoes-linha { text-align: left; display: flex; gap: 8px; flex-wrap: wrap; }
    .tabela-cartoes td.num { text-align: left; }
    .tabela-cartoes td.vazio { grid-column: 1 / -1; }

    .resumo-utente { grid-template-columns: 1fr 1fr; }
    .perfil-topo { flex-wrap: wrap; }
    .perfil-acoes { margin-left: 0; width: 100%; }
    .perfil-acoes .btn { flex: 1; }
    .barra-impressao { padding: 10px 14px; }
    .barra-impressao label { flex: 1 1 30%; }
    .barra-impressao .btn { flex: 1; }
    .folha { margin: 0; padding: 18px 14px; box-shadow: none; width: auto; min-height: 0; }
    .folha-topo img { height: 54px; }
    .tabela-impressao { display: block; overflow-x: auto; }
    .toast { bottom: calc(80px + var(--nav-inferior) + var(--seguro-baixo)); }
}

/* Telemóvel em horizontal: pouca altura */
@media (max-height: 500px) and (orientation: landscape) {
    .modal-caixa { max-height: 100vh; max-height: 100dvh; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

.so-movel-inline { display: none; }
@media (max-width: 640px) { .so-movel-inline { display: inline; color: var(--texto-2); font-weight: 500; } }

/* ---------- Instalação como aplicação ---------- */
.btn-instalar-login { margin-top: 12px; }
.faixa-instalar {
    position: fixed; left: 12px; right: 12px; z-index: 70;
    bottom: calc(12px + var(--nav-inferior) + var(--seguro-baixo));
    display: flex; align-items: center; gap: 12px;
    padding: 12px 12px 12px 14px; background: var(--superficie);
    border: 1px solid var(--borda); border-radius: 14px; box-shadow: var(--sombra-3);
    animation: caixa-entrar .3s ease-out;
}
.faixa-instalar img { width: 40px; height: 40px; border-radius: 10px; box-shadow: var(--sombra-1); flex-shrink: 0; }
.faixa-instalar div { flex: 1; min-width: 0; line-height: 1.3; }
.faixa-instalar strong { display: block; font-size: 14px; }
.faixa-instalar small { display: block; font-size: 12px; }
.faixa-fechar { border: 0; background: none; font-size: 22px; line-height: 1; color: var(--texto-3); cursor: pointer; padding: 4px 6px; }
.pagina-agenda .faixa-instalar { right: 92px; }
.passos-instalar { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.passos-instalar li { display: flex; align-items: flex-start; gap: 12px; line-height: 1.5; }
.passos-instalar .ico { width: 18px; height: 18px; color: var(--primaria-escura); vertical-align: -3px; }
.passo-num { width: 26px; height: 26px; border-radius: 50%; background: var(--primaria-suave); color: var(--primaria-escura); font-weight: 700; display: grid; place-items: center; flex-shrink: 0; font-size: 13px; }

/* Cards da grelha: mostram só as linhas que cabem inteiras (container queries) */
.fc .fc-timegrid-event .fc-event-main { height: 100%; container: ev / size; }
@container ev (max-height: 44px) { .ev-sub { display: none; } }
@container ev (max-height: 27px) { .ev { display: flex; gap: 5px; align-items: baseline; } .ev-hora { order: -1; } }
/* Primeira hora no topo da grelha: a etiqueta não sobe (ficaria cortada) */
.fc .fc-timegrid-slots tr:first-child .fc-timegrid-slot-label-cushion { top: 0 !important; }

/* ---------- QR code de configuração da app SMS ---------- */
.qr-config { display: flex; gap: 20px; align-items: center; margin-bottom: 10px; }
.qr-caixa { position: relative; flex-shrink: 0; width: 200px; padding: 12px; border: 1px solid var(--borda); border-radius: var(--raio); background: #fff; display: grid; place-items: center; }
.qr-codigo { width: 176px; height: 176px; }
.qr-codigo img, .qr-codigo canvas { display: block; width: 176px; height: 176px; transition: filter .25s; }
.qr-codigo.desfocado img, .qr-codigo.desfocado canvas { filter: blur(7px); opacity: .55; }
.btn-mostrar-qr { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); box-shadow: var(--sombra-2); }
.qr-config .passos-instalar { flex: 1; font-size: 13.5px; }
.form-url-servidor .copiar .btn-primario { flex-shrink: 0; }
.link-botao { border: 0; background: none; padding: 0; color: var(--primaria-escura); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
@media (max-width: 640px) {
    .qr-config { flex-direction: column; align-items: stretch; }
    .qr-caixa { margin: 0 auto; }
    .form-url-servidor .copiar { flex-wrap: wrap; }
    .form-url-servidor .copiar input { flex-basis: 100%; }
    .form-url-servidor .copiar .btn { flex: 1; }
}
