/* ==========================================================================
   RecipeBox — global styles
   Single stylesheet, no CSS-in-JS. Mobile-first with breakpoints at 600px
   (tablet) and 1024px (desktop).
   ========================================================================== */

/* ---- Reset & base -------------------------------------------------------- */

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

/* Guarantee the `hidden` attribute always wins over any component's own
   `display` rule (several components below set `display: flex` on the same
   element that also carries `hidden`, e.g. `.toast`, `.detail-loading`). */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background-color: #f5f5f5;
  color: #2c2c2c;
  line-height: 1.5;
  font-size: 15px;
}

h1,
h2,
h3 {
  font-family: inherit;
}

button {
  font-family: inherit;
}

a {
  color: #0066cc;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Consistent, visible focus ring across every interactive control. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #0066cc;
  outline-offset: 2px;
}

/* ---- Header --------------------------------------------------------------*/

.app-header {
  background-color: #fff;
  padding: 20px 16px;
  border-bottom: 1px solid #ddd;
}

.app-header h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: #2c2c2c;
}

/* ---- Main layout ----------------------------------------------------------*/

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

/* ---- Toolbar / search bar --------------------------------------------------*/

.toolbar {
  margin-bottom: 20px;
}

.search-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
}

.field-search {
  flex: 1;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

#search-input,
#sort-select {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  background-color: #fff;
  color: #1a1a1a;
  min-height: 44px;
}

#search-input {
  width: 100%;
  padding-right: 36px;
}

#sort-select {
  width: 100%;
}

#search-input:focus,
#sort-select:focus {
  outline: none;
  border-color: #3b82f6;
  border-width: 2px;
  padding: 9px 11px;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

#search-input:focus {
  padding-right: 35px;
}

/* ---- Search spinner (shown immediately on keystroke, hidden when the
   in-flight request settles) ------------------------------------------- */

.search-spinner {
  position: absolute;
  right: 10px;
  width: 16px;
  height: 16px;
  border: 2px solid #dbeafe;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  pointer-events: none;
}

/* ---- Favorites-only checkbox ------------------------------------------ */

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #1a1a1a;
  cursor: pointer;
  min-height: 44px;
  padding: 4px 0;
}

.checkbox-field input[type='checkbox'] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  accent-color: #3b82f6;
  cursor: pointer;
}

.checkbox-field input[type='checkbox']:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* ---- Tag filter pills --------------------------------------------------- */

.tag-filter-container {
  display: flex;
  flex-wrap: wrap;
  margin-top: 12px;
}

.tag-filter-container:empty {
  margin-top: 0;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 4px 4px 4px 0;
  padding: 6px 14px;
  min-height: 44px;
  border-radius: 16px;
  border: 1px solid transparent;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  background-color: #e5e7eb;
  color: #374151;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tag-pill:hover {
  background-color: #d1d5db;
}

.tag-pill:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* #1e40af (not the lighter #3b82f6 brand blue) so the white label text
   clears the 4.5:1 WCAG AA contrast minimum against the pill background. */
.tag-pill.is-active {
  background-color: #1e40af;
  color: #fff;
}

.tag-pill.is-active:hover {
  background-color: #1e3a8a;
}

.clear-filters-btn,
.export-btn {
  min-height: 44px;
  white-space: nowrap;
}

/* ---- Empty-state "clear filters" button (search/filters produced 0 rows) */

.empty-state .clear-filters-btn {
  min-width: 160px;
}

/* ---- Create-recipe form ----------------------------------------------------*/

.create-recipe-section {
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 20px 16px;
  margin-bottom: 20px;
  max-width: 600px;
}

.create-recipe-section h2 {
  margin: 0 0 16px;
  font-size: 18px;
  color: #2c2c2c;
}

#recipe-form {
  display: flex;
  flex-direction: column;
}

.form-group {
  display: flex;
  flex-direction: column;
  padding: 0 0 1rem;
}

.form-group label {
  font-weight: 600;
  color: #2c2c2c;
  margin-bottom: 6px;
  font-size: 14px;
}

