:root {
    --sidebar-width: 292px;
    --sidebar-collapsed-width: 92px;
    --topbar-height: 116px;
}

html {
    scrollbar-gutter: stable;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f3f4f6;
    color: #111827;
    font-family: Arial, sans-serif;
    overflow-x: hidden;
    overflow-y: scroll;
}

body.tower-confirm-open,
body.tower-modal-open {
    overflow: hidden;
}

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    width: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
    color: #ffffff;
    border-right: 3px solid var(--empresa-accent);
    box-shadow: inset 0 0 0 1px rgba(var(--empresa-accent-rgb), 0.12);
    transition: width 0.22s ease, transform 0.22s ease;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 18px 16px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 -1px 0 rgba(var(--empresa-accent-rgb), 0.18);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.sidebar-brand-icon {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: rgba(var(--empresa-accent-rgb), 0.18);
    color: #ffffff;
    font-size: 20px;
    flex: 0 0 auto;
}

.sidebar-brand-text {
    min-width: 0;
}

.sidebar-brand-title,
.sidebar-brand-subtitle {
    display: block;
    white-space: nowrap;
}

.sidebar-brand-title {
    font-size: 18px;
    font-weight: 700;
    color: #f9fafb;
}

.sidebar-brand-subtitle {
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #94a3b8;
    margin-top: 2px;
}

.sidebar-icon-btn {
    width: 40px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #f9fafb;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.sidebar-icon-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(var(--empresa-accent-rgb), 0.35);
    transform: translateY(-1px);
}

.sidebar-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 12px 18px 12px;
}

.sidebar-search-row {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.sidebar-search {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
}

.sidebar-search-icon,
.sidebar-search-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #cbd5e1;
    flex: 0 0 auto;
}

.sidebar-search-clear {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.sidebar-groups-toggle {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border: 1px solid rgba(var(--empresa-accent-rgb), 0.75);
    border-radius: 10px;
    background: rgb(var(--empresa-accent-rgb));
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: filter 0.18s ease, transform 0.18s ease;
}

.sidebar-groups-toggle:hover {
    filter: brightness(1.12);
    transform: translateY(-1px);
}

.sidebar-groups-toggle:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.9);
    outline-offset: 2px;
}

.sidebar-search-input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    color: #f8fafc;
    font-size: 14px;
}

.sidebar-search-input::placeholder {
    color: #94a3b8;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-section-administracao {
    margin-top: 8px;
    padding-top: 14px;
    border-top: 1px solid rgba(167, 179, 198, 0.28);
}

.sidebar-section-title {
    padding: 12px 12px 4px 12px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: #a7b3c6;
    font-weight: 700;
}

.sidebar-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-group.is-filtered-out,
.menu-leaf-row.is-filtered-out,
.sidebar-section.is-filtered-out {
    display: none !important;
}

