:root {
    /* Paleta moderna */
    --primary-color: #0f172a; /* slate-900 */
    --secondary-color: #2563eb; /* blue-600 */
    --secondary-color-hover: #1d4ed8; /* blue-700 */
    --accent-color: #14b8a6; /* teal-500 */
    --background-color: #f5f7fb; /* subtle off-white */
    --surface-color: #ffffff;
    --muted-surface: #f8fafc; /* slate-50 */
    --danger-color: #ef4444; /* red-500 */
    --success-color: #10b981; /* emerald-500 */
    --warning-color: #f59e0b; /* amber-500 */
    --text-color: #111827; /* gray-900 */
    --text-muted: #6b7280; /* gray-500 */
    --border-color: #e5e7eb; /* gray-200 */
    --shadow: 0 8px 24px rgba(2, 6, 23, 0.08);
    --shadow-soft: 0 4px 12px rgba(2, 6, 23, 0.06);
    --border-radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --transition: all 0.25s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: radial-gradient(1200px 600px at 10% -10%, #e5edff 0%, transparent 40%),
                radial-gradient(1000px 500px at 110% 10%, #d9f7f1 0%, transparent 35%),
                var(--background-color);
    color: var(--text-color);
    line-height: 1.65;
    padding-bottom: 80px;
}

header {
    background: linear-gradient(135deg, var(--primary-color), #0b1223);
    color: white;
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
}

.site-logo {
    height: 36px;
    width: auto;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

header .site-logo + h1 {
    display: inline-block;
    vertical-align: middle;
}

/* Aviso Discreto */
.discrete-notice {
    background: rgba(52, 152, 219, 0.1);
    border: 1px solid rgba(52, 152, 219, 0.3);
    border-radius: var(--border-radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--primary-color);
    opacity: 0.8;
    transition: var(--transition);
}

.discrete-notice:hover {
    opacity: 1;
    background: rgba(52, 152, 219, 0.15);
}

.discrete-notice i {
    color: var(--secondary-color);
    font-size: 1rem;
    flex-shrink: 0;
}

.discrete-notice span {
    line-height: 1.4;
}

main {
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.container {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 1.75rem;
    box-shadow: var(--shadow-soft);
    margin-bottom: 1rem;
}

.section {
    display: none;
}

.section.active {
    display: block;
}

h2 {
    color: var(--primary-color);
    margin-bottom: 1.25rem;
    font-size: 1.4rem;
    font-weight: 600;
}
/* Espaçamento consistente entre blocos internos */
.container > * + * {
    margin-top: 1rem;
}

/* Seção de Fontes */
.sources-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.source-section {
    background: #f8f9fa;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--secondary-color);
    width: 100%;
}

.source-section h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.source-section h4 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.source-section ul {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.source-section li {
    margin-bottom: 0.5rem;
}

.legal-notice {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-top: 1rem;
}

.legal-notice p {
    color: #856404;
    margin-bottom: 0.5rem;
}

.legal-notice ul {
    margin-left: 1.5rem;
    color: #856404;
}

.useful-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.useful-links a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--secondary-color);
    text-decoration: none;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.useful-links a:hover {
    background: rgba(52, 152, 219, 0.1);
    transform: translateX(5px);
}

.howto-steps {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 768px) {
    .howto-steps {
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
    }
    .source-section { width: 100%; max-width: 100%; flex: 1 1 100%; }
}

.cta-row {
    display: flex;
    justify-content: center;
    margin-top: 0.5rem;
}

.metadata-info {
    background: white;
    padding: 1rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.metadata-info p {
    margin-bottom: 0.5rem;
}

.status-ok {
    color: var(--success-color);
    font-weight: 600;
}

.status-warning {
    color: var(--warning-color);
    font-weight: 600;
}

.calculation-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    color: var(--primary-color);
}

.form-group input,
.form-group select {
    padding: 0.85rem 0.9rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--surface-color);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.btn-primary,
.btn-secondary,
.btn-danger {
    padding: 0.8rem 1.2rem;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 0.98rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
}
@media (max-width: 480px) {
    .btn-primary,
    .btn-secondary,
    .btn-danger {
        width: 100%;
    }
}

.btn-primary {
    background: linear-gradient(180deg, var(--secondary-color), var(--secondary-color-hover));
    color: white;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(37, 99, 235, 0.28);
}

.btn-secondary {
    background: linear-gradient(180deg, var(--success-color), #0ca678);
    color: white;
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.25);
}

.btn-secondary:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(16, 185, 129, 0.28);
}

.btn-danger {
    background: linear-gradient(180deg, var(--danger-color), #dc2626);
    color: white;
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.25);
}

.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(239, 68, 68, 0.28);
}

.result-container {
    margin-top: 2rem;
    padding: 1.25rem 1.5rem;
    background: var(--muted-surface);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-soft);
}

.result-container h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e9ecef;
}

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

.result-item .label {
    font-weight: 500;
    color: var(--text-muted);
}

.result-item .value {
    font-weight: 700;
    color: var(--secondary-color);
    background: rgba(52, 152, 219, 0.08);
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
}

.result-item.highlight {
    background: rgba(37, 99, 235, 0.08);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin: 0.5rem 0;
}

.result-item.total {
    background: rgba(16, 185, 129, 0.1);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin: 0.5rem 0;
    font-size: 1.1rem;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.history-controls {
    margin-bottom: 1rem;
    text-align: right;
}

.history-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.history-item {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--secondary-color);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.history-item-date {
    font-size: 0.9rem;
    color: #6c757d;
}

.history-item-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    font-size: 0.9rem;
}
.history-item-details div {
    background: #ffffff;
    border: 1px solid #eef2f4;
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
}

.history-item-actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
}