.required {
  color: #d32f2f;
}

.form-group input[type='text'],
.form-group textarea {
  padding: 10px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 15px;
  font-family: inherit;
  background-color: #fff;
  color: #2c2c2c;
  min-height: 44px;
  resize: vertical;
}

.form-group textarea {
  min-height: 96px;
}

.form-group input[type='text']:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #0066cc;
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.2);
}

.form-group.has-error input[type='text'],
.form-group.has-error textarea {
  border-color: #d32f2f;
}

.form-group.has-error input[type='text']:focus,
.form-group.has-error textarea:focus {
  box-shadow: 0 0 0 3px rgba(211, 47, 47, 0.2);
}

.error-text {
  min-height: 16px;
  margin-top: 6px;
  font-size: 13px;
  color: #d32f2f;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.form-actions .btn {
  width: 100%;
}

.btn:disabled {
  background-color: #ccc;
  color: #888;
  border-color: #ccc;
  cursor: not-allowed;
}

.btn-secondary:disabled {
  background-color: #fff;
  color: #aaa;
  border-color: #ddd;
}

.success-toast-fixed {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 1100;
  max-width: 420px;
  margin: 0 auto;
}

/* ---- Recipe list -----------------------------------------------------------*/

#recipe-list {
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
  min-height: 120px;
}

.recipe-rows {
  display: flex;
  flex-direction: column;
}

.recipe-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

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

.recipe-row:hover {
  background-color: #f9f9f9;
}

.recipe-row:active {
  background-color: #f0f0f0;
}

.title {
  font-weight: 600;
  color: #0066cc;
  font-size: 16px;
  /* AC-14: titles may be up to 200 characters with no spaces at all
     (app/schemas.py only bounds the length), which would otherwise push the
     row past a 375px viewport and introduce horizontal scrolling. */
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ---- Star-favorite toggle button (list row + detail panel) ----------------*/

.star-favorite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: #999;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease, transform 0.05s ease;
  flex-shrink: 0;
}

.star-favorite:hover:not(:disabled) {
  background-color: rgba(253, 184, 19, 0.12);
  color: #fca311;
}

.star-favorite:active:not(:disabled) {
  transform: scale(0.94);
}

.star-favorite.is-favorite {
  color: #fdb813;
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.15);
}

.star-favorite.is-favorite:hover:not(:disabled) {
  color: #fca311;
}

.star-favorite:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.row-star-favorite {
  order: -1;
}

@media (min-width: 600px) {
  .row-star-favorite {
    order: 0;
  }
}

.detail-star-favorite {
  font-size: 28px;
}

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

.tag {
  display: inline-block;
  background-color: #e8f4f8;
  color: #0066cc;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  border: 1px solid #b3d9e8;
  white-space: nowrap;
}

.created-date {
  font-size: 13px;
  color: #666;
  white-space: nowrap;
}

.ingredients-preview {
  font-size: 13px;
  color: #666;
  /* Same reason as `.title`: a single long ingredient string must wrap
     instead of widening the row (AC-14, 375px viewport). */
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ---- Empty / error states --------------------------------------------------*/

.empty-state {
  text-align: center;
  padding: 56px 24px;
}

.empty-state-icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.empty-state h2 {
  font-size: 20px;
  margin: 0 0 8px;
  color: #2c2c2c;
}

.empty-state p {
  color: #666;
  margin: 0 0 20px;
}

.empty-state.error-state h2 {
  color: #c62828;
}

.btn {
  padding: 10px 22px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.05s ease;
  min-height: 44px;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background-color: #0066cc;
  color: #fff;
}

.btn-primary:hover {
  background-color: #0052a3;
}

.btn-secondary {
  background-color: #fff;
  color: #0066cc;
  border: 1px solid #0066cc;
}

.btn-secondary:hover {
  background-color: #e8f4f8;
}

/* ---- Loading spinner --------------------------------------------------------*/

.spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 56px 24px;
  color: #666;
  font-size: 14px;
}

