/* =======================================================================
   SDD Clínicas — estilos customizados
   Todo CSS próprio do sistema vive neste arquivo.
   ======================================================================= */

:root {
    --bs-primary-rgb: 13, 110, 253;
    --brand-accent: #0d6efd;
    --sidebar-width: 260px;
}

body {
    background-color: #f4f6f9;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow-x: hidden;
}

/* ------------------------------------------------------- Utilitários extra */

.fs-7 {
    font-size: 0.78rem !important;
}

.uppercase {
    text-transform: uppercase;
}

.hover-shadow {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hover-shadow:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08) !important;
}

/* --------------------------------------------------------------- Estrutura */

.wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background-color: #212529;
    color: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    transition: all 0.3s;
    overflow-x: hidden;
    box-sizing: border-box;
}

.sidebar .nav {
    width: 100%;
    padding: 0;
    margin: 0;
}

/*
 * Cabeçalho de grupo do menu. Espaçamento igual entre todos os grupos, para
 * não sobrar um vão maior entre um bloco e outro.
 */
.sidebar-group {
    padding: 0 1rem;
    margin: 14px 0 6px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: #6c757d;
}

.sidebar-group:first-of-type {
    margin-top: 0;
}

.sidebar .nav-item {
    width: 100%;
    padding: 0 12px;
    box-sizing: border-box;
}

.sidebar .nav-link {
    color: #ced4da;
    padding: 12px 16px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: all 0.2s ease;
    background: transparent;
    border: none;
    width: 100%;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
}

.sidebar .nav-link i {
    width: 24px;
    flex-shrink: 0;
}

.sidebar .nav-link:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.08);
}

.sidebar .nav-link.active {
    color: #fff;
    background-color: var(--brand-accent);
    box-shadow: 0 4px 10px rgba(13, 110, 253, 0.3);
    font-weight: 600;
}

.main-content {
    flex-grow: 1;
    padding: 24px;
    max-width: calc(100% - var(--sidebar-width));
}

/*
 * No desktop o menu fica preso na tela e só o conteúdo rola. Como a sidebar
 * sai do fluxo, o conteúdo recebe a margem equivalente à largura dela.
 */
@media (min-width: 992px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .main-content {
        margin-left: var(--sidebar-width);
    }
}

/* ------------------------------------------------------- Identidade visual */

.sidebar-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
    padding: 2px;
    flex-shrink: 0;
}

.logo-preview {
    width: 92px;
    height: 92px;
    object-fit: contain;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    background: #fff;
    padding: 6px;
}

.color-swatch {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.color-swatch.selected {
    border-color: #111827;
    box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.12);
}

.portal-logo {
    height: 42px;
    width: auto;
    max-width: 160px;
    object-fit: contain;
    background: #fff;
    border-radius: 8px;
    padding: 3px;
}

/* ------------------------------------------------------------------ Cards */

.stat-card {
    border: none;
    border-radius: 12px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06) !important;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding: 16px 20px;
}

/* ------------------------------------------------------------ Etapas/steps */

.step-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #e9ecef;
    color: #6c757d;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.step-active .step-icon,
.step-icon.step-active {
    background-color: var(--brand-accent);
    color: #fff;
}

.step-icon.step-done {
    background-color: #198754;
    color: #fff;
}

/* ---------------------------------------------------------- Badges "soft" */

