/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:       #0d47a1;
  --navy-dark:  #0a3d91;
  --gold:       #c8a96e;
  --green:      #00897b;
  --orange:     #f59e0b;
  --red:        #ef4444;
  --bg:         #f0ede8;
  --surface:    #ffffff;
  --border:     #e3eaf5;
  --text:       #1a2340;
  --muted:      #5f7494;
  --radius:     10px;
  --shadow:     0 2px 12px rgba(0,0,0,0.08);
  --font:       'IBM Plex Sans', 'Segoe UI', system-ui, -apple-system, 'Arial', sans-serif;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 0 1rem 2rem;
  max-width: 600px;
  margin: 0 auto;
}

/* ── Typography ───────────────────────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; color: var(--navy); margin-bottom: .5rem; }
h2 { font-size: 1.15rem; font-weight: 600; color: var(--text); }
p  { font-size: .9rem; line-height: 1.55; color: var(--muted); }
a  { color: var(--navy); }

/* ── Nav ──────────────────────────────────────────────────────────────────── */
.nav {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 10px 0 14px; margin-bottom: 4px;
}
.nav a {
  padding: 6px 14px; border-radius: 999px; font-size: .8rem; font-weight: 500;
  text-decoration: none; border: 1.5px solid var(--gold);
  color: var(--muted); transition: all .15s;
}
.nav a.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.nav a:hover   { border-color: var(--navy); color: var(--navy); }

/* ── Brand header ─────────────────────────────────────────────────────────── */
.brand-header { text-align: center; padding: 16px 0 8px; }
.brand-header a { text-decoration: none; }
.brand-name { font-size: 1.3rem; font-weight: 700; color: var(--navy); letter-spacing: .5px; }
.brand-name b, .wm b { color: var(--gold); font-weight: inherit; }
.brand-sub  { font-size: .75rem; color: var(--muted); display: block; margin-top: 2px; }

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--gold);
  padding: 1rem;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card.green  { border-color: var(--green); }
.card.navy   { border-color: var(--navy); }
.card.danger { border-color: var(--red); }

.group-title {
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--muted); margin-bottom: 8px;
}

/* ── Form elements ────────────────────────────────────────────────────────── */
input[type=text], input[type=email], input[type=password],
input[type=url], input[type=tel], input[type=number],
input[type=time], input[type=datetime-local],
select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--gold);
  border-radius: 8px; font-size: .9rem; font-family: var(--font);
  color: var(--text); background: var(--surface);
  margin-bottom: 10px; outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--navy); }
textarea { resize: vertical; }

button, .btn {
  display: inline-block; width: 100%; padding: 12px 20px;
  background: var(--navy); color: #fff; font-size: .95rem; font-weight: 600;
  border: 1.5px solid var(--navy); border-radius: 8px; cursor: pointer;
  text-decoration: none; text-align: center; transition: all .15s;
}
button:hover, .btn:hover { opacity: .88; }
.btn-sm    { padding: 6px 14px; font-size: .8rem; width: auto; }
.btn-gold  { background: var(--gold); border-color: var(--gold); color: var(--text); }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-red   { background: var(--red); border-color: var(--red); color: #fff; }
.btn-outline {
  background: transparent; border: 1.5px solid var(--gold);
  color: var(--muted);
}
.btn-outline:hover { border-color: var(--navy); color: var(--navy); background: transparent; }

/* ── Pills (allergen toggles) ─────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: 999px; font-size: .8rem;
  border: 2px solid var(--gold);
  background: var(--surface); color: var(--text);
  cursor: pointer; user-select: none;
  transition: all .15s; margin: 2px;
}
.pill input { display: none; }
.pill.active,
.pill:has(input:checked) {
  background: rgba(0, 137, 123, 0.75);
  border-color: var(--green);
  color: #fff;
}

/* ── Allergen grid ────────────────────────────────────────────────────────── */
.allergen-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px;
}
.allergen-category .cat-title {
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); margin-bottom: 5px;
}
.pill-group { display: flex; flex-wrap: wrap; gap: 4px; }

/* ── Restaurant cards ─────────────────────────────────────────────────────── */
.restaurant-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 80px;
}
.restaurant-card {
  background: var(--surface); border: 2px solid var(--gold);
  border-radius: var(--radius); padding: 12px; text-decoration: none;
  display: block; transition: border-color .15s, box-shadow .15s;
}
.restaurant-card:hover { border-color: var(--navy); box-shadow: var(--shadow); }
.restaurant-card .r-name   { font-size: .9rem; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.restaurant-card .r-sub    { font-size: .75rem; color: var(--muted); }
.restaurant-card .r-action { font-size: .75rem; color: var(--navy); font-weight: 500; margin-top: 6px; display: block; }

/* ── Result cards ─────────────────────────────────────────────────────────── */
.result-card {
  background: var(--surface); border-radius: var(--radius);
  border: 1.5px solid var(--gold); padding: 12px; margin-bottom: 8px;
}
.result-card.safe     { border-left: 4px solid var(--green); }
.result-card.modified { border-left: 4px solid var(--gold); }
.dish-name   { font-size: 1rem; font-weight: 600; color: var(--text); }
.dish-status { font-size: .8rem; margin-top: 4px; color: var(--muted); }
.dish-mod    { font-size: .8rem; color: var(--gold); font-weight: 500; }

/* ── Home cards ───────────────────────────────────────────────────────────── */
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 4px 0; }
.home-card {
  background: var(--surface); border: 2px solid var(--gold);
  border-radius: var(--radius); padding: 14px; text-decoration: none; display: block;
  transition: border-color .15s;
}
.home-card:hover { border-color: var(--navy); }
.home-card .hc-title { font-size: .9rem; font-weight: 600; color: var(--navy); margin-bottom: 2px; }
.home-card .hc-sub   { font-size: .75rem; color: var(--muted); }

