/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;
    
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    --border: #e2e8f0;
    --shadow: 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);
    
    /* Spacing */
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-height: 70px;
    --header-height: 120px;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
    overflow-x: hidden;
}

/* ===== HEADER ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
    box-shadow: var(--shadow);
}

.header h1 {
    color: white;
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 12px;
}

.list-selector {
    display: flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.15);
    padding: 4px;
    border-radius: 12px;
}

.list-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.list-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow);
}

/* ===== MAIN CONTENT ===== */
.main-content {
    padding: 16px;
    padding-bottom: 24px;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== STORES SECTION ===== */
.stores-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.stores-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-add-store {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-add-store:active {
    transform: scale(0.95);
    background: var(--primary-dark);
}

.stores-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    min-height: 40px;
}

.store-tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow);
}

.store-tag .delete-store {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--danger-light);
    color: var(--danger);
    border: none;
    border-radius: 50%;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.store-tag .delete-store:active {
    background: var(--danger);
    color: white;
}

/* ===== ITEMS TABLE ===== */
.items-table-container {
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.items-table th,
.items-table td {
    padding: 12px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.items-table th {
    background: var(--bg-input);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
}

.item-col {
    min-width: 120px;
}

.qty-col {
    width: 45px;
    text-align: center !important;
}

.price-col {
    min-width: 90px;
}

.items-table tbody tr:nth-child(even) {
    background: var(--bg-input);
}

.items-table tbody tr:last-child td {
    border-bottom: none;
}

.item-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.8rem;
    line-height: 1.3;
}

.item-qty {
    text-align: center;
    font-weight: 600;
    color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    border-radius: 6px;
    padding: 4px 8px;
}

.price-input-wrapper {
    position: relative;
}

.price-input {
    width: 100%;
    padding: 8px;
    padding-left: 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    background: var(--bg-input);
    transition: all 0.2s ease;
    -webkit-appearance: none;
    -moz-appearance: textfield;
}

.price-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.price-input-wrapper::before {
    content: 'R$';
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.75rem;
    pointer-events: none;
}

.subtotal-cell {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 4px;
}

.best-price {
    background: var(--success-light) !important;
}

.best-price .price-input {
    border-color: var(--success);
    background: white;
}

/* Table Footer */
.items-table tfoot {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.items-table tfoot td {
    padding: 16px 8px;
    border: none;
    color: white;
    font-weight: 700;
}

.total-label {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.total-value {
    font-size: 1rem;
    text-align: center;
}

/* ===== COMPARISON TAB ===== */
.comparison-section {
    margin-bottom: 24px;
}

.comparison-section h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.best-budget-card {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
    border-radius: 16px;
    padding: 20px;
    color: white;
    box-shadow: var(--shadow-lg);
}

.best-budget-card .store-name {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.best-budget-card .total-value {
    font-size: 2rem;
    font-weight: 800;
}

.best-budget-card .savings {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-top: 8px;
}

.budget-ranking {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.ranking-position {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.9rem;
}

.ranking-position.first {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: white;
}

.ranking-position.second {
    background: var(--bg-input);
    color: var(--text-secondary);
}

.ranking-position.third {
    background: var(--bg-input);
    color: var(--text-muted);
}

.ranking-info {
    flex: 1;
}

.ranking-info .store-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.ranking-info .filled-items {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.ranking-total {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
}

/* ===== BEST BUY TAB ===== */
.best-buy-section h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.section-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.best-items-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.best-item-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--success);
}

.best-item-card .item-info {
    flex: 1;
}

.best-item-card .item-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.best-item-card .store-name {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.best-item-card .item-price {
    font-weight: 700;
    font-size: 1rem;
    color: var(--success);
}

.best-item-card .item-qty-badge {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.optimized-total {
    margin-top: 20px;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: 16px;
    color: white;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.optimized-total .label {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-bottom: 4px;
}

.optimized-total .value {
    font-size: 2rem;
    font-weight: 800;
}

.optimized-total .savings {
    font-size: 0.9rem;
    margin-top: 8px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    display: inline-block;
}

/* ===== BOTTOM NAVIGATION ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    padding-bottom: var(--safe-bottom);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    z-index: 1000;
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 12px;
}

.nav-btn.active {
    color: var(--primary);
}

.nav-btn:active {
    transform: scale(0.95);
}

.nav-icon {
    font-size: 1.5rem;
}

.nav-label {
    font-size: 0.7rem;
    font-weight: 600;
}

/* ===== MODAL ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 24px;
    width: 100%;
    max-width: 340px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-content h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    text-align: center;
}

.modal-content input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    margin-bottom: 20px;
    transition: all 0.2s ease;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.modal-actions {
    display: flex;
    gap: 12px;
}

.btn-secondary, .btn-primary {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:active, .btn-secondary:active {
    transform: scale(0.97);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ===== RESPONSIVE - TABLETS & DESKTOP ===== */
@media (min-width: 768px) {
    :root {
        --nav-height: 0px;
    }
    
    body {
        padding-bottom: 0;
    }
    
    .header {
        padding: 24px;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .list-selector {
        max-width: 300px;
        margin: 0 auto;
    }
    
    .main-content {
        max-width: 1200px;
        margin: 0 auto;
        padding: 24px;
    }
    
    .bottom-nav {
        position: fixed;
        top: 0;
        bottom: auto;
        left: auto;
        right: 0;
        width: auto;
        height: auto;
        flex-direction: row;
        gap: 8px;
        padding: 12px 24px;
        border-radius: 0 0 0 20px;
        border-top: none;
        border-left: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
    }
    
    .nav-btn {
        flex-direction: row;
        padding: 10px 20px;
    }
    
    .nav-icon {
        font-size: 1.2rem;
    }
    
    .nav-label {
        font-size: 0.85rem;
    }
    
    .items-table {
        font-size: 0.95rem;
    }
    
    .items-table th,
    .items-table td {
        padding: 16px 12px;
    }
    
    .price-input {
        max-width: 120px;
    }
}

/* ===== HIDE SCROLLBAR (WEBKIT) ===== */
.items-table-container::-webkit-scrollbar {
    height: 4px;
}

.items-table-container::-webkit-scrollbar-track {
    background: var(--bg-input);
}

.items-table-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ===== HORIZONTAL SCROLL INDICATOR ===== */
.items-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ===== INPUT NUMBER SPINNERS ===== */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}
