body { background-color: var(--fl-bg, #f6f5f1); }

/* ---------------------------------------------------------------------
   Layout - full width on mobile, comfortably centered on desktop.
   The navbar stays full-bleed; only the page content is constrained so
   text/tables/cards don't stretch edge-to-edge on wide monitors.
   --------------------------------------------------------------------- */
.app-content {
  max-width: 1320px;
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 992px) {
  .app-content { padding-left: 1.5rem; padding-right: 1.5rem; }
}

h3 { font-weight: 600; }

/* ---------------------------------------------------------------------
   Cards (Browse grid, filter panel, modal content)
   --------------------------------------------------------------------- */
.card {
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.result-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.result-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.result-thumb { height: 160px; object-fit: cover; }

@media (min-width: 992px) {
  .result-thumb { height: 190px; }
}

/* One extra column of results on very large screens */
@media (min-width: 1400px) {
  #resultsGrid > .col-6.col-md-4.col-lg-3 {
    flex: 0 0 auto;
    width: 16.6667%; /* 6 columns */
  }
}

/* ---------------------------------------------------------------------
   Food log table
   --------------------------------------------------------------------- */
#foodlogTable thead th {
  background-color: #fff;
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}
.foodlog-row:hover { background-color: rgba(13, 110, 253, 0.05); }

.col-picture { width: 56px; }
.row-thumb {
  width: 44px; height: 44px; object-fit: cover; border-radius: 6px; display: block;
}
.row-thumb-placeholder {
  width: 44px; height: 44px; border-radius: 6px; background: #eee;
  display: flex; align-items: center; justify-content: center; color: #adb5bd;
}

/* ---------------------------------------------------------------------
   Star rating / save feedback
   --------------------------------------------------------------------- */
.star-rating .star, .star-display i {
  color: #f5a623;
  cursor: pointer;
  font-size: 1.2rem;
}
.star-display i { cursor: default; font-size: 1rem; }

.save-ok { outline: 2px solid #28a745 !important; transition: outline 0.3s; }
.save-error { outline: 2px solid #dc3545 !important; transition: outline 0.3s; }

/* ---------------------------------------------------------------------
   Files & pictures gallery (detail modal)
   --------------------------------------------------------------------- */
.thumb-img {
  width: 80px; height: 80px; object-fit: cover; border-radius: 6px; cursor: pointer;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
.file-icon { font-size: 2.5rem; color: #6c757d; }
/* file-card sizes to its content (image + filename + principal radio +
   action buttons) - only .thumb-img/.file-icon get a fixed square size.
   A fixed height here previously caused overflowing content to visually
   bleed into whatever followed the gallery (e.g. the upload input). */
.file-card { width: 100px; display: flex; flex-direction: column; align-items: center; }
.files-gallery { align-items: flex-start; }

@media (min-width: 992px) {
  .thumb-img { width: 110px; height: 110px; }
  .file-card { width: 110px; }
}

/* ---------------------------------------------------------------------
   Occurrences (a dish logged multiple times) - editable cards in the
   dish modal, and a simpler read-only variant in the Browse detail popup.
   --------------------------------------------------------------------- */
.occurrence-card {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-left: 3px solid #198754;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  background: #fff;
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}
.occurrence-card-highlight {
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}
.occurrence-card-readonly {
  border-left-color: #6c757d;
}

/* ---------------------------------------------------------------------
   Search bar clear (x) button
   --------------------------------------------------------------------- */
#clearSearchBtn {
  font-size: 0.7rem;
}

/* ---------------------------------------------------------------------
   Modals - a bit more breathing room on large screens
   --------------------------------------------------------------------- */
@media (min-width: 1400px) {
  #foodlogModal .modal-xl,
  #browseDetailModal .modal-xl { max-width: 1180px; }
}

/* ---------------------------------------------------------------------
   Image preview popup - cap displayed size so a huge original photo
   (e.g. straight off a phone) never overflows the viewport.
   --------------------------------------------------------------------- */
#imagePreviewImg {
  max-height: 80vh;
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

/* ---------------------------------------------------------------------
   Mobile overrides
   --------------------------------------------------------------------- */
@media (max-width: 576px) {
  .thumb-img { width: 60px; height: 60px; }
  .file-card { width: 60px; }
  .result-thumb { height: 120px; }
  .col-picture { width: 40px; }
  .row-thumb, .row-thumb-placeholder { width: 32px; height: 32px; }
  #imagePreviewImg { max-height: 70vh; }
}

/* ---------------------------------------------------------------------
   Login / first-run setup (v1.7)
   --------------------------------------------------------------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(2rem, env(safe-area-inset-top)) 1rem 2rem;
}
@media (min-height: 700px) {
  .auth-page { align-items: center; }
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-wrap-wide { max-width: 620px; }
.auth-logo { border-radius: 18px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15); }
.auth-card { box-shadow: 0 8px 28px rgba(0, 0, 0, 0.08); }

.setup-steps {
  display: flex; gap: .5rem; justify-content: center;
  list-style: none; padding: 0; margin: 0 0 1rem; counter-reset: step;
  font-size: .875rem; color: #6c757d;
}
.setup-steps li { counter-increment: step; display: flex; align-items: center; gap: .4rem; }
.setup-steps li::before {
  content: counter(step); display: inline-flex; align-items: center; justify-content: center;
  width: 1.6rem; height: 1.6rem; border-radius: 50%; border: 1px solid #ced4da; background: #fff;
}
.setup-steps li + li::after { content: none; }
.setup-steps li.active { color: #212529; font-weight: 600; }
.setup-steps li.active::before { background: #212529; border-color: #212529; color: #fff; }
.setup-steps li.done::before { content: "\2713"; background: #198754; border-color: #198754; color: #fff; }
.setup-log { white-space: pre-wrap; font-size: .8rem; max-height: 260px; overflow: auto; }

/* ---------------------------------------------------------------------
   Installed app (PWA, standalone window): respect the phone's notch/
   home-indicator areas.
   --------------------------------------------------------------------- */
@media (display-mode: standalone) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .navbar { padding-top: max(.5rem, env(safe-area-inset-top)); }
}

/* =====================================================================
   v1.8 visual refresh - calmer, warmer, and consistent form fields.
   Everything below overrides earlier rules on purpose.
   ===================================================================== */
:root {
  --fl-bg: #f6f5f1;
  --fl-surface: #ffffff;
  --fl-surface-alt: #faf9f6;
  --fl-border: #e3e0d8;
  --fl-border-strong: #cfcbc1;
  --fl-text-muted: #6f6b63;
  --fl-radius: .6rem;
  --fl-radius-sm: .45rem;
  --fl-shadow: 0 1px 2px rgba(40, 35, 25, .05), 0 2px 8px rgba(40, 35, 25, .04);
  --fl-shadow-hover: 0 10px 26px rgba(40, 35, 25, .12);
  --fl-focus: 0 0 0 .2rem rgba(13, 110, 253, .18);
  --fl-chip-bg: #f1eee6;

  /* Bootstrap hooks */
  --bs-border-color: var(--fl-border);
  --bs-border-radius: var(--fl-radius-sm);
  --bs-border-radius-sm: .375rem;

  /* Choices.js (searchable dropdowns) hooks - make them look like Bootstrap fields */
  --choices-bg-color: var(--fl-surface);
  --choices-bg-color-dropdown: var(--fl-surface);
  --choices-keyline-color: var(--fl-border);
  --choices-border-radius: var(--fl-radius-sm);
  --choices-guttering: 0;
  --choices-font-size-lg: 1rem;
  --choices-font-size-md: 1rem;
  --choices-font-size-sm: .875rem;
  --choices-input-height: calc(1.5em + .75rem + 2px);
  --choices-inner-padding: .375rem 2.25rem .375rem .75rem;
  --choices-inner-one-padding: .375rem;
  --choices-list-single-padding: 0;
  --choices-z-index: 20;
}

body { color: #26231e; }
h3 { font-weight: 650; letter-spacing: -.01em; }

.navbar { box-shadow: 0 1px 0 rgba(255, 255, 255, .04), 0 2px 10px rgba(0, 0, 0, .12); }
.navbar .nav-link.active { font-weight: 600; }

/* ---------- Cards & surfaces ---------- */
.card {
  border: 1px solid var(--fl-border);
  border-radius: var(--fl-radius);
  box-shadow: var(--fl-shadow);
}
.card-header { border-bottom-color: var(--fl-border); }
.modal-content { border: 0; border-radius: calc(var(--fl-radius) + .2rem); }
.modal-header { border-bottom-color: var(--fl-border); }
.modal-body { background: var(--fl-surface-alt); }
.modal-footer { border-top-color: var(--fl-border); }

.section-block {
  background: var(--fl-surface);
  border: 1px solid var(--fl-border);
  border-radius: var(--fl-radius);
  padding: 1rem;
}
.section-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--fl-text-muted);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.section-title .badge { font-size: .7rem; letter-spacing: 0; color: var(--fl-text-muted); }

.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .6rem;
  border-radius: 999px;
  background: var(--fl-chip-bg);
  color: #4a463e;
  font-size: .8rem;
  font-weight: 500;
  white-space: nowrap;
}

/* ---------- Form fields: one consistent look ---------- */
.form-control, .form-select {
  border-color: var(--fl-border-strong);
  background-color: var(--fl-surface);
}
.form-control:focus, .form-select:focus {
  border-color: #86b7fe;
  box-shadow: var(--fl-focus);
}
.form-label { font-weight: 500; color: #3b3832; }

/* No browser spin-arrows on number fields - steppers have their own -/+ */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* Choices.js dropdown = Bootstrap .form-select (same height, border, radius, chevron, focus) */
.choices { margin-bottom: 0; font-size: 1rem; overflow: visible; }
.choices__inner {
  display: flex; align-items: center;
  border: 1px solid var(--fl-border-strong);
  border-radius: var(--fl-radius-sm);
  background-color: var(--fl-surface);
  line-height: 1.5;
  transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.choices[data-type*=select-multiple] .choices__inner { flex-wrap: wrap; gap: .25rem; padding-right: .75rem; }
.choices__list--single { padding: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choices__list--single .choices__item { overflow: hidden; text-overflow: ellipsis; }
.choices__placeholder { opacity: .6; }
.is-focused .choices__inner, .is-open .choices__inner {
  border-color: #86b7fe;
  box-shadow: var(--fl-focus);
}
.is-open .choices__inner { border-radius: var(--fl-radius-sm); }
.choices[data-type*=select-one]::after {
  border: 0; width: 16px; height: 12px; margin-top: -6px; right: .75rem;
  background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e") center / 16px 12px no-repeat;
}
.choices[data-type*=select-one].is-open::after { margin-top: -6px; transform: rotate(180deg); border: 0; }
.choices__list--dropdown, .choices__list[aria-expanded] {
  margin-top: .25rem;
  border: 1px solid var(--fl-border-strong);
  border-radius: var(--fl-radius-sm);
  box-shadow: 0 8px 24px rgba(40, 35, 25, .12);
  word-break: normal;
}
.is-flipped .choices__list--dropdown, .is-flipped .choices__list[aria-expanded] { margin-bottom: .25rem; border-radius: var(--fl-radius-sm); }
.choices__list--dropdown .choices__item, .choices__list[aria-expanded] .choices__item { font-size: .95rem; padding: .45rem .75rem; }
.choices__list--dropdown .choices__item--selectable.is-highlighted,
.choices__list[aria-expanded] .choices__item--selectable.is-highlighted { background-color: #eef3fe; }
.choices[data-type*=select-one] .choices__input { padding: .5rem .75rem; border-bottom-color: var(--fl-border); font-size: .95rem; }
.choices__list--multiple .choices__item {
  background: var(--fl-chip-bg); border: 1px solid var(--fl-border-strong); color: #3b3832;
  border-radius: 999px; font-size: .8rem; padding: .1rem .55rem; margin: 0;
}
.choices[data-type*=select-multiple] .choices__button { border-left-color: var(--fl-border-strong); filter: invert(.6); }
.choices__input--cloned { background: transparent; margin: 0; padding: 0; font-size: .95rem; }

/* Small variant (next to form-control-sm fields) */
.choices.choices-sm .choices__inner {
  min-height: calc(1.5em + .5rem + 2px);
  padding: .25rem 2rem .25rem .5rem;
  font-size: .875rem;
  border-radius: .375rem;
}
.choices.choices-sm[data-type*=select-one]::after { right: .5rem; }

/* ---------- Stepper  [ - | 2 | + ] ---------- */
.stepper { flex-wrap: nowrap; }
.stepper .form-control { min-width: 3rem; font-weight: 600; }
.stepper .stepper-btn {
  border: 1px solid var(--fl-border-strong);
  background: var(--fl-surface-alt);
  color: #3b3832;
  padding-left: .65rem; padding-right: .65rem;
}
.stepper .stepper-btn:hover { background: var(--fl-chip-bg); }
.stepper .stepper-btn:active { background: #e6e2d8; }
.servings-control .stepper { width: 8.25rem; }
.occurrence-card .stepper { max-width: 9rem; }

/* Square icon buttons (delete etc.) */
.btn-icon { display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; padding: 0; }
.btn { border-radius: var(--fl-radius-sm); }
.btn-sm { border-radius: .375rem; }

/* ---------- Ingredients ---------- */
.ingredient-lines { margin-bottom: .75rem; }
.ingredient-line { padding: .4rem 0; border-bottom: 1px dashed var(--fl-border); }
.ingredient-line:first-child { padding-top: 0; }
.ingredient-name { font-weight: 500; }
.ingredient-add-row { padding-top: .25rem; }

.ingredient-readonly-list { list-style: none; padding: 0; }
.ingredient-readonly-list li { padding: .35rem 0; border-bottom: 1px dashed var(--fl-border); }
.ingredient-readonly-list li:last-child { border-bottom: 0; }
.ingredient-readonly-list .qty { font-weight: 600; font-variant-numeric: tabular-nums; margin-right: .15rem; }

.recipe-text { white-space: pre-wrap; line-height: 1.65; }
.lead-text { font-size: 1.05rem; color: #3b3832; }

/* ---------- Occurrences ---------- */
.occurrence-card {
  border: 1px solid var(--fl-border);
  border-left: 4px solid #2f9e6a;
  border-radius: var(--fl-radius);
  background: var(--fl-surface);
  padding: .85rem 1rem;
}
.occurrence-card-readonly { border-left-color: #c9a227; }
.occurrence-card-highlight { border-color: #86b7fe; border-left-color: #0d6efd; box-shadow: var(--fl-focus); }

.star-rating .star { font-size: 1.25rem; padding-right: .1rem; transition: transform .1s; }
.star-rating .star:hover { transform: scale(1.15); }
.star-rating-lg .star { font-size: 1.5rem; }
.star-rating-sm .star { font-size: 1.15rem; }

/* ---------- Browse grid ---------- */
.result-card {
  overflow: hidden;
  border-radius: var(--fl-radius);
  cursor: pointer;
}
.result-card:hover { transform: translateY(-3px); box-shadow: var(--fl-shadow-hover); }
.result-card:focus-visible { outline: 0; box-shadow: var(--fl-focus), var(--fl-shadow-hover); }
.result-media { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: #ece9e1; }
.result-media .result-thumb { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; border-radius: 0; }
.result-card:hover .result-media .result-thumb { transform: scale(1.04); }
.result-media .bg-light { background: #ece9e1 !important; }
.result-count {
  position: absolute; top: .5rem; right: .5rem;
  background: rgba(33, 37, 41, .78); color: #fff;
  font-size: .75rem; font-weight: 600;
  padding: .15rem .5rem; border-radius: 999px;
  backdrop-filter: blur(2px);
}
.result-card .card-body { padding: .65rem .75rem .75rem; }
.result-title {
  font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.result-sub { font-size: .8rem; color: var(--fl-text-muted); margin-top: .15rem; }
/* aspect-ratio replaces the old fixed heights */
.result-thumb, .result-media .result-thumb { height: 100%; }
@media (min-width: 992px) { .result-media .result-thumb { height: 100%; } }
@media (max-width: 576px) { .result-media .result-thumb { height: 100%; } }

/* ---------- Food log table ---------- */
#foodlogTable { --bs-table-bg: transparent; }
.table-responsive:has(#foodlogTable) {
  background: var(--fl-surface); border: 1px solid var(--fl-border);
  border-radius: var(--fl-radius); box-shadow: var(--fl-shadow);
}
#foodlogTable thead th {
  background: var(--fl-surface-alt);
  font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--fl-text-muted);
  border-bottom-color: var(--fl-border);
}
#foodlogTable td { border-bottom-color: var(--fl-border); }
#foodlogTable tbody tr:last-child td { border-bottom: 0; }
.foodlog-row:hover { background-color: #faf8f2; }
.row-thumb, .row-thumb-placeholder { border-radius: .5rem; }

/* ---------- Files gallery ---------- */
.thumb-img { border-radius: .5rem; border-color: var(--fl-border); }

/* Save feedback, softer */
.save-ok { outline: 2px solid rgba(25, 135, 84, .65) !important; outline-offset: 1px; }
.save-error { outline: 2px solid rgba(220, 53, 69, .75) !important; outline-offset: 1px; }

@media (max-width: 576px) {
  .section-block { padding: .75rem; }
  .occurrence-card { padding: .75rem; }
  .modal-body { padding: .75rem; }
}
#newOccurrenceModal .stepper, #foodlogForm .stepper { max-width: 11rem; }

/* v1.9: pictures fade in once loaded instead of popping in line by line */
img.result-thumb, img.row-thumb { opacity: 0; transition: opacity .25s ease; }
img.result-thumb.is-loaded, img.row-thumb.is-loaded { opacity: 1; }
.row-thumb { background: #ece9e1; }

/* Admin users list (v1.10.2): no inner scroll container - rounded card
   corners kept by clipping only the header row, menus may overflow. */
.users-table-wrap { overflow: visible; }
#usersTable td, #usersTable th { white-space: normal; }
#usersTable td:last-child { white-space: nowrap; }
#usersTable tbody tr:last-child td { border-bottom: 0; }
@media (max-width: 400px) {
  #usersTable td, #usersTable th { padding-left: .4rem; padding-right: .4rem; }
}

/* ---------------------------------------------------------------------
   v1.10.3 - popups on a phone: keep clear of the notch / status bar.
   The page is drawn edge-to-edge (viewport-fit=cover), so on an iPhone
   (especially the installed app) a popup used to start under the status
   bar: its header - with the close button - sat behind it and couldn't be
   tapped. The inset is 0 on screens without a notch, so nothing changes there.
   --------------------------------------------------------------------- */
.modal {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* "+ Add ... as new ..." option inside searchable dropdowns */
.choices__item--choice[data-value="__new__"] {
  color: var(--bs-primary);
  font-weight: 600;
  border-top: 1px solid var(--fl-border);
}
.choices__item--choice[data-value="__new__"].is-highlighted { color: var(--bs-primary); }
