/* ============================================
   VARIÁVEIS CSS - TEMA CLARO E ESCURO
   ============================================ */
:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #93c5fd;
    --secondary: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #06b6d4;

    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: #ffffff;

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    --border: #e2e8f0;
    --border-focus: #3b82f6;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;

    --border: #334155;
    --border-focus: #60a5fa;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.5);
}

/* ============================================
   RESET E BASE
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    overflow-x: hidden;
    transition: var(--transition);
    min-height: 100vh;
}

/* ============================================
   PARTICLES BACKGROUND
   ============================================ */
.particles-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--primary-light);
    border-radius: 50%;
    opacity: 0.3;
    animation: floatParticle 15s infinite ease-in-out;
}

@keyframes floatParticle {
    0%, 100% { transform: translateY(0) translateX(0); opacity: 0.3; }
    25% { transform: translateY(-100px) translateX(50px); opacity: 0.6; }
    50% { transform: translateY(-200px) translateX(-30px); opacity: 0.2; }
    75% { transform: translateY(-100px) translateX(-50px); opacity: 0.5; }
}

/* ============================================
   HEADER
   ============================================ */
header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    font-size: 2.5rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

header h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 0.85rem;
    opacity: 0.85;
    font-weight: 300;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.btn-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.1);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: var(--transition);
    backdrop-filter: blur(10px);
}

.btn-icon:hover {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.6);
    transform: scale(1.1);
}

/* ============================================
   TABS NAVIGATION
   ============================================ */
.tabs-nav {
    display: flex;
    gap: 0;
    background: rgba(0,0,0,0.15);
    padding: 0 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.tab-btn {
    padding: 0.9rem 1.5rem;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-main);
}

.tab-btn:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

.tab-btn.active {
    color: white;
    background: rgba(255,255,255,0.15);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: white;
    border-radius: 3px 3px 0 0;
}

/* ============================================
   MAIN
   ============================================ */
main {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1.5rem;
    position: relative;
    z-index: 1;
}

/* ============================================
   PROGRESS BAR
   ============================================ */
.progress-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 10px;
    transition: width 0.5s ease;
}

.progress-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 100px;
    text-align: right;
}

/* ============================================
   TABS CONTENT
   ============================================ */
.tab-content {
    display: none;
    animation: fadeInTab 0.4s ease;
}

.tab-content.active {
    display: block;
}

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

/* ============================================
   FORM SECTIONS
   ============================================ */
.form-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.form-section:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--bg-tertiary);
}

.section-header i {
    font-size: 1.5rem;
    color: var(--primary);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(59,130,246,0.1), rgba(139,92,246,0.1));
    border-radius: var(--radius-md);
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
}

/* ============================================
   FORM GRID
   ============================================ */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
}

.col-span-2 {
    grid-column: span 2;
}

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

.form-group label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================
   INPUT STYLES
   ============================================ */
.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper i {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-size: 0.9rem;
    z-index: 1;
    transition: var(--transition);
}

.input-wrapper input,
.input-wrapper select {
    width: 100%;
    padding: 0.75rem 0.75rem 0.75rem 2.5rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-family: var(--font-main);
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: var(--transition);
    outline: none;
}

.input-wrapper input:focus,
.input-wrapper select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.input-wrapper input:focus + i,
.input-wrapper input:focus ~ i {
    color: var(--primary);
}

.input-wrapper:has(input:focus) i,
.input-wrapper:has(select:focus) i {
    color: var(--primary);
}

.input-wrapper input::placeholder {
    color: var(--text-muted);
}

/* CEP Search Button */
.btn-cep {
    position: absolute;
    right: 4px;
    top: 4px;
    bottom: 4px;
    padding: 0 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.85rem;
}

.btn-cep:hover {
    background: var(--primary-dark);
}

/* ============================================
   CHECKBOX
   ============================================ */
.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.checkbox-wrapper input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* ============================================
   ITEMS TABLE
   ============================================ */
.items-table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.items-table thead {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
}

