/* Admin CSS - Clean, Professional, Dark/Light Corporate Theme */
:root {
    /* Cores Padrão DSGov (Governo Federal) */
    --admin-primary: #1351b4; /* Azul Gov */
    --admin-primary-hover: #0c326f;
    --admin-secondary: #333333;
    --admin-success: #168821; /* Verde Gov */
    --admin-danger: #e52207; /* Vermelho Gov */
    --admin-warning: #ffcd07; /* Amarelo Gov */
    
    --admin-bg: #f4f6f8;
    --admin-surface: #ffffff;
    --admin-sidebar-bg: #ffffff; /* Fundo branco e clean */
    --admin-sidebar-hover: #f4f6f8; /* Cinza claro no hover */
    --admin-border: #dcdcdc;
    
    --admin-text-main: #333333;
    --admin-text-muted: #666666;
    --admin-sidebar-text: #333333; /* Texto escuro */
    --admin-sidebar-muted: #777777; /* Texto atenuado */
    
    /* Design mais estruturado/sóbrio */
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.1);
    --shadow-md: 0 2px 4px rgba(0,0,0,0.1);

    /* Compatibilidade com componentes e fichas do sistema */
    --border-color: #cbd5e1;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --primary: #1351b4;
    --border-radius: 8px;
}

html, body {
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'rawline', 'Raleway', 'Roboto', sans-serif;
}

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

body.admin-theme {
    background: var(--admin-bg);
    color: var(--admin-text-main);
    overflow: hidden;
    height: 100%;
    height: 100dvh;
}

/* Previne "Piscada" (FOUC) do texto das fontes antes de carregar */
.material-symbols-rounded {
    display: inline-block;
    width: 1em;
    height: 1em;
    overflow: hidden;
    white-space: nowrap;
    text-transform: none;
    line-height: 1;
    direction: ltr;
}

/* Loader */
.fullscreen-loader {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; height: 100dvh;
    background: var(--admin-bg);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
}
.loader-content { text-align: center; }
.spinner-large {
    width: 50px; height: 50px;
    border: 4px solid var(--admin-border);
    border-top-color: var(--admin-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout */
.admin-layout {
    display: flex;
    height: 100%;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* Sidebar */
.admin-sidebar {
    width: 260px;
    background: var(--admin-sidebar-bg);
    color: var(--admin-sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
    border-right: 1px solid var(--admin-border);
}

.sidebar-header {
    padding: 8px 20px;
    border-bottom: 1px solid var(--admin-border);
    height: 64px; /* Fixando a altura para alinhar perfeitamente com o topbar */
    display: flex;
    align-items: center;
    justify-content: flex-start; /* Alinhado à esquerda como os itens do menu */
    border-left: 3px solid transparent; /* Para alinhar pixel perfect com o border-left dos menus */
}
.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}
.logo h1 { font-size: 1.2rem; font-weight: 700; letter-spacing: 0.5px; }

.sidebar-user {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--admin-border);
}
.avatar {
    width: 40px; height: 40px;
    background: var(--admin-primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 1.2rem;
}
.user-info .name { font-weight: 600; font-size: 0.95rem; }
.user-info .role { font-size: 0.8rem; color: var(--admin-sidebar-muted); }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}
.nav-section {
    padding: 0 20px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--admin-sidebar-muted);
    margin-bottom: 8px;
    margin-top: 16px;
    letter-spacing: 1px;
}
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px;
    color: var(--admin-sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    cursor: pointer;
    background: transparent;
    width: 100%;
    text-align: left;
    font-size: 0.95rem;
}
.nav-item:hover {
    background: var(--admin-sidebar-hover);
    color: var(--admin-primary);
}
.nav-item.active {
    background: rgba(19, 81, 180, 0.08); /* Fundo azul bem fraco */
    border-left-color: var(--admin-primary);
    color: var(--admin-primary);
    font-weight: 600;
}
.nav-item .material-symbols-rounded { font-size: 20px; flex-shrink: 0; }

/* Submenu & Accordion Styles */
.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 20px;
    color: var(--admin-sidebar-text);
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    font-size: 0.95rem;
    font-weight: 500;
    user-select: none;
}
.nav-group-header:hover {
    background: var(--admin-sidebar-hover);
    color: var(--admin-primary);
}
.nav-group-header.open {
    color: var(--admin-primary);
    font-weight: 600;
    background: rgba(19, 81, 180, 0.04);
}
.nav-group-header .group-chevron {
    font-size: 18px;
    transition: transform 0.25s ease;
    color: var(--admin-sidebar-muted);
}
.nav-group-header.open .group-chevron {
    transform: rotate(180deg);
    color: var(--admin-primary);
}
.nav-submenu {
    display: none;
    background: rgba(0, 0, 0, 0.02);
    padding: 4px 0 6px 0;
    border-left: 2px solid rgba(19, 81, 180, 0.15);
    margin-left: 28px;
    margin-right: 12px;
    border-radius: 0 6px 6px 0;
}
.nav-submenu.open {
    display: flex;
    flex-direction: column;
}
.nav-subitem {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    color: var(--admin-sidebar-muted);
    text-decoration: none;
    font-size: 0.86rem;
    transition: all 0.18s ease;
    border-radius: 4px;
    cursor: pointer;
}
.nav-subitem:hover {
    color: var(--admin-primary);
    background: rgba(19, 81, 180, 0.06);
}
.nav-subitem.active {
    color: var(--admin-primary);
    font-weight: 600;
    background: rgba(19, 81, 180, 0.12);
}
.nav-subitem .material-symbols-rounded {
    font-size: 18px;
    flex-shrink: 0;
}

