/* ============================================================
   Pisão 360 — Design System
   Tokens da marca + componentes base
   ============================================================ */

:root {
    /* Marca */
    --p360-primary: #877D38;          /* dourado/azeitona */
    --p360-primary-600: #756c30;
    --p360-primary-700: #5f5827;
    --p360-primary-100: #ece9da;      /* fundo suave do primário */
    --p360-on-primary: #FFFFFF;

    /* Superfícies */
    --p360-surface: #FFFFFF;
    --p360-background: #F3F4F6;
    --p360-background-2: #e7e9ee;     /* faixa "afundada" — um tom acima do fundo da página */
    --p360-border: #e5e7eb;

    /* Funcionais */
    --p360-success: #16a34a;
    --p360-success-bg: #dcfce7;
    --p360-danger: #dc2626;
    --p360-danger-bg: #fee2e2;
    --p360-warning: #d97706;
    --p360-warning-bg: #fef3c7;
    --p360-info: #2563eb;
    --p360-info-bg: #dbeafe;

    /* Texto */
    --p360-text: #1f2937;
    --p360-text-muted: #6b7280;

    /* Forma / elevação */
    --p360-radius: 0.5rem;
    --p360-radius-sm: 0.25rem;
    --p360-shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px -1px rgba(0,0,0,.1);
    --p360-shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);

    /* Layout */
    --p360-header-h: 56px;
    --p360-nav-h: 46px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--p360-text);
    background: var(--p360-background);
}

