:root {
  --bg: #eef6f2;
  --bg-2: #e3f0ea;
  --card: #ffffff;
  --text: #0f2a22;
  --muted: #5b7a6f;
  --line: #e2efe9;
  --accent: #0d9488;
  --accent-2: #0f766e;
  --accent-soft: #ccfbf1;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 18px 40px -18px rgba(13, 60, 46, 0.28);
  --radius: 18px;
}

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

html { scroll-behavior: smooth; scroll-padding-top: 90px; }

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1000px 480px at 88% -10%, rgba(13, 148, 136, 0.16), transparent 60%),
    radial-gradient(900px 420px at -10% 12%, rgba(22, 163, 74, 0.12), transparent 60%),
    linear-gradient(160deg, var(--bg), var(--bg-2));
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------- TOPBAR ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 18px; height: 68px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-icon {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 18px; box-shadow: 0 8px 18px -6px rgba(13, 148, 136, 0.6);
}
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -0.3px; }
.brand-name span { color: var(--accent); }
.topnav { margin-left: auto; display: flex; gap: 4px; }
.topnav a {
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px;
  padding: 9px 14px; border-radius: 999px; transition: 0.18s;
}
.topnav a:hover { background: var(--accent-soft); color: var(--accent-2); }
.model-badge {
  display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600;
  color: var(--muted); background: rgba(255, 255, 255, 0.7); border: 1px solid var(--line);
  padding: 7px 13px; border-radius: 999px; white-space: nowrap;
}
.model-badge .dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--warn);
  box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.45); animation: pulse 1.8s infinite;
}
.model-badge.ready .dot { background: var(--ok); animation: none; box-shadow: none; }
.model-badge.error .dot { background: var(--danger); animation: none; box-shadow: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(217,119,6,.5); } 70% { box-shadow: 0 0 0 7px rgba(217,119,6,0); } 100% { box-shadow: 0 0 0 0 rgba(217,119,6,0); } }

/* ---------- HERO / DROPZONE ---------- */
.hero { position: relative; text-align: center; padding: 56px 0 34px; }
.hero-glow {
  position: absolute; inset: 0; margin: 0 auto; width: min(680px, 90%);
  height: 100%; border-radius: 50%; z-index: 0;
  background: radial-gradient(closest-side, rgba(13, 148, 136, 0.18), transparent);
  filter: blur(10px);
}
.hero-title { position: relative; z-index: 1; font-size: clamp(28px, 5vw, 46px); font-weight: 800; letter-spacing: -0.8px; line-height: 1.15; }
.hero-title span {
  background: linear-gradient(90deg, var(--accent), var(--ok));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { position: relative; z-index: 1; max-width: 640px; margin: 14px auto 30px; color: var(--muted); font-size: 15.5px; line-height: 1.7; }
.hero-sub strong { color: var(--text); }

.dropzone {
  position: relative; z-index: 1; max-width: 720px; margin: 0 auto;
  background: rgba(255, 255, 255, 0.75); border: 2px dashed #b7d9cf;
  border-radius: 22px; padding: 42px 24px; cursor: pointer; transition: 0.22s;
}
.dropzone:hover, .dropzone.drag, .dropzone:focus-visible {
  border-color: var(--accent); background: rgba(204, 251, 241, 0.55);
  box-shadow: var(--shadow); outline: none;
}
.dropzone-icon { font-size: 44px; color: var(--accent); margin-bottom: 10px; }
.dropzone-title { font-size: 17px; font-weight: 700; margin-bottom: 16px; }
.dropzone-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.dropzone-hint { margin-top: 16px; font-size: 12.5px; color: var(--muted); }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: none; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: 14px; border-radius: 12px;
  padding: 11px 18px; transition: 0.18s; text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 10px 20px -8px rgba(13, 148, 136, 0.65);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.06); }
