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

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #dee2e6;
  --text: #212529;
  --text-muted: #6c757d;
  --primary: #e67e22;
  --primary-hover: #d35400;
  --danger: #dc3545;
  --danger-hover: #bb2d3b;
  --success: #198754;
  --sidebar-width: 240px;
  --topbar-height: 52px;
  --bottom-nav-height: 56px;

  --rating-yes: #198754;
  --rating-no: #dc3545;
  --rating-sort-of: #fd7e14;

  /* Safe area insets — filled by the browser on notched devices */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

html {
  /* Prevent elastic overscroll revealing white behind the bars */
  background: var(--surface);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  /* Prevent text size adjustment on orientation change */
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ─── Buttons ─── */
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: background 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 36px;
}

button.btn-primary {
  background: var(--primary);
  color: #fff;
}
button.btn-primary:hover { background: var(--primary-hover); }
button.btn-primary:active { opacity: 0.85; }

button.btn-danger {
  background: var(--danger);
  color: #fff;
}
button.btn-danger:hover { background: var(--danger-hover); }
button.btn-danger:active { opacity: 0.85; }

button.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
button.btn-ghost:hover { background: var(--border); color: var(--text); }
button.btn-ghost:active { opacity: 0.75; }

button.btn-sm {
  padding: 4px 10px;
  font-size: 0.82rem;
  min-height: 32px;
}

button.btn-icon {
  background: transparent;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 8px;
  line-height: 1;
  min-height: 36px;
}
button.btn-icon:hover { background: var(--border); color: var(--text); }

/* ─── Desktop layout ─── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
}

.sidebar-section {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.sidebar-section-title {
  padding: 4px 16px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.sidebar-link {
  display: block;
  padding: 9px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  min-height: 0;
  border-radius: 0;
  transition: background 0.1s;
}
.sidebar-link:hover { background: var(--bg); text-decoration: none; }
.sidebar-link.active { background: #fff3e0; color: var(--primary); font-weight: 600; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px;
  max-width: 900px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
}

/* ─── Mobile topbar ─── */
#mobile-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  /* Push content down below the notch */
  padding-top: var(--sat);
  height: calc(var(--topbar-height) + var(--sat));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: flex-end;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
  gap: 4px;
  z-index: 200;
}

/* The actual row of content below the safe area */
#mobile-topbar > * {
  margin-bottom: 0;
  /* Vertically center within the 52px strip below the notch */
  height: var(--topbar-height);
  display: flex;
  align-items: center;
}

#back-btn {
  background: none;
  border: none;
  border-radius: 8px;
  padding: 0 10px;
  color: var(--primary);
  font-size: 1rem;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
#back-btn:active { opacity: 0.6; }

#mobile-title {
  flex: 1;
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#topbar-action {
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 4px;
}

#topbar-action button {
  min-height: 44px;
  padding: 0 10px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.95rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Bottom nav ─── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-height) + var(--sab));
  padding-bottom: var(--sab);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 200;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 6px 4px;
  min-height: var(--bottom-nav-height);
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.tab-btn svg { transition: transform 0.15s; }
.tab-btn:active svg { transform: scale(0.9); }
.tab-btn.active { color: var(--primary); }
.tab-btn.active svg { stroke: var(--primary); }

/* ─── Account sheet ─── */
#account-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 300;
  display: flex;
  align-items: flex-end;
}

#account-sheet-inner {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(20px + var(--sab));
  width: 100%;
}

.account-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 0 auto 20px;
}

/* ─── Sidebar backdrop (unused on mobile now, kept for safety) ─── */
#sidebar-backdrop { display: none; }

/* ─── Mobile overrides ─── */
@media (max-width: 768px) {
  #mobile-topbar { display: flex; }
  #bottom-nav { display: flex !important; }

  .sidebar { display: none; }

  .main-content {
    margin-left: 0;
    padding: 16px 16px 24px;
    padding-left: calc(16px + var(--sal));
    padding-right: calc(16px + var(--sar));
    /* Space for topbar above + bottom nav below */
    padding-top: calc(var(--topbar-height) + var(--sat) + 16px);
    padding-bottom: calc(var(--bottom-nav-height) + var(--sab) + 16px);
    max-width: 100%;
  }

  /* On mobile, page-title and back-link are replaced by the topbar */
  .page-title { display: none; }
  .back-link { display: none; }

  /* Inputs: 16px prevents iOS auto-zoom */
  input[type="text"],
  input[type="url"],
  input[type="email"],
  textarea,
  select {
    font-size: 16px;
  }

  /* Bigger touch targets for small buttons */
  button.btn-sm {
    min-height: 36px;
    padding: 6px 12px;
  }

  /* Recipe cards: active state for touch */
  .recipe-card:active {
    background: var(--bg);
    border-color: var(--primary);
  }

  /* Full-bleed recipe detail on mobile */
  .recipe-detail {
    border-radius: 0;
    border-left: none;
    border-right: none;
    margin: 0 -16px;
  }

  .recipe-detail-header {
    padding: 16px 16px;
  }

  .recipe-detail-title {
    font-size: 1.25rem;
  }

  .recipe-detail-body {
    padding: 16px;
  }

  /* PDF embed shorter on phone */
  .recipe-pdf-embed {
    height: 420px;
  }

  /* Filter members: horizontal scroll */
  .filter-members {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .filter-members::-webkit-scrollbar { display: none; }

  .filter-member-btn {
    flex-shrink: 0;
    /* Larger touch target */
    padding: 8px 16px;
    font-size: 0.9rem;
  }

  /* Rating buttons: bigger for thumbs */
  .rating-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    min-height: 40px;
  }

  .rating-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
  }

  .rating-row:last-child { border-bottom: none; }

  .rating-member-name {
    width: auto;
    font-size: 1rem;
    font-weight: 600;
  }

  .rating-buttons { gap: 8px; }

  /* Member items: taller touch target */
  .member-item {
    padding: 14px;
    min-height: 56px;
  }

  /* Collection items */
  .collection-item {
    padding: 14px;
    min-height: 56px;
  }

  /* Form container: no border/shadow on mobile */
  .form-container {
    border: none;
    border-radius: 0;
    padding: 0;
    background: transparent;
    margin: 0 -16px;
    padding: 0 16px;
  }

  /* Inline file input: looks better on iOS */
  input[type="file"] {
    font-size: 15px;
    padding: 8px 0;
  }

  /* Account sheet only shown on mobile */
  #account-sheet { display: none; }
  #account-sheet.open { display: flex; }
}