.items-table th {
    padding: 0.85rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.items-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.items-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.items-table tbody tr {
    transition: var(--transition);
}

.col-item { width: 50px; text-align: center; }
.col-quant { width: 80px; }
.col-valor { width: 120px; }
.col-actions { width: 60px; text-align: center; }

.input-table {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
    font-size: 0.88rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: var(--transition);
}

.input-table:focus {
    border-color: var(--border-focus);
    outline: none;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.input-number {
    text-align: center;
}

.items-table tfoot {
    background: var(--bg-tertiary);
    font-weight: 700;
}

.items-table tfoot td {
    padding: 0.85rem 1rem;
    border: none;
}

.totals-label {
    text-align: right;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.total-value {
    color: var(--primary);
    font-size: 1rem;
}

.btn-remove-item {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(239,68,68,0.1);
    color: var(--danger);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

.btn-remove-item:hover {
    background: var(--danger);
    color: white;
    transform: scale(1.1);
}

/* ============================================
   ADD ITEM BUTTON
   ============================================ */
.btn-add {
    padding: 0.5rem 1rem;
    background: var(--success);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-main);
}

.btn-add:hover {
    background: #059669;
    transform: translateY(-1px);
}

/* ============================================
   LEGAL TEXT
   ============================================ */
.legal-text {
    background: var(--bg-tertiary);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--warning);
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.8;
}

.legal-text p + p {
    margin-top: 0.75rem;
}

/* ============================================
   ACTION BUTTONS
   ============================================ */
.form-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    padding: 2rem 0;
}

.btn {
    padding: 0.85rem 1.75rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-main);
    box-shadow: var(--shadow-sm);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }

.btn-info { background: var(--info); color: white; }
.btn-info:hover { background: #0891b2; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

/* ============================================
   ENDEREÇADOR
   ============================================ */
.enderecador-preview {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.hint-text {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

.enderecador-card {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    background: var(--bg-tertiary);
}

.enderecador-box {
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    margin-bottom: 1rem;
}

.enderecador-box:last-child {
    margin-bottom: 0;
}

.box-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--primary);
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.box-field {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.box-row {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.box-row.three-cols {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
}

.field-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.3px;
}

.enderecador-divider {
    height: 2px;
    background: repeating-linear-gradient(90deg, var(--border) 0, var(--border) 8px, transparent 8px, transparent 16px);
    margin: 1rem 0;
}

/* ============================================
   HISTORY
   ============================================ */
.history-list {
    min-height: 200px;
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

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

.history-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    transition: var(--transition);
    border: 1px solid transparent;
}

.history-item:hover {
    border-color: var(--primary-light);
    transform: translateX(4px);
}

.history-item .history-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.history-item .history-info {
    flex: 1;
}

.history-item .history-info h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.history-item .history-info p {
    font-size: 0.78rem;
    color: var(--text-muted);
}

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

.history-item .history-actions button {
    padding: 0.4rem 0.75rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font-main);
    font-weight: 500;
}

.btn-load {
    background: var(--primary);
    color: white;
}

.btn-load:hover {
    background: var(--primary-dark);
}

.btn-delete-history {
    background: rgba(239,68,68,0.1);
    color: var(--danger);
}

.btn-delete-history:hover {
    background: var(--danger);
    color: white;
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border);
    animation: slideInRight 0.4s ease;
    min-width: 300px;
    max-width: 400px;
}

.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-error { border-left: 4px solid var(--danger); }
.toast.toast-info { border-left: 4px solid var(--info); }
.toast.toast-warning { border-left: 4px solid var(--warning); }

.toast i {
    font-size: 1.2rem;
}

.toast.toast-success i { color: var(--success); }
.toast.toast-error i { color: var(--danger); }
.toast.toast-info i { color: var(--info); }
.toast.toast-warning i { color: var(--warning); }

.toast .toast-message {
    flex: 1;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-primary);
}

.toast .toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.25rem;
    transition: var(--transition);
}

.toast .toast-close:hover {
    color: var(--text-primary);
}

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

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

.toast.removing {
    animation: slideOutRight 0.3s ease forwards;
}

/* ============================================
   FOOTER
   ============================================ */
footer {
    text-align: center;
    padding: 2rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    margin-top: 3rem;
    position: relative;
    z-index: 1;
}

.footer-content p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.footer-info {
    margin-top: 0.25rem;
    font-size: 0.75rem !important;
    opacity: 0.7;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .header-content {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .subtitle {
        display: none;
    }

    .tabs-nav {
        padding: 0 0.5rem;
        overflow-x: auto;
    }

    .tab-btn {
        padding: 0.75rem 1rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    .tab-btn span {
        display: none;
    }

    main {
        padding: 0 0.75rem;
        margin: 1rem auto;
    }

    .form-section {
        padding: 1.25rem;
    }

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

    .col-span-2 {
        grid-column: span 1;
    }

    .form-actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .section-header {
        flex-wrap: wrap;
    }

    .btn-add {
        margin-top: 0.5rem;
        width: 100%;
        justify-content: center;
    }

    .box-row.three-cols {
        grid-template-columns: 1fr;
    }

    .progress-container {
        flex-direction: column;
        gap: 0.5rem;
    }

    .progress-text {
        text-align: center;
    }

    .toast-container {
        top: auto;
        bottom: 20px;
        right: 10px;
        left: 10px;
    }

    .toast {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .logo-icon {
        font-size: 1.75rem;
    }

    .header-actions {
        gap: 0.4rem;
    }

    .btn-icon {
        width: 36px;
        height: 36px;
    }
}
