/**
 * Oppus Framework - Theme Customizations
 * Based on Tabler.io v1.4.0
 *
 * This file contains Oppus-specific customizations including:
 * - Brand colors
 * - Typography
 * - Logo styles
 * - Custom utilities
 *
 * Note: Inter font is loaded via inline <style> in app.twig layout
 */

/* ============================================
   CSS Variables - Brand Customization
   ============================================ */

:root {
    /* Oppus Primary Color */
    --tblr-primary: #0054a6;
    --tblr-primary-rgb: 0, 84, 166;
    --tblr-primary-darken: #003d7a;
    --tblr-primary-lighten: #0066cc;

    /* Typography - Using Inter font family */
    --tblr-font-sans-serif: Inter, -apple-system, BlinkMacSystemFont,
                            San Francisco, Segoe UI, Roboto, Helvetica Neue,
                            sans-serif;

    /* Border Radius */
    --tblr-border-radius: 6px;
    --tblr-border-radius-lg: 8px;
    --tblr-border-radius-sm: 4px;

    /* Shadows */
    --tblr-shadow-sm: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --tblr-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    --tblr-shadow-lg: 0 1rem 3rem rgba(0, 0, 0, 0.175);
}

/* Use variable font for modern browsers that support it */
@supports (font-variation-settings: normal) {
    :root {
        --tblr-font-sans-serif: "Inter Var", Inter, -apple-system, BlinkMacSystemFont,
                                San Francisco, Segoe UI, Roboto, Helvetica Neue,
                                sans-serif;
    }
}

/* Dark Mode Variables */
[data-bs-theme="dark"] {
    --tblr-primary: #0066cc;
    --tblr-primary-rgb: 0, 102, 204;
}


/* ============================================
   Logo Styles
   ============================================ */

.navbar-brand-image {
    height: 2rem;
    width: auto;
}

.navbar-brand-autodark .logo-oppus {
    display: block;
    height: 2rem;
    width: auto;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center left;
}

/* Light theme logo */
.logo-oppus {
    background-image: url('../img/oppus-logo.svg');
}

/* Dark theme logo */
[data-bs-theme="dark"] .logo-oppus,
.navbar-brand-autodark[data-bs-theme="dark"] .logo-oppus {
    background-image: url('../img/oppus-logo-dark.svg');
}

/* Sidebar logo (smaller) */
.navbar-vertical .navbar-brand-image {
    height: 1.75rem;
}


/* ============================================
   Custom Utility Classes
   ============================================ */

/* Text Colors */
.text-oppus {
    color: var(--tblr-primary) !important;
}

/* Background Colors */
.bg-oppus {
    background-color: var(--tblr-primary) !important;
}

.bg-oppus-subtle {
    background-color: rgba(var(--tblr-primary-rgb), 0.1) !important;
}

/* Border Colors */
.border-oppus {
    border-color: var(--tblr-primary) !important;
}


/* ============================================
   Custom Button Variants
   ============================================ */

.btn-oppus {
    --tblr-btn-color: #fff;
    --tblr-btn-bg: var(--tblr-primary);
    --tblr-btn-border-color: var(--tblr-primary);
    --tblr-btn-hover-color: #fff;
    --tblr-btn-hover-bg: var(--tblr-primary-darken);
    --tblr-btn-hover-border-color: var(--tblr-primary-darken);
    --tblr-btn-focus-shadow-rgb: var(--tblr-primary-rgb);
    --tblr-btn-active-color: #fff;
    --tblr-btn-active-bg: var(--tblr-primary-darken);
    --tblr-btn-active-border-color: var(--tblr-primary-darken);
}

.btn-outline-oppus {
    --tblr-btn-color: var(--tblr-primary);
    --tblr-btn-border-color: var(--tblr-primary);
    --tblr-btn-hover-color: #fff;
    --tblr-btn-hover-bg: var(--tblr-primary);
    --tblr-btn-hover-border-color: var(--tblr-primary);
    --tblr-btn-focus-shadow-rgb: var(--tblr-primary-rgb);
    --tblr-btn-active-color: #fff;
    --tblr-btn-active-bg: var(--tblr-primary);
    --tblr-btn-active-border-color: var(--tblr-primary);
}


