/* ==========================================================================
   Contratos e Fiscais — Design System Enterprise
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Colors */
    --cf-primary: #1e40af;
    --cf-primary-hover: #1d4ed8;
    --cf-primary-soft: #dbeafe;
    --cf-secondary: #475569;
    --cf-accent: #0ea5e9;

    --cf-bg: #f1f5f9;
    --cf-surface: #ffffff;
    --cf-surface-elevated: #ffffff;
    --cf-border: #e2e8f0;
    --cf-border-strong: #cbd5e1;

    --cf-text: #0f172a;
    --cf-text-muted: #64748b;
    --cf-text-inverse: #f8fafc;

    --cf-success: #059669;
    --cf-success-bg: #d1fae5;
    --cf-warning: #d97706;
    --cf-warning-bg: #fef3c7;
    --cf-danger: #dc2626;
    --cf-danger-bg: #fee2e2;
    --cf-info: #0284c7;
    --cf-info-bg: #e0f2fe;

    /* Typography */
    --cf-font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --cf-text-xs: 0.75rem;
    --cf-text-sm: 0.875rem;
    --cf-text-base: 0.9375rem;
    --cf-text-lg: 1.125rem;
    --cf-text-xl: 1.375rem;
    --cf-text-2xl: 1.75rem;

    /* Spacing */
    --cf-space-1: 0.25rem;
    --cf-space-2: 0.5rem;
    --cf-space-3: 0.75rem;
    --cf-space-4: 1rem;
    --cf-space-5: 1.25rem;
    --cf-space-6: 1.5rem;
    --cf-space-8: 2rem;

    /* Radius */
    --cf-radius-sm: 6px;
    --cf-radius: 10px;
    --cf-radius-lg: 14px;
    --cf-radius-xl: 18px;

    /* Shadows */
    --cf-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --cf-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
    --cf-shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

    /* Layout */
    --cf-nav-height: 64px;
    --cf-content-max: 1440px;
    --cf-transition: 0.18s ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--cf-font);
    font-size: var(--cf-text-base);
    color: var(--cf-text);
    background: var(--cf-bg);
    line-height: 1.5;
    margin: 0;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* App shell */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    width: 100%;
    max-width: var(--cf-content-max);
    margin: 0 auto;
    padding: var(--cf-space-6) var(--cf-space-5) var(--cf-space-8);
}

.app-main--wide {
    max-width: 96%;
}

/* Page header */
.page-header {
    margin-bottom: var(--cf-space-6);
}

.page-header h1,
.page-title {
    font-size: var(--cf-text-2xl);
    font-weight: 700;
    color: var(--cf-text);
    margin: 0 0 var(--cf-space-2);
    letter-spacing: -0.02em;
}

.page-subtitle {
    color: var(--cf-text-muted);
    margin: 0;
    font-size: var(--cf-text-sm);
}

/* Navbar */
.cf-navbar {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: var(--cf-shadow);
    min-height: var(--cf-nav-height);
    padding: 0 var(--cf-space-4);
}

.cf-navbar .navbar-brand img {
    height: 38px;
    width: auto;
    filter: brightness(1.05);
}

.cf-navbar .nav-link {
    color: rgba(248, 250, 252, 0.85) !important;
    font-weight: 500;
    font-size: var(--cf-text-sm);
    padding: var(--cf-space-2) var(--cf-space-4) !important;
    border-radius: var(--cf-radius-sm);
    transition: background var(--cf-transition), color var(--cf-transition);
}

.cf-navbar .nav-link:hover,
.cf-navbar .nav-link:focus {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.1);
}

.cf-navbar .nav-link.active {
    color: #fff !important;
    background: var(--cf-primary);
}

.cf-navbar .btn-logout {
    background: var(--cf-danger) !important;
    color: #fff !important;
    font-weight: 600;
    border-radius: var(--cf-radius-sm);
    padding: var(--cf-space-2) var(--cf-space-5) !important;
    margin-left: var(--cf-space-2);
}

.cf-navbar .btn-logout:hover {
    background: #b91c1c !important;
    color: #fff !important;
}

/* Cards */
.cf-card {
    background: var(--cf-surface);
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius-lg);
    box-shadow: var(--cf-shadow-sm);
    overflow: hidden;
}

.cf-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--cf-space-4);
    padding: var(--cf-space-4) var(--cf-space-5);
    border-bottom: 1px solid var(--cf-border);
    background: linear-gradient(180deg, #fafbfc 0%, #f8fafc 100%);
}