.menu-item,
.sidebar-group-trigger {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    padding-left: calc(14px + (var(--menu-level, 0) * 14px));
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: #e5e7eb;
    text-decoration: none;
    text-align: left;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.sidebar-group-trigger {
    font-size: 12px;
    font-weight: 700;
    color: #f8fafc;
}

.menu-item {
    font-size: 12px;
    font-weight: 500;
}

.menu-leaf-row {
    display: flex;
    align-items: stretch;
    gap: 6px;
}

.menu-leaf-row .menu-item {
    flex: 1 1 auto;
}

.menu-item:hover,
.sidebar-group-trigger:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.menu-item.ativo,
.sidebar-group.active-branch > .sidebar-group-trigger {
    background: linear-gradient(135deg, rgba(var(--empresa-accent-rgb), 0.92), rgba(var(--empresa-accent-rgb), 0.72));
    color: var(--empresa-accent-text);
    box-shadow: 0 12px 24px rgba(var(--empresa-accent-rgb), 0.18);
}

.menu-item.is-disabled {
    opacity: 0.72;
    cursor: default;
}

.menu-favorite-btn {
    width: 40px;
    min-width: 40px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: #94a3b8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.menu-favorite-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fbbf24;
    transform: translateY(-1px);
}

.menu-favorite-btn.is-active {
    color: #fbbf24;
}

.menu-leaf-row.is-favorito .menu-item {
    border-color: rgba(251, 191, 36, 0.25);
}

.menu-icon {
    width: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-size: 14px;
}

.menu-label {
    min-width: 0;
    flex: 1 1 auto;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.22;
}

.sidebar-group > .sidebar-group-trigger .menu-label {
    font-weight: 700;
    letter-spacing: 0.01em;
}

.menu-chevron {
    width: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease;
    flex: 0 0 auto;
}

.sidebar-group-trigger.is-open .menu-chevron {
    transform: rotate(180deg);
}

.sidebar-submenu {
    display: none;
    flex-direction: column;
    gap: 6px;
}

.sidebar-submenu.is-open {
    display: flex;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 1030;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
}

.menu-context {
    position: fixed;
    z-index: 1100;
    min-width: 180px;
    padding: 8px;
    border: 1px solid #d1d5db;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 18px 35px rgba(15, 23, 42, 0.16);
}

.menu-context-action {
    width: 100%;
    min-height: 40px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #111827;
    text-align: left;
    padding: 10px 12px;
}

.menu-context-action:hover {
    background: #f3f4f6;
}

.page-shell {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.22s ease;
}

.navbar {
    position: relative;
    z-index: 1020;
    min-height: var(--topbar-height);
    border-top: 4px solid var(--empresa-accent);
    overflow: hidden;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    background: linear-gradient(90deg, rgba(var(--empresa-accent-rgb), 0.24), rgba(var(--empresa-accent-rgb), 0.10) 28%, rgba(255, 255, 255, 0.98) 62%, rgba(255, 255, 255, 1) 100%) !important;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.10);
}

.topbar-container {
    min-height: calc(var(--topbar-height) - 4px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding-top: 8px;
    padding-bottom: 8px;
}

.topbar-start,
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.empresa-contexto {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0 8px 18px;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.empresa-contexto::before {
    content: "";
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 5px;
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(var(--empresa-accent-rgb), 0.96), rgba(var(--empresa-accent-rgb), 0.28));
    box-shadow: 0 0 16px rgba(var(--empresa-accent-rgb), 0.22);
}

.empresa-contexto-indicador {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: var(--empresa-accent);
    box-shadow: 0 0 0 4px rgba(var(--empresa-accent-rgb), 0.14);
    flex: 0 0 auto;
}

.empresa-contexto-conteudo {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.empresa-contexto-linha,
.empresa-contexto-nome,
.empresa-contexto-codigo,
.empresa-contexto-fantasia,
.empresa-contexto-meta {
    margin: 0;
}

.empresa-contexto-topo-linha {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.empresa-contexto-nome {
    font-size: 17px;
    font-weight: 700;
    color: #111827;
}

.empresa-contexto-fantasia {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
}

.empresa-contexto-codigo {
    font-size: 12px;
    color: #4b5563;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.empresa-contexto-meta {
    font-size: 13px;
    color: #6b7280;
}

.empresa-status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.empresa-status-badge.ativa {
    background: #dcfce7;
    color: #166534;
}

.empresa-status-badge.inativa {
    background: #fee2e2;
    color: #991b1b;
}

.topbar-designer-form {
    margin: 0;
}

.topbar-designer-toggle {
    padding: 5px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
    color: #334155;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.topbar-designer-toggle[aria-pressed="true"] {
    border-color: #2563eb;
    background: #dbeafe;
    color: #1e40af;
}

.topbar-designer-toggle:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.topbar-user {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}

.topbar-company-switch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid rgba(var(--empresa-accent-rgb), 0.34);
    border-radius: 12px;
    background: rgba(var(--empresa-accent-rgb), 0.07);
    color: #1f2937;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.topbar-company-switch:hover {
    border-color: rgba(var(--empresa-accent-rgb), 0.58);
    background: rgba(var(--empresa-accent-rgb), 0.12);
    color: #111827;
    transform: translateY(-1px);
}

.topbar-company-switch:focus-visible {
    outline: 3px solid rgba(var(--empresa-accent-rgb), 0.20);
    outline-offset: 2px;
}

.topbar-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 12px;
    border: 1px solid #fca5a5;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #ffffff;
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 12px 22px rgba(220, 38, 38, 0.18);
    transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.topbar-logout:hover {
    color: #ffffff;
    transform: translateY(-1px);
    filter: brightness(1.02);
    box-shadow: 0 16px 28px rgba(220, 38, 38, 0.24);
}

.content {
    padding: 24px;
    min-height: calc(100vh - var(--topbar-height));
}

.mensagens-container {
    margin-bottom: 20px;
}

.mensagem {
    padding: 14px 18px;
    border-radius: 12px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    font-size: 14px;
    border: 1px solid transparent;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.mensagem.success {
    background-color: #e6f4ea;
    color: #1e7e34;
    border-color: #c3e6cb;
}

.mensagem.error {
    background-color: #fdecea;
    color: #b02a37;
    border-color: #f5c2c7;
}

.mensagem.warning {
    background-color: #fff3cd;
    color: #856404;
    border-color: #ffe69c;
}

.mensagem.info {
    background-color: #e7f1ff;
    color: #084298;
    border-color: #b6d4fe;
}

.fechar-mensagem {
    margin-left: auto;
    flex: 0 0 auto;
    align-self: center;
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
}

.fechar-mensagem:hover {
    opacity: 1;
}

.tower-confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 1600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.48);
}

.tower-confirm-modal[hidden] {
    display: none;
}

.tower-confirm-card {
    width: min(460px, 100%);
    border-radius: 18px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    background: #ffffff;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.28);
    overflow: hidden;
}

.tower-confirm-header {
    padding: 18px 22px 10px 22px;
    border-bottom: 1px solid #e5e7eb;
}

.tower-confirm-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #111827;
}