h1, h2, h3, h4, h5 { margin: 0 0 .5rem; font-weight: 600; }
h1:focus { outline: none; }
a { color: var(--p360-primary-700); text-decoration: none; }
a:hover { text-decoration: underline; }
code { color: #c02d76; }

/* ---------- Validação de formulários ---------- */
.valid.modified:not([type=checkbox]) { outline: 1px solid var(--p360-success); }
.invalid { outline: 1px solid var(--p360-danger); }
.validation-message { color: var(--p360-danger); }

/* ---------- App shell ---------- */
.p360-app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.p360-header {
    height: var(--p360-header-h);
    background: var(--p360-primary);
    color: var(--p360-on-primary);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1rem;
    box-shadow: var(--p360-shadow);
    position: sticky; top: 0; z-index: 40;
}
.p360-header__brand {
    font-size: 1.15rem; font-weight: 700; letter-spacing: .3px; color: var(--p360-on-primary);
    display: inline-flex; align-items: center; gap: .5rem; white-space: nowrap;
}
.p360-header__brand:hover { text-decoration: none; }
/* Logótipo da casa no cabeçalho (F7.15, opcional). Fundo branco por baixo porque a barra é dourada
   e um logótipo a cores sobre ela fica ilegível — e um PNG opaco traria o seu próprio fundo. */
.p360-header__logo {
    width: 28px; height: 28px; flex: none; display: grid; place-items: center;
    background: #fff; border-radius: var(--p360-radius-sm); padding: 2px; overflow: hidden;
}
.p360-header__logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.p360-header__spacer { flex: 1; }
.p360-header__user { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.p360-header__avatar {
    width: 32px; height: 32px; border-radius: 9999px;
    background: rgba(255,255,255,.2); display: grid; place-items: center; font-weight: 600;
}
/* Botão "Instalar app" (PWA) no cabeçalho — só aparece quando instalável; no telemóvel fica só o ícone */
.p360-header__install {
    background: rgba(255,255,255,.14); color: var(--p360-on-primary);
    border: 1px solid rgba(255,255,255,.45); font-size: .85rem; padding: .35rem .7rem; white-space: nowrap;
}
.p360-header__install:hover { background: rgba(255,255,255,.24); }
@media (max-width: 640px) { .p360-header__install-lbl { display: none; } }

/* ---------- Top-nav de módulos ---------- */
.p360-nav {
    height: var(--p360-nav-h);
    background: var(--p360-surface);
    border-bottom: 1px solid var(--p360-border);
    display: flex; align-items: stretch; gap: .25rem;
    padding: 0 .5rem;
    overflow-x: auto; white-space: nowrap;
    position: sticky; top: var(--p360-header-h); z-index: 30;
}
.p360-nav__link {
    display: inline-flex; align-items: center; gap: .45rem;
    padding: 0 .85rem; font-size: .9rem; color: var(--p360-text-muted);
    border-bottom: 3px solid transparent; text-decoration: none;
}
.p360-nav__link:hover { color: var(--p360-primary); text-decoration: none; background: var(--p360-background); }
.p360-nav__link.active {
    color: var(--p360-primary-700); font-weight: 600;
    border-bottom-color: var(--p360-primary);
}
.p360-nav__link i { width: 1.1em; text-align: center; }

/* ---------- Grupos da barra de topo (F7.9: menu parametrizável) ----------
   A barra agrupada NÃO é um contentor de scroll: um dropdown posicionado dentro de um
   "overflow-x: auto" seria cortado pela altura da barra. Em vez disso deixa-se passar para
   segunda linha (min-height mantém a altura de cada linha) — assim, mesmo que uma casa crie
   grupos a mais, nenhum fica inalcançável. O scroll horizontal fica só para a apresentação
   em linha, onde não há dropdowns para cortar. */
.p360-nav { overflow: visible; flex-wrap: wrap; height: auto; min-height: var(--p360-nav-h); }
.p360-nav__link { min-height: calc(var(--p360-nav-h) - 3px); }
.p360-nav--inline { flex-wrap: nowrap; overflow-x: auto; }

.p360-nav__group { position: relative; display: inline-flex; }
.p360-nav__link--group {
    background: transparent; border: none; font: inherit; cursor: pointer;
    border-top: 3px solid transparent;   /* espelha o border-bottom do indicador ativo */
}
.p360-nav__link--open { color: var(--p360-primary-700); background: var(--p360-background); }
.p360-nav__chevron { font-size: .7rem; opacity: .7; transition: transform .12s; width: auto; }
.p360-nav__link--open .p360-nav__chevron { transform: rotate(180deg); }

.p360-nav__dropdown {
    position: absolute; top: 100%; left: 0; z-index: 35; min-width: 236px;
    background: var(--p360-surface);
    border: 1px solid var(--p360-border);
    border-radius: var(--p360-radius);
    box-shadow: var(--p360-shadow-lg);
    padding: .35rem;
}
.p360-nav__dropdown-link {
    display: flex; align-items: center; gap: .6rem; width: 100%;
    padding: .55rem .7rem; border-radius: var(--p360-radius-sm);
    font-size: .9rem; color: var(--p360-text); white-space: nowrap; text-decoration: none;
}
.p360-nav__dropdown-link:hover { background: var(--p360-background); color: var(--p360-primary-700); text-decoration: none; }
.p360-nav__dropdown-link.active { background: var(--p360-primary-100); color: var(--p360-primary-700); font-weight: 600; }
.p360-nav__dropdown-link i { width: 1.1em; text-align: center; color: var(--p360-text-muted); }
.p360-nav__dropdown-link.active i { color: var(--p360-primary-700); }
/* Apanha o clique fora do grupo aberto (só no desktop; em telemóvel o grupo é um acordeão). */
.p360-nav__catch { position: fixed; inset: 0; z-index: 25; }

/* ---------- Menu de conta (F7.9: apresentação do menu por utilizador) ---------- */
.p360-header__user { position: relative; }
.p360-header__avatar--btn { border: none; cursor: pointer; font-family: inherit; color: var(--p360-on-primary); }
.p360-header__avatar--btn:hover { background: rgba(255,255,255,.34); }
.p360-usermenu {
    position: absolute; right: 0; top: calc(100% + .4rem); z-index: 50;
    min-width: 272px; padding: .5rem; text-align: left;
    background: var(--p360-surface); color: var(--p360-text);
    border: 1px solid var(--p360-border);
    border-radius: var(--p360-radius);
    box-shadow: var(--p360-shadow-lg);
}
.p360-usermenu__who { padding: .35rem .55rem .5rem; border-bottom: 1px solid var(--p360-border); margin-bottom: .35rem; }
.p360-usermenu__name { font-weight: 600; font-size: .9rem; }
.p360-usermenu__label {
    font-size: .7rem; letter-spacing: .06em; text-transform: uppercase;
    color: var(--p360-text-muted); font-weight: 700; padding: .35rem .55rem .2rem;
}
.p360-usermenu__opt {
    display: flex; gap: .55rem; align-items: flex-start; width: 100%;
    padding: .45rem .55rem; border: none; background: transparent;
    font: inherit; font-size: .87rem; color: var(--p360-text);
    border-radius: var(--p360-radius-sm); cursor: pointer; text-align: left;
}
.p360-usermenu__opt:hover { background: var(--p360-background); }
.p360-usermenu__opt:disabled { cursor: default; opacity: .7; }
.p360-usermenu__opt--on { color: var(--p360-primary-700); font-weight: 600; }
.p360-usermenu__radio {
    width: 15px; height: 15px; border-radius: 50%; flex: none; margin-top: .18rem;
    border: 1.5px solid var(--p360-text-muted);
}
.p360-usermenu__opt--on .p360-usermenu__radio {
    border-color: var(--p360-primary); background: var(--p360-primary);
    box-shadow: inset 0 0 0 2.5px var(--p360-surface);
}
.p360-usermenu__hint { display: block; font-weight: 400; color: var(--p360-text-muted); font-size: .78rem; }
.p360-usermenu__locked { padding: .35rem .55rem .5rem; font-size: .8rem; color: var(--p360-text-muted); }
.p360-usermenu__catch { position: fixed; inset: 0; z-index: 49; }

/* Botão de menu (hambúrguer) no cabeçalho — escondido no desktop, visível só em telemóvel (sm) */
.p360-header__menu {
    display: none;
    align-items: center; justify-content: center;
    width: 40px; height: 40px; margin-left: -.35rem; flex: none;
    background: transparent; border: none; cursor: pointer;
    color: var(--p360-on-primary); font-size: 1.15rem; border-radius: var(--p360-radius-sm);
}
.p360-header__menu:hover { background: rgba(255,255,255,.15); }
/* Fundo escurecido da gaveta — só aparece em telemóvel quando o menu está aberto */
.p360-nav__backdrop { display: none; }

/* ---------- Conteúdo ---------- */
.p360-content { flex: 1; min-width: 0; padding: 1.25rem; padding-bottom: max(1.25rem, env(safe-area-inset-bottom)); }

/* ---------- Cartão ---------- */
.p360-card {
    background: var(--p360-surface);
    border: 1px solid var(--p360-border);
    border-radius: var(--p360-radius);
    box-shadow: var(--p360-shadow);
    padding: 1rem;
}
.p360-card__title { font-weight: 600; margin-bottom: .5rem; }

/* Grelha de módulos (dashboard) */
.p360-grid {
    display: grid; gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.p360-module-card {
    background: var(--p360-surface);
    border: 1px solid var(--p360-border);
    border-left: 4px solid var(--p360-primary);
    border-radius: var(--p360-radius);
    box-shadow: var(--p360-shadow);
    padding: 1rem; display: flex; gap: .85rem; align-items: center;
    color: var(--p360-text); transition: box-shadow .15s, transform .15s;
}
.p360-module-card:hover { box-shadow: var(--p360-shadow-lg); transform: translateY(-2px); text-decoration: none; }
.p360-module-card__icon {
    width: 42px; height: 42px; border-radius: var(--p360-radius-sm);
    background: var(--p360-primary-100); color: var(--p360-primary-700);
    display: grid; place-items: center; font-size: 1.2rem; flex: none;
}
.p360-module-card__label { font-weight: 600; }
.p360-module-card__hint { font-size: .8rem; color: var(--p360-text-muted); }

/* ---------- Botões ---------- */
.p360-btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .45rem .9rem; border-radius: var(--p360-radius-sm);
    border: 1px solid transparent; font-size: .9rem; font-weight: 500; cursor: pointer;
}
.p360-btn:disabled { opacity: .45; cursor: not-allowed; }
.p360-btn--primary { background: var(--p360-primary); color: var(--p360-on-primary); }
.p360-btn--primary:hover { background: var(--p360-primary-600); }
.p360-btn--ghost { background: transparent; border-color: var(--p360-border); color: var(--p360-text); }
.p360-btn--ghost:hover { background: var(--p360-background); }
.p360-btn--success { background: var(--p360-success); color: #fff; }
.p360-btn--danger { background: var(--p360-danger); color: #fff; }

/* ---------- Badges ---------- */
.p360-badge {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .15rem .55rem; border-radius: 9999px; font-size: .75rem; font-weight: 600;
}
.p360-badge--success { background: var(--p360-success-bg); color: var(--p360-success); }
.p360-badge--danger { background: var(--p360-danger-bg); color: var(--p360-danger); }
.p360-badge--warning { background: var(--p360-warning-bg); color: var(--p360-warning); }
.p360-badge--info { background: var(--p360-info-bg); color: var(--p360-info); }
.p360-badge--neutral { background: var(--p360-background); color: var(--p360-text-muted); }

/* ---------- Backoffice ---------- */
.p360-admin-link {
    display: flex; align-items: center; gap: .5rem;
    padding: .5rem .6rem; border-radius: var(--p360-radius-sm);
    color: var(--p360-text); font-size: .9rem;
}
.p360-admin-link:hover { background: var(--p360-background); text-decoration: none; }
.p360-admin-link.active { background: var(--p360-primary-100); color: var(--p360-primary-700); font-weight: 600; }
.p360-admin-link--disabled { color: var(--p360-text-muted); cursor: default; }

/* Shell do backoffice — sidebar de secções + conteúdo (classes extraídas de estilos inline) */
.p360-adminshell { display: flex; gap: 1.25rem; align-items: flex-start; }
.p360-adminshell__aside { width: 230px; flex: none; }
.p360-adminshell__nav { padding: .4rem; }
.p360-adminshell__label { font-weight: 600; padding: .4rem .5rem .25rem; color: var(--p360-text-muted); font-size: .75rem; letter-spacing: .05em; }
.p360-adminshell__soon { margin-left: auto; }

/* Faixa de "só leitura": quem tem a secção em consulta vê porque é que não há botões (B.3.7). */
.p360-admin-readonly {
    display: flex; align-items: center; gap: .6rem;
    margin-bottom: 1rem; padding: .6rem .8rem;
    background: var(--p360-info-bg); color: var(--p360-text);
    font-size: .85rem;
}
.p360-admin-readonly i { color: var(--p360-info); }
.p360-adminshell__main { flex: 1; min-width: 0; }

/* Master-detail responsivo do backoffice (lista + detalhe) — substitui os grids inline
   "300px 1fr" / "repeat(3,1fr)" das páginas admin (docs/05: estilo fora do markup, sem hardcode).
   Colapsam para 1 coluna no telemóvel. */
.p360-md { display: grid; grid-template-columns: minmax(240px, 300px) 1fr; gap: 1rem; align-items: start; }
.p360-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; align-items: start; }
@media (max-width: 820px) { .p360-md { grid-template-columns: 1fr; } }

/* Secção recolhível reutilizável — só em telemóvel (no desktop fica sempre aberta).
   Uso: cartão com class p360-coll (+ p360-coll--open), título com p360-coll__head (+ @onclick
   toggle e um <i class="... p360-coll__chev">), corpo em p360-coll__body. */
.p360-coll__right { display: inline-flex; align-items: center; gap: .5rem; }
.p360-coll__chev { display: none; color: var(--p360-text-muted); transition: transform .15s; }
@media (max-width: 820px) {
    .p360-coll__head { cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
    .p360-coll__chev { display: inline-block; }
    .p360-coll--open .p360-coll__chev { transform: rotate(180deg); }
    .p360-coll:not(.p360-coll--open) .p360-coll__body { display: none; }
    .p360-coll:not(.p360-coll--open) .p360-coll__head { margin-bottom: 0; }
}
.p360-admin-link i { width: 1.1em; text-align: center; }

.p360-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.p360-table th, .p360-table td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--p360-border); vertical-align: middle; }
.p360-table th { color: var(--p360-text-muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
.p360-table tbody tr:hover { background: var(--p360-background); }

/* Ações de linha: ação principal + menu "⋮" (mais ações) */
.p360-rowactions { position: relative; display: inline-flex; align-items: center; gap: .35rem; }
.p360-rowactions--open { z-index: 62; }
.p360-iconbtn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border: 1px solid transparent; border-radius: var(--p360-radius-sm);
    background: transparent; color: var(--p360-text-muted); cursor: pointer;
}
.p360-iconbtn:hover { background: var(--p360-background); color: var(--p360-text); }
.p360-menu-backdrop { position: fixed; inset: 0; z-index: 60; }
.p360-menu {
    position: absolute; top: calc(100% + 4px); right: 0; min-width: 170px;
    background: var(--p360-surface); border: 1px solid var(--p360-border);
    border-radius: var(--p360-radius); box-shadow: var(--p360-shadow-lg);
    padding: .25rem; z-index: 63; display: flex; flex-direction: column;
}
.p360-menu button {
    display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left;
    padding: .45rem .6rem; border: none; background: transparent; border-radius: var(--p360-radius-sm);
    font-size: .88rem; color: var(--p360-text); cursor: pointer;
}
.p360-menu button:hover { background: var(--p360-background); }
.p360-menu button i { width: 1.1em; text-align: center; }
.p360-menu .p360-menu__danger { color: var(--p360-danger); }

.p360-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--p360-border); margin-bottom: 1rem; }
.p360-tab { padding: .5rem .85rem; cursor: pointer; border-bottom: 3px solid transparent; color: var(--p360-text-muted); }
.p360-tab:hover { color: var(--p360-primary); }
.p360-tab.active { color: var(--p360-primary-700); border-bottom-color: var(--p360-primary); font-weight: 600; }

/* ---------- Vista do utente (shell: sidebar + tabs de módulo) ---------- */
.p360-patient { display: flex; gap: 1.25rem; align-items: flex-start; }
.p360-patient__aside { width: 260px; flex: none; }
.p360-patient__main { flex: 1; min-width: 0; }
/* Espaço entre a barra de módulos (ou banner de alertas) e o conteúdo — ritmo vertical de 1rem,
   igual ao espaçamento entre cards; vale com ou sem faixa de sub-separadores */
.p360-modpanel { padding-top: 1rem; }

.p360-kv { display: flex; justify-content: space-between; gap: .5rem; font-size: .85rem; padding: .12rem 0; }
.p360-kv .p360-kv__label { margin-bottom: 0; }

/* Separadores de módulo (Admissão / Médico / Enfermagem …) — barra branca elevada */
.p360-modtabs {
    display: flex; gap: .15rem; align-items: stretch;
    background: var(--p360-surface);
    border: 1px solid var(--p360-border);
    border-radius: var(--p360-radius);
    box-shadow: var(--p360-shadow);
    padding: 0 .35rem;
    overflow-x: auto; white-space: nowrap;
}
.p360-modtab {
    display: inline-flex; align-items: center; gap: .45rem;
    padding: .6rem .85rem; font-size: .9rem; color: var(--p360-text-muted);
    border-bottom: 3px solid transparent; text-decoration: none;
}
.p360-modtab:hover { color: var(--p360-primary); text-decoration: none; }
.p360-modtab--active { color: var(--p360-primary-700); font-weight: 600; border-bottom-color: var(--p360-primary); }
.p360-modtab i { width: 1.1em; text-align: center; }

/* Sub-separadores dentro de um módulo (Registo / Medicação / …) — faixa cinza destacada */
.p360-subtabs {
    display: flex; flex-wrap: wrap; gap: .15rem; align-items: stretch;
    background: var(--p360-background-2);
    border: 1px solid var(--p360-border);
    border-radius: var(--p360-radius);
    padding: .2rem .45rem 0;
    margin-bottom: .75rem;   /* respiração entre a faixa de sub-tabs e o conteúdo (como as .dash-tabs) */
}
.p360-subtab {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .4rem .8rem; cursor: pointer; font-size: .88rem;
    background: none; border: none; border-bottom: 3px solid transparent; color: var(--p360-text-muted);
}
.p360-subtab:hover { color: var(--p360-primary); }
.p360-subtab--active { color: var(--p360-primary-700); border-bottom-color: var(--p360-primary); font-weight: 600; }

/* Seletor de módulo (só telemóvel) — botão que abre a folha inferior de módulos; escondido no desktop */
.p360-modpick { display: none; }

/* Folha de módulos (lista) — reutiliza o bottom-sheet global (.p360-modal no telemóvel) */
.p360-modsheet__list { display: flex; flex-direction: column; gap: .1rem; padding: .35rem; }
.p360-modsheet__item {
    display: flex; align-items: center; gap: .65rem;
    padding: .8rem .9rem; min-height: 48px; border-radius: var(--p360-radius-sm);
    color: var(--p360-text); text-decoration: none; font-size: .95rem;
}
.p360-modsheet__item:hover { background: var(--p360-background); text-decoration: none; }
.p360-modsheet__item--active { background: var(--p360-primary-100); color: var(--p360-primary-700); font-weight: 600; }
.p360-modsheet__item i { width: 1.3em; text-align: center; color: var(--p360-primary); }

@media (max-width: 820px) {
    /* Ao empilhar, os filhos esticam à largura do ecrã (align-items:stretch). Sem isto, o
       align-items:flex-start do desktop deixava o conteúdo com a largura do seu conteúdo
       (ex.: banner de alergias/CID) → o painel transbordava para a direita e as margens
       não batiam certo com a sidebar. Com stretch: tabelas deslizam no seu .p360-scroll-x,
       grelhas colapsam e o banner quebra. */
    .p360-patient { flex-direction: column; align-items: stretch; }
    .p360-patient__aside { width: 100%; }
}

/* Grelha de formulário responsiva (colapsa para 1 coluna em ecrãs estreitos) */
.p360-formgrid { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.p360-formgrid .p360-field { margin-bottom: 0; }
.p360-formgrid .col-span-2 { grid-column: 1 / -1; }

/* Tabela responsiva: scroll horizontal em vez de rebentar o layout no telemóvel */
.p360-scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Utilitários de layout partilhados (extraídos dos *.razor.css scoped da rollout MVVM) */
.p360-row-between { display: flex; justify-content: space-between; align-items: center; }
.p360-muted { color: var(--p360-text-muted); }

/* Layout padrão dos separadores de registo: editor à esquerda, Histórico Diário à direita */
.p360-registo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: stretch; }
@media (max-width: 1100px) { .p360-registo-grid { grid-template-columns: 1fr; align-items: start; } }

/* O card de registo (1.ª coluna) iguala a altura do Histórico Diário (2.ª coluna): o card vira
   coluna flex e o editor de texto cresce para preencher, em vez de deixar espaço vazio por baixo
   do botão. Aplica-se a todas as áreas que usam esta grelha (S. Social, Enfermagem, Médico, Psicologia). */
.p360-registo-grid > .p360-card:first-child { display: flex; flex-direction: column; }
.p360-registo-grid > .p360-card:first-child .p360-rte { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.p360-registo-grid > .p360-card:first-child .p360-rte__area { flex: 1 1 auto; max-height: none; }

/* Editor de texto rico (WYSIWYG) */
.p360-rte { border: 1px solid var(--p360-border); border-radius: var(--p360-radius-sm); overflow: hidden; background: var(--p360-surface); }
.p360-rte__toolbar { display: flex; flex-wrap: wrap; gap: .15rem; padding: .3rem; border-bottom: 1px solid var(--p360-border); background: var(--p360-background); }
.p360-rte__toolbar button, .p360-rte__color {
    display: inline-flex; align-items: center; gap: .25rem; min-width: 28px; height: 28px; justify-content: center;
    border: 1px solid transparent; border-radius: var(--p360-radius-sm); background: transparent; cursor: pointer;
    font-size: .85rem; color: var(--p360-text);
}
.p360-rte__toolbar button:hover, .p360-rte__color:hover { background: var(--p360-surface); border-color: var(--p360-border); }
.p360-rte__color { position: relative; overflow: hidden; padding: 0 .4rem; }
.p360-rte__color input[type=color] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.p360-rte__area { padding: .55rem .65rem; font-size: .9rem; line-height: 1.5; outline: none; overflow-y: auto; max-height: 360px; }
.p360-rte__area:focus { box-shadow: inset 0 0 0 2px var(--p360-primary-100); }

/* Render do texto rico (no histórico) */
.p360-rich { white-space: normal; }
.p360-rich p { margin: 0 0 .35rem; }
.p360-rich ul, .p360-rich ol { margin: .25rem 0 .25rem 1.25rem; }
.p360-rich mark { padding: 0 .1em; }

/* Indicadores numéricos (resumo de ocupação) */
.p360-stat { background: var(--p360-background); border-radius: var(--p360-radius-sm); padding: .6rem .75rem; text-align: center; }
.p360-stat__num { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.p360-stat__label { font-size: .75rem; color: var(--p360-text-muted); text-transform: uppercase; letter-spacing: .03em; }

/* Barra de progresso de ocupação */
.p360-bar { height: 8px; border-radius: 4px; background: var(--p360-background); overflow: hidden; }
.p360-bar__fill { height: 100%; background: var(--p360-primary); transition: width .2s; }

/* Paginação de listas (componente PagerBar) */
.p360-pager { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; margin-top: .6rem; }
.p360-pager__info { font-size: .8rem; color: var(--p360-text-muted); min-width: 9ch; text-align: center; }

/* Modal largo (ex.: rastreio do lote — vista densa de dados) */
.p360-modal.p360-modal--wide { max-width: 920px; }

/* Rastreio do lote: resumo (KPIs) + chips de filtro por tipo de movimento */
.trace-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
@media (max-width: 640px) { .trace-kpis { grid-template-columns: repeat(2, 1fr); } }
.trace-filters { display: flex; flex-wrap: wrap; gap: .35rem; margin: .7rem 0 .5rem; }
.trace-chip {
    border: 1px solid var(--p360-border); background: var(--p360-surface); color: var(--p360-text-muted);
    border-radius: 999px; padding: .25rem .75rem; font-size: .82rem; cursor: pointer; transition: all .15s;
}
.trace-chip:hover { border-color: var(--p360-primary); color: var(--p360-primary); }
.trace-chip.is-active { background: var(--p360-primary); border-color: var(--p360-primary); color: #fff; }

/* ---------- Modal ---------- */
.p360-modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.5);
    display: grid; place-items: center; z-index: 60; padding: 1rem;
}
.p360-modal {
    background: var(--p360-surface); border-radius: var(--p360-radius);
    box-shadow: var(--p360-shadow-lg); width: 100%; max-width: 520px;
    max-height: 90vh; overflow-y: auto;
}
.p360-modal__header {
    display: flex; justify-content: space-between; align-items: center;
    padding: .85rem 1rem; border-bottom: 1px solid var(--p360-border); font-weight: 600;
}
.p360-modal__body { padding: 1rem; }
.p360-modal__footer {
    display: flex; justify-content: flex-end; gap: .5rem;
    padding: .85rem 1rem; border-top: 1px solid var(--p360-border);
}
.p360-modal__close { background: none; border: none; cursor: pointer; font-size: 1.1rem; color: var(--p360-text-muted); }

/* ---------- Formulário ---------- */
.p360-field { margin-bottom: .85rem; }
.p360-field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .25rem; color: var(--p360-text); }
.p360-input {
    width: 100%; padding: .5rem .6rem; border: 1px solid var(--p360-border);
    border-radius: var(--p360-radius-sm); font-size: .9rem; background: var(--p360-surface);
    /* Sem isto, um <textarea> com esta classe escreve em monoespaçado (é o que o browser faz por
       omissão) e fica diferente dos <input> ao lado. Apanhado na figura do mural. */
    font-family: inherit;
}
.p360-input:focus { outline: 2px solid var(--p360-primary-100); border-color: var(--p360-primary); }
.p360-checks { display: flex; flex-wrap: wrap; gap: .5rem; }
.p360-check {
    display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .6rem;
    border: 1px solid var(--p360-border); border-radius: 9999px; font-size: .82rem; cursor: pointer;
}
.p360-check input { accent-color: var(--p360-primary); }
.p360-kv__label { font-size: .72rem; font-weight: 600; letter-spacing: .03em; color: var(--p360-text-muted); margin-bottom: .15rem; }

/* ---------- Placeholder "em construção" ---------- */
.p360-placeholder {
    display: grid; place-items: center; text-align: center;
    min-height: 50vh; color: var(--p360-text-muted);
}
.p360-placeholder i { font-size: 3rem; color: var(--p360-primary); margin-bottom: 1rem; }

/* ---------- Splash de carregamento ---------- */
.p360-splash { display: grid; place-items: center; min-height: 100vh; gap: 1rem; }
.p360-splash__brand { font-size: 2rem; font-weight: 700; color: var(--p360-primary); }

/* ---------- Estado de erro Blazor ---------- */
#blazor-error-ui {
    color-scheme: light only;
    background: var(--p360-warning-bg); color: var(--p360-text);
    bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); box-sizing: border-box;
    display: none; left: 0; padding: .6rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.blazor-error-boundary { background: #b32121; padding: 1rem; color: #fff; }
.blazor-error-boundary::after { content: "Ocorreu um erro."; }

.loading-progress { position: relative; display: block; width: 8rem; height: 8rem; margin: 0 auto; }
.loading-progress circle {
    fill: none; stroke: var(--p360-border); stroke-width: .6rem; transform-origin: 50% 50%; transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: var(--p360-primary); stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * .8), 500%;
    transition: stroke-dasharray .05s ease-in-out;
}
.loading-progress-text { text-align: center; font-weight: 600; color: var(--p360-text-muted); }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "A carregar"); }