/* ─── Forms ─── */
.form-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.form-hint {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

input[type="text"],
input[type="url"],
input[type="email"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.12);
}

textarea {
  resize: vertical;
  min-height: 160px;
  line-height: 1.6;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 6px;
}

/* ─── Recipe list ─── */
.recipe-list {
  display: grid;
  gap: 10px;
}

.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.recipe-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.recipe-card-body { flex: 1; min-width: 0; }

.recipe-card-title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 4px;
}

.recipe-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.recipe-card-ratings {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ─── Rating badges ─── */
.rating-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}

.rating-badge.yes    { background: #d1e7dd; color: #0a3622; }
.rating-badge.no     { background: #f8d7da; color: #58151c; }
.rating-badge.sort_of{ background: #ffe8cd; color: #7d3e00; }
.rating-badge.unrated{ background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }

/* ─── Filter panel ─── */
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.filter-panel-title {
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.filter-members {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.filter-member-btn {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.875rem;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 36px;
}

.filter-member-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.filter-threshold {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-threshold label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  cursor: pointer;
  min-height: 36px;
}

/* ─── Recipe detail ─── */
.recipe-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.recipe-detail-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.recipe-detail-title {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
}

.recipe-detail-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.recipe-detail-body { padding: 24px; }

.recipe-file-section { margin-bottom: 24px; }

.recipe-file-section img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}

.recipe-pdf-embed {
  width: 100%;
  height: 600px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.recipe-url-section {
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.recipe-content-section { margin-bottom: 24px; }

.recipe-content-section h1,
.recipe-content-section h2,
.recipe-content-section h3 { margin: 16px 0 8px; }
.recipe-content-section p  { margin-bottom: 8px; }
.recipe-content-section ul,
.recipe-content-section ol { padding-left: 24px; margin-bottom: 8px; }
.recipe-content-section li { margin-bottom: 4px; line-height: 1.6; }

.ratings-section {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 4px;
}

.ratings-section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.rating-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.rating-member-name {
  width: 120px;
  font-weight: 500;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.rating-buttons { display: flex; gap: 6px; flex-wrap: wrap; }

.rating-btn {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}
.rating-btn:active { opacity: 0.75; }

.rating-btn.active-yes    { border-color: var(--rating-yes);    background: var(--rating-yes);    color: #fff; }
.rating-btn.active-no     { border-color: var(--rating-no);     background: var(--rating-no);     color: #fff; }
.rating-btn.active-sort_of{ border-color: var(--rating-sort-of);background: var(--rating-sort-of);color: #fff; }

/* ─── Family members ─── */
.member-list { display: grid; gap: 8px; margin-bottom: 20px; }

.member-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
}

.member-name { font-weight: 500; font-size: 1rem; }
.member-actions { display: flex; gap: 6px; }

/* ─── Collections ─── */
.collection-list {
  list-style: none;
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.collection-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 52px;
}

.collection-name { flex: 1; font-weight: 500; font-size: 1rem; cursor: pointer; }
.collection-recipe-count { font-size: 0.8rem; color: var(--text-muted); }
.shared-by-label { font-size: 0.8rem; color: var(--text-muted); font-style: italic; }
.collection-shares-row { list-style: none; }

.share-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-top: -4px;
  margin-bottom: 4px;
}

.share-panel-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 8px; }

.share-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.875rem;
}

.share-email { color: var(--text-muted); font-size: 0.8rem; }
.share-empty { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 8px; }

/* ─── Login ─── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.login-card h1 { font-size: 2rem; color: var(--primary); margin-bottom: 8px; }
.login-card p  { color: var(--text-muted); margin-bottom: 28px; font-size: 0.95rem; }

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 24px;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s;
  min-height: 48px;
}
.btn-google:hover { background: var(--bg); box-shadow: 0 2px 8px rgba(0,0,0,0.1); text-decoration: none; }
.btn-google:active { opacity: 0.8; }

/* ─── Misc ─── */
.loading { padding: 60px 24px; text-align: center; color: var(--text-muted); }

.empty-state { padding: 60px 24px; text-align: center; color: var(--text-muted); }
.empty-state p { margin-bottom: 16px; font-size: 1rem; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 16px;
  cursor: pointer;
  min-height: 36px;
}
.back-link:hover { color: var(--text); text-decoration: none; }

.collection-edit-input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  flex: 1;
  min-height: 40px;
}