.history-item-actions button {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6c757d;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.map-container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    background: white;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.map-info {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: var(--border-radius);
}

.selected-states {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.state-selection {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.state-selection strong {
    color: var(--primary-color);
    min-width: 80px;
}

.faq-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.faq-item {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.faq-question {
    width: 100%;
    padding: 1rem;
    background: white;
    border: none;
    text-align: left;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
    color: var(--primary-color);
}

.faq-question:hover {
    background: #f8f9fa;
}

.faq-question[aria-expanded="true"] {
    background: var(--secondary-color);
    color: white;
}

.faq-question[aria-expanded="true"] .faq-icon {
    transform: rotate(45deg);
}

.faq-icon {
    font-size: 1.2rem;
    transition: var(--transition);
}

.faq-answer {
    padding: 1rem;
    background: #f8f9fa;
    border-top: 1px solid var(--border-color);
    animation: fadeIn 0.3s ease;
}

.faq-answer[hidden] {
    display: none;
}

/* Configurações */
.settings-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.file-input-label {
    cursor: pointer;
}

.settings-meta {
    margin-bottom: 1rem;
    color: #6c757d;
    font-size: 0.9rem;
}

.settings-table-wrapper {
    overflow-x: auto;
}

.settings-table {
    width: 100%;
    border-collapse: collapse;
}

.settings-table th,
.settings-table td {
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    text-align: left;
}
.settings-table td:first-child,
.settings-table th:first-child {
    position: sticky;
    left: 0;
    background: #ffffff;
    z-index: 2;
}

.settings-table thead th {
    background: #f8f9fa;
    position: sticky;
    top: 0;
    z-index: 1;
}
.settings-table tbody tr:nth-child(odd) {
    background: #fcfdff;
}
.settings-table tbody tr:hover {
    background: #f2f6fb;
}

.settings-table input[type="number"] {
    width: 110px;
    padding: 0.5rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.95rem;
}

.settings-table input[type="number"]:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bottom-nav {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: saturate(180%) blur(10px);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 0.6rem 0.6rem;
    box-shadow: var(--shadow);
    z-index: 1000;
    border-radius: 14px;
    gap: 0.25rem;
    width: calc(100% - 2rem);
    max-width: 680px;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #475569;
    transition: var(--transition);
    padding: 0.5rem 0.75rem;
    border-radius: 10px;
    min-width: 60px;
}

.nav-item:hover,
.nav-item.active {
    color: var(--secondary-color);
    background: rgba(37, 99, 235, 0.12);
}
.nav-item.active::after {
    content: "";
    display: block;
    width: 24px;
    height: 3px;
    background: var(--secondary-color);
    border-radius: 2px;
}

.nav-item i {
    font-size: 1.2rem;
    margin-bottom: 0.25rem;
}

.nav-item span {
    font-size: 0.7rem;
    font-weight: 500;
}

footer {
    text-align: center;
    padding: 2rem 1rem;
    color: #6c757d;
    font-size: 0.9rem;
    background: white;
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.footer-content {
    max-width: 600px;
    margin: 0 auto;
}

.footer-content a.footer-link,
footer a.footer-link {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted transparent;
    transition: var(--transition);
}

.footer-content a.footer-link:hover,
footer a.footer-link:hover {
    border-bottom-color: currentColor;
}

/* Remover aparência de link de todos os links do footer (FAQ/Privacidade/Termos) */
footer a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted transparent;
    transition: var(--transition);
}

footer a:hover {
    border-bottom-color: currentColor;
}

.footer-note {
    color: #6c757d;
    font-size: 0.8rem;
    margin-top: 0.5rem;
    opacity: 0.7;
}

.brazil-map {
    width: 100%;
    height: auto;
    display: block;
}

.state-path {
    fill: #ecf0f1;
    stroke: #bdc3c7;
    stroke-width: 1;
    cursor: pointer;
    transition: var(--transition);
}

.state-path:hover {
    fill: #d5dbdb;
}

.state-path.origin {
    fill: var(--secondary-color);
}

.state-path.destination {
    fill: var(--success-color);
}

.state-path.both {
    fill: var(--danger-color);
}

/* Comparação de Estados */
.state-comparison-form {
    margin-bottom: 2rem;
}

.state-selectors {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.state-selector {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.state-selector label {
    font-weight: 500;
    color: var(--primary-color);
}

.state-selector select {
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
    background: white;
}

.state-selector select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.comparison-container {
    margin-top: 2rem;
    padding: 1.5rem;
    background: #f8f9fa;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--secondary-color);
}

.comparison-container h3 {
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    text-align: center;
}

.comparison-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 2rem;
    align-items: center;
    margin-bottom: 2rem;
}

.comparison-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 2px solid transparent;
    transition: var(--transition);
}
.comparison-card .rates-list .rate-value {
    background: rgba(52, 152, 219, 0.08);
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
}

.comparison-card.origin {
    border-color: var(--secondary-color);
}

.comparison-card.destination {
    border-color: var(--success-color);
}

.card-header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-header h4 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}

.state-code {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
}

.comparison-vs {
    display: flex;
    justify-content: center;
    align-items: center;
}

.vs-circle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--secondary-color), var(--success-color));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    box-shadow: var(--shadow);
}

