:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #0f172a;
    --text-primary: #fff;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --accent-color: #10b981;
}

[data-theme="light"] {
    --bg-primary: #f1f5f9;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #cbd5e1;
    --accent-color: #059669;
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-user-select: none;
    user-select: none;
    transition: background 0.3s, color 0.3s;
}

.app {
    max-width: 430px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
    background: var(--bg-secondary);
    transition: background 0.3s;
}
#camera, #portion-camera {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);  /* Mirror the video if needed */
}


.header {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    padding: 20px 20px 16px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header p {
    font-size: 13px;
    opacity: 0.9;
    margin-top: 4px;
}

.nav-tabs {
    display: flex;
    background: var(--bg-tertiary);
    padding: 0;
    overflow-x: auto;
}

/* Panels */
.panel {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  margin-bottom: 16px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-title h3 {
  font-size: 15px;
  margin: 0;
  color: var(--text-primary);
}

.panel-icon {
  font-size: 18px;
}

.panel-cta {
  padding: 10px 14px;
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.panel-body {
  padding: 16px;
}

.panel-help {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 12px;
}

.secondary-btn {
  background: #334155;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.scan-extras {
  text-align: center;
  margin: 12px 0 4px;
}

.mute-note {
  color: #64748b;
  font-size: 12px;
  margin-top: 8px;
}

.glasses-status {
  color: #10b981;
  font-size: 13px;
  margin-top: 8px;
}

/* Ensure camera fills within the panel */
#scan-tab .camera-container {
  margin-bottom: 12px;
}

#camera, #portion-camera {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.nav-tab {
    flex: 1;
    padding: 14px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-tab.active {
    color: #10b981;
    border-bottom-color: #10b981;
}

.content {
    padding: 20px;
    min-height: calc(100vh - 200px);
}

.camera-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 20px;
}

.camera-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 280px;
    height: 180px;
    border: 3px solid #10b981;
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.7); /* Darker for better focus */
}

/* Add animated scanning line */
.camera-overlay::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: #10b981;
    animation: scan 2s ease-in-out infinite;
}

@keyframes scan {
    0%, 100% { top: 0; }
    50% { top: calc(100% - 3px); }
}

.app .content #scan-tab .camera-hint {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    padding: 8px 2px;
    border-radius: 20px;
    font-size: 13px;
    color: #10b981;
}
.guide-text {
    background: rgba(0, 0, 0, 0.7);
    bottom: 10px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    color: #10b981;
    margin-top: -5px;
}

.scan-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    transition: transform 0.2s;
}
#manual-barcode {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 12px;
}

#manual-barcode::placeholder {
    color: var(--text-secondary);
}
.scan-btn:active {
    transform: scale(0.98);
}
/* Product overlay sections */
.product-section {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 12px;
}

.product-section h3 {
    color: var(--accent-color);
    font-size: 14px;
    margin-bottom: 12px;
}

.timeline-container {
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 8px;
}

.additive-item,
.alternative-item,
.insight-card {
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.text-muted {
    color: var(--text-secondary);
}

/* History items */
.history-item .date {
    color: var(--text-secondary);
}

/* Insights sections */
#carbon-milestones,
#weekly-comparison,
#allergen-streak,
#sustainable-choices {
    color: var(--text-primary);
}

/* Light mode specific overrides */
[data-theme="light"] .product-overlay {
    background: rgba(0, 0, 0, 0.5);
}

[data-theme="light"] #portion-result {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.product-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.product-overlay.active {
    display: flex;
}

.product-card {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 24px;
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

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

.product-card h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.product-card .brand {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

.alert-badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    margin: 4px 4px 4px 0;
}

.alert-danger {
    background: #dc2626;
    color: white;
}

.alert-warning {
    background: #f59e0b;
    color: white;
}

.alert-success {
    background: #10b981;
    color: white;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid #334155;
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-secondary);
    font-size: 14px;
}

.info-value {
    font-weight: 600;
    font-size: 14px;
}

.alternatives {
    background: #0f172a;
    padding: 16px;
    border-radius: 12px;
    margin-top: 16px;
}

.alternatives h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: #10b981;
}

.alternative-item {
    background: #1e293b;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 13px;
}

.close-btn {
    width: 100%;
    padding: 14px;
    background: #334155;
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 16px;
}

.history-item {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 12px;
}

.history-item h3 {
    font-size: 16px;
    margin-bottom: 4px;
}

.history-item .date {
    color: #94a3b8;
    font-size: 12px;
    margin-bottom: 8px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-tertiary);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #10b981;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.setting-group {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 12px;
}

.setting-group h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: #10b981;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #334155;
}

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

.toggle {
    width: 48px;
    height: 26px;
    background: #334155;
    border-radius: 13px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle.active {
    background: #10b981;
}

.toggle-knob {
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}

.toggle.active .toggle-knob {
    transform: translateX(22px);
}

.allergen-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.allergen-tag {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
}

.allergen-tag.selected {
    background: #10b981;
    border-color: #10b981;
    color: white;
}
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #64748b;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

/* Glasses Mode Styles */
body.glasses-mode .camera-hint {
    font-size: 16px;
    background: rgba(99, 102, 241, 0.9);
}

body.glasses-mode .product-overlay {
    font-size: 18px;
}

/* Portion Control Styles */
.portion-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}

.guide-circle {
    width: 250px;
    height: 250px;
    border: 4px dashed #10b981;
    border-radius: 50%;
    margin: 0 auto 12px;
    animation: pulse 2s infinite;
}



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

#manual-barcode {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 12px;
}

#manual-barcode::placeholder {
    color: var(--text-secondary);
}
.setting-description {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 12px;
}
.insight-section {
    background: var(--bg-tertiary);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 16px;
}

.insight-section h3 {
    color: var(--text-primary);
}

.insight-section p {
    color: var(--text-secondary);
}

.mode-btn {
    flex: 1;
    padding: 12px;
    background: #334155;
    border: 2px solid transparent;
    border-radius: 10px;
    color: #94a3b8;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn.active {
    background: #10b981;
    border-color: #10b981;
    color: white;
}

.mode-btn:hover {
    background: #475569;
}

.mode-btn.active:hover {
    background: #059669;
}

#portion-canvas {
    pointer-events: none;
}

.portion-indicator {
    position: absolute;
    border: 3px solid #10b981;
    border-radius: 50%;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
}
.portion-tips {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 12px;
    margin-top: 16px;
}

.portion-tips h3 {
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-primary);
}

.portion-tips ul {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.6;
    padding-left: 20px;
}

.portion-too-large {
    border-color: #dc2626;
    box-shadow: 0 0 20px rgba(220, 38, 38, 0.5);
}

.portion-perfect {
    border-color: #10b981;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.8);
    animation: perfectPulse 1s;
}

@keyframes perfectPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
.about-card p {
  color: var(--text-secondary);
}

.about-card h2 {
  text-align: center;
  font-weight: 700;
}
