/* === Variáveis === */
:root {
    --primary-color: #008080;
    --primary-dark: #006666;
    --secondary-color: #333333;
    --background-color: #f4f7f6;
    --text-color: #333;
    --card-bg: #FFFFFF;
    --border-color: #E0E0E0;
    --input-bg: #FAFAFA;
    --sidebar-width: 260px;
    --header-height-mobile: 60px;
}

/* === Reset e Base === */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--background-color);
    color: var(--text-color);
    font-family: 'Inter', sans-serif;
    line-height: 1.6;
    display: flex;
    /* Para layout sidebar */
    min-height: 100vh;
}

/* === Estrutura Principal (Sidebar Layout) === */
.main-content {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    /* Desktop: Espaço do menu */
    width: calc(100% - var(--sidebar-width));
    padding: 2rem;
    transition: margin-left 0.3s ease;
}

/* Ajuste específico para main.container (usado em quase todas as páginas) */
main.container {
    margin-left: var(--sidebar-width) !important;
    /* Força margem esquerda */
    width: auto !important;
    max-width: none !important;
    padding: 2rem 3rem !important;
    /* Espaçamento interno generoso */
    flex-grow: 1;
}

/* Se houver .container genérico dentro de main, ele deve ocupar 100% */
.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* === Sidebar (Desktop) === */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--secondary-color);
    color: white;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.3s ease;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.1);
    /* Sombra para separar visualmente */
}

.sidebar-header {
    padding: 1.5rem;
    background-color: rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    letter-spacing: 1px;
    border-bottom: 1px solid #444;
}

.sidebar-menu {
    flex-grow: 1;
    list-style: none;
    padding: 1rem 0;
    /* Espaço vertical */
    margin: 0;
    overflow-y: auto;
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: #555 transparent;
}

.sidebar-menu::-webkit-scrollbar {
    width: 6px;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background-color: #555;
    border-radius: 3px;
}

.sidebar-menu a {
    display: block;
    padding: 1rem 1.5rem;
    /* Item espaçoso */
    color: #ccc;
    text-decoration: none;
    transition: all 0.2s;
    border-left: 4px solid transparent;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.sidebar-menu a:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
}

.sidebar-menu a.active {
    background-color: rgba(0, 128, 128, 0.2);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 600;
}

.sidebar-section-title {
    padding: 1.5rem 1.5rem 0.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #888;
    font-weight: bold;
    letter-spacing: 1px;
    margin-top: 0.5rem;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid #444;
    font-size: 0.9rem;
    color: #888;
    text-align: center;
    background-color: rgba(0, 0, 0, 0.1);
}

/* === Mobile Elements === */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--header-height-mobile);
    background-color: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    display: none;
    /* Desktop hidden */
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 900;
}

.mobile-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--secondary-color);
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
}

.overlay.active {
    display: block;
}


/* === Estilos de Conteúdo (Cards, Forms, Tables) === */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

h2,
h3 {
    color: var(--primary-dark);
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.section-card,
.table-card,
.filters-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 2rem;
    margin: 2rem 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    border-top: 4px solid var(--primary-color);
}

.filters-card {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.table-card {
    padding: 0;
    border-top: none;
}

/* Formulários */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: #555;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--input-bg);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.3s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 128, 128, 0.1);
}

input[readonly],
select[disabled] {
    background-color: #E9ECEF;
    color: #6C757D;
    cursor: not-allowed;
}

/* Tabelas */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #f8f9fa;
    color: #495057;
    font-weight: 600;
}

/* Badges e Links */
.status-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
}

.status-aberto {
    background: #ffeeba;
    color: #856404;
}

.status-preenchido {
    background: #cce5ff;
    color: #004085;
}

.status-finalizado {
    background: #d4edda;
    color: #155724;
}

.action-link {
    text-decoration: none;
    color: var(--primary-color);
    font-weight: 600;
    margin-right: 10px;
}

.action-link:hover {
    text-decoration: underline;
}