.spinner-icon {
  width: 28px;
  height: 28px;
  border: 3px solid #ddd;
  border-top-color: #0066cc;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- Pagination --------------------------------------------------------------*/

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.pagination-button {
  padding: 10px 18px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background-color: #fff;
  color: #0066cc;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background-color 0.15s ease;
}

.pagination-button:hover:not(:disabled) {
  background-color: #e8f4f8;
}

.pagination-button:disabled {
  color: #aaa;
  border-color: #e2e2e2;
  cursor: not-allowed;
}

.pagination-status {
  font-size: 14px;
  color: #666;
  white-space: nowrap;
}

/* ---- Recipe detail panel ---------------------------------------------------*/

body.detail-panel-open {
  overflow: hidden;
}

.detail-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 1200;
}

.detail-panel {
  position: fixed;
  inset: 0;
  z-index: 1201;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-panel-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.detail-panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

.detail-panel-header h2 {
  margin: 0;
  font-size: 20px;
  color: #2c2c2c;
  word-break: break-word;
  flex: 1;
}

.detail-close-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 22px;
  line-height: 1;
  color: #666;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  order: -1;
}

.detail-close-btn:hover {
  background-color: #f0f0f0;
  color: #2c2c2c;
}

.detail-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.detail-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 56px 24px;
  color: #666;
  font-size: 14px;
}

.detail-favorite-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  color: #666;
}

.detail-section {
  margin-bottom: 24px;
}

.detail-section h3 {
  margin: 0 0 10px;
  font-size: 15px;
  color: #2c2c2c;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-list {
  margin: 0;
  padding-left: 22px;
  color: #2c2c2c;
  font-size: 15px;
  line-height: 1.7;
}

.detail-list li {
  margin-bottom: 4px;
}

#detail-tags-section .tags {
  gap: 8px;
}

.detail-meta {
  border-top: 1px solid #eee;
  padding-top: 12px;
  margin-top: 8px;
}

.detail-meta p {
  margin: 0 0 4px;
  font-size: 13px;
  color: #666;
}

.detail-panel-actions {
  display: flex;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid #eee;
  flex-shrink: 0;
}

.detail-panel-actions .btn {
  flex: 1;
}

.btn-danger {
  background-color: #fff;
  color: #c62828;
  border: 1px solid #c62828;
}

.btn-danger:hover {
  background-color: #ffebee;
}

/* ---- Unsaved-changes guard modal --------------------------------------------*/

.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1300;
}

.modal-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1301;
  background-color: #fff;
  border-radius: 8px;
  padding: 24px;
  width: min(400px, calc(100% - 32px));
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.modal-dialog h3 {
  margin: 0 0 8px;
  font-size: 18px;
  color: #2c2c2c;
}

.modal-dialog p {
  margin: 0 0 20px;
  color: #555;
  font-size: 14px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
}

.modal-actions .btn {
  width: 100%;
}

@media (min-width: 600px) {
  .modal-actions {
    flex-direction: row;
    justify-content: flex-end;
  }

  .modal-actions .btn {
    width: auto;
    min-width: 110px;
  }
}

/* ---- Delete-confirmation modal ----------------------------------------------*/

.modal-dialog-danger {
  border-top: 4px solid #dc2626;
}

#delete-confirm-recipe-title {
  font-weight: 600;
  color: #1f2937;
  word-break: break-word;
}

.modal-dialog-danger .btn-danger {
  background-color: #dc2626;
  color: #fff;
  border: none;
}

.modal-dialog-danger .btn-danger:hover {
  background-color: #b91c1c;
}

.modal-dialog-danger .btn-danger:disabled {
  background-color: #f3a8a8;
  color: #fff;
  border-color: transparent;
}

/* ---- Row delete button + fade-out ---------------------------------------------*/