@media (max-width: 640px) {
    /* Esconde o nome do utilizador (fica só o avatar). O ">" é deliberado: sem ele, esta regra
       apagava também o texto do menu de conta, que vive dentro deste bloco. */
    .p360-header__user > span { display: none; }
}

/* ---------- Toasts (feedback global) ---------- */
.p360-toasts {
    position: fixed; top: 1rem; right: 1rem; z-index: 200;
    display: flex; flex-direction: column; gap: .55rem;
    max-width: min(380px, calc(100vw - 2rem)); pointer-events: none;
}

.p360-toast {
    position: relative; overflow: hidden;
    display: flex; align-items: flex-start; gap: .65rem;
    padding: .7rem .85rem .8rem;
    border-radius: var(--p360-radius);
    background: var(--p360-surface);
    border: 1px solid var(--p360-border);
    border-left: 4px solid var(--p360-text-muted);
    box-shadow:
        0 1px 2px rgba(17, 24, 39, .06),
        0 8px 18px -6px rgba(17, 24, 39, .16);
    font-size: .9rem; color: var(--p360-text); pointer-events: auto;
    transition: transform .14s ease-out, box-shadow .14s ease-out;
    animation: p360-toast-in .22s cubic-bezier(.2, .8, .2, 1) both;
}

.p360-toast:hover {
    transform: translateY(-1px);
    box-shadow:
        0 2px 4px rgba(17, 24, 39, .08),
        0 12px 24px -6px rgba(17, 24, 39, .2);
}