/* Botões */
.actions {
    margin-top: 2rem;
    text-align: right;
}

.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: #6C757D;
    color: white;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
}

/* Canvas */
.canvas-wrapper {
    border: 2px dashed var(--border-color);
    border-radius: 4px;
    background: #fff;
    cursor: crosshair;
    margin-bottom: 1rem;
    width: 100%;
    display: flex;
    justify-content: center;
}

canvas {
    max-width: 100%;
}

/* === Responsividade Mobile === */
@media (max-width: 768px) {

    /* Layout */
    body {
        display: block;
    }

    /* Sidebar vira Drawer */
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content,
    main.container {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1rem !important;
        padding-top: calc(var(--header-height-mobile) + 1rem) !important;
    }

    /* Header visível */
    .mobile-header {
        display: flex;
    }

    .overlay.active {
        display: block;
    }

    /* Ajustes Gerais */
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
}

/* === Utilitários de Visibilidade (Global) === */
.print-only {
    display: none !important;
}

.screen-only {
    display: inline-block;
    /* ou block, conforme a necessidade */
}

/* === Impressão === */
/* === Impressão (PDF A4) === */
@media print {
    /* ... (outras regras de layout) ... */

    /* Inverter visibilidade na impressão */
    .screen-only,
    .no-print,
    .sidebar,
    .mobile-header,
    .mobile-toggle,
    .actions,
    .btn,
    .photo-controls,
    .overlay,
    form>input[type="hidden"] {
        display: none !important;
    }

    .print-only,
    .print-header {
        display: block !important;
    }

    /* ... */

    /* Layout Full Width */
    .main-content,
    main.container {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: none !important;
    }

    /* Cabeçalho de Impressão */
    .print-header {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        border-bottom: 2px solid #000;
        padding-bottom: 10px;
        margin-bottom: 20px;
    }

    .print-logo img {
        height: 60px;
        width: auto;
    }

    .print-title {
        text-align: right;
    }

    .print-title h1 {
        font-size: 18px;
        margin: 0;
        color: #000;
        text-transform: uppercase;
    }

    .print-title p {
        margin: 0;
        font-size: 12px;
        font-weight: bold;
    }

    /* Ajuste de Cards para economizar tinta/papel */
    .section-card {
        box-shadow: none;
        border: 1px solid #ccc;
        border-radius: 4px;
        margin-bottom: 15px;
        padding: 10px;
        page-break-inside: avoid;
    }

    .section-card h2 {
        font-size: 14px;
        border-bottom: 1px solid #000;
        padding-bottom: 5px;
        margin-bottom: 10px;
        color: #000;
    }

    /* Formulários "Read-only" na impressão */
    input,
    textarea,
    select {
        border: none !important;
        background: transparent !important;
        padding: 0 !important;
        font-size: 12px !important;
        color: #000 !important;
        width: auto !important;
        height: auto !important;
        resize: none;
    }

    label {
        font-size: 10px;
        text-transform: uppercase;
        color: #666;
        margin-bottom: 0;
    }

    .form-group {
        margin-bottom: 5px;
    }

    /* Grid mais denso */
    .grid-2 {
        gap: 10px;
    }

    /* Fotos */
    .photo-item {
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }

    .photo-gallery {
        border: none;
        padding: 0;
        gap: 10px;
    }
}

/* Ocultar cabeçalho de impressão na tela */
.print-header {
    display: none;
}

/* === Upload de Fotos === */
.photo-section {
    margin-top: 2rem;
}

.photo-upload-box {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
    background: #fafafa;
    position: relative;
    transition: all 0.3s;
}

.photo-upload-box:hover {
    border-color: var(--primary-color);
    background: #f0f8ff;
}

.hidden-file-input {
    display: none !important;
    visibility: hidden !important;
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
}

.preview-area {
    width: 100%;
    min-height: 50px;
    /* Reduzido para não ocupar muito espaço vazio */
    width: 100%;
    height: 150px;
    background: #eee;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    margin-top: 0.5rem;
}