.badge-soft-primary { background: #e0edff; color: #0d6efd; }
.badge-soft-success { background: #d1e7dd; color: #0f5132; }
.badge-soft-warning { background: #fff3cd; color: #664d03; }
.badge-soft-info    { background: #cff4fc; color: #055160; }
.badge-soft-secondary { background: #e2e8f0; color: #475569; }
.badge-soft-danger  { background: #f8d7da; color: #842029; }

/* -------------------------------------------------------- Assinatura digital */

.canvas-container {
    border: 2px dashed #cbd5e1;
    border-radius: 10px;
    background-color: #f8fafc;
    position: relative;
    touch-action: none;
    width: 100%;
}

.canvas-container canvas {
    width: 100%;
    height: 200px;
    display: block;
    border-radius: 8px;
    cursor: crosshair;
    touch-action: none;
}

.canvas-hint {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #adb5bd;
    font-size: 0.85rem;
    pointer-events: none;
}

.canvas-container.has-signature .canvas-hint {
    display: none;
}

.assinatura-preview {
    max-width: 250px;
    max-height: 100px;
    border-bottom: 2px solid #000;
}

.assinatura-mini {
    max-height: 44px;
    max-width: 130px;
}

/*
 * Modal rolável com <form> por dentro.
 *
 * O Bootstrap monta .modal-content como coluna flex e faz .modal-body encolher.
 * Quando existe um <form> entre os dois, essa corrente quebra: o corpo não
 * encolhe, estoura a altura e o .modal-content (overflow: hidden) corta o
 * rodapé — o botão de confirmar some em telas baixas, como as de notebook.
 * Repassar o comportamento de coluna para o form resolve em qualquer tamanho.
 */
.modal-dialog-scrollable .modal-content > form {
    display: flex;
    flex-direction: column;
    max-height: 100%;
    overflow: hidden;
}

.modal-dialog-scrollable .modal-body {
    min-height: 0;
}

/*
 * Telas de pouca altura: o quadro de assinatura e a leitura do termo cedem
 * espaço para o rodapé continuar visível sem precisar rolar.
 */
@media (max-height: 820px) {
    .canvas-container canvas {
        height: 150px;
    }

    .modal-body [data-sign-content],
    .modal-body [data-term-content],
    .modal-body .sdd-term-content {
        max-height: 130px !important;
    }
}

@media (max-height: 680px) {
    .canvas-container canvas {
        height: 120px;
    }

    .modal-body [data-sign-content],
    .modal-body [data-term-content],
    .modal-body .sdd-term-content {
        max-height: 90px !important;
    }
}

/*
 * Modal de assinatura no celular.
 *
 * O problema: 100vh (e o "100%" que o Bootstrap usa) contam a faixa escondida
 * atrás da barra de endereço do navegador, então o rodapé com os botões
 * "Li e Assino" / "Voltar" ficava abaixo da área visível. A unidade dvh
 * acompanha a altura realmente disponível.
 */
@media (max-width: 575.98px) {
    .modal-dialog-scrollable {
        height: calc(100vh - 1rem);
        height: calc(100dvh - 1rem);
    }

    .modal-dialog-scrollable .modal-footer {
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: #fff;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, .08);
        /* Espaço para a faixa do gesto de início do iPhone. */
        padding-bottom: calc(.5rem + env(safe-area-inset-bottom, 0px));
    }

    .modal-dialog-scrollable .modal-footer .btn {
        flex: 1 1 auto;
    }

    /* Sobra mais espaço para o termo e para o quadro de assinatura. */
    .canvas-container canvas {
        height: 150px;
    }

    .modal-body .sdd-term-content,
    .modal-body [data-term-content],
    .modal-body [data-sign-content] {
        max-height: 26vh !important;
    }
}

/* -------------------------------------------------------- Trilha de auditoria */

.audit-timeline {
    position: relative;
    padding-left: 20px;
}

.audit-timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 5px;
    bottom: 5px;
    width: 2px;
    background: #e2e8f0;
}

.audit-item {
    position: relative;
    margin-bottom: 16px;
}

.audit-item::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--brand-accent);
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.2);
}

/* --------------------------------------------------------------- Agenda */

.agenda-board {
    max-height: 68vh;
    overflow-y: auto;
}

.agenda-slot {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid #eef1f5;
    min-height: 62px;
}

.agenda-slot:last-child {
    border-bottom: none;
}

.agenda-slot-time {
    flex: 0 0 96px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    border-right: 1px solid #eef1f5;
    padding: 10px 8px;
}

.agenda-slot-time strong {
    font-size: 0.98rem;
    line-height: 1.1;
}

.agenda-slot-time small {
    font-size: 0.7rem;
    color: #adb5bd;
}

.agenda-slot-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 10px 16px;
    min-width: 0;
}

.agenda-slot.is-free .agenda-slot-body {
    background: #fff;
}

.agenda-slot.is-free:hover .agenda-slot-body {
    background: #f8fbff;
}

.agenda-slot.is-busy {
    border-left: 4px solid var(--brand-accent);
}

.agenda-slot.is-busy .agenda-slot-time {
    background: #fff;
}

.agenda-slot.is-blocked {
    border-left: 4px solid #adb5bd;
}

.agenda-slot.is-blocked .agenda-slot-body {
    background: repeating-linear-gradient(
        45deg,
        #f8f9fa,
        #f8f9fa 10px,
        #f1f3f5 10px,
        #f1f3f5 20px
    );
}

/* Calendário lateral */

.agenda-calendar-card {
    position: sticky;
    top: 16px;
}

.agenda-calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.agenda-calendar-weekday {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #adb5bd;
    text-transform: uppercase;
    padding-bottom: 4px;
}

.agenda-calendar-day {
    position: relative;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.85rem;
    color: #212529;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background .15s ease, border-color .15s ease;
}

.agenda-calendar-day:hover {
    background: #eef2f7;
    color: #212529;
}

.agenda-calendar-day.is-outside {
    color: #ced4da;
}

.agenda-calendar-day.is-closed {
    background: #f8f9fa;
    color: #ced4da;
}

.agenda-calendar-day.is-today {
    border-color: var(--brand-accent);
    font-weight: 700;
}

.agenda-calendar-day.is-selected {
    background: var(--brand-accent);
    color: #fff;
    font-weight: 700;
}

.agenda-calendar-day.is-selected:hover {
    background: var(--brand-accent);
    color: #fff;
}

.agenda-calendar-dot {
    position: absolute;
    bottom: 3px;
    right: 3px;
    font-style: normal;
    font-size: 0.58rem;
    font-weight: 700;
    line-height: 1;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    border-radius: 7px;
    background: #198754;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.agenda-calendar-day.is-selected .agenda-calendar-dot {
    background: #fff;
    color: var(--brand-accent);
}

.agenda-legend {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    margin-right: 4px;
    vertical-align: middle;
}

.agenda-legend.is-selected { background: var(--brand-accent); }
.agenda-legend.is-closed { background: #e9ecef; }
.agenda-legend.is-dot { background: #198754; }

@media (max-width: 991.98px) {
    .agenda-calendar-card {
        position: static;
    }

    .agenda-board {
        max-height: none;
    }
}

/* ----------------------------------------------- Coluna de ações da tabela */

/*
 * Faz a coluna encolher até o tamanho do botão e centraliza cabeçalho e
 * conteúdo, para o título "Ação" ficar exatamente sobre o botão.
 */
th.col-acoes,
td.col-acoes {
    width: 1%;
    white-space: nowrap;
    text-align: center;
}

/* ------------------------------- Lista rótulo/valor do detalhe do atendimento */

/*
 * Rótulo à esquerda e valor à direita, um par por linha. Evita a fila de
 * badges que quebrava quando havia desconto.
 */
.detalhe-valores {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 12px;
    row-gap: 4px;
    align-items: baseline;
    font-size: 0.86rem;
}

.detalhe-valores dt {
    font-weight: 600;
    color: #6c757d;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
}

.detalhe-valores dd {
    margin: 0;
    font-weight: 600;
}

/* ------------------------------------------------------------- Evoluções */

.evolucao-img-preview {
    max-width: 120px;
    max-height: 120px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    cursor: pointer;
    transition: transform 0.2s;
}

.evolucao-img-preview:hover {
    transform: scale(1.05);
}

/* --------------------------------------------------- Portal do paciente (web) */

.portal-body {
    background: linear-gradient(180deg, #eef2f7 0%, #f4f6f9 260px);
    min-height: 100vh;
}

.portal-topbar {
    background: #212529;
    color: #fff;
    padding: 18px 0;
}

.portal-shell {
    max-width: 960px;
}

/* Assistente em etapas do portal: só um painel por vez. */

.portal-pane {
    display: none;
}

.portal-pane.is-active {
    display: block;
}

.portal-steps {
    display: flex;
    align-items: center;
    gap: 8px;
}

.portal-step {
    flex: 1 1 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease;
    min-width: 0;
}

.portal-step:hover {
    border-color: var(--brand-accent);
}

.portal-step.is-active {
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), .12);
}

.portal-step-badge {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #e9ecef;
    color: #6c757d;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.portal-step.is-active .portal-step-badge {
    background: var(--brand-accent);
    color: #fff;
}

.portal-step.is-done .portal-step-badge {
    background: #198754;
    color: #fff;
}

.portal-step-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.portal-step-text strong {
    font-size: .9rem;
}

.portal-step-text small {
    font-size: .72rem;
    color: #6c757d;
}

.portal-step-line {
    flex: 0 0 24px;
    height: 2px;
    background: #e9ecef;
}

@media (max-width: 575.98px) {
    .portal-step-text small {
        display: none;
    }

    .portal-step {
        padding: 10px;
    }

    .portal-step-line {
        flex-basis: 12px;
    }
}

.portal-doc-item {
    border: 1px solid #e9ecef;
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 10px;
    background: #fff;
}

/* ----------------------------------------------------------- Sidebar mobile */

.sidebar-toggle {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1060;
    border-radius: 8px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(33, 37, 41, 0.5);
    z-index: 1035;
}

.sidebar-backdrop.show {
    display: block;
}

@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1040;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        max-width: 100%;
        padding: 68px 14px 24px;
    }
}