.cf-card-header h2,
.cf-card-header h3 {
    margin: 0;
    font-size: var(--cf-text-lg);
    font-weight: 700;
    color: var(--cf-text);
}

.cf-card-body {
    padding: var(--cf-space-5);
}

/* Filter panel */
.filter-panel {
    background: var(--cf-surface);
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius-lg);
    padding: var(--cf-space-5);
    margin-bottom: var(--cf-space-6);
    box-shadow: var(--cf-shadow-sm);
}

.filter-panel .form-label {
    font-size: var(--cf-text-sm);
    font-weight: 600;
    color: var(--cf-secondary);
    margin-bottom: var(--cf-space-2);
}

/* Expiring contracts panel */
.expiring-panel {
    border: 0;
    border-radius: var(--cf-radius-lg);
    overflow: hidden;
    background: var(--cf-surface);
    box-shadow: var(--cf-shadow);
    margin-bottom: var(--cf-space-6);
}

.expiring-panel .panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--cf-space-3);
    padding: var(--cf-space-4) var(--cf-space-5);
    background: linear-gradient(135deg, #fffbeb, #fef3c7);
    border-bottom: 1px solid #fde68a;
}

.expiring-panel .panel-heading h2 {
    margin: 0;
    font-size: var(--cf-text-lg);
    font-weight: 700;
    color: #92400e;
}

.expiring-panel thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #fffbeb;
    color: #78350f;
    font-weight: 600;
    font-size: var(--cf-text-sm);
    white-space: nowrap;
    border-bottom: 1px solid #fde68a;
}

.expiring-panel .urgent-row {
    background-color: #fef2f2 !important;
}

.expiring-panel .empty-state {
    padding: var(--cf-space-8);
    text-align: center;
    color: var(--cf-text-muted);
}

/* Process list card */
.processos-card .card-header,
.processos-card .cf-card-header {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border-bottom: 1px solid #bfdbfe;
}

.processos-card .cf-card-header h2 {
    color: #1e3a8a;
}

/* Tables — enterprise */
.cf-table-wrap {
    overflow-x: auto;
    border-radius: 0 0 var(--cf-radius-lg) var(--cf-radius-lg);
}

.table.cf-table,
#tabelaProcessos,
.expiring-panel .table {
    margin-bottom: 0;
    font-size: var(--cf-text-sm);
}

.table.cf-table thead th,
#tabelaProcessos thead th {
    background: #f8fafc;
    color: #334155;
    font-weight: 700;
    font-size: var(--cf-text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    border-bottom: 2px solid var(--cf-border);
    padding: var(--cf-space-3) var(--cf-space-4);
    position: sticky;
    top: 0;
    z-index: 2;
}

.table.cf-table tbody td,
#tabelaProcessos tbody td {
    padding: var(--cf-space-3) var(--cf-space-4);
    vertical-align: middle;
    border-color: var(--cf-border);
}

.table.cf-table tbody tr:nth-child(even),
#tabelaProcessos tbody tr:nth-child(even) {
    background-color: #fafbfc;
}

.table.cf-table tbody tr:hover,
#tabelaProcessos tbody tr:hover {
    background-color: #eff6ff;
    transition: background var(--cf-transition);
}

/* Column widths (dashboard) */
#tabelaProcessos th:nth-child(3),
#tabelaProcessos td:nth-child(3) {
    min-width: 140px;
}

#tabelaProcessos th:nth-child(6),
#tabelaProcessos td:nth-child(6),
#tabelaProcessos th:nth-child(9),
#tabelaProcessos td:nth-child(9),
#tabelaProcessos th:nth-child(10),
#tabelaProcessos td:nth-child(10) {
    min-width: 110px;
    text-align: center;
}

/* DataTables overrides */
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius-sm);
    padding: var(--cf-space-2) var(--cf-space-3);
    font-size: var(--cf-text-sm);
}

.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius-sm);
    padding: var(--cf-space-1) var(--cf-space-2);
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--cf-primary) !important;
    border-color: var(--cf-primary) !important;
    color: #fff !important;
    border-radius: var(--cf-radius-sm) !important;
}

.dt-buttons .btn,
.dt-button {
    border-radius: var(--cf-radius-sm) !important;
    font-size: var(--cf-text-sm) !important;
    font-weight: 600 !important;
}