/* ============================================
   Custom Badge Variants
   ============================================ */

.badge-oppus {
    color: #fff;
    background-color: var(--tblr-primary);
}


/* ============================================
   Enhanced Components
   ============================================ */

/* Cards with Oppus accent */
.card-oppus {
    border-top: 3px solid var(--tblr-primary);
}

/* Sidebar active state */
.navbar-vertical .nav-link.active {
    background-color: rgba(var(--tblr-primary-rgb), 0.1);
    color: var(--tblr-primary);
}

.navbar-vertical .nav-link.active::before {
    background-color: var(--tblr-primary);
}


/* ============================================
   Loading States
   ============================================ */

.spinner-oppus {
    color: var(--tblr-primary);
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

[data-bs-theme="dark"] .loading-overlay {
    background-color: rgba(0, 0, 0, 0.9);
}


/* ============================================
   Empty States
   ============================================ */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}

.empty-state-icon {
    width: 8rem;
    height: 8rem;
    margin: 0 auto 1rem;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.empty-state-subtitle {
    color: var(--tblr-secondary);
    margin-bottom: 1.5rem;
}


/* ============================================
   Form Enhancements
   ============================================ */

/* Required field indicator */
.form-label.required::after {
    content: " *";
    color: var(--tblr-danger);
}

/* Input focus state with Oppus color */
.form-control:focus {
    border-color: var(--tblr-primary);
    box-shadow: 0 0 0 0.25rem rgba(var(--tblr-primary-rgb), 0.25);
}

.form-select:focus {
    border-color: var(--tblr-primary);
    box-shadow: 0 0 0 0.25rem rgba(var(--tblr-primary-rgb), 0.25);
}


/* ============================================
   Table Enhancements
   ============================================ */

/* Hoverable rows with Oppus highlight */
.table-hover tbody tr:hover {
    background-color: rgba(var(--tblr-primary-rgb), 0.05);
}

/* Striped tables with Oppus tint */
.table-striped-oppus tbody tr:nth-of-type(odd) {
    background-color: rgba(var(--tblr-primary-rgb), 0.03);
}


/* ============================================
   Navbar Customizations
   ============================================ */

/* Navbar with Oppus branding */
.navbar-oppus {
    background-color: var(--tblr-primary);
    color: #fff;
}

.navbar-oppus .navbar-brand {
    color: #fff;
}

.navbar-oppus .nav-link {
    color: rgba(255, 255, 255, 0.8);
}

.navbar-oppus .nav-link:hover {
    color: #fff;
}


/* ============================================
   Responsive Utilities
   ============================================ */

/* Better mobile spacing */
@media (max-width: 767.98px) {
    .page-header {
        padding: 1rem 0;
    }

    .page-body {
        padding: 1rem 0;
    }

    .card {
        margin-bottom: 1rem;
    }
}


/* ============================================
   Accessibility Enhancements
   ============================================ */

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--tblr-primary);
    outline-offset: 2px;
}

/* Skip to content link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--tblr-primary);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 10000;
}

.skip-to-content:focus {
    top: 0;
}


/* ============================================
   Print Styles
   ============================================ */

@media print {
    .navbar,
    .navbar-vertical,
    .page-header,
    .btn,
    .card-actions,
    .d-print-none {
        display: none !important;
    }

    .page-wrapper {
        margin: 0;
        padding: 0;
    }

    .card {
        border: 1px solid #dee2e6;
        break-inside: avoid;
    }
}


/* ============================================
   Animation Utilities
   ============================================ */

/* Fade in animation */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-in;
}

