:root {
    /* Fallbacks (serão sobrescritos pelo theme.js) */
    --primary: #D4AF37;
    --bg-body: #f4f6f9;
    --bg-card: #ffffff;
    --border-color: #dee2e6;
    --text-main: #333333;
    --text-muted: #6c757d;
    --color-success: #28a745;
    --color-danger: #dc3545;
    --color-warning: #ffc107;
}

* { box-sizing: border-box; outline: none; }

/* input[type=date] (e similares): evita overflow no mobile (largura intrínseca do browser) */
input[type="date"],
input[type="datetime-local"],
input[type="month"],
input[type="week"],
input[type="time"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-body);
    margin: 0;
    color: var(--text-main);
}

/* Utilitários */
.hidden { display: none !important; }
.fade-in { animation: fadeIn 0.5s ease-in; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Botões */
.btn-main {
    background-color: var(--primary);
    color: var(--text-main);
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: 0.2s;
}
.btn-main:hover { filter: brightness(0.9); }

.btn-sec {
    background-color: color-mix(in srgb, var(--text-main) 6%, transparent);
    color: var(--text-main);
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
}

/* Header Global */
.app-header {
    background-color: var(--bg-card);
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 2px 5px color-mix(in srgb, var(--text-main) 8%, transparent);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-brand { font-size: 1.2rem; font-weight: bold; color: var(--primary); display: flex; align-items: center; gap: 10px; }
.app-brand img { height: 35px; }

.app-user { display: flex; align-items: center; gap: 15px; }
.user-info { text-align: right; line-height: 1.2; }
.user-name { font-weight: bold; font-size: 0.9rem; }
.user-role { font-size: 0.75rem; color: var(--text-muted); }
.btn-logout { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.2rem; }
.btn-logout:hover { color: var(--color-danger); }

/* Context Switcher (Dropdown no Header) */
.context-badge {
    background: color-mix(in srgb, var(--text-main) 6%, transparent);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}
.context-badge:hover { background: color-mix(in srgb, var(--text-main) 12%, transparent); }

/* Cards de Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    padding: 20px;
}

.dash-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 5px color-mix(in srgb, var(--text-main) 8%, transparent);
    transition: 0.3s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    border: 1px solid transparent;
}
.dash-card:hover { transform: translateY(-5px); border-color: var(--primary); }
.dash-card i { font-size: 2rem; color: var(--primary); margin-bottom: 15px; }
.dash-card h3 { margin: 0; font-size: 1.1rem; color: var(--text-main); }

/* TOAST NOTIFICATIONS */
.toast-container {
    position: fixed;
    top: 90px; /* Abaixo do header */
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none; /* Permite clicar através do container */
}

.toast {
    background: var(--bg-card);
    color: var(--text-main);
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--text-main) 18%, transparent);
    border-left: 5px solid var(--primary);
    min-width: 300px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: slideInRight 0.3s ease-out;
    font-size: 0.95rem;
    pointer-events: auto;
}

.toast.success { border-left-color: var(--color-success); }
.toast.error { border-left-color: var(--color-danger); }
.toast.warning { border-left-color: var(--color-warning); }

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    margin-left: 15px;
}
.toast-close:hover { color: var(--text-main); }

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.termo-aceite-item {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.termo-aceite-item:last-child {
    border-bottom: none;
}

/*
 * AppDialog (theme.js) + fallback comum de modais sem .modal-body:
 * mensagem longa (ex.: validação de dados obrigatórios do WF) não pode
 * empurrar o botão OK para fora da viewport.
 */
#app-dialog-overlay.app-dialog-overlay,
.app-dialog-overlay {
    overflow: auto;
    box-sizing: border-box;
}

#app-dialog-overlay .app-dialog-box,
.app-dialog-box {
    max-height: min(90vh, calc(100vh - 32px));
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

#app-dialog-overlay .app-dialog-message,
.app-dialog-message {
    overflow: auto;
    flex: 1 1 auto;
    min-height: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#app-dialog-overlay .app-dialog-actions,
.app-dialog-actions,
#app-dialog-overlay .app-dialog-title,
.app-dialog-title {
    flex-shrink: 0;
}

/*
 * Baseline de overflow para modais em qualquer tela (global.css carrega cedo).
 * Telas com CSS próprio reforçam; aqui garante que conteúdo longo não
 * empurre botões/fechar para fora da viewport.
 */
.modal-overlay:not(.hidden) {
    overflow: auto;
    box-sizing: border-box;
}

.modal-box {
    max-height: min(90vh, calc(100vh - 32px));
    min-height: 0;
    min-width: 0;
}

.modal-body {
    overflow: auto;
    min-height: 0;
    min-width: 0;
}

.modal-header,
.modal-footer {
    flex-shrink: 0;
}