:root {
    --primary: #22C55E;
    --secondary: #4ADE80;
    --accent: #86EFAC;
    --bg: #0A1A0F;
    --surface: #112518;
    --text-main: #FFFFFF;
    --text-muted: #A3B8AA;
    --border: #1E3A28;
    --error: #EF4444;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
header {
    background-color: var(--surface);
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary);
}

/* Main Content */
main {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    padding: 1rem;
    padding-bottom: 5rem; /* Space for bottom nav */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    background-color: var(--bg);
}

.view.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 1;
}

.view.hidden {
    display: none;
}

/* Scanner View */
.scanner-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    background-color: #000;
    border-radius: var(--radius);
    overflow: hidden;
}

#reader {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Hide html5-qrcode standard elements we don't need */
#reader__dashboard_section_csr span,
#reader__dashboard_section_swaplink {
    display: none !important;
}

.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scan-frame {
    width: 280px;
    height: 280px;
    border: 2px solid var(--primary);
    border-radius: 20px;
    position: relative;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.scan-frame::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 10%;
    width: 80%;
    height: 2px;
    background: var(--error);
    animation: scan-line 2s infinite;
    box-shadow: 0 0 4px var(--error);
}

@keyframes scan-line {
    0% { top: 10%; opacity: 0; }
    50% { opacity: 1; }
    100% { top: 90%; opacity: 0; }
}

.scan-instructions {
    margin-top: 1rem;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.6);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
}

.scanner-controls {
    position: absolute;
    bottom: 2rem;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 1rem;
    z-index: 5;
}

/* Product List View */
.search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

input, select {
    background-color: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.75rem;
    border-radius: var(--radius);
    font-size: 1rem;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

#product-search {
    flex: 1;
}

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

.product-card {
    background-color: var(--surface);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.product-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.product-info h3 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.product-info p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.price-badge {
    background-color: rgba(34, 197, 94, 0.1);
    color: var(--primary);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-weight: 600;
}

.fab {
    position: fixed;
    bottom: 5rem; /* Above nav */
    right: 1.5rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--primary);
    color: #fff;
    border: none;
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    cursor: pointer;
    z-index: 20;
    transition: transform 0.2s;
}

.fab:active {
    transform: scale(0.95);
}

/* Product Detail View */
.back-btn {
    background: none;
    border: none;
    color: var(--secondary);
    font-size: 1rem;
    cursor: pointer;
    margin-bottom: 1rem;
    display: inline-flex;
    align-items: center;
    padding: 0;
}

.product-header {
    margin-bottom: 1.5rem;
}

.barcode-text {
    font-family: monospace;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background-color: var(--surface);
    padding: 0.75rem;
    border-radius: var(--radius);
    text-align: center;
    border: 1px solid var(--border);
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

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

.chart-container {
    background-color: var(--surface);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
    height: 250px;
}

.price-log-section h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

#price-history-list {
    list-style: none;
    margin-bottom: 1rem;
}

.price-entry {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.price-entry:last-child {
    border-bottom: none;
}

.price-meta {
    display: flex;
    flex-direction: column;
}

.store-name {
    font-weight: 500;
}

.scan-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Scan History View */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.secondary-btn {
    background-color: transparent;
    border: 1px solid var(--secondary);
    color: var(--secondary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
}

/* Bottom Navigation */
.bottom-nav {
    height: 4rem;
    background-color: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-shrink: 0;
    z-index: 100;
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0.5rem;
    transition: color 0.2s;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item .icon {
    font-size: 1.25rem;
}

/* Buttons */
.primary-btn {
    background-color: var(--primary);
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 600;
    width: 100%;
    cursor: pointer;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 1.5rem;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.text-btn {
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
}

.modal-content h3 {
    margin-bottom: 1.5rem;
    text-align: center;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.confirm-btn {
    flex: 1;
    background-color: var(--primary);
    color: #fff;
    border: none;
    padding: 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
}

.cancel-btn {
    flex: 1;
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
}

/* Animations */
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.product-card, .price-entry {
    animation: slideUp 0.3s ease forwards;
}
