* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-light: #64748b;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1700px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 2rem 0;
    margin-bottom: 2rem;
}

header > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

header h1 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5rem;
    letter-spacing: -0.025em;
}

header p {
    color: var(--text-light);
    font-size: 0.9375rem;
}

.dashboard {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

section {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

section h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1.5rem;
    letter-spacing: -0.01em;
}

/* Estatísticas */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    overflow: visible;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.25rem;
    transition: all 0.2s ease;
    min-width: fit-content;
    overflow: visible; /* Permite que valores grandes sejam visíveis */
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.stat-label {
    font-size: clamp(0.65rem, 0.5vw + 0.5rem, 0.8125rem);
    color: var(--text-light);
    margin-bottom: 0.5rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1.3;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.stat-value {
    font-size: clamp(0.875rem, 1.5vw + 0.5rem, 1.75rem);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.025em;
    line-height: 1.2;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: none;
}

/* Filtros */
.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    padding: 0;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-group input,
.filter-group select {
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    background: var(--surface);
    color: var(--text);
    transition: all 0.2s ease;
    font-family: inherit;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-group input::placeholder {
    color: var(--text-light);
}

.filter-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg);
    border-color: var(--text-light);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Tabela */
.table-section {
    overflow: hidden;
}

.table-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.table-controls span {
    font-size: 0.875rem;
    color: var(--text-light);
    font-weight: 500;
}

.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    font-size: 0.9375rem;
}

thead {
    background: var(--bg);
    border-bottom: 2px solid var(--border);
}

th {
    padding: 0.875rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    user-select: none;
}

th.sortable {
    position: relative;
    transition: color 0.2s ease, background-color 0.2s ease;
}

th.sortable:hover {
    background-color: var(--bg);
    color: var(--primary);
}

.sort-indicator {
    display: inline-block;
    margin-left: 0.25rem;
    font-size: 0.75rem;
    transition: opacity 0.2s ease;
    color: var(--primary);
}

td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

tbody tr {
    transition: background 0.15s ease;
}

tbody tr:hover {
    background: var(--bg);
}

tbody tr:last-child td {
    border-bottom: none;
}

.loading {
    text-align: center;
    padding: 3rem !important;
    color: var(--text-light);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-sat {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.badge-nfce {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

.badge-autorizada {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.badge-cancelada {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.badge-inutilizada {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.btn-view {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-view:hover {
    background: var(--primary);
    color: white;
}

.btn-download {
    background: transparent;
    color: var(--success);
    border: 1px solid var(--success);
    padding: 0.375rem 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-download:hover {
    background: var(--success);
    color: white;
}

.btn-download svg {
    width: 16px;
    height: 16px;
}

/* Paginação */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.pagination button {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
}

.pagination button:hover:not(:disabled) {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination .active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    overflow: auto;
}

.modal-content {
    background: var(--surface);
    margin: 2rem auto;
    padding: 2rem;
    border-radius: 0.75rem;
    max-width: 1000px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.close {
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
}

.close:hover {
    color: var(--text);
    background: var(--bg);
}

#notaDetalhes {
    margin-top: 1rem;
}

.modal-header-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.modal-header-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-header-actions .btn svg {
    width: 16px;
    height: 16px;
}

.detalhe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.detalhe-item {
    padding: 1.25rem;
    background: var(--bg);
    border-radius: 0.5rem;
    border: 1px solid var(--border);
}

.detalhe-item-full {
    grid-column: 1 / -1;
}

.detalhe-item h3 {
    color: var(--text);
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border);
}

.detalhe-content {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.detalhe-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 1rem;
    align-items: start;
}

.detalhe-label {
    font-size: 0.875rem;
    color: var(--text-light);
    font-weight: 500;
}

.detalhe-value {
    font-size: 0.9375rem;
    color: var(--text);
    word-break: break-word;
}

.table-container {
    overflow-x: auto;
    margin-top: 0.75rem;
}

.detalhe-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
    font-size: 0.875rem;
}

.detalhe-table thead {
    background: var(--bg);
}

.detalhe-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.detalhe-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.detalhe-table tbody tr:hover {
    background: var(--bg);
}

.detalhe-table tbody tr:last-child td {
    border-bottom: none;
}

/* Responsivo */
@media (max-width: 1400px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }

    .stat-value {
        font-size: clamp(0.8rem, 1.8vw + 0.3rem, 1.5rem);
    }
}

@media (max-width: 992px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .stat-value {
        font-size: clamp(0.75rem, 2vw + 0.2rem, 1.3rem);
    }

    .stat-label {
        font-size: clamp(0.6rem, 0.7vw + 0.4rem, 0.75rem);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header {
        padding: 1.5rem 0;
    }

    header h1 {
        font-size: 1.5rem;
    }

    section {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-card {
        padding: 0.875rem;
    }

    .stat-label {
        font-size: clamp(0.6rem, 1vw + 0.3rem, 0.72rem);
        margin-bottom: 0.375rem;
    }

    .stat-value {
        font-size: clamp(0.7rem, 2.5vw + 0.2rem, 1.1rem);
    }

    .filters-grid {
        grid-template-columns: 1fr;
    }

    .table-wrapper {
        font-size: 0.875rem;
    }

    th, td {
        padding: 0.625rem 0.75rem;
    }
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.625rem;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-label {
        font-size: clamp(0.55rem, 1.2vw + 0.25rem, 0.68rem);
        margin-bottom: 0.3rem;
    }

    .stat-value {
        font-size: clamp(0.65rem, 3vw + 0.15rem, 1rem);
        line-height: 1.15;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.75rem;
    }

    header {
        padding: 1rem 0;
    }

    header > div {
        flex-direction: column;
        align-items: flex-start;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.625rem;
    }

    .stat-card {
        padding: 0.875rem;
    }

    .stat-label {
        font-size: clamp(0.6rem, 1.5vw + 0.3rem, 0.72rem);
        margin-bottom: 0.375rem;
    }

    .stat-value {
        font-size: clamp(0.75rem, 3.5vw + 0.2rem, 1.2rem);
        line-height: 1.2;
    }
}

@media (max-width: 360px) {
    .stats-grid {
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.625rem;
    }

    .stat-label {
        font-size: clamp(0.55rem, 2vw + 0.2rem, 0.65rem);
        margin-bottom: 0.25rem;
    }

    .stat-value {
        font-size: clamp(0.7rem, 4vw + 0.15rem, 1.1rem);
        line-height: 1.15;
    }
}