/* ── Section divider ──────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--gold); margin: 12px 0; }

/* ── CTA section ──────────────────────────────────────────────────────────── */
.cta-section { text-align: center; padding: 1rem 0; margin-bottom: 16px; }
.cta-section h1 { margin-bottom: 6px; }

/* ── Floating back ────────────────────────────────────────────────────────── */
.floating-back {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 999; display: inline-flex; align-items: center;
  background: var(--navy); color: #fff; font-weight: 600; font-size: .9rem;
  padding: 12px 24px; border-radius: 999px; text-decoration: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.2); border: 2px solid var(--gold);
}

/* ── Onboarding modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
}
.modal {
  background: var(--surface); border-radius: 12px; max-width: 360px;
  width: 100%; padding: 1.5rem; border: 2px solid var(--gold);
  max-height: 90vh; overflow-y: auto;
}

/* ── Progress bar ─────────────────────────────────────────────────────────── */
.progress-bg   { background: var(--border); border-radius: 8px; height: 8px; }
.progress-fill { background: var(--green); height: 8px; border-radius: 8px; transition: width .3s; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .7rem; font-weight: 700; border: 1px solid transparent;
}
.badge-blue  { background: #e8f0fe; color: var(--navy); border-color: var(--navy); }
.badge-green { background: #e8f5f1; color: var(--green); border-color: var(--green); }
.badge-gold  { background: #fff8e1; color: #854f0b; border-color: var(--gold); }
.badge-red   { background: #fef2f2; color: var(--red); border-color: var(--red); }
.badge-grey  { background: #f3f4f6; color: #6b7280; border-color: #d1d5db; }

/* ── Table ────────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.data-table th {
  padding: 8px 10px; text-align: left; color: var(--muted);
  font-weight: 500; border-bottom: 2px solid var(--gold); font-size: .75rem;
}
.data-table td { padding: 10px; border-bottom: 1px solid var(--gold); vertical-align: top; }
.data-table tr:hover td { background: #f8faff; }

/* ── Dropdown filters ─────────────────────────────────────────────────────── */
.filter-row  { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-wrap { position: relative; }
.filter-btn  {
  display: flex; align-items: center; gap: 6px; padding: 8px 14px;
  border: 1.5px solid var(--gold); border-radius: 8px; background: var(--surface);
  font-size: .85rem; color: var(--text); cursor: pointer;
}
.filter-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 10;
  background: var(--surface); border: 1.5px solid var(--gold);
  border-radius: 8px; min-width: 160px; box-shadow: var(--shadow); display: none;
}
.filter-menu.open { display: block; }
.filter-item {
  display: block; padding: 8px 14px; font-size: .85rem;
  color: var(--text); text-decoration: none; cursor: pointer;
}
.filter-item:hover { background: var(--bg); }

/* ── Admin sidebar ────────────────────────────────────────────────────────── */
.admin-wrap    { display: flex; gap: 0; min-height: 80vh; margin: -1rem; }
.admin-sidebar {
  width: 200px; flex-shrink: 0; background: var(--navy);
  padding: 1.5rem 0; border-radius: 12px 0 0 12px;
}
.admin-sidebar h2 {
  font-size: .7rem; color: var(--gold); font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; padding: 0 1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: .5rem;
}
.admin-sidebar a {
  display: flex; align-items: center; gap: 8px; padding: 9px 1rem;
  font-size: .85rem; color: rgba(255,255,255,.75); text-decoration: none;
  border-left: 3px solid transparent; transition: all .15s;
}
.admin-sidebar a:hover  { background: rgba(255,255,255,.08); color: #fff; }
.admin-sidebar a.active {
  background: rgba(255,255,255,.12); color: #fff;
  border-left-color: var(--gold); font-weight: 600;
}
.admin-content { flex: 1; padding: 1.5rem; overflow-x: auto; }
.admin-section { display: none; }
.admin-section.active { display: block; }

/* ── Stat grid ────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 14px;
  border: 1.5px solid var(--gold); text-align: center;
}
.stat-num   { font-size: 1.8rem; font-weight: 700; color: var(--navy); }
.stat-label { font-size: .75rem; color: var(--muted); margin-top: 2px; }

/* ── Flash messages ───────────────────────────────────────────────────────── */
.flash {
  padding: 10px 14px; border-radius: 8px; font-size: .9rem;
  margin-bottom: 12px; font-weight: 500; border: 1.5px solid transparent;
}
.flash-info    { background: #e8f0fe; color: var(--navy); border-color: var(--navy); }
.flash-success { background: #e8f5f1; color: var(--green); border-color: var(--green); }
.flash-error   { background: #fef2f2; color: var(--red); border-color: var(--red); }

/* ── Logout link ──────────────────────────────────────────────────────────── */
.logout-link {
  display: block; text-align: center; padding: 12px;
  color: var(--muted); font-size: .85rem; text-decoration: none; margin-top: 8px;
}

/* ── Desktop layout ───────────────────────────────────────────────────────── */
@media (min-width: 640px) {
  body { padding: 0 2rem 2rem; max-width: 900px; }
  .allergen-grid { grid-template-columns: repeat(3, 1fr); }
  .restaurant-grid { grid-template-columns: repeat(3, 1fr); }
  .home-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .allergen-grid   { grid-template-columns: 1fr; }
  .restaurant-grid { grid-template-columns: 1fr; }
  .home-grid       { grid-template-columns: 1fr 1fr; }
  .admin-wrap      { flex-direction: column; }
  .admin-sidebar   { width: 100%; border-radius: 12px 12px 0 0; }
}

@media print {
  .floating-back, nav, button { display: none !important; }
  body { background: white; padding: 0; }
}