/* =============================================
   MOBILE FIRST - Base styles (mobile)
   ============================================= */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --navbar-height: 56px;
    --primary-color: #0d6efd;
    --dark-color: #212529;
}

* {
    box-sizing: border-box;
}

html {
    font-size: 14px;
    position: relative;
    min-height: 100%;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f8f9fa;
    min-height: 100vh;
}

/* =============================================
   SIDEBAR - Mobile (hidden by default)
   ============================================= */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar.show {
    transform: translateX(0);
}

.sidebar-header {
    position: relative;
    min-height: 60px;
}

.sidebar-nav {
    padding: 0.5rem 0;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.25rem;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    color: rgba(255, 255, 255, 0.85);
}

.sidebar .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-left-color: var(--primary-color);
    color: #fff;
}

.sidebar .nav-link.active {
    background-color: rgba(255, 255, 255, 0.15);
    border-left-color: var(--primary-color);
    color: #fff;
}

.sidebar .nav-link i {
    width: 24px;
    font-size: 1.15rem;
    margin-right: 0.875rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar .submenu {
    background-color: rgba(0, 0, 0, 0.25);
}

.sidebar .submenu .nav-link {
    padding: 0.625rem 1.25rem 0.625rem 3.5rem;
    font-size: 0.875rem;
}

.sidebar .submenu .nav-link i {
    font-size: 0.9rem;
    margin-right: 0.5rem;
}

.sidebar .submenu .nav-link:hover {
    color: #fff !important;
}

/* Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* =============================================
   MAIN CONTENT - Mobile
   ============================================= */

.main-content {
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.main-content .navbar {
    padding: 0.5rem 1rem;
    min-height: var(--navbar-height);
}

/* =============================================
   CARDS - Mobile optimized
   ============================================= */

.card {
    border-radius: 0.75rem;
    margin-bottom: 1rem;
    border: none;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

/* =============================================
   TABLES - Mobile responsive
   ============================================= */

.table-responsive {
    margin: -0.5rem;
    padding: 0.5rem;
}

.table th {
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    color: #6c757d;
}

.table td {
    font-size: 0.85rem;
    vertical-align: middle;
}

/* =============================================
   BUTTONS - Touch friendly (44px min touch target)
   ============================================= */

.btn {
    min-height: 44px;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
}

.btn-sm {
    min-height: 36px;
    padding: 0.375rem 0.75rem;
}

.btn-group .btn {
    min-width: 40px;
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

/* =============================================
   FORMS - Mobile optimized (16px to prevent iOS zoom)
   ============================================= */

.form-control,
.form-select {
    min-height: 44px;
    font-size: 16px;
    border-radius: 0.5rem;
}

.form-label {
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.375rem;
}

/* =============================================
   ALERTS
   ============================================= */

.alert {
    border-radius: 0.5rem;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================
   LOGIN PAGE - Mobile
   ============================================= */

.min-vh-100 .card {
    margin: 1rem;
    max-width: 100%;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.min-vh-100 .card:hover {
    transform: none;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

/* =============================================
   BADGES
   ============================================= */

.badge {
    font-weight: 500;
    padding: 0.4em 0.65em;
}

/* =============================================
   DROPDOWN
   ============================================= */

.dropdown-menu {
    border-radius: 0.5rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    border: none;
}

.dropdown-item {
    padding: 0.5rem 1rem;
}

/* =============================================
   PAGE HEADERS
   ============================================= */

.h3, h3 {
    font-size: 1.25rem;
}

/* =============================================
   UTILITIES
   ============================================= */

.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* =============================================
   LOADING SPINNER / OVERLAY
   ============================================= */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    flex-direction: column;
    gap: 1rem;
}

.loading-overlay.show {
    display: flex;
}

.loading-overlay .spinner-border {
    width: 3rem;
    height: 3rem;
}

.loading-overlay .loading-text {
    font-size: 0.95rem;
    color: #6c757d;
    font-weight: 500;
}

/* Botão com loading interno */
.btn.is-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.75;
}

.btn.is-loading .btn-text {
    visibility: hidden;
}

.btn.is-loading .btn-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Link com loading */
a.is-loading,
.nav-link.is-loading {
    pointer-events: none;
    opacity: 0.6;
}

/* Card loading state */
.card.is-loading {
    position: relative;
    pointer-events: none;
}

.card.is-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: inherit;
}

/* =============================================
   SMALL MOBILE - 576px and up
   ============================================= */

@media (min-width: 576px) {
    .min-vh-100 .card {
        margin: 0;
        max-width: 400px;
    }
}

/* =============================================
   TABLET - 768px and up
   ============================================= */

@media (min-width: 768px) {
    html {
        font-size: 15px;
    }

    .min-vh-100 .card {
        max-width: 420px;
    }

    .table th {
        font-size: 0.75rem;
    }

    .table td {
        font-size: 0.875rem;
    }

    .h3, h3 {
        font-size: 1.5rem;
    }
}

/* =============================================
   DESKTOP - 992px and up
   ============================================= */

@media (min-width: 992px) {
    html {
        font-size: 16px;
    }

    /* Sidebar visible by default on desktop */
    .sidebar {
        transform: translateX(0);
        box-shadow: none;
    }

    .sidebar-overlay {
        display: none !important;
    }

    /* Main content with margin for sidebar */
    .main-content {
        margin-left: var(--sidebar-width);
    }

    .main-content.expanded {
        margin-left: var(--sidebar-collapsed-width);
    }

    /* Collapsed sidebar */
    .sidebar.collapsed {
        width: var(--sidebar-collapsed-width);
    }

    .sidebar.collapsed .sidebar-text {
        display: none;
    }

    .sidebar.collapsed .sidebar-header {
        padding: 1rem 0.5rem;
    }

    .sidebar.collapsed .sidebar-header .fs-6 {
        display: none;
    }

    .sidebar.collapsed .nav-link {
        justify-content: center;
        padding: 0.875rem 0.5rem;
    }

    .sidebar.collapsed .nav-link i {
        margin-right: 0;
        font-size: 1.35rem;
    }

    .sidebar.collapsed .submenu {
        display: none;
    }

    /* Cards with hover effect on desktop */
    .card {
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    .card:hover {
        transform: translateY(-2px);
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.12) !important;
    }

    /* Form controls back to normal size */
    .form-control,
    .form-select {
        min-height: 38px;
        font-size: inherit;
    }

    .btn {
        min-height: 38px;
    }

    .btn-sm {
        min-height: 32px;
    }

    .h3, h3 {
        font-size: 1.75rem;
    }
}

/* =============================================
   LARGE DESKTOP - 1200px and up
   ============================================= */

@media (min-width: 1200px) {
    .container-fluid {
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

/* =============================================
   EXTRA LARGE - 1400px and up
   ============================================= */

@media (min-width: 1400px) {
    .container-fluid {
        max-width: 1600px;
        margin: 0 auto;
    }
}

/* =============================================
   PRINT STYLES
   ============================================= */

@media print {
    .sidebar,
    .sidebar-overlay,
    .navbar,
    .btn,
    .dropdown,
    #menuToggle {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #dee2e6 !important;
    }

    body {
        background: white;
    }
}

/* =============================================
   ACCESSIBILITY - Reduced Motion
   ============================================= */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .sidebar {
        transition: none;
    }
}

/* Focus visible para acessibilidade (teclado) */
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.nav-link:focus-visible,
.dropdown-item:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* =============================================
   SAFE AREA (iPhone X+)
   ============================================= */

@supports (padding: max(0px)) {
    .sidebar {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    .main-content .navbar {
        padding-top: max(0.5rem, env(safe-area-inset-top));
    }
}
