:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --ink: #15211e;
  --muted: #5d6d68;
  --line: #dfe6e3;
  --brand: #0f5c4d;
  --brand-soft: #e3f1ed;
  --halal: #157347;
  --halal-soft: #e0f3e8;
  --haram: #b42318;
  --haram-soft: #fde8e6;
  --mashbooh: #9a5b00;
  --mashbooh-soft: #fdf0d5;
  --unknown: #4f5d75;
  --unknown-soft: #e9edf3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 40, 34, .06), 0 8px 24px rgba(15, 40, 34, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--brand);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 11px;
  background: rgba(255, 255, 255, .14);
}
.brand h1 { margin: 0; font-size: 17px; line-height: 1.2; font-weight: 650; }
.brand p { margin: 0; font-size: 13px; opacity: .8; }
.status {
  flex: none; padding: 3px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, .14); font-size: 12px;
}
.status.offline { background: #f4b740; color: #3b2a00; }

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.input-panel { padding: 8px; position: sticky; top: 16px; }
.results-panel { padding: 20px; min-height: 340px; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--bg); border-radius: 11px; }
.tab {
  padding: 9px 6px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font: inherit; font-size: 14px; font-weight: 550; cursor: pointer;
}
.tab.active { background: var(--surface); color: var(--brand); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.tab-body { display: grid; gap: 12px; padding: 12px 8px 8px; }

.dropzone {
  display: grid; place-items: center; min-height: 196px; overflow: hidden;
  border: 1.5px dashed #b7c7c1; border-radius: 12px; background: #fafcfb;
  color: var(--muted); text-align: center; cursor: pointer;
}
.dropzone.dragging, .dropzone:hover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone img { display: block; width: 100%; max-height: 300px; object-fit: contain; background: #10201c; }
#dropzone-empty { display: grid; justify-items: center; gap: 4px; padding: 20px; }
#dropzone-empty svg { color: var(--brand); margin-bottom: 4px; }
#dropzone-empty strong { color: var(--ink); font-weight: 600; }
#dropzone-empty small { font-size: 13px; }

.field { display: grid; gap: 5px; }
.field span { font-size: 13px; color: var(--muted); }
input, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font: inherit;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}

button.primary, button.ghost {
  width: 100%; min-height: 46px; padding: 10px 16px; border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer;
}
button.primary { border: 0; background: var(--brand); color: #fff; }
button.primary:hover:not(:disabled) { background: #0b4a3e; }
button.primary:disabled { background: #b9c7c3; cursor: not-allowed; }
button.ghost { border: 1px solid var(--line); background: #fff; color: var(--brand); }
button.ghost:hover { background: var(--brand-soft); }

.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.search-results { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.search-results button {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--ink); font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.search-results button:hover { background: var(--brand-soft); }
.search-results small { display: block; color: var(--muted); }

.empty { display: grid; place-content: center; justify-items: center; min-height: 300px; text-align: center; }
.empty h2 { margin: 0; font-size: 19px; font-weight: 620; }
.empty p { margin: 4px 0 18px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; margin: 0; padding: 0; list-style: none; font-size: 14px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.dot { width: 11px; height: 11px; border-radius: 50%; }
.dot.halal { background: var(--halal); }
.dot.haram { background: var(--haram); }
.dot.mashbooh { background: var(--mashbooh); }
.dot.unknown { background: var(--unknown); }

.loading { display: grid; place-content: center; justify-items: center; gap: 12px; min-height: 300px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.error { padding: 12px 14px; border-radius: 10px; background: var(--haram-soft); color: var(--haram); }

.verdict { padding: 18px; border-radius: 12px; }
.verdict h2 { margin: 0 0 2px; font-size: 22px; line-height: 1.25; font-weight: 680; }
.verdict p { margin: 0; }
.verdict.halal { background: var(--halal-soft); color: var(--halal); }
.verdict.haram { background: var(--haram-soft); color: var(--haram); }
.verdict.mashbooh { background: var(--mashbooh-soft); color: var(--mashbooh); }
.verdict.unknown { background: var(--unknown-soft); color: var(--unknown); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.stat { padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px; text-align: center; }
.stat b { display: block; font-size: 21px; line-height: 1.15; font-weight: 680; }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat.halal b { color: var(--halal); }
.stat.haram b { color: var(--haram); }
.stat.mashbooh b { color: var(--mashbooh); }
.stat.unknown b { color: var(--unknown); }

.notice { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--mashbooh-soft); color: #6d4100; font-size: 14px; }

.product { display: flex; gap: 12px; align-items: center; margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.product img { width: 52px; height: 52px; object-fit: contain; border-radius: 8px; background: #fff; }
.product strong { display: block; line-height: 1.3; }
.product small { color: var(--muted); }
.pill { display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: 12px; font-weight: 600; }

.section-title { margin: 22px 0 8px; font-size: 15px; font-weight: 650; }
.ingredients { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.ingredient { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.ingredient-head {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 46px; padding: 9px 11px;
  border: 0; background: #fff; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.ingredient-head:hover { background: #f7faf9; }
.ingredient-name { flex: 1; min-width: 0; overflow-wrap: anywhere; text-transform: capitalize; }
.chevron { flex: none; color: var(--muted); transition: transform .15s; }
.ingredient-head[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.ingredient-detail { padding: 10px 12px; border-top: 1px solid var(--line); background: #fafcfb; font-size: 14px; }
.ingredient-detail p { margin: 0 0 6px; }
.ingredient-detail dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; color: var(--muted); font-size: 13px; }
.ingredient-detail dd { margin: 0; overflow-wrap: anywhere; }

.badge { flex: none; min-width: 84px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; text-align: center; }
.badge.halal { background: var(--halal-soft); color: var(--halal); }
.badge.haram { background: var(--haram-soft); color: var(--haram); }
.badge.mashbooh { background: var(--mashbooh-soft); color: var(--mashbooh); }
.badge.unknown { background: var(--unknown-soft); color: var(--unknown); }

details.edit-box { margin-top: 18px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; font-size: 14px; }
details.edit-box summary { cursor: pointer; font-weight: 600; }
details.edit-box p { margin: 8px 0; color: var(--muted); }
details.edit-box textarea { width: 100%; box-sizing: border-box; margin-bottom: 10px; font-size: 15px; }
details.edit-box button { width: 100%; }
details.raw { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 14px; color: var(--muted); }
details.raw summary { cursor: pointer; }
details.raw pre { margin: 8px 0 0; padding: 10px; border-radius: 8px; background: var(--bg); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.disclaimer { margin: 14px 0 0; color: var(--muted); font-size: 13px; }

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px; gap: 12px; }
  .input-panel { position: static; }
  .results-panel { padding: 14px; min-height: 0; }
  .empty, .loading { min-height: 200px; }
}
@media (max-width: 380px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .badge { min-width: 72px; }
}
