/* ─── Variables ──────────────────────────────────────────────────── */
:root {
    --sidebar-width: 240px;
    --sidebar-bg: #1a1d23;
    --sidebar-accent: #3b82f6;
    --topbar-height: 56px;
    --text-muted-light: #6b7280;
}

html, body {
    height: 100%;
    margin: 0;
    font-size: 14px;
}

/* ─── App Layout ─────────────────────────────────────────────────── */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    background: #f0f2f5;
}

/* ─── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #c9d1d9;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform 0.25s ease;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 20px 20px 16px;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.avatar {
    width: 36px; height: 36px;
    background: var(--sidebar-accent);
    color: #fff;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem;
    flex-shrink: 0;
}

.user-info {
    overflow: hidden;
    display: flex; flex-direction: column;
}

.user-info small { color: var(--text-muted-light); font-size: 0.7rem; line-height: 1; }
.user-info span { font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-nav {
    flex: 1;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: #8b949e;
    text-decoration: none;
    font-size: 0.78rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .06em;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
    cursor: pointer;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.06);
    color: #e6edf3;
}

.sidebar-link.active {
    background: rgba(59,130,246,0.15);
    color: #60a5fa;
    border-left-color: var(--sidebar-accent);
    font-weight: 600;
}

.sidebar-footer {
    padding: 12px 0;
    border-top: 1px solid rgba(255,255,255,0.06);
}

/* ─── Main Content ───────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ─── Topbar ─────────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    position: sticky; top: 0; z-index: 99;
}

.sidebar-toggle { color: #6b7280 !important; }
.sidebar-toggle:hover { color: #111 !important; }

/* ─── Sidebar Collapsed (modo só ícones) ───────────────────────────── */
.sidebar, .main-content { transition: width .2s ease, margin-left .2s ease; }

body.sidebar-collapsed .sidebar { width: 64px; overflow-x: hidden; }
body.sidebar-collapsed .main-content { margin-left: 64px; }

/* Esconder texto e elementos que só fazem sentido em modo expandido */
body.sidebar-collapsed .sidebar-brand,
body.sidebar-collapsed .sidebar-user,
body.sidebar-collapsed .sidebar-sublink,
body.sidebar-collapsed .sidebar-chevron,
body.sidebar-collapsed .gp-sidebar-module .gp-mod-text { display: none !important; }

/* Forçar collapse fechado (esconder submenus) */
body.sidebar-collapsed .collapse.show,
body.sidebar-collapsed .collapse { display: none !important; }

/* O texto dos links é text node directo (não em <span>); colapsar com font-size:0
   e re-aplicar font-size só ao ícone. !important necessário porque _Layout.cshtml
   força padding/gap com !important. */
body.sidebar-collapsed .sidebar-link {
    font-size: 0 !important;
    padding: 12px 0 !important;
    gap: 0 !important;
    justify-content: center !important;
    text-align: center;
}
body.sidebar-collapsed .sidebar-link i,
body.sidebar-collapsed .sidebar-link .material-symbols-outlined {
    font-size: 1.3rem !important;
    margin: 0 !important;
    width: auto !important;
}
/* Module no rodapé: esconde texto, mantém o ícone */
body.sidebar-collapsed .gp-sidebar-module {
    justify-content: center;
    padding: 14px 0 !important;
    font-size: 0 !important;
}
body.sidebar-collapsed .gp-sidebar-module .gp-mod-icon { font-size: 1.1rem; }

/* Mobile: já tem comportamento próprio (média query do _Layout) — não interferir */
@media (max-width: 768px) {
    body.sidebar-collapsed .sidebar { width: var(--sidebar-width); }
    body.sidebar-collapsed .main-content { margin-left: 0; }
}

/* ─── Stats Cards ────────────────────────────────────────────────── */
.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}

.stat-icon {
    width: 48px; height: 48px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.78rem; color: var(--text-muted-light); margin-top: 3px; }

/* ─── Tables ─────────────────────────────────────────────────────── */
.table th { font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: #6b7280; }
.table td { vertical-align: middle; font-size: 0.875rem; }

/* ─── Login ──────────────────────────────────────────────────────── */
.login-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1d23 0%, #23293a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    margin: 0;
}