/* Collapsed Sidebar State */
.admin-sidebar.collapsed {
    width: 70px;
}
.admin-sidebar.collapsed .logo {
    justify-content: center;
}
.admin-sidebar.collapsed .logo img {
    display: none;
}
.admin-sidebar.collapsed .logo::before {
    content: "e-A";
    font-weight: 800;
    color: var(--admin-primary);
    font-size: 1.2rem;
}
.admin-sidebar.collapsed .user-info,
.admin-sidebar.collapsed .nav-section,
.admin-sidebar.collapsed .nav-item span:not(.material-symbols-rounded) {
    display: none;
}
.admin-sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 12px 0;
}
.admin-sidebar.collapsed .avatar {
    width: 32px; height: 32px; font-size: 1rem;
}
.admin-sidebar.collapsed .sidebar-user {
    justify-content: center; padding: 20px 0;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--admin-border);
}
.nav-item.danger { color: var(--admin-danger); }
.nav-item.danger:hover { background: rgba(229, 34, 7, 0.08); color: var(--admin-danger); }

/* Main Content */
.admin-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    overflow: hidden;
}

/* Topbar */
.admin-topbar {
    height: 64px;
    background: var(--admin-surface);
    border-bottom: 1px solid var(--admin-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.breadcrumb { font-weight: 600; font-size: 1.1rem; color: var(--admin-text-main); }
.d-mobile-only { display: none; }
.icon-btn {
    background: transparent; border: none; cursor: pointer;
    color: var(--admin-text-muted);
    display: flex; align-items: center; justify-content: center;
    padding: 8px; border-radius: 50%;
}
.icon-btn:hover { background: var(--admin-bg); }

.sync-status {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.85rem; font-weight: 500;
    padding: 6px 12px; border-radius: 20px;
    background: var(--admin-bg);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.sync-status.online .status-dot { background: var(--admin-success); }
.sync-status.offline .status-dot { background: var(--admin-danger); }

/* Content Area */
.admin-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 32px 80px 32px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Utils */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); /* 60% menor para caber em uma linha */
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--admin-surface);
    border-radius: var(--radius-lg);
    padding: 16px; /* Padding menor */
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--admin-border);
    display: flex; align-items: center; gap: 16px;
}
.stat-icon {
    width: 48px; height: 48px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.stat-icon .material-symbols-rounded { font-size: 24px; }
.stat-info p { color: var(--admin-text-muted); font-size: 0.85rem; font-weight: 500; margin-bottom: 4px; } /* Sem maiúsculas forçadas */
.stat-info h2 { font-size: 1.5rem; color: var(--admin-text-main); line-height: 1; }

.admin-panel {
    background: var(--admin-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--admin-border);
    overflow: hidden;
}
.panel-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--admin-border);
    display: flex; justify-content: space-between; align-items: center;
}
.panel-title { font-weight: 600; font-size: 1.1rem; }