/* ícone num badge circular tonal por nível */
.p360-toast__icon {
    flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
    width: 1.85rem; height: 1.85rem; margin-top: .05rem;
    border-radius: 999px;
    background: var(--p360-background); color: var(--p360-text-muted);
    font-size: 1rem; line-height: 1;
}

.p360-toast__body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.p360-toast__title { font-weight: 600; font-size: .9rem; line-height: 1.25; color: var(--p360-text); }
.p360-toast__text { color: var(--p360-text-muted); font-size: .85rem; line-height: 1.35; word-wrap: break-word; overflow-wrap: anywhere; }

.p360-toast__close {
    flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
    width: 1.5rem; height: 1.5rem; margin: -.15rem -.2rem 0 0;
    background: none; border: none; border-radius: var(--p360-radius-sm);
    cursor: pointer; color: var(--p360-text-muted);
    font-size: 1.15rem; line-height: 1;
    transition: background .12s ease-out, color .12s ease-out;
}
.p360-toast__close:hover { background: var(--p360-background); color: var(--p360-text); }
.p360-toast__close:focus-visible { outline: 2px solid var(--p360-primary); outline-offset: 1px; }

/* barra de progresso de auto-dismiss (4s) — pausa no hover para dar controlo ao clínico */
.p360-toast__bar {
    position: absolute; left: 0; bottom: 0; height: 3px; width: 100%;
    transform-origin: left center;
    background: var(--p360-text-muted);
    animation: p360-toast-bar 4s linear forwards;
}
.p360-toast:hover .p360-toast__bar { animation-play-state: paused; }

/* ---- variantes por nível ---- */
.p360-toast--success { border-left-color: var(--p360-success); }
.p360-toast--success .p360-toast__icon { background: var(--p360-success-bg); color: var(--p360-success); }
.p360-toast--success .p360-toast__bar { background: var(--p360-success); }

.p360-toast--error { border-left-color: var(--p360-danger); }
.p360-toast--error .p360-toast__icon { background: var(--p360-danger-bg); color: var(--p360-danger); }
.p360-toast--error .p360-toast__bar { background: var(--p360-danger); }

.p360-toast--warning { border-left-color: var(--p360-warning); }
.p360-toast--warning .p360-toast__icon { background: var(--p360-warning-bg); color: var(--p360-warning); }
.p360-toast--warning .p360-toast__bar { background: var(--p360-warning); }

.p360-toast--info { border-left-color: var(--p360-info); }
.p360-toast--info .p360-toast__icon { background: var(--p360-info-bg); color: var(--p360-info); }
.p360-toast--info .p360-toast__bar { background: var(--p360-info); }