/* Slide in from top */
@keyframes slideInDown {
    from {
        transform: translateY(-10px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.slide-in-down {
    animation: slideInDown 0.3s ease-out;
}


/* ============================================
   Custom Scrollbar (Webkit browsers)
   ============================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

[data-bs-theme="dark"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

[data-bs-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}


/* ============================================
   Oppus-Specific Components
   ============================================ */

/* Status indicators */
.status-indicator {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    margin-right: 0.5rem;
}

.status-indicator-success {
    background-color: var(--tblr-success);
}

.status-indicator-warning {
    background-color: var(--tblr-warning);
}

.status-indicator-danger {
    background-color: var(--tblr-danger);
}

.status-indicator-info {
    background-color: var(--tblr-info);
}

/* Code blocks */
.code-block {
    background-color: var(--tblr-bg-surface);
    border: 1px solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius);
    padding: 1rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    overflow-x: auto;
}


/* ============================================
   Permissions Manager Styles
   ============================================ */

/* Permission changed indicator */
.permission-changed strong {
    background-color: rgba(var(--tblr-warning-rgb), 0.2);
    border-radius: 2px;
    transition: background-color 0.2s ease;
}

/* Search highlight */
mark {
    background-color: rgba(var(--tblr-primary-rgb), 0.25);
    color: inherit;
    padding: 0.125rem 0.25rem;
    border-radius: 2px;
    font-weight: 500;
}

/* Permission card animations */
.permission-card {
    transition: all 0.3s ease;
}

.permission-card:hover {
    box-shadow: var(--tblr-shadow-sm);
}

/* Card status top enhancement */
.card-status-top {
    height: 3px;
}

/* Permission item transitions */
.permission-item {
    transition: all 0.2s ease;
}

.permission-item[style*="display: none"] {
    opacity: 0;
    max-height: 0;
    overflow: hidden;
}

/* Accordion button styling */
.card-header .btn-link {
    color: var(--tblr-body-color);
}

.card-header .btn-link:hover {
    color: var(--tblr-primary);
}

.card-header .btn-link[aria-expanded="false"]::after {
    content: "";
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 0.5rem;
    border-left: 0.25rem solid transparent;
    border-right: 0.25rem solid transparent;
    border-top: 0.25rem solid currentColor;
    transition: transform 0.2s ease;
}

.card-header .btn-link[aria-expanded="true"]::after {
    transform: rotate(180deg);
}

/* Form switch enhancements */
.form-switch .form-check-input {
    cursor: pointer;
}

.form-switch .form-check-input:focus {
    border-color: var(--tblr-primary);
    box-shadow: 0 0 0 0.25rem rgba(var(--tblr-primary-rgb), 0.25);
}

/* Sticky sidebar enhancement */
.sticky-top {
    top: 1rem;
    z-index: 10;
}

/* No results message */
#no-search-results {
    animation: fadeIn 0.3s ease-in;
}

/* Icon colors matching metadata */
.text-blue {
    color: var(--tblr-blue) !important;
}

.text-green {
    color: var(--tblr-green) !important;
}

.text-red {
    color: var(--tblr-red) !important;
}

.text-orange {
    color: var(--tblr-orange) !important;
}

/* Responsive adjustments for permissions */
@media (max-width: 991.98px) {
    .sticky-top {
        position: relative !important;
        top: 0 !important;
    }

    .permission-card .card-header {
        flex-wrap: wrap;
    }

    .permission-card .card-actions {
        width: 100%;
        margin-top: 0.5rem;
    }
}

/* Dark mode adjustments */
[data-bs-theme="dark"] .permission-changed strong {
    background-color: rgba(var(--tblr-warning-rgb), 0.25);
}

[data-bs-theme="dark"] mark {
    background-color: rgba(var(--tblr-primary-rgb), 0.3);
}


/* ============================================
   Oppus Framework - Premium Toasts
   Usando as cores do alert-important do Tabler
   ============================================ */

.toast-container {
    z-index: 1056; /* Garante que fique acima de modais do Bootstrap (1055) */
}

.oppus-toast {
    border: none;
    border-radius: 6px; /* Cantos levemente arredondados */
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06); /* Sombra suave (Elevation) */
    overflow: hidden;
    position: relative;
    max-width: 380px;
    width: 100%;
    margin-bottom: 0.75rem;
    pointer-events: auto;
}

/* Cores Semânticas - Fundo Colorido (alert-important style) */
.oppus-toast-success {
    background-color: #2fb344; /* Tabler Success */
    color: #ffffff;
}