.btn {
    padding: 8px 16px; border-radius: var(--radius-md); border: none;
    font-weight: 600; font-size: 0.9rem; cursor: pointer;
    display: flex; align-items: center; gap: 8px; transition: all 0.2s;
}
.btn-primary { background: var(--admin-primary); color: white; }
.btn-primary:hover { background: var(--admin-primary-hover); }
.btn-secondary { background: #ffffff; color: var(--admin-text-main); border: 1px solid var(--admin-border); }
.btn-secondary:hover { background: var(--admin-bg); border-color: #bbb; }

/* Form Controls & Inputs */
.admin-input, input.admin-input, select.admin-input, textarea.admin-input {
    background: #ffffff;
    border: 1px solid var(--admin-border);
    border-radius: 8px !important;
    padding: 8px 12px;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--admin-text-main);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    height: 38px;
    box-sizing: border-box;
}

.admin-input:focus, input.admin-input:focus, select.admin-input:focus, textarea.admin-input:focus {
    border-color: var(--admin-primary);
    box-shadow: 0 0 0 3px rgba(19, 81, 180, 0.12);
}

select.admin-input {
    cursor: pointer;
    background-color: #ffffff;
}

textarea.admin-input {
    height: auto;
    min-height: 80px;
}

/* Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.admin-table {
    width: 100%; border-collapse: collapse; text-align: left;
}
.admin-table th {
    padding: 16px 24px;
    background: var(--admin-bg);
    color: var(--admin-text-muted);
    font-weight: 600; font-size: 0.8rem; text-transform: uppercase;
    border-bottom: 1px solid var(--admin-border);
}
.admin-table td {
    padding: 16px 24px;
    border-bottom: 1px solid var(--admin-border);
    font-size: 0.95rem;
}
.admin-table tr:hover td { background: rgba(0,0,0,0.01); }

/* --- Responsividade Específica para Tablets & Mobiles --- */
@media (max-width: 1024px) {
    .admin-sidebar {
        position: fixed; z-index: 100; height: 100%; height: 100dvh;
        transform: translateX(-100%);
    }
    .admin-sidebar.open { transform: translateX(0); }
    .admin-topbar {
        position: sticky;
        top: 0;
        z-index: 50;
    }
    .admin-content {
        padding: 20px 20px 120px 20px !important; /* 120px de espaço inferior para barras de navegação de tablets */
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 768px) {
    .admin-sidebar {
        position: fixed; z-index: 100; height: 100%; height: 100dvh;
        transform: translateX(-100%);
    }
    .admin-sidebar.open { transform: translateX(0); }
    .d-mobile-only { display: flex; }
    .admin-content {
        padding: 16px 16px 140px 16px !important; /* 140px no mobile */
        -webkit-overflow-scrolling: touch;
    }
}
/* --- Global Custom Modal Design System --- */
.custom-modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(15, 23, 42, 0.72) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    z-index: 999999 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 0;
    animation: fadeInModal 0.22s ease-out forwards;
    padding: 16px !important;
    box-sizing: border-box !important;
}

@keyframes fadeInModal {
    to { opacity: 1; }
}

.custom-modal-box {
    background: #ffffff !important;
    border-radius: 18px !important;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(255, 255, 255, 0.15) !important;
    max-width: 440px !important;
    width: 100% !important;
    padding: 26px 28px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    text-align: center !important;
    transform: scale(0.92);
    animation: scaleUpModal 0.24s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    position: relative !important;
    font-family: 'Inter', system-ui, -apple-system, sans-serif !important;
    box-sizing: border-box !important;
}

@keyframes scaleUpModal {
    to { transform: scale(1); }
}

.custom-modal-icon-badge {
    width: 58px !important;
    height: 58px !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-bottom: 16px !important;
}

.custom-modal-icon-badge .material-symbols-rounded {
    font-size: 32px !important;
}

.custom-modal-icon-badge.info {
    background: rgba(14, 165, 233, 0.12) !important;
    color: #0284c7 !important;
}

.custom-modal-icon-badge.warning {
    background: rgba(245, 158, 11, 0.12) !important;
    color: #d97706 !important;
}

.custom-modal-icon-badge.success {
    background: rgba(16, 185, 129, 0.12) !important;
    color: #059669 !important;
}

.custom-modal-icon-badge.error {
    background: rgba(239, 68, 68, 0.12) !important;
    color: #dc2626 !important;
}

.custom-modal-title {
    font-size: 1.15rem !important;
    font-weight: 700 !important;
    color: #0f172a !important;
    margin-bottom: 8px !important;
    line-height: 1.3 !important;
}

.custom-modal-message {
    font-size: 0.92rem !important;
    color: #475569 !important;
    line-height: 1.5 !important;
    margin-bottom: 24px !important;
    word-break: break-word !important;
}

.custom-modal-actions {
    display: flex !important;
    gap: 12px !important;
    width: 100% !important;
    justify-content: center !important;
}

.custom-modal-btn {
    flex: 1 !important;
    padding: 12px 18px !important;
    border-radius: 10px !important;
    font-size: 0.95rem !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    border: none !important;
    transition: all 0.2s ease !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-family: inherit !important;
}

.custom-modal-btn-primary {
    background: #0f766e !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.25) !important;
}

.custom-modal-btn-primary:hover {
    background: #0d655e !important;
    transform: translateY(-1px) !important;
}

.custom-modal-btn-secondary {
    background: #f1f5f9 !important;
    color: #475569 !important;
    border: 1px solid #cbd5e1 !important;
}

.custom-modal-btn-secondary:hover {
    background: #e2e8f0 !important;
}

.custom-modal-btn-danger {
    background: #dc2626 !important;
    color: #ffffff !important;
}

.custom-modal-btn-danger:hover {
    background: #b91c1c !important;
}

/* --- Global Typography & Table Formatting Rules --- */
body, input, select, button, table, th, td, .summary-card, .pill-filter-btn, .status-badge, .status-click-badge, .badge, .card-value, .stat-info h2 {
    font-variant-numeric: lining-nums tabular-nums !important;
    -moz-font-feature-settings: "lnum" 1, "tnum" 1 !important;
    -webkit-font-feature-settings: "lnum" 1, "tnum" 1 !important;
    font-feature-settings: "lnum" 1, "tnum" 1 !important;
}

th, td {
    white-space: nowrap !important;
}

/* RT Dashboard & Polo Cards Carousel */
.polo-cards-scroll {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 12px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.polo-cards-scroll::-webkit-scrollbar {
    height: 6px;
}
.polo-cards-scroll::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
.polo-cards-scroll::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.polo-cards-scroll::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Polo Profile Tabs */
.polo-tab-btn {
    padding: 10px 18px;
    border: none;
    background: transparent;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--admin-text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}
.polo-tab-btn:hover {
    color: var(--admin-primary);
    background: rgba(19, 81, 180, 0.04);
    border-radius: 6px 6px 0 0;
}
.polo-tab-btn.active {
    color: var(--admin-primary);
    border-bottom: 2px solid var(--admin-primary);
}

/* Modal Backdrops & Containers */
.admin-modal-backdrop {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(15, 23, 42, 0.65) !important;
    backdrop-filter: blur(6px) !important;
    -webkit-backdrop-filter: blur(6px) !important;
    z-index: 100000 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 16px !important;
    box-sizing: border-box !important;
    animation: fadeInModal 0.2s ease-out forwards;
}

.admin-modal-backdrop .admin-modal {
    background: #ffffff !important;
    border-radius: 16px !important;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25) !important;
    width: 100% !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    display: flex !important;
    flex-direction: column !important;
    animation: scaleUpModal 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* ════════════════════════════════════════════════════════════════════════════
   FICHAS OFICIAIS E TABELAS DE PRODUÇÃO NO PAINEL ADMIN / RT
   ════════════════════════════════════════════════════════════════════════════ */
table.report-table {
    width: 100%;
    border-collapse: collapse !important;
    margin-top: 12px;
    background: #ffffff !important;
    color: #1e293b !important;
    border: 1px solid #cbd5e1 !important;
}

table.report-table th,
table.report-table td {
    border: 1px solid #cbd5e1 !important;
    padding: 6px 8px !important;
    color: #1e293b !important;
    font-size: 0.8rem !important;
}

table.report-table th {
    background-color: #f1f5f9 !important;
    font-weight: 700 !important;
    text-align: center !important;
    color: #0f172a !important;
}

table.report-table tbody tr:hover {
    background-color: #f8fafc !important;
}

#print-area-ficha04,
#print-area-ficha08,
#print-area-ficha03,
#print-area-ficha07 {
    background: #ffffff !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px;
    color: #1e293b !important;
}

.ficha03-input::-webkit-outer-spin-button,
.ficha03-input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
}

.ficha03-input {
    -webkit-appearance: none !important;
    -moz-appearance: textfield !important;
    appearance: none !important;
    margin: 0 !important;
    text-align: center !important;
    box-sizing: border-box !important;
}

/* ════════════════════════════════════════════════════════════════════════════
   REGRAS GLOBAIS DE IMPRESSÃO / EXPORTAÇÃO PDF (ADMIN & RT)
   ════════════════════════════════════════════════════════════════════════════ */
@media print {
    .no-print,
    .admin-sidebar,
    .admin-topbar,
    .sidebar,
    .bottom-nav,
    .top-header,
    header,
    nav,
    aside,
    .custom-modal-overlay,
    .toast,
    #autosync-toast,
    .floating-action-btn {
        display: none !important;
        visibility: hidden !important;
    }
}
