/* ========================================
   GESTÃO DE DESPESAS DE OBRA - ESTILOS
   Versão: 1.1 (Correção de layout Dashboard)
   ======================================== */

:root {
    /* Cores principais */
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #06b6d4;
    
    /* Neutros */
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    
    /* Background */
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    
    /* Fontes */
    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'DM Sans', sans-serif;
    
    /* Sombras */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    
    /* Bordas */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    /* Navbar */
    --navbar-height: 64px;
}

/* ========================================
   BASE
   ======================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    /* IMPEDE SCROLL HORIZONTAL GLOBAL */
    overflow-x: hidden;
}

body {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    color: var(--gray-700);
    background: var(--bg-body);
    min-height: 100vh;
    /* IMPEDE SCROLL HORIZONTAL GLOBAL */
    overflow-x: hidden;
    max-width: 100vw;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--gray-800);
    line-height: 1.3;
}

/* ========================================
   NAVBAR
   ======================================== */

.navbar {
    background: linear-gradient(135deg, var(--gray-800) 0%, var(--gray-900) 100%);
    height: var(--navbar-height);
    box-shadow: var(--shadow-md);
    z-index: 1030;
}

.navbar-brand {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar-brand i {
    font-size: 1.5rem;
    color: var(--primary-light);
}

.nav-link {
    font-weight: 500;
    padding: 0.5rem 1rem !important;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link:hover {
    background: rgba(255,255,255,0.1);
}

.nav-link.active {
    background: var(--primary);
    color: white !important;
}

.user-name {
    color: rgba(255,255,255,0.8);
    font-size: 0.875rem;
}

/* ========================================
   MAIN CONTENT
   ======================================== */

.main-content {
    padding-top: calc(var(--navbar-height) + 1rem);
    min-height: calc(100vh - var(--navbar-height));
    width: 100%;
    max-width: 100%;
    overflow-x: hidden; /* Segurança extra */
}

/* ========================================
   PAGE HEADER
   ======================================== */

.page-header h1 {
    font-size: 1.75rem;
    margin-bottom: 0.25rem;
    /* Quebra de linha para títulos longos */
    word-break: break-word;
}

.page-header p {
    margin-bottom: 0;
}

/* ========================================
   STAT CARDS
   ======================================== */

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.stat-card-primary::before { background: var(--primary); }
.stat-card-success::before { background: var(--success); }
.stat-card-info::before { background: var(--info); }
.stat-card-warning::before { background: var(--warning); }

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0; /* Impede que o ícone encolha */
}

.stat-card-primary .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-card-success .stat-icon { background: #d1fae5; color: var(--success); }
.stat-card-info .stat-icon { background: #cffafe; color: var(--info); }
.stat-card-warning .stat-icon { background: #fef3c7; color: var(--warning); }

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-500);
    display: block;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-800);
    margin: 0;
    word-break: break-word;
}

/* ========================================
   CARDS
   ======================================== */

.card {
    background: var(--bg-card);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden; /* Garante que conteúdo não vaze */
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem 1.25rem;
}

.card-header h5, .card-header h4 {
    font-size: 1rem;
    font-weight: 600;
    /* Permite quebra de linha no header se necessário */
    word-break: break-word;
}

.card-body {
    padding: 1.25rem;
    /* Scroll interno vertical se conteúdo for muito alto */
    max-height: 600px; 
    overflow-y: auto;
}

/* ========================================
   TABLES - CORREÇÃO PRINCIPAL
   ======================================== */

.table-responsive {
    /* Permite scroll DENTRO da tabela, não na página */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Suaviza scroll no iOS */
    width: 100%;
}

.table {
    margin-bottom: 0;
    width: 100%;
    min-width: 600px; /* Força scroll horizontal interno em telas pequenas */
}

.table th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    padding: 1rem;
    background: var(--gray-50);
    white-space: nowrap; /* Headers não quebram */
}

.table td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    font-size: 0.9rem;
}

.table tbody tr:hover {
    background: var(--gray-50);
}