.preview-area img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.preview-area span {
    color: #888;
    font-size: 0.9rem;
    pointer-events: none;
}

.existing-photo {
    margin-bottom: 0.5rem;
}

.photo-preview-static {
    max-width: 100%;
    max-height: 150px;
    border-radius: 4px;
    border: 1px solid #ddd;
    display: block;
    margin: 0 auto;
}

.small-text {
    font-size: 0.8rem;
    color: #666;
    margin-top: 4px;
}

/* === Galeria de Fotos Múltiplas === */
.photo-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
    background: #f9f9f9;
    padding: 10px;
    border-radius: 8px;
    min-height: 100px;
    border: 1px dashed #ccc;
}

.photo-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    background: #fff;
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: zoom-in;
}

.photo-item .btn-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(255, 0, 0, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-item.new {
    border: 2px solid var(--primary-color);
}

/* === Tabela de Horas === */
.hours-grid {
    display: grid;
    grid-template-columns: 140px 1fr 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

.hours-header {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    background: #f8f9fa;
    padding: 5px;
    border-radius: 4px;
}

.hour-range {
    display: flex;
    align-items: center;
    gap: 5px;
}

.hour-input {
    width: 100% !important;
    padding: 0.4rem !important;
    font-size: 0.9rem !important;
    text-align: center;
}

@media print {
    .hours-grid {
        grid-template-columns: 100px 1fr 1fr 1fr;
        gap: 0;
        border: 1px solid #000;
    }

    .hours-header {
        background: #eee !important;
        color: #000 !important;
        border: 1px solid #000;
        font-weight: bold;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .hour-range,
    .hour-input {
        border: 1px solid #000;
        border-radius: 0;
        margin: 0 !important;
        background: transparent !important;
        height: auto !important;
    }

    /* Tabela de Horas - Impressão */
    .table-responsive {
        overflow: visible !important;
        display: block !important;
    }

    .hours-matrix table {
        width: 100%;
        border-collapse: collapse;
        border: 1px solid #000;
    }

    .hours-matrix th {
        background: #eee !important;
        color: #000 !important;
        border: 1px solid #000 !important;
        font-size: 10px !important;
        padding: 4px !important;
    }

    .hours-matrix td {
        border: 1px solid #000 !important;
        padding: 0 !important;
    }

    .no-print {
        display: none !important;
    }

    .hours-matrix input {
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
        text-align: center !important;
        font-family: inherit;
        font-size: 11px !important;
        color: #000 !important;
        width: 100% !important;
        height: auto !important;
        padding: 4px !important;
        margin: 0 !important;
        /* Remover placeholder na impressão */
        color: transparent;
        text-shadow: 0 0 0 #000;
    }

    .hours-matrix input::placeholder {
        color: transparent !important;
        opacity: 0 !important;
    }

    /* Input date vazio fica feio no chrome, tentar limpar */
    .hours-matrix input[type="date"]::-webkit-inner-spin-button,
    .hours-matrix input[type="date"]::-webkit-calendar-picker-indicator {
        display: none;
        -webkit-appearance: none;
    }
}

.signature-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    /* Flex via JS */
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.signature-modal-content {
    background: white;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

@media (min-width: 768px) {

    /* Em desktop não precisa ser fullscreen total */
    .signature-modal-content {
        width: 90%;
        height: 90%;
        border-radius: 8px;
    }
}

.signature-modal-header {
    padding: 1rem;
    background: var(--primary-color);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.signature-modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    border: none;
    color: white;
    padding: 0;
}

.close-modal {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.signature-modal-body {
    flex-grow: 1;
    background: #fff;
    position: relative;
    overflow: hidden;
    touch-action: none;
    /* Impede scroll enquanto desenha */
}

.signature-modal-body canvas {
    display: block;
    cursor: crosshair;
}

.signature-modal-footer {
    padding: 1rem;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    background: #f9f9f9;
}