/* Badges */
.badge.cf-badge {
    font-weight: 600;
    padding: 0.35em 0.65em;
    border-radius: var(--cf-radius-sm);
}

/* Forms */
.form-section {
    background: var(--cf-surface);
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius-lg);
    padding: var(--cf-space-6);
    margin-bottom: var(--cf-space-6);
    box-shadow: var(--cf-shadow-sm);
}

.form-section-title {
    font-size: var(--cf-text-lg);
    font-weight: 700;
    color: var(--cf-primary);
    margin: 0 0 var(--cf-space-5);
    padding-bottom: var(--cf-space-3);
    border-bottom: 2px solid var(--cf-primary-soft);
    display: flex;
    align-items: center;
    gap: var(--cf-space-2);
}

.form-control,
.form-select {
    border-color: var(--cf-border-strong);
    border-radius: var(--cf-radius-sm);
    font-size: var(--cf-text-sm);
    transition: border-color var(--cf-transition), box-shadow var(--cf-transition);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--cf-primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

.form-label {
    font-weight: 600;
    font-size: var(--cf-text-sm);
    color: var(--cf-secondary);
}

/* Detail view */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--cf-space-4) var(--cf-space-6);
}

.detail-item {
    padding: var(--cf-space-3) 0;
    border-bottom: 1px solid var(--cf-border);
}

.detail-item strong {
    display: block;
    font-size: var(--cf-text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--cf-text-muted);
    font-weight: 600;
    margin-bottom: var(--cf-space-1);
}

.detail-item span {
    font-size: var(--cf-text-base);
    color: var(--cf-text);
    word-break: break-word;
}

.detail-docs {
    margin-top: var(--cf-space-6);
    padding-top: var(--cf-space-5);
    border-top: 1px solid var(--cf-border);
}

/* Settings hub */
.settings-hub {
    display: grid;
    gap: var(--cf-space-4);
    max-width: 480px;
    margin: 0 auto var(--cf-space-6);
}

.settings-hub .btn {
    padding: var(--cf-space-4);
    font-weight: 600;
    border-radius: var(--cf-radius);
}

/* Param cards */
.param-card {
    border-radius: var(--cf-radius-lg) !important;
    border: 1px solid var(--cf-border) !important;
}

/* Buttons */
.btn-primary {
    background: var(--cf-primary);
    border-color: var(--cf-primary);
    font-weight: 600;
    border-radius: var(--cf-radius-sm);
}

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

.btn-outline-primary {
    color: var(--cf-primary);
    border-color: var(--cf-primary);
    font-weight: 600;
    border-radius: var(--cf-radius-sm);
}

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

/* Alerts container */
.app-alerts {
    max-width: var(--cf-content-max);
    margin: 0 auto;
    padding: var(--cf-space-3) var(--cf-space-5) 0;
}

.app-alerts .alert {
    border: none;
    border-radius: var(--cf-radius);
    font-size: var(--cf-text-sm);
    box-shadow: var(--cf-shadow-sm);
}

/* Toggle / utility */
.cf-toggle-btn {
    border-radius: var(--cf-radius);
    font-weight: 500;
    font-size: var(--cf-text-sm);
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #1e40af 100%);
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('img/contratos_e_fiscais.png') center/cover no-repeat;
    opacity: 0.12;
    filter: blur(2px);
}

.login-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--cf-radius-xl);
    padding: var(--cf-space-8);
    box-shadow: var(--cf-shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.login-card h1 {
    font-size: var(--cf-text-xl);
    font-weight: 700;
    text-align: center;
    color: var(--cf-text);
    margin-bottom: var(--cf-space-6);
}

.login-card .form-label {
    color: var(--cf-secondary);
}

.login-brand {
    text-align: center;
    margin-bottom: var(--cf-space-5);
    color: var(--cf-text-muted);
    font-size: var(--cf-text-sm);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Select2 */
.select2-container--default .select2-selection--single {
    border-color: var(--cf-border-strong);
    border-radius: var(--cf-radius-sm);
    min-height: 38px;
    padding: 4px 8px;
}

.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: var(--cf-primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

/* Action bar */
.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--cf-space-3);
    margin-top: var(--cf-space-5);
}

/* Responsive */
@media (max-width: 768px) {
    .app-main {
        padding: var(--cf-space-4) var(--cf-space-3);
    }

    .page-header h1,
    .page-title {
        font-size: var(--cf-text-xl);
    }

    .cf-card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}
