/* styles.css — Meal Planner
   English LTR UI, mobile-first, polished, light + dark. Fully offline
   (system font stack, no external assets). Arabic meal text renders RTL
   inside its own element. */

:root {
  --bg: #f4f5fb;
  --bg-grad-1: #eef1fb;
  --bg-grad-2: #f7f5fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-soft: #475569;
  --muted: #94a3b8;
  --line: #e8ebf3;
  --line-strong: #dde2ee;
  --primary: #4f46e5;
  --primary-ink: #ffffff;
  --primary-soft: #eef0fe;
  --danger: #e11d48;
  --ring: rgba(79, 70, 229, 0.32);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 16px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.16);
  --radius: 16px;
  --radius-sm: 12px;

  /* Section accent colors */
  --breakfast: #f59e0b;
  --lunch: #10b981;
  --dinner: #6366f1;
  --snack: #f43f5e;

  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1d;
    --bg-grad-1: #0d1424;
    --bg-grad-2: #0a0f1d;
    --surface: #121a2c;
    --surface-2: #0f1626;
    --ink: #eef2fb;
    --ink-soft: #aab6cf;
    --muted: #6b7a99;
    --line: #23304b;
    --line-strong: #2c3a58;
    --primary: #7c83ff;
    --primary-ink: #0b1020;
    --primary-soft: #1a2138;
    --danger: #fb7185;
    --ring: rgba(124, 131, 255, 0.4);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
/* Ensure the hidden attribute always wins over display rules below. */
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  padding: 0;
}
html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--bg-grad-1), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, var(--bg-grad-2), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100dvh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* --- Top bar (sticky) --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.12));
}
.brand-text h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.brand-text p {
  margin: 1px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* --- Search --- */
.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 14px;
  width: 19px;
  height: 19px;
  color: var(--muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  height: 48px;
  padding: 0 44px 0 42px;
  font-size: 16px; /* >=16px avoids iOS zoom-on-focus */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-input::placeholder {
  color: var(--muted);
}
.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--ring);
}
.search-clear {
  position: absolute;
  right: 8px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.search-clear:hover {
  color: var(--ink);
  background: var(--surface-2);
}

/* --- Filter tabs (sticky, part of the top bar) --- */
.tabs-bar {
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}
.tabs {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar {
  display: none;
}
.tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 15px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.tab:hover {
  border-color: var(--primary);
}
.tab.active {
  color: var(--primary-ink);
  background: var(--primary);
  border-color: var(--primary);
}
.tab-icon {
  font-size: 1.05em;
  line-height: 1;
}
.tab-count {
  min-width: 20px;
  padding: 1px 6px;
  font-size: 0.72rem;
  font-weight: 750;
  text-align: center;
  color: var(--ink-soft);
  background: var(--surface-2);
  border-radius: 999px;
}
.tab.active .tab-count {
  color: var(--primary-ink);
  background: rgba(255, 255, 255, 0.22);
}

/* --- Page --- */
.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 16px calc(40px + var(--safe-b));
}

/* --- Actions row --- */
.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-bottom: 12px;
}
.btn-upload {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 48px;
  padding: 0 20px;
  font-size: 0.98rem;
  font-weight: 650;
  color: var(--primary-ink);
  background: linear-gradient(180deg, var(--primary), color-mix(in srgb, var(--primary) 82%, #000));
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, filter 0.15s ease;
}
.btn-upload svg {
  width: 20px;
  height: 20px;
}
.btn-upload:hover {
  filter: brightness(1.06);
}
.btn-upload:active {
  transform: translateY(1px) scale(0.99);
}
.hint {
  font-size: 0.82rem;
  color: var(--muted);
}

/* --- Status toast --- */
.status {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin: 0;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 550;
  transition: max-height 0.25s ease, opacity 0.25s ease, margin 0.25s ease, padding 0.25s ease;
}
.status.show {
  max-height: 80px;
  opacity: 1;
  margin: 0 0 14px;
  padding: 11px 14px;
}
.status-info {
  background: var(--primary-soft);
  color: var(--primary);
}
.status-success {
  background: color-mix(in srgb, #10b981 16%, var(--surface));
  color: #0a7c53;
}
.status-error {
  background: color-mix(in srgb, var(--danger) 15%, var(--surface));
  color: var(--danger);
}
@media (prefers-color-scheme: dark) {
  .status-success {
    color: #5eead4;
  }
}

/* --- Results / sections --- */
.results {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: rise 0.32s ease both;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent) 10%, var(--surface)),
    var(--surface)
  );
}
.section-head::before {
  content: "";
  width: 4px;
  align-self: stretch;
  margin: -14px 0 -14px -16px;
  background: var(--accent);
}
.section-icon {
  font-size: 20px;
  line-height: 1;
}
.section-title {
  margin: 0;
  font-size: 1.04rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  flex: 1;
}
.count-pill {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 24px;
  padding: 0 9px;
  font-size: 0.78rem;
  font-weight: 750;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border-radius: 999px;
}

.meal-list {
  list-style: none;
  margin: 0;
  padding: 6px;
}
.meal {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.14s ease;
}
.meal + .meal {
  border-top: 1px solid var(--line);
}
.meal:hover {
  background: var(--surface-2);
}
.meal-text {
  flex: 1;
  min-width: 0;
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--ink);
  /* Arabic content */
  direction: rtl;
  text-align: right;
  overflow-wrap: anywhere;
}
.meal-delete {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  transition: color 0.14s ease, background 0.14s ease, border-color 0.14s ease;
}
.meal-delete svg {
  width: 18px;
  height: 18px;
}
.meal-delete:hover,
.meal-delete:active {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

/* --- Empty / no-results states --- */
.empty {
  text-align: center;
  padding: 40px 22px;
  background: var(--surface);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  transition: border-color 0.18s ease, background 0.18s ease;
}
.empty.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.empty-emoji {
  font-size: 46px;
  line-height: 1;
}
.empty h2 {
  margin: 14px 0 4px;
  font-size: 1.15rem;
  font-weight: 700;
}
.empty p {
  margin: 0 auto;
  max-width: 30ch;
  color: var(--muted);
  font-size: 0.92rem;
}

/* --- Drag overlay --- */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--primary) 24%, rgba(2, 6, 23, 0.55));
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.drop-card {
  text-align: center;
  color: #fff;
  padding: 32px 40px;
  border: 2px dashed rgba(255, 255, 255, 0.8);
  border-radius: 22px;
}
.drop-emoji {
  font-size: 54px;
}
.drop-card p {
  margin: 12px 0 0;
  font-size: 1.1rem;
  font-weight: 650;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* --- Larger screens --- */
@media (min-width: 680px) {
  .topbar-inner {
    flex-direction: row;
    align-items: center;
  }
  .brand {
    flex: 0 0 auto;
  }
  .search {
    flex: 1;
    max-width: 420px;
    margin-left: auto;
  }
  .brand-text p {
    display: block;
  }
}
