/* ============================================================
   Identidade visual do sistema sobre Bootstrap 5.3.
   A base segue um visual mais corporativo: contraste moderado,
   superfícies limpas, tabelas densas e ações bem delimitadas.
   ============================================================ */

:root {
    --app-primary: #24292f;
    --app-primary-rgb: 36, 41, 47;
    --app-primary-strong: #111827;
    --app-accent: #525866;
    --app-bg: #f3f4f6;
    --app-surface: #ffffff;
    --app-surface-muted: #f7f7f8;
    --app-border: #d8dce2;
    --app-text-muted: #667085;
    --app-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --app-sidebar-bg: #344258;
    --app-sidebar-bg-strong: #2d394d;
    --app-sidebar-text: #d8e0ea;
    --app-sidebar-muted: #91a0b4;
    --app-sidebar-active: #2f3b50;
    --app-sidebar-accent: #22d3c5;
    --bs-primary: var(--app-primary);
    --bs-primary-rgb: var(--app-primary-rgb);
    --bs-link-color-rgb: var(--app-primary-rgb);
    --bs-border-radius: 0.45rem;
    --bs-border-radius-sm: 0.35rem;
    --bs-border-radius-lg: 0.55rem;
}

[data-bs-theme="dark"] {
    --app-primary: #f3f4f6;
    --app-primary-rgb: 243, 244, 246;
    --app-primary-strong: #ffffff;
    --app-accent: #a1a1aa;
    --app-bg: #0d0f12;
    --app-surface: #15181d;
    --app-surface-muted: #1d2128;
    --app-border: #303641;
    --app-text-muted: #a0a7b4;
    --app-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
    --app-sidebar-bg: #202733;
    --app-sidebar-bg-strong: #181e28;
    --app-sidebar-text: #e5e7eb;
    --app-sidebar-muted: #9ca3af;
    --app-sidebar-active: #2a3342;
    --app-sidebar-accent: #22d3c5;
}

[data-app-skin="blue"] {
    --app-primary: #1d4ed8;
    --app-primary-rgb: 29, 78, 216;
    --app-primary-strong: #1e40af;
    --app-accent: #5b63c7;
    --app-sidebar-bg: #273a56;
    --app-sidebar-bg-strong: #223249;
    --app-sidebar-active: #21324b;
    --app-sidebar-accent: #60a5fa;
}

[data-app-skin="teal"] {
    --app-primary: #0f766e;
    --app-primary-rgb: 15, 118, 110;
    --app-primary-strong: #115e59;
    --app-accent: #14b8a6;
    --app-sidebar-bg: #2f4650;
    --app-sidebar-bg-strong: #293d45;
    --app-sidebar-active: #263a42;
    --app-sidebar-accent: #22d3c5;
}

[data-bs-theme="dark"][data-app-skin="blue"] {
    --app-primary: #93c5fd;
    --app-primary-rgb: 147, 197, 253;
    --app-primary-strong: #bfdbfe;
    --app-accent: #818cf8;
    --app-sidebar-bg: #1b2637;
    --app-sidebar-bg-strong: #151e2c;
    --app-sidebar-active: #24344d;
    --app-sidebar-accent: #60a5fa;
}

[data-bs-theme="dark"][data-app-skin="teal"] {
    --app-primary: #5eead4;
    --app-primary-rgb: 94, 234, 212;
    --app-primary-strong: #99f6e4;
    --app-accent: #2dd4bf;
    --app-sidebar-bg: #1e2d31;
    --app-sidebar-bg-strong: #19262a;
    --app-sidebar-active: #263b40;
    --app-sidebar-accent: #2dd4bf;
}

html, body { height: 100%; }

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background:
        linear-gradient(180deg, rgba(15, 23, 42, 0.05), transparent 280px),
        var(--app-bg);
    color: var(--bs-body-color);
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 0.95rem;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

main { flex: 1; }
footer { margin-top: auto; }

.app-main {
    padding-top: 1.5rem;
    padding-bottom: 2rem;
}

.app-shell {
    display: flex;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--app-bg);
}

.app-workspace {
    display: flex;
    flex: 1;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
    flex-direction: column;
    background: var(--app-bg);
}

.app-sidebar {
    width: 264px;
    flex: 0 0 264px;
    flex-direction: column;
    align-self: stretch;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.045), transparent 180px),
        var(--app-sidebar-bg);
    color: var(--app-sidebar-text);
    box-shadow: 10px 0 30px rgba(15, 23, 42, 0.14);
}