.row-delete-btn {
  align-self: flex-start;
  background: none;
  border: 1px solid #c62828;
  color: #c62828;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.row-delete-btn:hover {
  background-color: #ffebee;
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.recipe-row.fading-out {
  animation: fadeOut 0.3s ease-out forwards;
  pointer-events: none;
}

@media (min-width: 600px) {
  .row-delete-btn {
    align-self: center;
    margin-left: auto;
  }
}

/* ---- Toast notifications ------------------------------------------------------*/

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  left: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  max-width: 420px;
  width: 100%;
  animation: toast-slide-in 0.25s ease;
}

.toast-leaving {
  animation: toast-slide-out 0.2s ease forwards;
}

.toast-message {
  flex: 1;
  font-size: 14px;
  line-height: 1.4;
}

.toast-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.toast-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-error {
  background-color: #ffebee;
  color: #c62828;
}

.toast-error .toast-close {
  color: #c62828;
}

.toast-success {
  background-color: #e8f5e9;
  color: #1b5e20;
}

.toast-success .toast-close {
  color: #1b5e20;
}

.toast-info {
  background-color: #e3f2fd;
  color: #0d47a1;
}

.toast-info .toast-close {
  color: #0d47a1;
}

/* #664d00 (not a lighter amber) so warning-toast text clears the 4.5:1
   WCAG AA contrast minimum against the pale-yellow background. */
.toast-warning {
  background-color: #fff8e1;
  color: #664d00;
}

.toast-warning .toast-close {
  color: #664d00;
}

@keyframes toast-slide-in {
  from {
    transform: translateY(-16px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes toast-slide-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

@keyframes detail-slide-in {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

/* ---- Tablet (>= 600px) -----------------------------------------------------*/

@media (min-width: 600px) {
  .search-bar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .create-recipe-section {
    padding: 24px;
  }

  .form-actions {
    flex-direction: row;
  }

  .form-actions .btn {
    width: auto;
  }

  .success-toast-fixed {
    left: auto;
  }

  .detail-panel {
    inset: 0 0 0 auto;
    width: min(480px, 100%);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    animation: detail-slide-in 0.2s ease;
  }

  .detail-panel-actions .btn {
    flex: 0 0 auto;
    min-width: 120px;
  }

  .detail-panel-actions {
    justify-content: flex-end;
  }

  .field-sort {
    min-width: 220px;
  }

  #sort-select {
    width: auto;
  }

  .recipe-row {
    flex-direction: row;
    align-items: center;
    gap: 16px;
  }

  .title {
    flex: 1 1 auto;
    min-width: 140px;
  }

  .tags {
    flex: 0 1 auto;
  }

  .created-date {
    flex-shrink: 0;
  }

  .ingredients-preview {
    flex: 1 1 auto;
    min-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  main {
    padding: 24px;
  }
}

/* ---- Desktop (>= 1024px) ---------------------------------------------------*/

@media (min-width: 1024px) {
  .app-header {
    padding: 24px;
  }

  .app-header h1 {
    font-size: 28px;
  }

  main {
    padding: 24px 32px;
  }

  .recipe-row {
    padding: 14px 24px;
  }
}

/* ---- Reduced motion (AC-14 accessibility) ----------------------------------
   Users who ask their OS to minimize animation get a static UI: the five
   @keyframes animations (spin, fadeOut, toast-slide-in, toast-slide-out,
   detail-slide-in) and all hover/press transitions are reduced to a single
   near-instant step, and programmatic smooth scrolling is disabled (the
   matching JS guard lives in `focusCreateForm()` in app.js, for browsers that
   ignore `scroll-behavior`).

   Animations are collapsed to 0.01ms rather than `none` on purpose: the
   `animationend` event still fires, so row-removal logic that waits for it
   (`fadeAndRemoveRow`) keeps working. `iteration-count: 1` stops the
   otherwise-infinite loading spinner. */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }

  html {
    scroll-behavior: auto;
  }

  /* The spinners convey "loading" through their two-tone border, not their
     rotation, so stopping them outright loses nothing. */
  .spinner-icon,
  .search-spinner {
    animation: none !important;
  }
}
