:root { 
      /* Variáveis de cor dinâmicas */
      --primary-color: #3b82f6; 
      --primary-hover: #2563eb;
      --sidebar-bg: #0f172a; 
      
      --sidebar-width: 260px; 
      --row-height: 50px; 
      --day-width: 48px;
      --bg-body: #f8fafc; 
      --surface-card: #ffffff;
      --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
      --text-main: #334155;
  }

  /* --- FIX: Texto Branco nas Abas Ativas (Manutenção) --- */
#maintTabs .nav-link.active {
    color: #ffffff !important;
}

  body { font-family: 'Inter', sans-serif; background-color: var(--bg-body); color: var(--text-main); overflow-x: hidden; -webkit-font-smoothing: antialiased; }
  
  /* UI Components */
  .card { border: none; background: var(--surface-card); box-shadow: var(--shadow-sm); border-radius: 12px; transition: transform 0.2s; }
  
  .card-header { background-color: transparent; border-bottom: 1px solid #e2e8f0; font-weight: 600; padding: 12px 20px; }
  .btn { border-radius: 8px; font-weight: 500; transition: all 0.2s; }
  .btn-primary { background-color: var(--primary-color); border-color: var(--primary-color); color: white; }
  .btn-primary:hover { background-color: var(--primary-hover); border-color: var(--primary-hover); transform: translateY(-1px); }
  .text-primary { color: var(--primary-color) !important; }
  .bg-primary { background-color: var(--primary-color) !important; }
  
  .form-control, .form-select { border-radius: 8px; border: 1px solid #cbd5e1; padding: 0.5rem 0.75rem; }
  .form-control:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); }

  /* Login */
  #login-screen { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: linear-gradient(135deg, var(--sidebar-bg) 0%, #1e293b 100%); z-index: 2000; display: flex; align-items: center; justify-content: center; }
  .login-box { background: rgba(255, 255, 255, 0.95); padding: 40px; border-radius: 16px; width: 100%; max-width: 400px; text-align: center; backdrop-filter: blur(10px); }
  #app-container { display: none; } 

  /* Sidebar */
  #sidebar { 
      width: var(--sidebar-width); 
      height: 100vh; 
      position: fixed; 
      left: 0; 
      top: 0; 
      background-color: var(--sidebar-bg); 
      color: #fff; 
      overflow: hidden; 
      transition: transform 0.3s; 
      z-index: 1040; 
      display: flex; 
      flex-direction: column; 
      border-right: 1px solid rgba(255,255,255,0.1); 
  }

  /* Área de navegação scrollável */
  #sidebar .nav-scroll-area {
      flex: 1; 
      overflow-y: auto; 
      overflow-x: hidden;
  }

  #sidebar .nav-link { color: rgba(255,255,255,0.6); padding: 10px 20px; transition: all 0.2s; cursor: pointer; display: flex; align-items: center; font-size: 0.85rem; border-left: 3px solid transparent; }
  #sidebar .nav-link:hover { color: #fff; background-color: rgba(255,255,255,0.05); }
  #sidebar .nav-link.active { color: #fff; background: linear-gradient(90deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%); border-left-color: var(--primary-color); }
  #sidebar .menu-category { font-size: 0.7rem; text-transform: uppercase; color: rgba(255,255,255,0.4); margin: 20px 20px 8px; font-weight: 800; letter-spacing: 1px; border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 4px; }
  
  .sidebar-brand-box { 
      padding: 15px; 
      background: rgba(0,0,0,0.2); 
      border-bottom: 1px solid rgba(255,255,255,0.1); 
      display: flex; 
      align-items: center; 
      gap: 12px; 
      flex-shrink: 0;
  }
  .sidebar-brand-logo { width: 40px; height: 40px; object-fit: contain; border-radius: 6px; background: white; padding: 2px; flex-shrink: 0;}
  
  .user-profile-box { 
      margin-top: auto; 
      padding: 20px; 
      border-top: 1px solid rgba(255,255,255,0.1); 
      background: rgba(0,0,0,0.2); 
      flex-shrink: 0;
  }

  /* Layout & Footer */
  .mobile-nav { display: none; background-color: var(--sidebar-bg); color: white; padding: 10px 20px; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1030; }
  .overlay { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(15, 23, 42, 0.6); z-index: 1035; backdrop-filter: blur(4px); }
  .overlay.active { display: block; }
  #content { margin-left: var(--sidebar-width); height: 100vh; display: flex; flex-direction: column; position: relative; overflow: hidden; }
  .main-content-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; height: 100%; position: relative; }
  .hidden { display: none !important; }
  .page-padding { padding: 24px 32px; overflow-y: auto; height: 100%; }

  /* --- HOME PAGE LAYOUT --- */
  #page-home {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    padding: 24px 32px;
  }
  .home-fixed-top { flex-shrink: 0; } 
  .home-card-flex { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
  .home-card-header { flex-shrink: 0; }
  .scroll-column-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 1rem; min-height: 0; scrollbar-width: thin; scrollbar-color: #cbd5e1 #f1f5f9; }
  .scroll-column-body::-webkit-scrollbar { width: 6px; }
  .scroll-column-body::-webkit-scrollbar-track { background: #f1f5f9; }
  .scroll-column-body::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 10px; }
  #page-home .card-hover-effect:hover { transform: none; box-shadow: var(--shadow-sm); }
  
  /* --- PAGE SCROLL FIX: RESERVAS, CLIENTES, FROTA, FICHA TÉCNICA E STANDS --- */
  #page-reservations, #page-clients, #page-vehicles, #page-maintenance, #page-stands { 
      display: flex; 
      flex-direction: column; 
      height: 100vh; 
      max-height: 100vh;
      overflow: hidden; 
      padding: 24px 32px 45px 32px !important; /* Aumentado para 45px para não colidir com o rodapé */
  }
  #page-reservations .sticky-header-container, 
  #page-clients .sticky-header-container, 
  #page-vehicles .sticky-header-container,
  #page-maintenance .sticky-header-container,
  #page-stands .sticky-header-container { 
      flex: 1; 
      display: flex; 
      flex-direction: column; 
      min-height: 0; 
      overflow: hidden; 
  }
  #page-reservations .table-scrollable, 
  #page-clients .table-scrollable,
  #page-vehicles .table-scrollable,
  #page-maintenance .table-scrollable,
  #page-stands .table-scrollable { 
      flex: 1; 
      overflow-y: auto; 
      height: 100%;
      max-height: none !important; 
  }

  /* Specific Logic for Vehicles & Maintenance Tabs Scroll */
  #page-vehicles .tab-content, #page-maintenance .tab-content {
      flex: 1;
      display: flex;
      flex-direction: column;
      min-height: 0;
      overflow: hidden;
  }
  #page-vehicles .tab-pane, #page-maintenance .tab-pane {
      height: 100%;
      flex-direction: column;
      min-height: 0;
      overflow: hidden;
  }
  #page-vehicles .tab-pane.active, #page-maintenance .tab-pane.active {
      display: flex;
  }

  /* --- DAILY SERVICE PAGE --- */
  #page-daily {
      display: flex;
      flex-direction: column;
      height: 100vh;
      overflow: hidden;
      padding: 0 !important;
  }
  .daily-fixed-header {
      padding: 24px 32px 10px 32px;
      flex-shrink: 0;
      background-color: var(--bg-body);
      z-index: 10;
  }
  .daily-scroll-content {
      flex: 1;
      overflow-y: auto;
      padding: 0 32px 40px 32px;
      padding-bottom: 60px;
  }

  /* --- CALENDAR/GANTT PAGE SCROLL FIX --- */
  #page-calendar {
      display: flex;
      flex-direction: column;
      height: 100vh;
      max-height: 100vh;
      overflow: hidden;
      padding: 24px 32px 50px 32px !important; /* Aumentado para 50px para a barra de scroll ficar acima do rodapé */
  }
  #page-calendar .gantt-container {
      flex: 1;
      overflow: auto; /* Scroll horizontal e vertical ativado */
      width: 100%;    /* Forçar largura total */
      min-height: 0;
      border: 1px solid #e2e8f0;
      border-radius: 12px;
      background: white;
      position: relative; 
      display: block; 
  }
  
  /* Scrollbar customizada para o Gantt */
  #page-calendar .gantt-container::-webkit-scrollbar { height: 12px; width: 12px; }
  #page-calendar .gantt-container::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 0 0 12px 12px; }
  #page-calendar .gantt-container::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 6px; border: 3px solid #f1f5f9; }
  #page-calendar .gantt-container::-webkit-scrollbar-thumb:hover { background-color: #94a3b8; }

  .fixed-footer {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 100%; 
    background: #fff;
    border-top: 1px solid #e2e8f0;
    text-align: center;
    padding: 6px 0;
    font-size: 0.7rem;
    color: #64748b;
    z-index: 1039;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.02);
  }
  @media (min-width: 769px) {
    .fixed-footer { width: calc(100% - var(--sidebar-width)); }
  }

  /* Tables & Lists */
  .sticky-header-container { width: 100%; position: relative; border: 1px solid #e2e8f0; border-radius: 12px; background: white; }
  
  .sticky-header-container thead th { position: sticky; top: 0; background-color: #f8fafc; z-index: 10; padding: 12px 16px; font-size: 0.8rem; text-transform: uppercase; border-bottom: 2px solid #e2e8f0; white-space: nowrap; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
  .sticky-header-container tbody td { padding: 12px 16px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; font-size: 0.85rem; }
  .veh-sticky-top { position: sticky; top: 0; z-index: 20; background-color: var(--bg-body); padding-bottom: 15px; padding-top: 5px; }
  /* --- FIX: Ajuste Tabela Reservas e Scroll Horizontal Interno --- */
  .table-scrollable { 
      flex: 1; 
      overflow-y: auto; 
      overflow-x: auto; /* <-- Impede que a tabela alargue o ecrã inteiro */
      height: 100%; 
      max-height: none !important; 
  }
  
  #table-reservations { 
      table-layout: fixed; 
      width: 100%; 
      min-width: 950px; /* Impede que o texto esmague em ecrãs muito pequenos */
  }
  
  #table-reservations th { 
      font-size: 0.75rem; 
      letter-spacing: 0.5px; 
      background-color: #f8fafc; 
      padding: 10px; /* Reduzido para libertar espaço */
  }
  
  #table-reservations td { 
      white-space: normal !important; 
      word-wrap: break-word; 
      overflow-wrap: break-word; /* Força quebra de textos enormes que causam esticamento */
      padding: 8px 10px; 
      font-size: 0.85rem; 
      vertical-align: middle; 
  }
  
  #table-reservations td .info-group { display: flex; flex-direction: column; gap: 2px; }

  /* Gantt Specifics */
  .gantt-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
  /* Ajuste para centrar texto nos dias */
  .gantt-table thead th { position: sticky; top: 0; background: #f8fafc; z-index: 30; border-bottom: 1px solid #cbd5e1; height: 55px; border-right: 1px solid #e2e8f0; text-align: center; vertical-align: middle; }
  .gantt-table thead th div { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%; }
  
  /* Sticky Left Column for Vehicles */
  .gantt-table thead th.veh-col-header { position: sticky; left: 0; top: 0; z-index: 40; background: #f1f5f9; width: 240px; min-width: 240px; border-right: 2px solid #cbd5e1; text-align: left; padding-left: 10px; }
  .gantt-table tbody td { border-bottom: 1px solid #f1f5f9; border-right: 1px solid #f8fafc; height: var(--row-height); padding: 0; position: relative; }
  .gantt-table tbody td.veh-col-cell { position: sticky; left: 0; background: #fff; z-index: 20; border-right: 2px solid #cbd5e1; vertical-align: middle; width: 240px; min-width: 240px; }
  
  .veh-status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 10px; flex-shrink: 0; }
  .day-cell { width: var(--day-width); min-width: var(--day-width); cursor: pointer; transition: background 0.1s; }
  .day-cell:hover { background-color: #f1f5f9; }
  .day-blocked { background: #f8fafc; cursor: not-allowed; background-image: repeating-linear-gradient(45deg, #e2e8f0, #e2e8f0 1px, #f8fafc 1px, #f8fafc 8px); }
  
  .res-bar { position: absolute; top: 8px; bottom: 8px; border-radius: 6px; cursor: pointer; z-index: 10; font-size: 0.7rem; font-weight: 600; color: white; display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap; box-shadow: 0 2px 4px rgba(0,0,0,0.15); transition: transform 0.1s; border: 1px solid rgba(255,255,255,0.2); }
  .res-bar:hover { z-index: 15; transform: translateY(-2px); }
  .status-rented { background-color: #ef4444; } 
  .status-pickup-drop { background-color: #f59e0b; } 
  .status-conflict { background-color: #8b5cf6; border: 2px solid #fff; } 
  .status-inop { background-color: #334155; } 
  .status-sold { background-color: #94a3b8; } 

  #custom-tooltip { position: fixed; display: none; background: rgba(15, 23, 42, 0.95); color: white; padding: 12px; border-radius: 8px; font-size: 0.8rem; z-index: 9999; pointer-events: none; max-width: 300px; backdrop-filter: blur(4px); }
  .legend-box { width: 12px; height: 12px; display: inline-block; margin-right: 6px; vertical-align: middle; border-radius: 3px; }

  /* Modals & Forms */
  .modal-content { border: none; border-radius: 16px; }
  .modal-header { background-color: #fff !important; border-radius: 16px 16px 0 0; }
  .modal-body { background-color: #f8fafc !important; }
  .form-label-sm { font-size: 0.75rem; margin-bottom: 4px; font-weight: 600; color: #64748b; text-transform: uppercase; }
  .card-header-sm { padding: 8px 16px; font-weight: 700; font-size: 0.75rem; text-transform: uppercase; color: #475569; }

  /* Print Styles */
  .print-header-content { display: none; }
  .daily-print-header { display: none; }
  .company-hero { background: linear-gradient(135deg, var(--sidebar-bg) 0%, #1e293b 100%); color: white; border-radius: 16px; padding: 30px 40px; position: relative; overflow: hidden; flex-shrink: 0; }
  .company-hero::after { content: ''; position: absolute; right: 0; bottom: 0; width: 200px; height: 200px; background: rgba(255,255,255,0.05); border-radius: 50%; transform: translate(30%, 30%); }
  .alert-item { border-left: 4px solid #cbd5e1; background: white; padding: 12px 16px; margin-bottom: 8px; border-radius: 4px; font-size: 0.85rem; display: flex; justify-content: space-between; align-items: center; transition: all 0.2s; }
  .alert-item:hover { transform: translateX(5px); box-shadow: 0 2px 4px rgba(0,0,0,0.05); cursor: pointer; }
  .alert-urgent { border-left-color: #ef4444; }
  .alert-warning { border-left-color: #f59e0b; }
  .alert-today { border-left-color: #22c55e; }

  @media (max-width: 768px) {
      #sidebar { transform: translateX(-100%); width: 100%; max-width: 300px; }
      #sidebar.active { transform: translateX(0); }
      #content { margin-left: 0; padding-bottom: 60px; height: auto; overflow: visible; }
      .main-content-wrapper { height: auto; overflow: visible; }
      .mobile-nav { display: flex; }
      .fixed-footer { width: 100%; font-size: 0.65rem; }
      #page-home { overflow-y: auto; display: block; height: auto; } 
      .scroll-column-body { overflow: visible; height: auto; flex: none; }
      .home-card-flex { display: block; height: auto; overflow: visible; }
      
      #page-reservations { height: auto; overflow: visible; padding-bottom: 80px; display: block; max-height: none; }
      #page-reservations .sticky-header-container { flex: none; max-height: 80vh; overflow: auto; }
      
      #page-clients { height: auto; overflow: visible; padding-bottom: 80px; display: block; max-height: none; }
      #page-clients .sticky-header-container { flex: none; max-height: 80vh; overflow: auto; }

      #page-vehicles, #page-maintenance, #page-stands { height: auto; overflow: visible; padding-bottom: 80px; display: block; max-height: none; }
      #page-vehicles .sticky-header-container, #page-maintenance .sticky-header-container, #page-stands .sticky-header-container { flex: none; max-height: 80vh; overflow: auto; }

      /* Mobile Reset for Daily and Calendar */
      #page-daily { height: auto; overflow-y: auto; padding: 24px 32px !important; display: block; }
      .daily-fixed-header { padding: 0; }
      .daily-scroll-content { padding: 0; overflow: visible; }
      
      #page-calendar { height: auto; overflow-y: auto; padding: 24px 32px !important; display: block; max-height: none; }
      .gantt-container { max-height: 500px; overflow: auto; }
  }

  @media print {
      /* CONFIGURAÇÃO PARA VERTICAL (PORTRAIT) */
      body { background-color: white; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
      #sidebar, .mobile-nav, .overlay, #login-screen, .no-print, .fixed-footer { display: none !important; }
      #content { margin-left: 0; height: auto; overflow: visible; padding-bottom: 0; }
      .page-padding { padding: 0; overflow: visible; height: auto; }
      .print-header-content { display: block; margin-bottom: 20px; border-bottom: 2px solid #000; padding-bottom: 10px; }
      
      /* --- CABEÇALHO COMPACTO PARA IMPRESSÃO DIÁRIA --- */
      .daily-print-header { 
          display: block; 
          margin-bottom: 10px; 
          border: 2px solid #000; 
          padding: 8px 12px; 
          border-radius: 8px; 
      }
      .daily-print-header h3 { font-size: 1.1rem; margin-bottom: 0; }
      .daily-print-header .small { font-size: 0.7rem; }
      .daily-print-header h4 { font-size: 1rem; margin-top: 5px; margin-bottom: 2px; }
      .daily-print-header h5 { font-size: 0.9rem; margin-bottom: 0; }
      .daily-print-header hr { margin: 5px 0; opacity: 1; border-color: #000; }
      /* ------------------------------------------------ */

      .card { border: none !important; box-shadow: none !important; }
      .sticky-header-container { max-height: none !important; overflow: visible !important; border: none; }
      .sticky-header-container thead th { position: static !important; background-color: #ddd !important; color: black !important; border: 1px solid #000; }
      .table { width: 100%; border-collapse: collapse; }
      .table td, .table th { border: 1px solid #000 !important; padding: 4px 6px !important; font-size: 0.75rem !important; }
      table tr th:last-child, table tr td:last-child { display: none !important; }
      
      /* Reset Daily Page for Print */
      #page-daily { display: block; height: auto; overflow: visible; padding: 0 !important; }
      .daily-scroll-content { overflow: visible; padding: 0; }
      .daily-fixed-header { display: none; } /* Hide interactive header, show print header */
  }
  /* --- ESTILOS ESPECÍFICOS FOLHA DE CAIXA (HORIZONTAL) --- */
@media print {
    .cash-print-wrapper {
        display: flex;
        flex-direction: row;
        width: 100%;
        gap: 10px;
        border: 1px solid #000;
        margin-bottom: 20px;
        break-inside: avoid; /* Evita cortar a semana a meio */
    }
    .cash-print-half {
        width: 50%;
        padding: 0;
    }
    .cash-print-half:first-child {
        border-right: 1px solid #000;
    }
    /* Forçar fundos para diferenciar cabeçalhos na impressão */
    .bg-entradas { background-color: #d1e7dd !important; -webkit-print-color-adjust: exact; }
    .bg-saidas { background-color: #f8d7da !important; -webkit-print-color-adjust: exact; }
    
    /* Ajustes de tabela para caber tudo */
    .table-cash-print th, .table-cash-print td {
        font-size: 0.7rem !important;
        padding: 2px 4px !important;
        border: 1px solid #ccc;
    }
}

/* Ajuste visual no ecrã para simular o papel */
@media screen {
    .cash-print-wrapper {
        display: flex;
        flex-wrap: wrap;
        gap: 0;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        border-radius: 8px;
        overflow: hidden;
        margin-bottom: 1.5rem;
        background: white;
    }
    .cash-print-half {
        width: 50%;
        border-right: 1px solid #e2e8f0;
    }
    @media (max-width: 992px) {
        .cash-print-half { width: 100%; border-right: none; border-bottom: 1px solid #e2e8f0; }
    }
}

/* Cabeçalho de Impressão da Folha de Caixa */
.cash-print-header-container {
    display: none; /* Escondido no ecrã normal */
    border: 2px solid #000;
    padding: 15px;
    margin-bottom: 20px;
}

@media print {
    .cash-print-header-container {
        display: block; /* Visível na impressão */
    }
    
    /* Esconder controlos de ecrã na impressão */
    .no-print-controls { display: none !important; }
    
    .cash-header-grid {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 10px;
        align-items: center;
    }
    .cash-header-box {
        border: 1px solid #000;
        padding: 5px 10px;
        text-align: center;
    }
    .cash-header-title {
        font-weight: bold;
        font-size: 1.2rem;
        text-transform: uppercase;
        text-align: center;
    }
}

/* --- ESTILOS PARA O RELATÓRIO PDF EM ISOLAMENTO --- */
@media print {
    /* Força altura automática para não imprimir espaço fantasma */
    html, body.print-isolated-report {
        height: auto !important;
        min-height: auto !important;
        overflow: visible !important;
    }
    /* Esconde absolutamente TUDO no ecrã que seja filho direto do body (menus, página de fundo, etc)... */
    body.print-isolated-report > * { 
        display: none !important; 
    }
    /* ...EXCETO o contentor do relatório, e remove a posição absoluta que causava bugs */
    body.print-isolated-report > #print_report_container { 
        display: block !important; 
        position: static !important;
        width: 100%;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* CORREÇÃO CRÍTICA: Força a última coluna a aparecer nos relatórios (anula o bloqueio dos botões de ação) */
    body.print-isolated-report table tr th:last-child,
    body.print-isolated-report table tr td:last-child {
        display: table-cell !important;
    }
}