.tower-confirm-body {
    padding: 18px 22px;
}

.tower-confirm-body p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: #374151;
    white-space: pre-line;
}

.tower-confirm-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 0 22px 22px 22px;
}

.badge-status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
}

.badge-status.ativo {
    background-color: #e6f4ea;
    color: #1e7e34;
}

.badge-status.inativo {
    background-color: #fdecea;
    color: #b02a37;
}

.alerta {
    padding: 14px 16px;
    border-radius: 10px;
    font-weight: 500;
}

.alerta-erro {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.mensagem-fechavel {
    transition: opacity 0.35s ease, transform 0.35s ease, max-height 0.35s ease, margin 0.35s ease, padding 0.35s ease;
    overflow: hidden;
    max-height: 120px;
}

.mensagem-fechando {
    opacity: 0;
    transform: translateY(-6px);
    max-height: 0;
    margin-bottom: 0 !important;
    padding-top: 0;
    padding-bottom: 0;
    border-width: 0;
}

body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .page-shell {
    margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed .sidebar-section-title,
body.sidebar-collapsed .menu-label,
body.sidebar-collapsed .menu-chevron,
body.sidebar-collapsed .sidebar-search {
    display: none;
}

body.sidebar-collapsed .sidebar-header {
    justify-content: center;
}

body.sidebar-collapsed .sidebar-brand {
    justify-content: center;
}

body.sidebar-collapsed .menu-item,
body.sidebar-collapsed .sidebar-group-trigger {
    justify-content: center;
    padding-left: 14px;
    padding-right: 14px;
}

body.sidebar-collapsed .sidebar-submenu {
    display: none !important;
}

body.sidebar-collapsed .menu-favorite-btn {
    display: none;
}

.mobile-only {
    display: none;
}

@media (max-width: 991.98px) {
    .mobile-only {
        display: inline-flex;
    }

    .desktop-only {
        display: none;
    }

    .sidebar {
        transform: translateX(-100%);
        width: min(86vw, 320px);
    }

    .page-shell {
        margin-left: 0;
    }

    body.sidebar-collapsed .page-shell {
        margin-left: 0;
    }

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

    body.sidebar-mobile-open .sidebar-overlay {
        opacity: 1;
        visibility: visible;
    }

    .topbar-container {
        align-items: flex-start;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .content {
        padding: 18px;
    }

    .empresa-contexto {
        width: 100%;
        padding-left: 16px;
    }
}