/* --------------------------------------------------------- Select2 ajustes */

.select2-container .select2-selection--single,
.select2-container .select2-selection--multiple {
    min-height: 38px;
}

.select2-container--bootstrap-5 .select2-dropdown {
    z-index: 1080;
}

/* ------------------------------------------------------------- Impressão */

@media print {
    .sidebar,
    .sidebar-toggle,
    .sidebar-backdrop,
    .toast-container,
    .no-print {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .main-content {
        max-width: 100%;
        padding: 0;
    }

    .card {
        border: none !important;
        box-shadow: none !important;
    }

    .card-header {
        border-bottom: 1px solid #ccc;
    }

    .print-header {
        display: block !important;
        border-bottom: 2px solid #0d6efd;
        padding-bottom: 10px;
        margin-bottom: 20px;
    }

    /* Logo à esquerda, dados da empresa ao lado. */
    .print-header-inner {
        display: flex;
        align-items: center;
        gap: 16px;
    }

    .print-header-logo {
        max-height: 70px;
        max-width: 140px;
        object-fit: contain;
        flex-shrink: 0;
    }

    .print-header-data {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 10pt;
        line-height: 1.35;
    }

    .print-header-report {
        margin-top: 8px;
        padding-top: 6px;
        border-top: 1px solid #dee2e6;
        font-size: 10pt;
    }

    .print-header h2 {
        color: #0d6efd;
        margin-bottom: 2px;
        font-size: 1.3rem;
    }

    table th,
    table td {
        border: 1px solid #ddd !important;
        padding: 8px 12px !important;
        font-size: 11pt;
    }

    table thead th {
        background-color: #f2f2f2 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    @page {
        size: A4;
        margin: 14mm;
    }
}

.print-header {
    display: none;
}