/* Estilo específico para células com texto longo */
.table td.text-truncate, 
.table td.descricao, 
.table td.observacoes {
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========================================
   AVATARS
   ======================================== */

.avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.avatar-md {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light), #e0e7ff);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* ========================================
   BUTTONS
   ======================================== */

.btn {
    font-family: var(--font-body);
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    white-space: nowrap; /* Evita que botões quebrem linha */
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-lg {
    padding: 0.75rem 1.5rem;
}

/* ========================================
   FORMS
   ======================================== */

.form-label {
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.375rem;
}

.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: var(--gray-300);
    font-size: 0.95rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control-lg {
    padding: 0.75rem 1rem;
    font-size: 1rem;
}

/* ========================================
   BADGES
   ======================================== */

.badge {
    font-weight: 500;
    padding: 0.35rem 0.65rem;
    border-radius: var(--radius-sm);
}

/* ========================================
   EMPTY STATES
   ======================================== */

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

.empty-state i {
    font-size: 3rem;
    color: var(--gray-300);
    margin-bottom: 1rem;
    display: block;
}

.empty-state p {
    color: var(--gray-500);
}

.empty-state-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 4rem 2rem;
    text-align: center;
    border: 2px dashed var(--gray-300);
}

.empty-state-card i {
    font-size: 4rem;
    color: var(--gray-300);
    margin-bottom: 1.5rem;
    display: block;
}

.empty-state-card h4 {
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

/* ========================================
   LOGIN PAGE
   ======================================== */

.login-page {
    background: linear-gradient(135deg, var(--gray-800) 0%, var(--gray-900) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-icon {
    width: 72px;
    height: 72px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary-light), #e0e7ff);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 1rem;
}

.login-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.login-footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-200);
    text-align: center;
}

/* ========================================
   CATEGORY BARS (Dashboard)
   ======================================== */

.category-item {
    margin-bottom: 1.25rem;
}

.category-item:last-child {
    margin-bottom: 0;
}

.progress {
    background: var(--gray-200);
    border-radius: 4px;
}

.progress-bar {
    border-radius: 4px;
}

/* ========================================
   PAGINATION
   ======================================== */

.pagination {
    gap: 0.25rem;
    flex-wrap: wrap; /* Permite quebrar linha em mobile */
}

.page-link {
    border-radius: var(--radius-sm);
    border: none;
    color: var(--gray-600);
    padding: 0.5rem 0.75rem;
}

.page-link:hover {
    background: var(--gray-200);
    color: var(--primary);
}

.page-item.active .page-link {
    background: var(--primary);
    color: white;
}

/* ========================================
   FOOTER
   ======================================== */

.footer {
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
    text-align: center;
}

/* ========================================
   RESPONSIVE FIXES
   ======================================== */

@media (max-width: 991.98px) {
    .navbar-collapse {
        background: var(--gray-800);
        padding: 1rem;
        border-radius: var(--radius-md);
        margin-top: 0.5rem;
    }
    
    .navbar-nav {
        margin-bottom: 1rem;
    }
    
    .nav-link {
        padding: 0.75rem 1rem !important;
    }
    
    .d-flex.align-items-center {
        padding-top: 1rem;
        border-top: 1px solid rgba(255,255,255,0.1);
    }
    
    /* Tables: Força scroll interno e reduz fonte */
    .table {
        font-size: 0.85rem;
    }
    
    .table th, .table td {
        padding: 0.6rem;
    }
    
    /* Hide less important columns on mobile if needed */
    /* Exemplo: .table td:nth-child(4) { display: none; } */
}

@media (max-width: 767.98px) {
    /* Ajuste de padding geral */
    .main-content {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    .page-header h1 {
        font-size: 1.35rem;
    }
    
    /* Cards menores no mobile */
    .stat-card {
        padding: 1rem;
    }
    
    .stat-value {
        font-size: 1.35rem;
    }
    
    .stat-icon {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }
    
    .card-body {
        padding: 0.85rem;
    }
    
    /* Cards de listagem no dashboard */
    .card {
        margin-bottom: 1rem;
    }
    
    /* Tables: garante que não estoure a tela */
    .table-responsive {
        margin: 0 -0.85rem; /* Compensa padding do card-body */
        padding: 0 0.85rem;
        width: calc(100% + 1.7rem);
    }
    
    .table {
        min-width: 500px; /* Força scroll horizontal interno */
    }
    
    /* Esconde detalhes extras em telas muito pequenas */
    .table .d-none-mobile {
        display: none;
    }
    
    .login-card {
        padding: 1.5rem;
    }
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.card, .stat-card {
    animation: fadeIn 0.3s ease;
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .navbar, .footer, .btn, .dropdown, form {
        display: none !important;
    }
    
    .main-content {
        padding-top: 0;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid var(--gray-300);
    }
}