.login-wrapper {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-brand {
    text-align: center;
    margin-bottom: 24px;
}

.letter-spacing-3 { letter-spacing: 0.3em; }

/* ─── Viatura Status Dot ─────────────────────────────────────────── */
.viatura-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #6c757d;
}
.viatura-dot.estado-1 { background: #198754; box-shadow: 0 0 0 3px rgba(25,135,84,0.2); }
.viatura-dot.estado-2 { background: #fd7e14; box-shadow: 0 0 0 3px rgba(253,126,20,0.2); }

/* ─── Legend Dot ─────────────────────────────────────────────────── */
.legend-dot {
    width: 9px; height: 9px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

/* ─── Leaflet Map Marker ─────────────────────────────────────────── */
.viatura-marker {
    position: relative;
}
.viatura-marker-pin {
    width: 26px; height: 26px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    background: var(--mc, #6c757d);
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.viatura-marker-label {
    position: absolute;
    top: -22px; left: 50%;
    transform: translateX(-50%);
    background: rgba(15,15,15,0.82);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.02em;
}

/* ─── Detail Hero ────────────────────────────────────────────────── */
.detail-hero {
    background: linear-gradient(135deg, #1a1d23 0%, #2d3748 100%);
    border-radius: 12px;
    padding: 26px 28px 22px;
    color: #fff;
    position: relative;
    overflow: hidden;
}
.detail-hero::before {
    content: '';
    position: absolute;
    top: -30px; right: -30px;
    width: 180px; height: 180px;
    border-radius: 50%;
    background: rgba(59,130,246,0.1);
    pointer-events: none;
}

/* ─── Patient Avatar ─────────────────────────────────────────────── */
.patient-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1.1rem;
    flex-shrink: 0;
}

/* ─── Spin Animation ─────────────────────────────────────────────── */
.spin { animation: spin-anim 0.8s linear infinite; }
@keyframes spin-anim {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ─── Alert Row — Novo serviço (pisca 6x depois fica) ────────────── */
@keyframes row-blink-new {
    0%, 100% { background: #fff5f5; }
    50%       { background: #fecaca; }
}
.row-alert-new {
    animation: row-blink-new 0.8s ease-in-out 6;
    animation-fill-mode: forwards;
    background: #fff5f5;
}
.row-alert-new td,
.row-alert-new td span { color: #dc2626 !important; font-weight: 600; }

/* ─── Alert Row — Estado 98 / Chamada por outra ambulância ──────── */
@keyframes row-blink-98 {
    0%, 100% { background: #fff0f0; }
    50%       { background: #fca5a5; }
}
.row-alert-98 { animation: row-blink-98 1.2s ease-in-out infinite; }
.row-alert-98 td,
.row-alert-98 td span { color: #dc2626 !important; font-weight: 600; }

/* ─── Alert Card — Mapa ocorrências (novo / estado 98) ──────────── */
@keyframes card-blink-new {
    0%, 100% { background: #fff5f5; border-color: #fca5a5 !important; }
    50%       { background: #fecaca; border-color: #ef4444 !important; }
}
.card-alert-new {
    animation: card-blink-new 0.8s ease-in-out 6;
    animation-fill-mode: forwards;
    background: #fff5f5 !important;
    border-left-color: #ef4444 !important;
}
.card-alert-new .ocorrencia-num,
.card-alert-new .ocorrencia-nome { color: #dc2626 !important; font-weight: 600; }

@keyframes card-blink-98 {
    0%, 100% { background: #fff0f0; border-left-color: #fca5a5 !important; }
    50%       { background: #fca5a5; border-left-color: #ef4444 !important; }
}
.card-alert-98 { animation: card-blink-98 1.2s ease-in-out infinite; }
.card-alert-98 .ocorrencia-num,
.card-alert-98 .ocorrencia-nome { color: #dc2626 !important; font-weight: 600; }

/* ─── Toast notificação viaturas ─────────────────────────────────── */
@keyframes toast-slide-in {
    from { opacity: 0; transform: translateX(30px); }
    to   { opacity: 1; transform: translateX(0); }
}
.alert-toast {
    position: fixed;
    top: 68px;
    right: 20px;
    z-index: 9999;
    min-width: 270px;
    max-width: 360px;
    animation: toast-slide-in 0.3s ease;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

/* ─── Sidebar Submenu ────────────────────────────────────────────── */
.sidebar-sublink {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px 7px 32px;
    color: #8b949e;
    text-decoration: none;
    font-size: 0.74rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .06em;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-sublink:hover { background: rgba(255,255,255,0.06); color: #e6edf3; }
.sidebar-sublink.active { background: rgba(59,130,246,0.12); color: #60a5fa; border-left-color: var(--sidebar-accent); }
.sidebar-sublink .material-symbols-outlined { font-size: 13px; }

.sidebar-chevron { font-size: 11px; transition: transform 0.2s ease; }
/* Bootstrap mantém aria-expanded sincronizado com o collapse — usar como
   fonte da verdade. A classe .open (server-side) deixa de ser fiável quando
   o user expande/fecha sem refresh. */
.sidebar-link[aria-expanded="true"] .sidebar-chevron { transform: rotate(180deg); }

/* ─── Alert Row — Timeout de estado (pisca âmbar infinito) ──────── */
@keyframes row-blink-timeout {
    0%, 100% { background: #fffbeb; }
    50%       { background: #fde68a; }
}
.row-alert-timeout { animation: row-blink-timeout 1.4s ease-in-out infinite; }
.row-alert-timeout td,
.row-alert-timeout td span { color: #92400e !important; font-weight: 600; }

/* ─── Alert Card — Mapa timeout estado ──────────────────────────── */
@keyframes card-blink-timeout {
    0%, 100% { background: #fffbeb; border-left-color: #fcd34d !important; }
    50%       { background: #fde68a; border-left-color: #f59e0b !important; }
}
.card-alert-timeout { animation: card-blink-timeout 1.4s ease-in-out infinite; }
.card-alert-timeout .ocorrencia-num,
.card-alert-timeout .ocorrencia-nome { color: #92400e !important; font-weight: 600; }

/* ─── Material Symbols ───────────────────────────────────────────── */
.material-symbols-outlined { font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24; }
.ms-filled { font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24; }
.sidebar-link .material-symbols-outlined { font-size: 13px; }

/* ─── Filter Labels & Select Options ────────────────────────────── */
.card .form-label { color: #4b5563; text-transform: uppercase; font-size: .72rem; letter-spacing: .04em; }
.card .form-select,
.card .form-control { color: #374151; text-transform: uppercase; }
.card .form-select option { color: #374151; text-transform: uppercase; }

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
}