.app-sidebar-inner {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.app-sidebar-inner .app-menu {
    flex: 1 1 auto;
    overflow-y: auto;
    scrollbar-width: thin;
}

.app-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 74px;
    padding: 0 1rem;
    color: #fff;
    text-decoration: none;
    background: var(--app-sidebar-bg-strong);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.app-sidebar-brand:hover {
    color: #fff;
}

.app-brand-text {
    display: grid;
    gap: 0.08rem;
    line-height: 1.1;
}

.app-brand-name {
    font-size: 0.98rem;
    font-weight: 600;
}

.app-brand-subtitle {
    color: var(--app-sidebar-muted);
    font-size: 0.68rem;
    font-weight: 500;
    text-transform: uppercase;
}

.app-menu {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 1rem 0.85rem;
}

.app-menu-label {
    padding: 1rem 0.65rem 0.4rem;
    color: var(--app-sidebar-muted);
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: uppercase;
}

.app-menu-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 40px;
    padding: 0.62rem 0.7rem;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    color: var(--app-sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.app-menu-link i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    color: var(--app-sidebar-muted);
    font-size: 0.9rem;
}

.app-menu-link:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.app-menu-link.active {
    position: relative;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.08);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.app-menu-link.active::before {
    position: absolute;
    left: -0.86rem;
    width: 3px;
    height: 22px;
    border-radius: 999px;
    background: var(--app-sidebar-accent);
    content: "";
}

.app-menu-link.active i {
    color: var(--app-sidebar-accent);
}

.app-sidebar-logout {
    flex: 0 0 auto;
    margin: 0 0.85rem 1rem;
    color: var(--app-sidebar-text);
    background: var(--app-sidebar-bg);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 0;
    padding-top: 0.85rem;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    min-height: 64px;
    padding: 0 1.25rem;
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.app-topbar-title {
    color: var(--app-text-muted);
    font-size: 0.84rem;
    font-weight: 600;
    text-transform: uppercase;
}

.app-sidebar-canvas {
    width: 292px !important;
    color: var(--app-sidebar-text);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.045), transparent 180px),
        var(--app-sidebar-bg) !important;
}

.app-sidebar-canvas .offcanvas-header,
.app-sidebar-canvas .offcanvas-body {
    padding: 0;
    background: transparent;
}

.app-sidebar-canvas .offcanvas-header {
    min-height: 74px;
    background: var(--app-sidebar-bg-strong);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.app-sidebar-canvas .app-sidebar-brand {
    flex: 1;
    min-height: 74px;
    background: transparent;
    border-bottom: 0;
}

.app-sidebar-canvas .app-menu {
    padding-top: 0.75rem;
}

.app-sidebar-canvas .btn-close {
    margin-right: 0.75rem;
    opacity: 0.85;
}

.app-authenticated .app-footer {
    display: none;
}

.app-authenticated {
    background: var(--app-bg);
}

.app-authenticated .app-main {
    width: 100%;
    flex: 1;
    background: var(--app-bg);
}

.app-navbar {
    min-height: 60px;
    background: var(--app-surface) !important;
    border-color: var(--app-border) !important;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--bs-body-color);
    letter-spacing: 0;
}

.brand-logo {
    width: 36px;
    height: 36px;
    display: block;
    border-radius: 8px;
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.18);
}

.navbar .nav-link {
    border-radius: 0.4rem;
    color: var(--app-text-muted);
    font-weight: 500;
    padding: 0.55rem 0.75rem;
}

.navbar .nav-link:hover {
    background: rgba(100, 116, 139, 0.14);
    color: var(--app-primary-strong);
}

.navbar .nav-link.active {
    background: rgba(100, 116, 139, 0.16);
    color: var(--app-primary-strong);
}

.navbar .dropdown-toggle::after { margin-left: 0.4rem; }

.dropdown-menu {
    border-color: var(--app-border);
    border-radius: 0.55rem;
    box-shadow: var(--app-shadow);
}

.app-toast {
    --toast-tone: var(--app-primary);
    --toast-tone-rgb: var(--bs-primary-rgb);
    color: var(--bs-body-color);
    background: var(--app-surface);
    border-left: 4px solid var(--toast-tone) !important;
    box-shadow: var(--app-shadow) !important;
}

.app-toast .toast-body i {
    color: var(--toast-tone);
}

.app-toast-info {
    --toast-tone: var(--app-primary);
    --toast-tone-rgb: var(--bs-primary-rgb);
}

.app-toast-success {
    --toast-tone: var(--app-sidebar-accent);
    --toast-tone-rgb: 34, 211, 197;
}

.app-toast-warning {
    --toast-tone: #b7791f;
    --toast-tone-rgb: 183, 121, 31;
}