.btn-outline { background: #fff; color: var(--accent-2); border: 2px solid var(--accent); }
.btn-outline:hover { background: var(--accent-soft); }
.btn-ghost { background: var(--accent-soft); color: var(--accent-2); }
.btn-ghost:hover { filter: brightness(0.97); }
.btn-danger-ghost { background: #fee2e2; color: var(--danger); }
.btn-danger-ghost:hover { background: #fecaca; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; }

/* ---------- PANEL / CARD ---------- */
.panel { margin: 40px 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.panel-title { font-size: 22px; font-weight: 800; letter-spacing: -0.4px; }
.panel-title i { color: var(--accent); margin-right: 10px; }
.panel-sub { color: var(--muted); font-size: 14px; margin-top: 5px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}

/* ---------- SCAN ---------- */
.scan-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .scan-grid { grid-template-columns: 1fr; } }

.preview-wrap { position: relative; border-radius: 14px; overflow: hidden; background: #0d1f1a; min-height: 300px; display: grid; place-items: center; }
.preview-wrap img, #overlayCanvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.preview-wrap img { opacity: 0; transition: opacity 0.3s; }
.preview-wrap.has-img img { opacity: 1; }
.preview-wrap.has-img #overlayCanvas { display: block; }
#overlayCanvas { display: none; }
.preview-empty { color: #9db7ad; text-align: center; font-size: 14px; z-index: 1; }
.preview-empty i { font-size: 44px; display: block; margin-bottom: 10px; opacity: 0.8; }
.scan-loading { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: rgba(13, 31, 26, 0.5); color: #fff; font-size: 14px; font-weight: 600; }

.results-card { min-height: 340px; }
.results-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.results-head h3 { font-size: 16px; font-weight: 800; }
.result-count { font-size: 12.5px; font-weight: 700; color: var(--muted); background: var(--bg); padding: 5px 10px; border-radius: 999px; }
.scan-state { color: var(--muted); font-size: 14px; text-align: center; padding: 40px 10px; }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 12px; border-radius: 50%;
  border: 4px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results-list { list-style: none; display: flex; flex-direction: column; gap: 12px; max-height: 480px; overflow-y: auto; padding-right: 4px; }
.results-list::-webkit-scrollbar { width: 8px; }
.results-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.result-item { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.result-top { display: flex; align-items: center; gap: 12px; }
.result-emoji { font-size: 26px; width: 44px; height: 44px; display: grid; place-items: center; background: var(--bg); border-radius: 12px; flex-shrink: 0; }
.result-info { flex: 1; min-width: 0; }
.result-name { font-weight: 800; font-size: 14.5px; }
.result-kind { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; margin-top: 2px; }
.conf-bar { margin-top: 7px; height: 7px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.conf-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--ok)); transition: width 0.5s ease; }
.conf-label { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-left: auto; }
.not-food-tag { display: inline-block; margin-top: 7px; font-size: 10.5px; font-weight: 700; color: var(--muted); background: var(--bg); padding: 3px 8px; border-radius: 99px; }

/* ---------- STATS ---------- */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 640px) { .stats-row { grid-template-columns: 1fr; } }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; text-align: center; box-shadow: 0 8px 22px -14px rgba(13,60,46,.25);
}
.stat-num { font-size: 30px; font-weight: 800; display: block; color: var(--accent-2); }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat-warn .stat-num { color: var(--warn); }
.stat-danger .stat-num { color: var(--danger); }

/* ---------- ADD FORM ---------- */
.add-form { display: grid; grid-template-columns: 2fr 1.2fr 0.8fr 1.2fr 1.4fr auto; gap: 14px; align-items: end; margin-bottom: 20px; }
@media (max-width: 1000px) { .add-form { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .add-form { grid-template-columns: 1fr; } }
.form-field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 7px; }
.form-field input, .form-field select {
  width: 100%; font-family: inherit; font-size: 14px; color: var(--text);
  padding: 11px 13px; border: 2px solid var(--line); border-radius: 12px; background: #fff; outline: none; transition: 0.18s;
}
.form-field input:focus, .form-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(13,148,136,.12); }
.form-btn .btn { width: 100%; justify-content: center; padding: 12px 18px; }

/* ---------- TABLE ---------- */
.table-card { padding: 8px; }
.table-wrap { overflow-x: auto; }
.food-table { width: 100%; border-collapse: collapse; min-width: 600px; }
.food-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--muted); padding: 12px 14px; border-bottom: 2px solid var(--line);
}
.food-table td { padding: 13px 14px; border-bottom: 1px solid var(--bg); font-size: 14px; vertical-align: middle; }
.food-table tr:last-child td { border-bottom: none; }
.food-table tbody tr { transition: background 0.15s; }
.food-table tbody tr:hover { background: #f4fbf8; }
.food-name { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.food-emoji { font-size: 22px; }
.food-meta { font-size: 12px; color: var(--muted); font-weight: 600; }
.qty-tag { background: var(--bg); padding: 5px 10px; border-radius: 99px; font-weight: 700; font-size: 13px; white-space: nowrap; }
.days-tag { font-weight: 800; white-space: nowrap; }
.days-tag.good { color: var(--ok); }
.days-tag.warn { color: var(--warn); }
.days-tag.bad { color: var(--danger); }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 700; padding: 5px 11px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.3px; }
.chip.high { background: #fee2e2; color: var(--danger); }
.chip.med { background: #fef3c7; color: var(--warn); }
.chip.low { background: #dcfce7; color: var(--ok); }

.act-btn { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 15px; padding: 6px; border-radius: 8px; transition: 0.15s; }
.act-btn:hover { color: var(--danger); background: #fee2e2; }

.empty-state { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty-state i { font-size: 44px; color: #c3d8d0; margin-bottom: 12px; }
.empty-state p { font-size: 14.5px; }

/* ---------- RECIPES ---------- */
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.recipe-card { display: flex; flex-direction: column; gap: 12px; transition: 0.2s; }
.recipe-card:hover { transform: translateY(-4px); box-shadow: 0 24px 44px -20px rgba(13,60,46,.34); }
.recipe-emoji { font-size: 40px; }
.recipe-title { font-size: 17.5px; font-weight: 800; }
.recipe-meta { display: flex; gap: 14px; font-size: 13px; color: var(--muted); font-weight: 600; flex-wrap: wrap; }
.recipe-meta i { color: var(--accent); margin-right: 5px; }
.match-bar { height: 9px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.match-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, #22c55e, #0d9488); }
.match-label { font-size: 12.5px; font-weight: 700; color: var(--accent-2); margin-top: 6px; display: flex; justify-content: space-between; }
.ing-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.ing-chip { font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; }
.ing-chip.have { background: #dcfce7; color: #166534; }
.ing-chip.miss { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }
.recipe-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; }

/* ---------- MODAL ---------- */
[hidden] { display: none !important; }
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 27, 22, 0.55); backdrop-filter: blur(4px); }
.modal-card {
  position: relative; background: var(--card); border-radius: 22px; max-width: 640px; width: 100%;
  max-height: 86vh; overflow-y: auto; box-shadow: 0 30px 70px -20px rgba(0,0,0,.45); z-index: 1; padding: 30px;
}
.modal-close { position: sticky; top: 0; float: right; background: var(--bg); border: none; cursor: pointer; width: 36px; height: 36px; border-radius: 50%; color: var(--muted); font-size: 16px; transition: 0.15s; }
.modal-close:hover { background: #fee2e2; color: var(--danger); }
.modal-body .recipe-emoji { font-size: 52px; }
.modal-body h3 { font-size: 24px; font-weight: 800; margin: 8px 0 4px; }
.modal-body .modal-meta { color: var(--muted); font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.modal-body h4 { font-size: 15px; font-weight: 800; margin: 22px 0 10px; }
.modal-body ol { padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.modal-body li { font-size: 14.5px; line-height: 1.65; }
.notice { background: #fef3c7; color: #92400e; border-radius: 12px; padding: 12px 14px; font-size: 13.5px; font-weight: 600; margin-top: 16px; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 13px 22px; border-radius: 14px;
  font-size: 14px; font-weight: 600; box-shadow: 0 18px 34px -14px rgba(0,0,0,.5);
  z-index: 70; display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.28s ease;
}
.toast.success { background: var(--ok); }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }

.footer { text-align: center; color: var(--muted); font-size: 13.5px; padding: 30px 0 50px; }
.footer i { color: var(--danger); }

@media (max-width: 640px) {
  .topbar-inner { height: 60px; flex-wrap: wrap; padding-bottom: 8px; }
  .model-badge { display: none; }
  .topnav a { font-size: 12.5px; padding: 7px 10px; }
  .panel { margin: 28px 0; }
}