/* --- DESIGN SYSTEM & CSS VARIABLES --- */
:root {
  --color-primary: #2ECC71;
  --color-primary-dark: #27AE60;
  --color-danger: #E74C3C;
  --color-warning: #F39C12;
  --color-safe: #2ECC71;
  --color-bg: #F8F9FA;
  --color-card-bg: #FFFFFF;
  --color-text-primary: #2C3E50;
  --color-text-secondary: #7F8C8D;
  --color-border: #ECF0F1;

  --radius-card: 16px;
  --radius-pill: 50px;
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-fab: 0 6px 16px rgba(46, 204, 113, 0.4);

  --font-body: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --nav-height: 70px;
  --header-height: 60px;
}

/* --- RESET & LAYOUT --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  height: 100dvh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* App shell doesn't scroll, only content */
}

/* TABLET/DESKTOP RESPONSIVE CONTAINER */
@media (min-width: 768px) {
  body {
    align-items: center;
    background-color: #ECEFF1;
  }

  #app-header,
  #app-content,
  #bottom-nav {
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
  }

  #app-content {
    background-color: var(--color-bg);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
  }
}

@media (min-width: 1024px) {

  #app-header,
  #app-content,
  #bottom-nav {
    max-width: 480px;
  }
}

/* --- HEADER --- */
header {
  height: var(--header-height);
  background-color: var(--color-card-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
  position: relative;
  z-index: 10;
}

header .logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.icon-btn {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.icon-btn:hover {
  background-color: var(--color-border);
}

/* --- MAIN CONTENT AREA --- */
main {
  flex: 1;
  min-height: 0;
  /* Fixes flex child overflow issue */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 20px calc(var(--nav-height) + 20px + env(safe-area-inset-bottom));
  position: relative;
}

/* Screen transition styles */
.screen {
  display: none;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.screen.active {
  display: block;
}

.screen.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- BOTTOM NAV --- */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  background-color: var(--color-card-bg);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  z-index: 100;
}

.nav-tab {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  flex: 1;
  cursor: pointer;
  height: 100%;
  font-size: 0.75rem;
  gap: 4px;
  transition: color 0.2s;
}

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

.nav-tab svg {
  transition: transform 0.2s;
}

.nav-tab.active svg {
  transform: scale(1.1);
}

/* Floating Action Button for Camera */
.camera-fab {
  position: relative;
  top: -20px;
  flex: 0 0 auto;
  width: 70px;
}

.fab-inner {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  border-radius: 50%;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-fab);
  transition: transform 0.2s;
}

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

/* --- COMPONENTS --- */
.card {
  background-color: var(--color-card-bg);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-card);
  margin-bottom: 16px;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-card-bg);
  border-radius: 24px 24px 0 0;
  padding: 20px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1);
  z-index: 1000;
  /* Make sure max-height accommodates content, allow scroll */
  max-height: 85dvh;
  overflow-y: auto;
}

.bottom-sheet.open {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 40px;
  height: 5px;
  background-color: #E0E0E0;
  border-radius: 10px;
  margin: 0 auto 20px;
}

/* OVERLAY */
.overlay-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 999;
}

.overlay-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* BADGES & CHIPS */
.nutriscore-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  color: white;
  text-transform: uppercase;
}

.nutriscore-a {
  background-color: #038141;
}

.nutriscore-b {
  background-color: #85BB2F;
}

.nutriscore-c {
  background-color: #FECB02;
}

.nutriscore-d {
  background-color: #EE8100;
}

.nutriscore-e {
  background-color: #E63E11;
}

.nutriscore-unknown {
  background-color: var(--color-text-secondary);
}

.chip {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 0.8rem;
  font-weight: 600;
  margin: 4px;
}

.chip.safe {
  background-color: #E8F8F5;
  color: var(--color-primary-dark);
}

.chip.warning {
  background-color: #FDEDEC;
  color: var(--color-danger);
}

/* SPOIL REPORT ITEM */
.spoil-item {
  display: flex;
  align-items: center;
  background: var(--color-card-bg);
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  position: relative;
  overflow: hidden;
}

.spoil-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
}

.spoil-item.exp-red::before {
  background-color: var(--color-danger);
}

.spoil-item.exp-yellow::before {
  background-color: var(--color-warning);
}

.spoil-item.exp-green::before {
  background-color: var(--color-safe);
}

.spoil-item img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 8px;
  margin-right: 16px;
  background: var(--color-bg);
}

.spoil-details {
  flex: 1;
}

.spoil-details h3 {
  font-size: 1rem;
  margin-bottom: 4px;
}

.spoil-details p {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

.btn-delete {
  background: none;
  border: none;
  color: var(--color-danger);
  padding: 8px;
  cursor: pointer;
}

/* TOGGLE SWITCH */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #CCC;
  transition: .4s;
  border-radius: 28px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked+.toggle-slider {
  background-color: var(--color-primary);
}

input:checked+.toggle-slider:before {
  transform: translateX(22px);
}

/* CAMERA SCANNER */
#camera-container {
  position: relative;
  width: 100%;
  height: 65vh;
  background: #000;
  border-radius: var(--radius-card);
  overflow: hidden;
  margin-bottom: 20px;
}

#video-element,
#qr-reader {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-viewfinder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 250px;
  height: 150px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.4);
  /* Dim outside */
  border-radius: 12px;
  pointer-events: none;
}

.scan-viewfinder::before,
.scan-viewfinder::after,
.scan-viewfinder-inner::before,
.scan-viewfinder-inner::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: var(--color-primary);
  border-style: solid;
}

.scan-viewfinder::before {
  top: 0;
  left: 0;
  border-width: 4px 0 0 4px;
}

.scan-viewfinder::after {
  top: 0;
  right: 0;
  border-width: 4px 4px 0 0;
}

.scan-viewfinder-inner {
  position: absolute;
  inset: 0;
}

.scan-viewfinder-inner::before {
  bottom: 0;
  left: 0;
  border-width: 0 0 4px 4px;
}

.scan-viewfinder-inner::after {
  bottom: 0;
  right: 0;
  border-width: 0 4px 4px 0;
}

.camera-controls {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 10px;
}

.mode-btn {
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-primary);
  background: transparent;
  color: var(--color-primary);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.capture-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: white;
  border: 4px solid var(--color-border);
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  display: none;
  /* Only show in OCR mode */
}

.capture-btn:active {
  background: #eee;
  transform: scale(0.95);
}

/* SKELETON LOADER */
.loading-skeleton {
  background: #f0f0f0;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite linear;
  border-radius: 4px;
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }

  100% {
    background-position: 200% 0;
  }
}

/* BUTTONS */
.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  margin-top: 12px;
}

.btn-secondary {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--color-border);
  color: var(--color-text-primary);
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  margin-top: 12px;
}

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

/* FORMS */
.input-field {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
  margin-top: 8px;
  margin-bottom: 16px;
}

/* CHART CONTAINER */
.chart-container {
  position: relative;
  height: 200px;
  width: 100%;
  margin: 20px 0;
}

/* TOAST */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text-primary);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  z-index: 2000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 0.3s;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

.section-title {
  font-size: 1.1rem;
  margin-bottom: 12px;
  font-weight: 700;
  color: var(--color-text-primary);
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  margin-bottom: 20px;
}