.app-toast-danger {
    --toast-tone: #b42318;
    --toast-tone-rgb: 180, 35, 24;
}

[data-bs-theme="dark"] .app-toast {
    color: var(--bs-body-color);
    background: var(--app-surface);
}

[data-bs-theme="dark"] .app-toast-warning {
    --toast-tone: #fbbf24;
    --toast-tone-rgb: 251, 191, 36;
}

[data-bs-theme="dark"] .app-toast-danger {
    --toast-tone: #f87171;
    --toast-tone-rgb: 248, 113, 113;
}

.offcanvas {
    background: var(--app-surface);
}

.offcanvas .nav-link {
    color: var(--app-text-muted);
    font-weight: 600;
}

.offcanvas .nav-link.active {
    background: var(--app-primary);
    color: #fff;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.page-title {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin: 0;
    font-size: 1.35rem;
    font-weight: 600;
}

.page-title-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: rgba(100, 116, 139, 0.14);
    color: var(--app-primary-strong);
}

.page-kicker {
    margin: 0.25rem 0 0;
    color: var(--app-text-muted);
}

.card {
    border-color: var(--app-border);
    border-radius: 0.6rem;
    background: var(--app-surface);
}

.card.shadow-sm,
.erp-card {
    box-shadow: var(--app-shadow) !important;
}

.card-header,
.card-footer {
    border-color: var(--app-border);
}

.card-header {
    background: var(--app-surface-muted) !important;
}

.erp-panel-title {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.35rem;
    font-size: 1rem;
    font-weight: 600;
}

.stat-card {
    border-left: 4px solid var(--app-primary);
}

.stat-card.accent {
    border-left-color: var(--app-accent);
}

.stat-value {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-label {
    color: var(--app-text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
}

.metric-card {
    border: 0;
}

.metric-trend {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: #6b7280;
    background: rgba(107, 114, 128, 0.12);
}

.metric-trend.up {
    color: #14b8a6;
    background: rgba(20, 184, 166, 0.12);
}

.metric-progress {
    height: 5px;
    background: rgba(100, 116, 139, 0.14);
}

.metric-progress .progress-bar {
    background: var(--app-sidebar-accent);
}

.metric-progress .progress-bar.secondary {
    background: var(--app-accent);
}

.table {
    --bs-table-bg: var(--app-surface);
    --bs-table-hover-bg: rgba(100, 116, 139, 0.08);
    font-size: 0.92rem;
}

.table > :not(caption) > * > * {
    padding: 0.8rem 0.95rem;
    border-bottom-color: var(--app-border);
}

.table thead th {
    background: var(--app-surface-muted);
    color: var(--app-text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: uppercase;
    white-space: nowrap;
}

.btn {
    border-radius: 0.42rem;
    font-weight: 600;
}

.btn-primary {
    --bs-btn-bg: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary-strong);
    --bs-btn-hover-border-color: var(--app-primary-strong);
    --bs-btn-active-bg: var(--app-primary-strong);
    --bs-btn-active-border-color: var(--app-primary-strong);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.16);
}

[data-bs-theme="dark"] .btn-primary {
    --bs-btn-color: #111827;
    --bs-btn-hover-color: #111827;
    --bs-btn-active-color: #111827;
}

.btn-outline-secondary {
    --bs-btn-border-color: var(--app-border);
}

.btn-theme-choice {
    --bs-btn-color: var(--app-primary-strong);
    --bs-btn-border-color: rgba(var(--bs-primary-rgb), 0.42);
    --bs-btn-hover-color: var(--app-primary-strong);
    --bs-btn-hover-bg: rgba(var(--bs-primary-rgb), 0.08);
    --bs-btn-hover-border-color: rgba(var(--bs-primary-rgb), 0.7);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--app-primary);
    --bs-btn-active-border-color: var(--app-primary);
    background: rgba(var(--bs-primary-rgb), 0.03);
}

[data-bs-theme="dark"] .btn-theme-choice {
    --bs-btn-active-color: #111827;
}

.btn-check:checked + .btn-theme-choice {
    color: var(--bs-btn-active-color);
    background: var(--bs-btn-active-bg);
    border-color: var(--bs-btn-active-border-color);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.14);
}

.form-label {
    color: var(--bs-body-color);
    font-size: 0.86rem;
    font-weight: 600;
}

.form-control,
.form-select {
    border-color: var(--app-border);
    border-radius: 0.45rem;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(100, 116, 139, 0.75);
    box-shadow: 0 0 0 0.2rem rgba(100, 116, 139, 0.18);
}