.oppus-toast-error {
    background-color: #d63939; /* Tabler Danger */
    color: #ffffff;
}

.oppus-toast-warning {
    background-color: #f76707; /* Tabler Warning */
    color: #ffffff;
}

.oppus-toast-info {
    background-color: #4299e1; /* Tabler Info */
    color: #ffffff;
}

/* Layout Interno */
.oppus-toast-content {
    display: flex;
    align-items: flex-start;
    padding: 1rem;
    gap: 12px;
}

/* Área do Ícone */
.oppus-toast-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 2px;
    color: #ffffff;
    opacity: 0.95;
}

/* SVG Sizing */
.oppus-toast-icon svg {
    width: 20px;
    height: 20px;
}

/* Área de Texto */
.oppus-toast-body {
    flex-grow: 1;
    min-width: 0; /* Fix flexbox text overflow */
}

.oppus-toast-title {
    font-weight: 600;
    font-size: 0.925rem;
    color: #ffffff;
    margin-bottom: 2px;
    line-height: 1.4;
}

.oppus-toast-message {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.95);
    line-height: 1.5;
}

/* Botão Fechar */
.oppus-toast .btn-close {
    flex-shrink: 0;
    margin: -0.25rem -0.25rem 0 0;
    padding: 0.5rem;
    filter: invert(1) grayscale(100%) brightness(200%);
    opacity: 0.7;
    transition: opacity 0.2s;
}

.oppus-toast .btn-close:hover {
    opacity: 1;
}

/* ============================================
   Dark Mode Support
   ============================================ */
[data-bs-theme="dark"] .oppus-toast-success {
    background-color: #2fb344;
}

[data-bs-theme="dark"] .oppus-toast-error {
    background-color: #d63939;
}

[data-bs-theme="dark"] .oppus-toast-warning {
    background-color: #f76707;
}

[data-bs-theme="dark"] .oppus-toast-info {
    background-color: #4299e1;
}

/* ============================================
   Alert Transitions - Collapse Effect (Shrink)
   ============================================ */

/**
 * Sobrescreve a transição padrão do Bootstrap Alert (150ms)
 * para uma animação mais suave e visível (1000ms / 1.0s).
 *
 * Efeito: O alerta ENCOLHE (shrink/collapse) da direita para esquerda
 * e de baixo para cima, similar ao jQuery.hide('slow').
 *
 * O alerta colapsa suas dimensões até zero, criando um efeito
 * elegante de "desaparecimento gradual".
 *
 * Aplica-se tanto ao fechamento automático (auto-dismiss)
 * quanto ao fechamento manual (botão X).
 */
.alert.fade {
    transition: opacity 1.0s ease-out,
                max-height 1.0s ease-out,
                max-width 1.0s ease-out,
                padding 1.0s ease-out,
                margin 1.0s ease-out;

    /* Define o ponto de origem do colapso (canto inferior direito) */
    transform-origin: right bottom;

    /* Esconde conteúdo que vazaria durante o encolhimento */
    overflow: hidden;

    /* Define valores máximos "abertos" */
    max-height: 500px;  /* Maior que qualquer alerta */
    max-width: 100%;
}

/**
 * Transição suave completa incluindo altura e espaçamentos
 * para evitar "pulos" visuais quando o alerta desaparece
 */
.alert {
    transition: opacity 1.0s ease-out,
                height 1.0s ease-out,
                margin 1.0s ease-out,
                padding 1.0s ease-out,
                max-height 1.0s ease-out,
                max-width 1.0s ease-out;

    overflow: hidden;
}

/**
 * Efeito de encolhimento ao fechar
 * O alerta colapsa todas suas dimensões para zero
 *
 * FIX: line-height e font-size previnem text reflow que causava
 * "bounce back" visual quando alert estava quase fechado
 */
.alert.fade:not(.show) {
    opacity: 0;
    max-height: 0 !important;
    max-width: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    border-width: 0 !important;

    /* Previne text reflow durante colapso */
    line-height: 0 !important;
    font-size: 0 !important;
    overflow: hidden;
}