@keyframes p360-toast-in {
    from { opacity: 0; transform: translateX(1rem); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes p360-toast-bar {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

/* acessibilidade: respeitar prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .p360-toast { animation: none; transition: none; }
    .p360-toast:hover { transform: none; }
    .p360-toast__bar { animation: none; transform: scaleX(1); opacity: .45; }
}

/* ---------- Spinner em ações (botões a gravar/processar) ---------- */
.p360-spin { animation: p360-spin .7s linear infinite; }
@keyframes p360-spin { to { transform: rotate(360deg); } }

/* ---------- Grelha do blister (mapa de tomas) ---------- */
.p360-bgrid { overflow-x: auto; margin: .1rem 0 .2rem; }
.p360-bgrid__grid { display: grid; gap: 4px; align-items: stretch; }
.p360-bgrid__day { text-align: center; padding: 3px 0; border-radius: var(--p360-radius-sm); }
.p360-bgrid__day--today { background: var(--p360-info-bg); }
.p360-bgrid__day-d { font-size: .66rem; font-weight: 600; color: var(--p360-text-muted); }
.p360-bgrid__day-dt { font-size: .6rem; color: var(--p360-text-muted); }
.p360-bgrid__day--today .p360-bgrid__day-d, .p360-bgrid__day--today .p360-bgrid__day-dt { color: var(--p360-info); }
.p360-bgrid__moment { position: sticky; left: 0; z-index: 1; background: var(--p360-surface); display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; font-size: .74rem; font-weight: 500; }
.p360-bgrid__cell { min-width: 0; min-height: 34px; border-radius: var(--p360-radius-sm); padding: 4px; display: flex; flex-direction: column; gap: 3px; border: 1px solid var(--p360-border); background: var(--p360-surface); }
.p360-bgrid__cell--empty { border-style: dashed; background: transparent; }
.p360-bgrid__chip { display: flex; align-items: center; justify-content: space-between; gap: 6px; max-width: 100%; border-radius: var(--p360-radius-sm); padding: 2px 8px; font-size: .68rem; font-weight: 500; color: var(--p360-text); }
.p360-bgrid__chip:hover { filter: brightness(.97); }
.p360-bgrid__chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p360-bgrid__chip-qty { flex: none; font-weight: 700; font-size: .64rem; opacity: .9; }
.p360-bgrid__chip-qty.is-one { font-weight: 400; opacity: .4; }
.p360-bgrid__legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; margin-top: .4rem; font-size: .72rem; color: var(--p360-text-muted); }
.p360-bgrid__legend-item { display: inline-flex; align-items: center; gap: 6px; }
.p360-bgrid__legend-sw { flex: none; width: 11px; height: 11px; border-radius: 3px; }
/* Dias/células já preparados (cobertos por um blister) — realce verde "Preparado" (claro vs. proposta). */
.p360-bgrid__day--covered { background: var(--p360-success-bg); }
.p360-bgrid__day--covered .p360-bgrid__day-d, .p360-bgrid__day--covered .p360-bgrid__day-dt { color: var(--p360-success); }
.p360-bgrid__day-prep { font-size: .52rem; font-weight: 700; color: var(--p360-success); line-height: 1.1; margin-top: 1px; white-space: nowrap; }
.p360-bgrid__day-prep i { font-size: .5rem; }
.p360-bgrid__cell--covered { background: var(--p360-success-bg); border-color: var(--p360-success); }
.p360-bgrid__cell--covered .p360-bgrid__chip { box-shadow: 0 0 0 1px rgba(22, 163, 74, .25); } /* destaca o chip sobre o fundo verde */
/* Célula que vai na bandeja do polo CACI (marcada ANTES de preparar, para a divisão
   ser visível a quem abate o stock). Âmbar como as Saídas: também é medicação que sai.
   Sem rótulo por célula: a legenda por cima da grelha chega, e um selo repetido em cada
   célula só tapava o nome do medicamento, que é o que ali importa ler. */
.p360-bgrid__cell--caci { background: #fffbeb; box-shadow: inset 0 0 0 1px #b45309; }

/* ---------- Folha de preparação (PIM): faixa de filtros + progresso + faixa por fármaco ---------- */
.p360-chips-filter { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-bottom: .6rem; }
.p360-chips-filter__prog { margin-left: auto; flex: 0 1 240px; min-width: 160px; align-self: center; }
.p360-chips-filter__prog-head { display: flex; justify-content: space-between; gap: .75rem; font-size: .72rem; color: var(--p360-text-muted); margin-bottom: .2rem; white-space: nowrap; }
.p360-chips-filter__prog-val { font-weight: 600; color: var(--p360-text); }
.p360-chip-filter { font-size: .8rem; padding: .25rem .7rem; border-radius: 999px; border: 1px solid var(--p360-border); background: var(--p360-surface); color: var(--p360-text-muted); cursor: pointer; }
.p360-chip-filter:hover { color: var(--p360-text); }
.p360-chip-filter--active { background: var(--p360-info-bg); color: var(--p360-info); border-color: var(--p360-info-bg); font-weight: 600; }
.p360-card--done { opacity: .68; padding: .5rem .85rem; }
.p360-card--done:hover { opacity: 1; }
.p360-flines { display: flex; flex-direction: column; gap: .3rem; margin-top: .55rem; }
.p360-fline { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .4rem .55rem; border-radius: var(--p360-radius-sm); background: var(--p360-background); border-left: 3px solid var(--p360-text-muted); }
.p360-fline--ok { border-left-color: var(--p360-success); }
.p360-fline--warn { border-left-color: var(--p360-warning); }
.p360-fline--danger { border-left-color: var(--p360-danger); }
.p360-fline--side { background: transparent; margin-left: .8rem; }
.p360-fline__sw { width: 13px; height: 13px; border-radius: 50%; flex: none; border: 1.5px solid var(--p360-border); }
.p360-fline__name { font-size: .92rem; }
.p360-fline__gap { flex: 1 1 auto; }
.p360-fline__total { font-size: .82rem; color: var(--p360-text); }
.p360-fline__lot { font-size: .78rem; color: var(--p360-text-muted); }
.p360-fline__act { display: inline-flex; gap: .25rem; }
.p360-fline__note { font-size: .78rem; color: var(--p360-danger); margin: -.1rem 0 .15rem 1.2rem; }
.p360-flines__group { font-size: .74rem; font-weight: 600; color: var(--p360-text-muted); text-transform: uppercase; letter-spacing: .03em; margin-top: .35rem; }

/* Agenda — peças partilhadas por mais do que um componente, e por isso fora do CSS com escopo.
   O modal de criar atividade (ActivityCreateModal) e os campos de recorrência (RecurrenceFields)
   saíram da página Atividades.razor para poderem ser usados também na ficha do residente (PIS-038);
   o CSS com escopo do Blazor só se aplica ao componente dono do ficheiro, logo estas classes têm
   de viver aqui. As exclusivas de cada componente ficam no .razor.css respetivo. */
.atv-body { background: var(--p360-background, #f9fafb); }
.atv-section { border: 1px solid var(--p360-border, #e5e7eb); border-radius: .7rem; padding: .7rem; margin-bottom: .7rem; }
.atv-section__t { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--p360-primary); margin-bottom: .5rem; }
.atv-check { display: flex; align-items: center; gap: .45rem; font-size: .85rem; cursor: pointer; padding: .12rem 0; }
.atv-link { background: none; border: none; color: var(--p360-primary); cursor: pointer; font-size: .78rem; padding: 0; text-decoration: underline; }
.atv-chip { border: 1px solid var(--p360-border, #e5e7eb); background: #fff; border-radius: .45rem; padding: .25rem .55rem; font-size: .76rem; cursor: pointer; }
.atv-chip--on { background: var(--p360-primary); color: #fff; border-color: var(--p360-primary); }

/* Atividades — vista Lista do calendário (FullCalendar): conteúdo rico do evento. */
.atvcal-li { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.atvcal-li__title { font-weight: 600; }
.atvcal-li .atvcal-cat { font-size: .66rem; border: 1px solid; border-radius: 1rem; padding: .04rem .45rem; font-weight: 600; }
.atvcal-li__meta { color: var(--p360-text-muted); font-size: .8rem; display: inline-flex; align-items: center; gap: .35rem; }
.atvcal-li__status { margin-left: auto; font-size: .72rem; color: var(--p360-text-muted); }
.atvcal-li .atvcal-sep { color: #cbd5e1; }

/* Atividades — cards do calendário (Mês/Semana/Dia): barra da categoria à esquerda + fundo claro + estado. */
#atividades-cal .fc-event, #atividades-cal-residente .fc-event { border-width: 0 0 0 4px; border-radius: 4px; }
#atividades-cal .fc-event .fc-event-main, #atividades-cal-residente .fc-event .fc-event-main { padding: 0; }
/* Recorta o que não cabe (eventos curtos) e dá um pouco mais de altura por hora para o card respirar. */
#atividades-cal .fc-timegrid-event, #atividades-cal-residente .fc-timegrid-event { overflow: hidden; }
#atividades-cal .fc-timegrid-slot, #atividades-cal-residente .fc-timegrid-slot { height: 1.9rem; }
.atvev { padding: 1px 3px; line-height: 1.2; overflow: hidden; }
.atvev--xs { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.atvev--xs .atvev__time { flex: none; }
.atvev--xs .atvev__title { min-width: 0; }
.atvev__time { display: flex; align-items: center; gap: 4px; font-size: 11px; }
.atvev__title { font-weight: 600; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.atvev__meta { font-size: 11px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.atvev__foot { font-size: 11px; opacity: .9; }
.atvev-m { display: flex; align-items: center; gap: 4px; font-size: 12px; padding: 0 2px; overflow: hidden; white-space: nowrap; }
.atvev-m__time { font-weight: 600; }
/* Ausência (módulo Saídas) sobreposta à agenda: faixa de dia inteiro, sem hora nem presenças. */
.atvev--leave { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.atvev--leave .atvev__title { font-weight: 600; }

/* Telemóvel: a barra do FullCalendar empilha (prev/next · título · vistas) em vez de o título
   se sobrepor aos botões. Vale nos dois calendários (topo e ficha do residente). */
@media (max-width: 640px) {
    #atividades-cal .fc-toolbar.fc-header-toolbar,
    #atividades-cal-residente .fc-toolbar.fc-header-toolbar {
        flex-direction: column; align-items: stretch; gap: .5rem; margin-bottom: 1rem;
    }
    #atividades-cal .fc-toolbar-chunk,
    #atividades-cal-residente .fc-toolbar-chunk { display: flex; justify-content: center; }
    #atividades-cal .fc-toolbar-title,
    #atividades-cal-residente .fc-toolbar-title { font-size: 1.05rem; text-align: center; }
    /* Vista Lista: mantém as larguras naturais das colunas (legível) e o scroller do FullCalendar
       contém a tabela (desliza) em vez de rebentar o ecrã. A data curta (JS) minimiza o deslize.
       O !important vence o overflow inline que o FullCalendar aplica aos scrollers. */
    #atividades-cal .fc-scroller, #atividades-cal-residente .fc-scroller { overflow-x: auto !important; }
}

/* ============================================================
   Responsividade — breakpoints canónicos + adaptação a telemóvel
   Fonte única dos breakpoints (media queries não aceitam var()):
     • sm (telemóvel) : max-width 640px
     • md (tablet)    : max-width 900px
     • lg (desktop)   : > 900px
   Convenção: docs/09-Convencao-Responsiva-PWA.md. Trabalho novo usa SÓ
   estes valores; os legados (560/820/1100) normalizam-se ao tocar-lhes.
   ============================================================ */

@media (max-width: 640px) {
    /* Cabeçalho: mostrar o hambúrguer e respeitar as zonas seguras (notch) */
    .p360-header {
        gap: .5rem;
        padding-left: max(.75rem, env(safe-area-inset-left));
        padding-right: max(.75rem, env(safe-area-inset-right));
    }
    .p360-header__menu { display: inline-flex; }
    .p360-header__brand { font-size: 1.05rem; }

    /* Barra de módulos → gaveta vertical (drawer) por baixo do cabeçalho */
    .p360-nav {
        position: fixed; left: 0; right: 0; top: var(--p360-header-h); z-index: 45;
        flex-direction: column; align-items: stretch; gap: 0;
        height: auto;                /* anula a altura fixa (46px) da barra desktop — senão só cabe 1 link */
        padding: .25rem 0;
        max-height: calc(100dvh - var(--p360-header-h));
        overflow-x: hidden; overflow-y: auto; white-space: normal;
        box-shadow: var(--p360-shadow-lg);
        display: none;               /* fechada por omissão */
    }
    .p360-nav--open { display: flex; }
    .p360-nav .p360-header__spacer { display: none; }   /* o spacer flex não faz sentido na coluna */

    /* Ligações a toda a largura, com alvo de toque confortável (≥48px) */
    .p360-nav__link {
        padding: .85rem 1.1rem; min-height: 48px; font-size: .95rem;
        border-bottom: 1px solid var(--p360-border);
        border-left: 3px solid transparent;   /* indicador ativo à esquerda, não underline */
    }
    .p360-nav__link.active {
        border-bottom-color: var(--p360-border);
        border-left-color: var(--p360-primary);
        background: var(--p360-primary-100);
    }

    /* Grupos na gaveta: acordeão a toda a largura, sem dropdown flutuante (F7.9) */
    .p360-nav__group { display: block; width: 100%; position: static; }
    .p360-nav__link--group { width: 100%; justify-content: flex-start; border-top: 0; }
    .p360-nav__chevron { margin-left: auto; }
    .p360-nav__dropdown {
        position: static; min-width: 0; padding: 0;
        background: var(--p360-background); border: none; border-radius: 0; box-shadow: none;
    }
    .p360-nav__dropdown-link {
        padding: .8rem 1.1rem .8rem 2.4rem; min-height: 48px; white-space: normal;
        border-bottom: 1px solid var(--p360-border); border-radius: 0;
    }
    /* No desktop este apanha-cliques fecha o grupo; na gaveta taparia a própria gaveta. */
    .p360-nav__catch { display: none; }

    /* Fundo escurecido — tocar fora fecha a gaveta */
    .p360-nav__backdrop--show {
        display: block; position: fixed; inset: var(--p360-header-h) 0 0 0; z-index: 44;
        background: rgba(0,0,0,.35);
    }

    /* iOS: campos a ≥16px evitam o zoom automático ao focar */
    input, select, textarea { font-size: 16px; }

    /* Modais → bottom-sheet a toda a largura, com cabeçalho/rodapé fixos e zona segura.
       O !important é deliberado: vários componentes definem largura própria em CSS scoped
       (ex.: .vs-chart-modal[b-xxx] { max-width:1000px }) que, por especificidade, venceria esta
       regra e rebentaria o ecrã pequeno. É uma regra global de layout mobile, não um penso pontual. */
    .p360-modal-backdrop { padding: 0; place-items: end stretch; }
    .p360-modal, .p360-modal.p360-modal--wide {
        max-width: 100% !important; width: 100% !important; max-height: 92dvh;
        border-radius: var(--p360-radius) var(--p360-radius) 0 0;
    }
    .p360-modal__header { position: sticky; top: 0; background: var(--p360-surface); z-index: 1; }
    .p360-modal__footer {
        position: sticky; bottom: 0; background: var(--p360-surface);
        padding-bottom: max(.85rem, env(safe-area-inset-bottom));
    }

    /* Backoffice: a sidebar de secções vira uma faixa horizontal deslizável */
    .p360-adminshell { flex-direction: column; align-items: stretch; gap: .75rem; }
    .p360-adminshell__aside { width: 100%; }
    .p360-adminshell__nav { display: flex; gap: .25rem; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .p360-adminshell__label { display: none; }
    .p360-adminshell__nav .p360-admin-link { flex: none; white-space: nowrap; }

    /* Ficha do utente: nível 1 (módulos) vira botão-seletor; a barra deslizante esconde-se */
    .p360-modtabs { display: none; }
    .p360-modpick {
        display: flex; align-items: center; gap: .5rem; width: 100%;
        padding: .7rem .9rem; min-height: 48px;
        background: var(--p360-surface); border: 1px solid var(--p360-border);
        border-radius: var(--p360-radius); box-shadow: var(--p360-shadow);
        color: var(--p360-primary-700); font-weight: 600; font-size: .95rem; cursor: pointer;
    }
    .p360-modpick > i:first-child { color: var(--p360-primary); }
    .p360-modpick__label { flex: 1; text-align: left; }
    .p360-modpick__chev { color: var(--p360-text-muted); font-size: .8rem; }

    /* Nível 2 (sub-separadores): chips com alvo de toque confortável (já quebram para várias linhas) */
    .p360-subtab { padding: .5rem .85rem; }

    /* Tabelas: as não embrulhadas passam a deslizar horizontalmente (padrão GitHub);
       as que já vivem num .p360-scroll-x mantêm o comportamento (o wrapper é que desliza). */
    .p360-table { display: block; width: max-content; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .p360-scroll-x .p360-table { display: table; width: 100%; }

    /* Ações de linha ("⋮") e menus com alvo de toque confortável (≥40px) — vale em todas as listas */
    .p360-iconbtn { width: 40px; height: 40px; }
    .p360-menu { min-width: 200px; }
    .p360-menu button { padding: .7rem .8rem; font-size: .95rem; }
}

/* Nota da divisão em dois blisters (confirmação da preparação). Faixa discreta com barra à
   esquerda em vez de pastilha: o texto é uma frase, e uma pastilha arredondada com inline-flex
   quebrava as palavras em blocos difíceis de ler. */
.p360-caci-note {
  margin: .5rem 0 .2rem;
  padding: .55rem .7rem;
  border-left: 3px solid #b45309;
  border-radius: 0 .4rem .4rem 0;
  background: #fffbeb;
  color: var(--p360-text, #1f2937);
  font-size: .84rem;
  line-height: 1.45;
}
.p360-caci-note > p { margin: 0 0 .35rem; }
.p360-caci-note > label { display: flex; align-items: center; gap: .4rem; cursor: pointer; font-size: .82rem; }
.p360-caci-note > label > input { margin: 0; }

/* Nota em faixa — uma frase de contexto ou de aviso dentro de um cartão ou modal.
   Barra à esquerda em vez de pastilha (o texto é uma frase, e uma pastilha arredondada
   quebrava as palavras em blocos difíceis de ler, como se viu na nota do CACI).
   Cores pelos tokens semânticos, para funcionar em qualquer ecrã sem valores à mão. */
.p360-note {
  padding: .55rem .7rem;
  border-left: 3px solid var(--p360-info);
  border-radius: 0 var(--p360-radius-sm) var(--p360-radius-sm) 0;
  background: var(--p360-info-bg);
  color: var(--p360-text);
  font-size: .84rem;
  line-height: 1.45;
}
.p360-note--warning { border-left-color: var(--p360-warning); background: var(--p360-warning-bg); }
.p360-note--danger  { border-left-color: var(--p360-danger);  background: var(--p360-danger-bg); }
.p360-note--success { border-left-color: var(--p360-success); background: var(--p360-success-bg); }

/* ---------- Cliente em contexto no cabeçalho (F7.14) ----------
   Cor própria, diferente de tudo o resto da aplicação: é a peça que evita escrever no cliente
   errado, e só evita se se ler de relance. */
.p360-ctx-pick {
    display: inline-flex; align-items: center; gap: .45rem;
    padding: .35rem .7rem; border: 0; border-radius: var(--p360-radius-sm);
    background: rgba(255,255,255,.16); color: var(--p360-on-primary);
    font: inherit; font-size: .85rem; cursor: pointer;
}
.p360-ctx-pick:hover { background: rgba(255,255,255,.28); }
.p360-ctx {
    display: inline-flex; align-items: center; gap: .5rem; max-width: 46vw;
    padding: .25rem .35rem .25rem .6rem; border-radius: var(--p360-radius-sm);
    background: #dbeafe; color: #1e3a8a; font-size: .85rem;
}
.p360-ctx > i { color: #1d4ed8; }
.p360-ctx__name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p360-ctx__bed { color: #1d4ed8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .9; }
.p360-ctx__btn {
    border: 0; border-radius: 4px; padding: .15rem .4rem; cursor: pointer;
    background: rgba(29,78,216,.12); color: #1e3a8a; font: inherit; font-size: .76rem;
}
.p360-ctx__btn:hover { background: rgba(29,78,216,.24); }
.p360-ctx__btn--x { padding: .15rem .35rem; }

/* Janela de escolha do cliente.
   A janela é desenhada DENTRO do cabeçalho (é de lá que se abre) e o cabeçalho pinta o texto a
   branco: sem esta cor, o título saía invisível sobre o fundo branco da janela. */
.p360-ctxpick { max-width: 560px; color: var(--p360-text); }
.p360-ctxpick__body { padding: 1rem; }
.p360-ctxpick__hint { margin: 0 0 .6rem; color: var(--p360-text-muted); font-size: .85rem; }
.p360-ctxpick__body .p360-input { width: 100%; }
.p360-ctxpick__list { margin-top: .6rem; max-height: 46vh; overflow-y: auto; border-top: 1px solid var(--p360-border); }
.p360-ctxpick__row {
    display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left;
    padding: .6rem .5rem; border: 0; border-bottom: 1px solid var(--p360-border);
    background: transparent; font: inherit; cursor: pointer; color: var(--p360-text);
}
.p360-ctxpick__row:hover { background: var(--p360-primary-100); }
.p360-ctxpick__name { font-weight: 600; font-size: .9rem; display: block; }
.p360-ctxpick__empty { margin: .8rem 0 0; color: var(--p360-text-muted); font-size: .85rem; }

@media (max-width: 640px) {
    /* No telemóvel o nome chega: a cama faria o cabeçalho passar a duas linhas. */
    .p360-ctx { max-width: 52vw; }
    .p360-ctx__bed { display: none; }
    .p360-ctx-pick span { display: none; }
}

/* Linha do seletor de cliente: foto, nome com localização, e o mesmo «Abrir» da lista. */
.p360-ctxpick__who { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.p360-ctxpick__open { pointer-events: none; margin-left: auto; white-space: nowrap; }

/* ============================================================
   Painéis à medida (F7.17, docs/18): construtor, visuais e gráficos
   A paleta categórica é a validada para daltonismo (ordem fixa, nunca reciclada ao acaso);
   os valores com cor própria (estados, categorias) trazem-na do servidor.
   ============================================================ */
:root {
    --p360-chart-1: #2a78d6; --p360-chart-2: #eb6834; --p360-chart-3: #1baf7a; --p360-chart-4: #eda100;
    --p360-chart-5: #e87ba4; --p360-chart-6: #008300; --p360-chart-7: #4a3aa7; --p360-chart-8: #e34948;
    --p360-chart-other: #9aa0a6;
    --p360-chart-grid: #eceef1;
    --p360-chart-axis: #d1d5db;
    --p360-primary-50: #f8f6ee;
}

/* ---- barra dos painéis ---- */
.rpt-panels { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; margin-bottom: .6rem; }
.rpt-panel-tab {
    display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--p360-border);
    background: var(--p360-surface); color: var(--p360-text); border-radius: 999px; padding: .32rem .8rem;
    font-size: .85rem; cursor: pointer; max-width: 22rem;
}
.rpt-panel-tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-panel-tab:hover { border-color: var(--p360-primary); }
.rpt-panel-tab--on { background: var(--p360-primary-100); border-color: var(--p360-primary); color: var(--p360-primary-700); font-weight: 600; }
.rpt-panel-tab i { color: var(--p360-text-muted); font-size: .78rem; }
.rpt-panel-tab--on i { color: var(--p360-primary-700); }
.rpt-panel-tab--new { border-style: dashed; color: var(--p360-text-muted); }

/* ---- barra do painel aberto ---- */
.rpt-tb {
    background: var(--p360-surface); border: 1px solid var(--p360-border); border-radius: var(--p360-radius) var(--p360-radius) 0 0;
    display: flex; align-items: center; gap: .5rem .8rem; flex-wrap: wrap; padding: .55rem .8rem;
}
.rpt-tb__l { display: flex; align-items: center; gap: .5rem; flex: 1 1 18rem; min-width: 0; }
.rpt-tb__icon { color: var(--p360-primary-700); font-size: 1.15rem; }
.rpt-tb__name { font-size: 1.05rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-tb__input { font: inherit; font-size: 1.02rem; font-weight: 700; border: 1px solid var(--p360-border); border-radius: .35rem; padding: .2rem .45rem; min-width: 0; width: min(26rem, 100%); }
.rpt-tb__meta { font-size: .76rem; color: var(--p360-text-muted); white-space: nowrap; }
.rpt-tb__r { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.rpt-tb .p360-btn { font-size: .82rem; padding: .35rem .65rem; }
.rpt-dirty { color: var(--p360-warning); font-size: .76rem; font-weight: 600; white-space: nowrap; }

.rpt-seg { display: inline-flex; border: 1px solid var(--p360-border); border-radius: .4rem; overflow: hidden; }
.rpt-seg button { border: 0; background: var(--p360-surface); color: var(--p360-text); font: inherit; font-size: .82rem; padding: .32rem .7rem; cursor: pointer; }
.rpt-seg button + button { border-left: 1px solid var(--p360-border); }
.rpt-seg button.on { background: var(--p360-primary-100); color: var(--p360-primary-700); font-weight: 600; }
.rpt-seg button:disabled { opacity: .45; cursor: not-allowed; }

/* ---- filtros ---- */
.rpt-fbar {
    background: var(--p360-primary-50); border: 1px solid var(--p360-border); border-top: 0;
    padding: .45rem .8rem; display: flex; flex-wrap: wrap; gap: .4rem .6rem; align-items: center; font-size: .82rem;
}
.rpt-fbar__l { font-weight: 600; color: var(--p360-text); display: inline-flex; gap: .35rem; align-items: center; }
.rpt-fbar label { display: inline-flex; gap: .35rem; align-items: center; }
.rpt-sel { font: inherit; font-size: .82rem; padding: .26rem .4rem; border: 1px solid var(--p360-border); border-radius: .35rem; background: var(--p360-surface); color: var(--p360-text); max-width: 100%; min-width: 0; }
.rpt-sel--full { width: 100%; }
.rpt-chip { display: inline-flex; align-items: center; gap: .15rem; background: var(--p360-info-bg); color: var(--p360-info); border-radius: 999px; padding: .12rem .2rem .12rem .6rem; font-size: .78rem; }
.rpt-chip--sel { background: var(--p360-primary-100); color: var(--p360-primary-700); font-weight: 600; }
.rpt-chip button { border: 0; background: transparent; color: inherit; cursor: pointer; padding: 0 .25rem; font-size: .8rem; }
.rpt-fadd { display: inline-flex; gap: .3rem; flex-wrap: wrap; align-items: center; }

/* ---- área de trabalho ---- */
.rpt-main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; border: 1px solid var(--p360-border); border-top: 0; border-radius: 0 0 var(--p360-radius) var(--p360-radius); background: var(--p360-background); }
.rpt-main--read { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 980px) { .rpt-main { grid-template-columns: minmax(0, 1fr); } }
.rpt-stage { padding: .8rem; min-width: 0; }
.rpt-ptabs { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; margin-bottom: .7rem; }
.rpt-ptab { border: 1px solid var(--p360-border); background: var(--p360-surface); color: var(--p360-text); border-radius: .4rem .4rem 0 0; padding: .32rem .8rem; font-size: .82rem; cursor: pointer; border-bottom-width: 2px; }
.rpt-ptab--on { border-bottom-color: var(--p360-primary); color: var(--p360-primary-700); font-weight: 600; }
.rpt-ptab--add { border-style: dashed; color: var(--p360-text-muted); }
.rpt-ptab-edit { display: inline-flex; gap: .35rem; align-items: center; margin-left: auto; font-size: .78rem; color: var(--p360-text-muted); }
.rpt-ptab-edit input { font: inherit; font-size: .8rem; border: 1px solid var(--p360-border); border-radius: .3rem; padding: .18rem .4rem; width: 11rem; }

.rpt-canvas { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; align-items: start; min-height: 160px; border-radius: var(--p360-radius); }
.rpt-canvas--over { outline: 2px dashed var(--p360-primary); outline-offset: 4px; }
.rpt-card { grid-column: span var(--span, 6); background: var(--p360-surface); border: 1px solid var(--p360-border); border-radius: var(--p360-radius); box-shadow: var(--p360-shadow); min-width: 0; position: relative; }
.rpt-card--sel { outline: 2px solid var(--p360-primary); outline-offset: 1px; }
.rpt-card--over { outline: 2px dashed var(--p360-primary); outline-offset: 1px; }
@media (max-width: 1180px) {
    .rpt-canvas { grid-auto-flow: row dense; }
    .rpt-card[data-w="3"], .rpt-card[data-w="4"] { grid-column: span 6; }
    .rpt-card[data-w="8"] { grid-column: span 12; }
}
@media (max-width: 640px) { .rpt-card, .rpt-newvis { grid-column: span 12 !important; } }
.rpt-card__h { display: flex; align-items: flex-start; gap: .3rem; padding: .55rem .65rem .15rem; }
.rpt-card__tt { flex: 1; min-width: 0; }
.rpt-card__t { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-card__s { font-size: .72rem; color: var(--p360-text-muted); display: flex; gap: .2rem .6rem; flex-wrap: wrap; align-items: center; margin-top: .1rem; }
.rpt-card__acts { display: flex; gap: 0; opacity: .45; transition: opacity .12s; }
.rpt-card:hover .rpt-card__acts, .rpt-card:focus-within .rpt-card__acts, .rpt-card--sel .rpt-card__acts { opacity: 1; }
.rpt-card__b { padding: .25rem .65rem .75rem; min-height: 40px; position: relative; }
.rpt-warn { display: inline-flex; gap: .25rem; align-items: center; color: var(--p360-warning); }
.rpt-selbadge { display: inline-flex; gap: .25rem; align-items: center; color: var(--p360-primary-700); }
.rpt-ib { width: 28px; height: 28px; display: inline-grid; place-items: center; border: 0; background: transparent; color: var(--p360-text-muted); border-radius: .35rem; cursor: pointer; padding: 0; flex: none; }
.rpt-ib:hover { background: var(--p360-background); color: var(--p360-text); }
.rpt-ib:disabled { opacity: .35; cursor: not-allowed; }
.rpt-newvis { grid-column: span 4; border: 2px dashed var(--p360-border); border-radius: var(--p360-radius); background: transparent; min-height: 140px; display: grid; place-items: center; align-content: center; gap: .3rem; color: var(--p360-text-muted); cursor: pointer; padding: 1rem; text-align: center; font: inherit; font-size: .85rem; }
.rpt-newvis:hover, .rpt-newvis--over { border-color: var(--p360-primary); color: var(--p360-primary-700); background: var(--p360-primary-50); }
.rpt-newvis i { font-size: 1.4rem; }
.rpt-empty-page { grid-column: span 12; color: var(--p360-text-muted); text-align: center; padding: 2.5rem 1rem; }
.rpt-msg { display: grid; place-items: center; text-align: center; color: var(--p360-text-muted); padding: 1.2rem .6rem; gap: .45rem; font-size: .84rem; }
.rpt-msg > i { font-size: 1.3rem; }
.rpt-msg--error { color: var(--p360-danger); }
.rpt-loading { position: absolute; top: .5rem; right: .7rem; font-size: .75rem; color: var(--p360-text-muted); }

/* ---- painel lateral do construtor ---- */
.rpt-side { background: var(--p360-surface); border-left: 1px solid var(--p360-border); position: sticky; top: calc(var(--p360-header-h) + var(--p360-nav-h)); max-height: calc(100vh - var(--p360-header-h) - var(--p360-nav-h)); overflow: auto; border-radius: 0 0 var(--p360-radius) 0; }
@media (max-width: 980px) { .rpt-side { border-left: 0; border-top: 1px solid var(--p360-border); position: static; max-height: none; } }
.rpt-side__sec { padding: .7rem .85rem; border-bottom: 1px solid var(--p360-border); }
.rpt-side__t { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--p360-text-muted); font-weight: 700; margin-bottom: .5rem; display: flex; justify-content: space-between; gap: .5rem; }
.rpt-side__ds { text-transform: none; letter-spacing: 0; color: var(--p360-primary-700); font-weight: 600; }
.rpt-side__hint { font-size: .76rem; color: var(--p360-text-muted); margin-top: .45rem; }
.rpt-side__row { display: flex; gap: .5rem; align-items: flex-end; margin-top: .45rem; }
.rpt-side__row > div { flex: 1; min-width: 0; }
.rpt-side__row label { font-size: .74rem; color: var(--p360-text-muted); display: block; margin-bottom: .15rem; }
.rpt-vtypes { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .25rem; }
.rpt-vtype { aspect-ratio: 1; border: 1px solid var(--p360-border); border-radius: .35rem; background: var(--p360-surface); display: grid; place-items: center; cursor: pointer; color: var(--p360-text); padding: 0; }
.rpt-vtype:hover { border-color: var(--p360-primary); }
.rpt-vtype--on { border-color: var(--p360-primary); background: var(--p360-primary-100); color: var(--p360-primary-700); }
.rpt-wlabel { font-size: .75rem; font-weight: 600; color: var(--p360-text); margin: .6rem 0 .2rem; }
.rpt-well { border: 1px dashed var(--p360-border); border-radius: .4rem; padding: .3rem; min-height: 32px; display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; background: var(--p360-background); }
.rpt-well--over { border-color: var(--p360-primary); background: var(--p360-primary-50); }
.rpt-well__ph { font-size: .74rem; color: var(--p360-text-muted); padding: 0 .2rem; }
.rpt-wchip { display: inline-flex; align-items: center; gap: .25rem; background: var(--p360-surface); border: 1px solid var(--p360-border); border-radius: 999px; padding: .08rem .15rem .08rem .5rem; font-size: .78rem; max-width: 100%; }
.rpt-wchip--m { border-color: #d6d0a8; background: var(--p360-primary-50); }
.rpt-wchip--off { opacity: .5; text-decoration: line-through; }
.rpt-wchip button { border: 0; background: transparent; color: var(--p360-text-muted); cursor: pointer; padding: 0 .2rem; }
.rpt-check { display: flex; gap: .45rem; align-items: center; font-size: .82rem; margin-top: .55rem; }
.rpt-fgrp { border-top: 1px solid var(--p360-border); padding: .3rem 0; }
.rpt-fgrp:first-of-type { border-top: 0; }
.rpt-fgrp summary { font-weight: 600; cursor: pointer; padding: .3rem 0; display: flex; gap: .45rem; align-items: center; list-style: none; font-size: .86rem; }
.rpt-fgrp summary::-webkit-details-marker { display: none; }
.rpt-fgrp summary .rpt-caret { margin-left: auto; color: var(--p360-text-muted); transition: transform .15s; }
.rpt-fgrp[open] summary .rpt-caret { transform: rotate(180deg); }
.rpt-fgrp__h { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--p360-text-muted); margin: .35rem 0 .1rem .1rem; }
.rpt-fld { display: flex; width: 100%; align-items: center; gap: .45rem; border: 0; background: transparent; padding: .26rem .35rem; border-radius: .3rem; font: inherit; font-size: .82rem; color: var(--p360-text); cursor: grab; text-align: left; }
.rpt-fld:hover { background: var(--p360-background); }
.rpt-fld__i { width: 1.1rem; text-align: center; color: var(--p360-text-muted); font-size: .8rem; flex: none; }
.rpt-fld--m .rpt-fld__i { color: var(--p360-primary-700); font-weight: 700; }
.rpt-fld--used { font-weight: 600; color: var(--p360-primary-700); }
.rpt-fld--used::after { content: "\2713"; margin-left: auto; color: var(--p360-primary-700); }

/* ---- gráficos ---- */
.rpt-legend { display: flex; flex-wrap: wrap; gap: .25rem .8rem; font-size: .74rem; color: var(--p360-text); margin: .1rem 0 .4rem; }
.rpt-legend span { display: inline-flex; align-items: center; gap: .3rem; }
.rpt-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.rpt-legend i.ln { height: 3px; width: 14px; }
.rpt-readout { font-size: .76rem; color: var(--p360-text); min-height: 1.2rem; margin-bottom: .2rem; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.rpt-readout__k { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.rpt-readout b { font-variant-numeric: tabular-nums; }
.rpt-readout span.m { color: var(--p360-text-muted); }

/* barras (horizontais) */
.rpt-bars { display: grid; gap: .3rem; }
.rpt-bar { display: grid; grid-template-columns: minmax(6rem, 34%) minmax(0, 1fr) auto; align-items: center; gap: .5rem; border: 0; background: transparent; font: inherit; padding: .1rem .15rem; border-radius: .3rem; cursor: pointer; text-align: left; color: var(--p360-text); }
.rpt-bar:hover, .rpt-bar:focus-visible { background: var(--p360-primary-50); }
.rpt-bar--fade { opacity: .35; }
.rpt-bar__l { font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-bar__track { position: relative; height: 18px; background: repeating-linear-gradient(to right, var(--p360-chart-grid) 0 1px, transparent 1px 25%); border-left: 1px solid var(--p360-chart-axis); }
.rpt-bar__stack { display: flex; height: 100%; gap: 2px; }
.rpt-bar__seg { height: 100%; min-width: 1px; }
.rpt-bar__seg:last-child { border-radius: 0 4px 4px 0; }
.rpt-bar__group { display: grid; gap: 2px; height: 100%; align-content: center; }
.rpt-bar__group .rpt-bar__seg { height: 7px; border-radius: 0 3px 3px 0; }
.rpt-bar__v { font-size: .78rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rpt-bars__axis { display: grid; grid-template-columns: minmax(6rem, 34%) minmax(0, 1fr) auto; gap: .5rem; font-size: .7rem; color: var(--p360-text-muted); padding: 0 .15rem; }
.rpt-bars__ticks { position: relative; height: 1rem; }
.rpt-bars__ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.rpt-bars__ticks span:first-child { transform: none; }
.rpt-bars__ticks span:last-child { transform: translateX(-100%); }
@media (max-width: 460px) {
    .rpt-bar, .rpt-bars__axis { grid-template-columns: minmax(0, 1fr) auto; }
    .rpt-bar__l { grid-column: 1 / -1; }
    .rpt-bars__axis > span:first-child { display: none; }
}

/* colunas (verticais) */
.rpt-cols { position: relative; height: 200px; margin-left: 2.6rem; border-bottom: 1px solid var(--p360-chart-axis); }
.rpt-cols__grid { position: absolute; inset: 0; pointer-events: none; }
.rpt-cols__grid div { position: absolute; left: 0; right: 0; border-top: 1px solid var(--p360-chart-grid); }
.rpt-cols__grid span { position: absolute; right: calc(100% + .35rem); transform: translateY(-50%); font-size: .68rem; color: var(--p360-text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rpt-cols__bands { position: absolute; inset: 0; display: flex; align-items: flex-end; }
/* Sem padding em percentagem: mede-se pela largura do contentor e não da coluna, e com muitas colunas deixava-as com 0 px. */
.rpt-col { flex: 1 1 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; border: 0; background: transparent; padding: 0 1px; cursor: pointer; min-width: 0; font: inherit; }
.rpt-col:hover, .rpt-col:focus-visible { background: var(--p360-primary-50); }
.rpt-col--fade { opacity: .35; }
.rpt-col__stack { width: 64%; min-width: 2px; max-width: 34px; display: flex; flex-direction: column-reverse; gap: 2px; }
.rpt-col__seg { width: 100%; min-height: 1px; }
.rpt-col__stack .rpt-col__seg:last-child { border-radius: 4px 4px 0 0; }
.rpt-col__group { width: 76%; min-width: 3px; max-width: 44px; height: 100%; display: flex; align-items: flex-end; gap: 2px; }
.rpt-col__group .rpt-col__seg { flex: 1; border-radius: 3px 3px 0 0; }
/* Uma parte a zero num grupo lado a lado guarda o lugar (as outras não mudam de sítio) mas não se pinta:
   com o min-height, cada semana vazia ganhava um traço na linha de base. */
.rpt-col__seg--none, .rpt-bar__seg--none { visibility: hidden; }
.rpt-col__v { font-size: .68rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-bottom: .1rem; white-space: nowrap; }
.rpt-cols__x { display: flex; margin-left: 2.6rem; font-size: .68rem; color: var(--p360-text-muted); }
.rpt-cols__x span { flex: 1 1 0; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; padding-top: .2rem; }

/* linhas (SVG sem texto; rótulos em HTML por cima) */
.rpt-lines { position: relative; width: 100%; aspect-ratio: 600 / 220; }
.rpt-lines svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.rpt-lines__y, .rpt-lines__x { position: absolute; font-size: .68rem; color: var(--p360-text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; pointer-events: none; }
.rpt-lines__y { left: 0; width: 6.5%; text-align: right; transform: translateY(-50%); }
.rpt-lines__x { bottom: 0; transform: translateX(-50%); }
.rpt-lines__hit { position: absolute; top: 5%; bottom: 12%; display: flex; }
.rpt-lines__hit button { flex: 1 1 0; border: 0; background: transparent; padding: 0; cursor: pointer; }
.rpt-lines__hit button:hover, .rpt-lines__hit button:focus-visible { background: rgba(135, 125, 56, .08); }
/* A marca de cada ponto, com um anel da cor do fundo para se ler por cima da linha e da área. */
.rpt-lines__dot { position: absolute; width: 8px; height: 8px; border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 0 0 2px var(--p360-surface); pointer-events: none; }
.rpt-lines__dot--on { width: 11px; height: 11px; }

/* anel */
.rpt-donut { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.rpt-donut__ring { position: relative; width: 160px; height: 160px; flex: none; }
.rpt-donut__ring svg { width: 100%; height: 100%; }
.rpt-donut__ring path, .rpt-donut__ring circle { cursor: pointer; }
.rpt-donut__c { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.rpt-donut__c b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.rpt-donut__c span { font-size: .7rem; color: var(--p360-text-muted); }
.rpt-donut__leg { display: grid; gap: .2rem; font-size: .78rem; flex: 1 1 11rem; min-width: 11rem; }
.rpt-donut__leg button { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; gap: .45rem; align-items: center; cursor: pointer; border: 0; background: transparent; border-radius: .25rem; padding: .1rem .25rem; font: inherit; color: var(--p360-text); text-align: left; }
.rpt-donut__leg button:hover, .rpt-donut__leg button:focus-visible { background: var(--p360-background); }
.rpt-donut__leg i { width: 10px; height: 10px; border-radius: 2px; }
.rpt-donut__leg span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-donut__leg b { font-variant-numeric: tabular-nums; }
.rpt-donut__leg em { font-style: normal; color: var(--p360-text-muted); font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }
.rpt-fade { opacity: .3; }

/* cartão */
.rpt-kpis { display: flex; flex-wrap: wrap; gap: .5rem 1.6rem; padding: .2rem 0 .1rem; }
.rpt-kpi__v { font-size: 2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.rpt-kpi__v--none { font-size: 1.1rem; font-weight: 500; color: var(--p360-text-muted); padding: .45rem 0 .2rem; }
.rpt-kpi__l { font-size: .8rem; color: var(--p360-text); }
.rpt-kpi__c { font-size: .72rem; color: var(--p360-text-muted); }

/* tabela e matriz */
.rpt-tablewrap { overflow: auto; max-height: 360px; min-width: 0; }
.rpt-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.rpt-table th, .rpt-table td { padding: .34rem .5rem; border-bottom: 1px solid var(--p360-border); text-align: left; white-space: nowrap; }
.rpt-table thead th { font-size: .72rem; color: var(--p360-text-muted); font-weight: 600; background: var(--p360-background); position: sticky; top: 0; z-index: 1; }
.rpt-table tbody th { font-weight: 500; white-space: normal; min-width: 8.5rem; }
.rpt-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.rpt-table tfoot th, .rpt-table tfoot td { font-weight: 700; border-bottom: 0; background: var(--p360-surface); }
.rpt-table tr.rpt-row { cursor: pointer; }
.rpt-table tr.rpt-row:hover th, .rpt-table tr.rpt-row:hover td { background: var(--p360-primary-50); }
.rpt-table tr.rpt-row--fade { opacity: .35; }
.rpt-table td.rpt-none { color: var(--p360-text-muted); font-size: .72rem; }
.rpt-table td.rpt-heat { font-weight: 600; border: 2px solid #fff; border-radius: 4px; }
.rpt-heatleg { display: flex; align-items: center; gap: .4rem; font-size: .72rem; color: var(--p360-text); flex-wrap: wrap; margin: 0 0 .35rem; }
.rpt-heatleg__ramp { display: inline-flex; }
.rpt-heatleg__ramp i { display: block; width: 20px; height: 9px; }
.rpt-heatleg__ramp i:first-child { border-radius: 3px 0 0 3px; }
.rpt-heatleg__ramp i:last-child { border-radius: 0 3px 3px 0; }

/* ============================================================
   Aviso de mudança de endereço (js/relocation.js)
   Só aparece numa instalação com "Relocation:NewUrl" no appsettings.json do cliente.
   ============================================================ */
.p360-relocation {
    position: fixed; inset: 0; z-index: 10000;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    background: var(--p360-background);
    overflow-y: auto;
}
.p360-relocation__card {
    width: 100%; max-width: 560px;
    background: var(--p360-surface);
    border: 1px solid var(--p360-border);
    border-top: 4px solid var(--p360-primary);
    border-radius: var(--p360-radius);
    box-shadow: var(--p360-shadow-lg);
    padding: 28px 28px 24px;
    text-align: center;
}
.p360-relocation__brand {
    font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    color: var(--p360-primary-700);
}
.p360-relocation__title { margin: 10px 0 12px; font-size: 1.45rem; line-height: 1.25; }
.p360-relocation__text { margin: 0 0 14px; color: var(--p360-text-muted); line-height: 1.5; }
.p360-relocation__url {
    display: block; margin: 0 0 18px; padding: 12px;
    background: var(--p360-primary-100); color: var(--p360-primary-700);
    border-radius: var(--p360-radius-sm);
    font-weight: 700; font-size: 1.05rem;
}
.p360-relocation__url:hover { text-decoration: underline; }
.p360-relocation__countdown { margin-bottom: 16px; font-weight: 600; }
.p360-relocation__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.p360-relocation__btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; padding: 0 18px;
    border: 1px solid var(--p360-border); border-radius: var(--p360-radius-sm);
    background: var(--p360-surface); color: var(--p360-text);
    font: inherit; font-weight: 600; cursor: pointer;
}
.p360-relocation__btn:hover { background: var(--p360-background); text-decoration: none; }
.p360-relocation__btn--primary {
    background: var(--p360-primary); border-color: var(--p360-primary); color: var(--p360-on-primary);
}
.p360-relocation__btn--primary:hover { background: var(--p360-primary-600); color: var(--p360-on-primary); }
.p360-relocation__shutdown {
    margin-top: 20px; padding: 12px;
    background: var(--p360-warning-bg); color: #7c4a03;
    border-radius: var(--p360-radius-sm); line-height: 1.5;
}
.p360-relocation__clock { font-variant-numeric: tabular-nums; white-space: nowrap; }
.p360-relocation__note { margin: 12px 0 0; font-size: .85rem; color: var(--p360-text-muted); }
@media (max-width: 480px) {
    .p360-relocation__card { padding: 22px 16px 18px; }
    .p360-relocation__btn { width: 100%; }
}