.badge {
    font-weight: 600;
}

/* Avatar circular do dropdown do usuário */
.avatar-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(100, 116, 139, 0.16);
    color: var(--app-primary-strong);
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.login-shell {
    min-height: calc(100vh - 160px);
    align-items: center;
}

.auth-card {
    border-top: 4px solid var(--app-primary);
}

.skin-option {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.skin-swatch {
    display: inline-block;
    width: 0.9rem;
    height: 0.9rem;
    border-radius: 50%;
    background: #525866;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55);
}

.skin-option-blue .skin-swatch {
    background: #1d4ed8;
}

.skin-option-teal .skin-swatch {
    background: #0f766e;
}

/* ============================================================
   Botões de ícone + mini-swatch da navbar
   ============================================================ */
.btn-icon {
    --bs-btn-padding-x: 0.55rem;
    --bs-btn-padding-y: 0.4rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--app-text-muted);
    border: 1px solid transparent;
    border-radius: 0.5rem;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.btn-icon:hover,
.btn-icon:focus-visible,
.btn-icon[aria-expanded="true"] {
    background: rgba(100, 116, 139, 0.12);
    color: var(--app-primary-strong);
    border-color: var(--app-border);
}
.btn-icon .bi { font-size: 1.05rem; line-height: 1; }

/* Swatch pequeno usado dentro do dropdown da navbar */
.skin-swatch-mini {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #525866;
    box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.08);
    vertical-align: middle;
}
.skin-swatch-mini.skin-option-blue { background: #1d4ed8; }
.skin-swatch-mini.skin-option-teal { background: #0f766e; }

/* Estado "ativo" do dropdown-item nos seletores da navbar */
.dropdown-item.active,
.dropdown-item:active {
    background-color: rgba(var(--bs-primary-rgb), 0.1);
    color: var(--app-primary-strong);
}

/* ============================================================
   Olhinho de mostrar/ocultar senha em todo input[type="password"]
   ============================================================ */
.password-toggle-wrap {
    position: relative;
    display: block;
}
.password-toggle-wrap .password-toggle-input {
    padding-right: 2.5rem;
}
.password-toggle-btn {
    position: absolute;
    top: 50%;
    right: 0.4rem;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--app-text-muted);
    border-radius: 0.35rem;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.password-toggle-btn:hover,
.password-toggle-btn:focus-visible {
    background: rgba(100, 116, 139, 0.12);
    color: var(--app-primary-strong);
    outline: none;
}
.password-toggle-btn .bi { font-size: 1rem; line-height: 1; }

/* ============================================================
   Matriz de permissões (role_edit)
   ============================================================ */
.perm-matrix thead th {
    background: var(--app-surface-muted);
    color: var(--app-text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.perm-matrix tbody tr:hover {
    background: rgba(var(--bs-primary-rgb), 0.04);
}
.perm-matrix td {
    border-color: var(--app-border);
}
.perm-matrix .form-check-input {
    width: 1.15rem;
    height: 1.15rem;
    cursor: pointer;
}
.perm-matrix .perm-row-toggle {
    padding: 0.2rem 0.45rem;
    line-height: 1;
}

.quick-action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--app-border);
    border-radius: 0.55rem;
    color: var(--bs-body-color);
    text-decoration: none;
    background: var(--app-surface);
}

.quick-action:hover {
    border-color: rgba(100, 116, 139, 0.55);
    color: var(--app-primary-strong);
    background: rgba(100, 116, 139, 0.08);
}

/* Iconografia ligeiramente alinhada com texto */
.bi { vertical-align: -0.125em; }

/* Mobile: input com font-size 16px evita zoom automático do iOS */
@media (max-width: 575.98px) {
    .form-control, .form-select { font-size: 16px; }
    .page-title { font-size: 1.15rem; }
    .app-main {
        padding-top: 1rem;
        padding-bottom: 1.5rem;
    }
    .app-sidebar-canvas { width: min(82vw, 292px) !important; }
}

/* Página de erro com animação sutil */
.error-code-bs {
    color: var(--app-primary-strong);
    animation: errFloat 3.5s ease-in-out infinite;
}

@keyframes errFloat {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-10px); }
}

@media (prefers-reduced-motion: reduce) {
    .error-code-bs { animation: none; }
}

/* === Contas correntes === */
.account-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 1.05rem;
}

/* KPIs clicáveis no dashboard */
.kpi-link { display: block; color: inherit; }
.kpi-link:hover { color: inherit; }
.kpi-link:hover .metric-card { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08); }
.kpi-link .metric-card { transition: transform 160ms ease, box-shadow 160ms ease; }