.rates-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.rate-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.rate-item:hover {
    background: #e9ecef;
}

.rate-label {
    font-weight: 500;
    color: var(--primary-color);
    font-size: 0.9rem;
}

.rate-value {
    font-weight: 600;
    color: var(--secondary-color);
    font-size: 1.1rem;
}

.differential-analysis {
    background: white;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.differential-analysis h4 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    text-align: center;
}

.differential-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.differential-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--warning-color);
}
.differential-item .diff-value {
    background: #ffffff;
    border: 1px solid #eef2f4;
    border-radius: 6px;
    padding: 0.15rem 0.5rem;
}

.diff-label {
    font-weight: 500;
    color: var(--primary-color);
    font-size: 0.9rem;
}

.diff-value {
    font-weight: 600;
    font-size: 1rem;
}

.diff-value.positive {
    color: var(--success-color);
}

.diff-value.negative {
    color: var(--danger-color);
}

.diff-value.neutral {
    color: var(--text-color);
}

.comparison-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.comparison-actions button {
    min-width: 180px;
}

@media (min-width: 768px) {
    header h1 {
        font-size: 2rem;
    }
    
    h2 {
        font-size: 1.6rem;
    }
    
    .calculation-form {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
        align-items: end;
    }
    
    .calculation-form .btn-primary {
        grid-column: 1 / -1;
        justify-self: center;
        max-width: 300px;
    }
    
    .action-buttons {
        justify-content: center;
    }
    
    .history-item-details {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .selected-states {
        flex-direction: row;
        justify-content: space-around;
    }
    
    .sources-container {
        display: flex;
        flex-wrap: wrap;
        gap: 1.5rem;
    }
    .source-section {
        flex: 1 1 48%;
    }
    
    .source-section:nth-child(3) {
        grid-column: 1 / -1;
    }
    
    .bottom-nav {
        position: relative;
        background: var(--primary-color);
        border-top: none;
        box-shadow: var(--shadow);
        border-radius: var(--border-radius);
        margin: 2rem auto 0;
        max-width: 600px;
    }
    
    .nav-item {
        color: white;
    }
    
    .nav-item:hover,
    .nav-item.active {
        color: var(--secondary-color);
        background: rgba(255, 255, 255, 0.1);
    }
    
    body {
        padding-bottom: 0;
    }
}

@media (min-width: 1024px) {
    main {
        padding: 2rem;
    }
    
    .container {
        padding: 2rem;
    }
    
    /* HOME: Resultado sempre abaixo do formulário */
    #home .container {
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
        align-items: stretch;
    }
    #icms-form { width: 100%; }
    #calculation-result {
        width: 100%;
        margin-top: 0;
        position: static;
    }
    
    .calculation-form {
        grid-template-columns: repeat(3, 1fr);
    }
    .action-buttons { justify-content: flex-end; }
    
    .map-container {
        max-width: 800px;
    }
    
    .source-section {
        flex: 1 1 100%;
        max-width: 100%;
        width: 100%;
    }

    /* HISTORY: Lista em duas colunas quando houver espaço */
    #history .history-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
}

/* Tablets grandes: manter resultado abaixo do formulário */
@media (min-width: 768px) and (max-width: 1023px) {
    #home .container {
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
        align-items: stretch;
    }
    #icms-form { width: 100%; }
    #calculation-result { width: 100%; margin-top: 0; position: static; }
}

/* Bottom-nav: comportamento responsivo */
@media (max-width: 767px) {
    body { padding-bottom: 96px; }
    .bottom-nav {
        bottom: 0;
        left: 0;
        transform: none;
        width: 100%;
        border-radius: 0;
        max-width: none;
    }
}

@media (min-width: 1024px) {
    .bottom-nav {
        position: static;
        transform: none;
        width: auto;
        max-width: 820px;
        margin: 2rem auto 0;
    }
}

@media (max-width: 768px) {
    .state-selectors {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .comparison-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .comparison-vs {
        order: -1;
    }
    
    .vs-circle {
        width: 50px;
        height: 50px;
        font-size: 1rem;
    }
    
    .differential-grid {
        grid-template-columns: 1fr;
    }
    
    .comparison-actions {
        flex-direction: column;
        align-items: center;
    }
    
    .comparison-actions button {
        width: 100%;
        max-width: 300px;
    }
}
