:root {
  --green: #2d6a4f;
  --green-dark: #1b4332;
  --green-light: #d8f3dc;
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #1b1b1b;
  --muted: #6b7280;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Cairo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
  font-size: 1rem;
}

/* Header */
.app-header {
  background: var(--green);
  color: white;
  padding: 20px 16px 14px;
  padding-top: calc(20px + env(safe-area-inset-top));
  box-shadow: var(--shadow);
}

.app-header h1 {
  margin: 0 0 12px;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
}

.progress {
  position: relative;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  height: 22px;
  overflow: hidden;
}

.progress-bar {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  width: 0%;
  background: linear-gradient(90deg, #95d5b2, #52b788);
  transition: width 0.3s ease;
}

.progress-text {
  position: relative;
  display: block;
  text-align: center;
  font-size: 0.85rem;
  line-height: 22px;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Main */
main {
  flex: 1;
  padding: 16px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.primary-btn {
  background: var(--green);
  color: white;
  padding: 14px 20px;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: var(--shadow);
  transition: transform 0.05s ease, background 0.15s ease;
}

.primary-btn:active {
  transform: scale(0.98);
  background: var(--green-dark);
}

.primary-btn .icon { font-size: 1.4rem; }

.add-row {
  display: flex;
  gap: 8px;
  background: var(--card);
  padding: 6px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.add-row input {
  flex: 1;
  padding: 12px 14px;
  border: none;
  background: transparent;
  outline: none;
  text-align: right;
}

.add-btn {
  background: var(--green);
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  font-size: 1.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.add-btn:active { background: var(--green-dark); }

/* List */
.list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty {
  text-align: center;
  color: var(--muted);
  margin: 40px 0;
  font-size: 0.95rem;
}

.empty.hidden { display: none; }

.item {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.2s ease;
}

.item.done {
  background: var(--green-light);
}

.item.done .item-name {
  text-decoration: line-through;
  color: var(--muted);
}

.item-checkbox {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  accent-color: var(--green);
  cursor: pointer;
}

.item-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #f1efe9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
  overflow: hidden;
}

.item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.item-name {
  flex: 1;
  font-weight: 600;
  word-break: break-word;
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #f5f3ee;
  border-radius: 999px;
  padding: 2px;
}

.qty-control button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--card);
  font-weight: 700;
  color: var(--green-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: 1rem;
}

.qty-control button:active { background: var(--green-light); }

.qty-value {
  min-width: 22px;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
}

.item-remove {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.item-remove:active {
  background: #fde8e8;
  color: var(--danger);
}

/* Footer */
.app-footer {
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid #ece8e0;
  position: sticky;
  bottom: 0;
}

.ghost-btn, .danger-btn {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
}

.ghost-btn {
  background: #f5f3ee;
  color: var(--green-dark);
}

.ghost-btn:active { background: #ece8e0; }

.danger-btn {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fbcaca;
}

.danger-btn:active { background: #fde8e8; }

/* Scanner */
.scanner {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner.hidden { display: none; }

.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-frame {
  position: absolute;
  width: min(80vw, 320px);
  height: 200px;
  border: 3px solid #95d5b2;
  border-radius: 16px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.scanner-status {
  position: absolute;
  bottom: calc(30px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: white;
  background: rgba(0, 0, 0, 0.55);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
}

.scanner-close {
  position: absolute;
  top: calc(20px + env(safe-area-inset-top));
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: white;
  font-size: 1.6rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.hidden { display: none; }

.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.modal-card .muted {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.85rem;
  direction: ltr;
  text-align: right;
}

.modal-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #e2dfd7;
  outline: none;
  text-align: right;
}

.modal-card input:focus { border-color: var(--green); }

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.modal-actions .ghost-btn,
.modal-actions .primary-btn {
  flex: 1;
  padding: 12px;
  font-size: 1rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(27, 67, 50, 0.95);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 120;
  box-shadow: var(--shadow);
  max-width: 90vw;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* Auth screen */
.auth-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, var(--green) 0%, var(--green-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.auth-screen.hidden { display: none; }

.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
}

.auth-card h1 {
  margin: 0 0 4px;
  font-size: 1.6rem;
  color: var(--green-dark);
  text-align: center;
}

.auth-tagline {
  margin: 0 0 22px;
  color: var(--muted);
  text-align: center;
  font-size: 0.92rem;
}

.auth-card label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.auth-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #e2dfd7;
  outline: none;
  margin-bottom: 14px;
  text-align: right;
  font-size: 1rem;
}

.auth-card input:focus { border-color: var(--green); }

.auth-card .primary-btn {
  width: 100%;
  margin-bottom: 8px;
}

.auth-card .ghost-btn {
  width: 100%;
}

.otp-info {
  margin: 0 0 16px;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.55;
}

.auth-error {
  background: #fde8e8;
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 8px;
  font-size: 0.9rem;
}

.auth-error.hidden { display: none; }

/* Header row + sign-out */
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-row h1 {
  margin: 0 0 12px;
}

.header-icon-btn {
  color: white;
  background: rgba(255, 255, 255, 0.18);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 12px;
}

.header-icon-btn:active { background: rgba(255, 255, 255, 0.3); }

.header-meta {
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.78rem;
  text-align: center;
  margin-bottom: 8px;
  word-break: break-word;
}

/* Splash */
.splash {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 90;
  color: var(--green-dark);
  font-weight: 600;
}

.splash.hidden { display: none; }

.splash-spinner,
.busy-spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid var(--green-light);
  border-top-color: var(--green);
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Busy overlay */
.busy {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 130;
  color: var(--green-dark);
  font-weight: 600;
  padding: 24px;
}

.busy.hidden { display: none; }

.busy p { margin: 0; text-align: center; max-width: 320px; }

/* Vision modal extras */
.modal-help {
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.modal-photo-btn {
  width: 100%;
  margin-bottom: 10px;
}

.vision-manual {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  background: #f5f3ee;
  padding: 6px;
  border-radius: var(--radius);
}

.vision-manual input {
  flex: 1;
  padding: 10px 12px;
  border: none;
  background: transparent;
  outline: none;
  text-align: right;
}

.full-width { width: 100%; }

#appScreen.hidden { display: none; }

.check-email {
  text-align: center;
  padding: 8px 0 4px;
}

.check-email-icon {
  font-size: 2.4rem;
  margin-bottom: 8px;
}
