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

:root {
  --bg:           #FAFAF8;
  --accent:       #5B7FA6;
  --accent-hover: #4A6D91;
  --accent-faint: rgba(91, 127, 166, 0.07);
  --heading:      #1A1A1A;
  --text:         #555555;
  --text-light:   #999999;
  --border:       #E5E5E2;
  --border-dark:  #C8C8C4;
  --card-bg:      #FFFFFF;
  --input-bg:     #F2F2F0;
  --white:        #FFFFFF;
  --radius:       8px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 1.75rem 1.5rem;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-brand {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.header-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--heading);
  line-height: 1.15;
}

.header-tagline {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-light);
  letter-spacing: 0.01em;
}

/* ── Logout button ── */
.logout-btn {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--border-dark);
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 0.25rem 0;
  transition: color 0.15s, text-decoration-color 0.15s;
  flex-shrink: 0;
}

.logout-btn:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

h1 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--heading);
}

/* ── Auth view toggling ── */
#login-view,
#app-view {
  flex: 1;
  display: flex;
  flex-direction: column;
}

#login-view.hidden,
#app-view.hidden {
  display: none;
}

/* ── Login screen ── */
#login-view {
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  min-height: 100vh;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 1.75rem 2rem;
}

@media (min-width: 480px) {
  .login-card {
    padding: 3rem 2.75rem 2.5rem;
  }
}

.login-header {
  text-align: center;
  margin-bottom: 2.25rem;
}

.login-logo {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--heading);
  margin-bottom: 0.4rem;
}

.login-tagline {
  font-size: 0.875rem;
  color: var(--text-light);
  font-weight: 400;
}

.login-field {
  margin-bottom: 1.1rem;
}

.login-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--heading);
  margin-bottom: 0.45rem;
}

.login-field input {
  width: 100%;
  padding: 0.8rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  color: var(--heading);
  background: var(--input-bg);
  outline: none;
  transition: background 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

.login-field input:focus {
  background: #ECEAE7;
}

.login-field input::placeholder {
  color: var(--text-light);
  font-weight: 300;
}

.login-error {
  font-size: 0.83rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
  line-height: 1.45;
}

.login-submit {
  display: block;
  width: 100%;
  margin-top: 1.5rem;
  padding: 0.875rem;
  background: var(--accent);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  letter-spacing: 0.01em;
}

.login-submit:hover {
  background: var(--accent-hover);
}

.login-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ── Recipe count ── */
.recipe-count {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-bottom: 0.6rem;
  padding: 0 0.2rem;
  min-height: 1em;
}

/* ── Main ── */
main {
  flex: 1;
  padding: 2rem 1.25rem 5rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ── Search ── */
.search-wrap {
  margin-bottom: 1.25rem;
}

#search {
  width: 100%;
  padding: 0.8rem 1.2rem;
  border: none;
  border-radius: 99px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--heading);
  background: var(--input-bg);
  outline: none;
  transition: background 0.15s;
  appearance: none;
}

#search:focus {
  background: #ECEAE7;
}

#search::placeholder {
  color: var(--text-light);
}

/* ── Category pills ── */
.categories-row {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  margin-bottom: 1.5rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.categories-row::-webkit-scrollbar {
  display: none;
}

.cat-pill {
  flex-shrink: 0;
  padding: 0.4rem 0.95rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  line-height: 1;
}

.cat-pill:hover {
  border-color: var(--border-dark);
  color: var(--heading);
}

.cat-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--white);
}

.cat-pill--add {
  border-style: dashed;
  font-size: 1rem;
  font-weight: 300;
  line-height: 1;
  color: var(--text-light);
  padding: 0.4rem 0.65rem;
}

.cat-pill--add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Add category inline row ── */
.add-cat-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: -0.75rem;
  margin-bottom: 1.5rem;
}

.add-cat-input {
  flex: 1;
  max-width: 220px;
  padding: 0.45rem 0.75rem;
  border: 1.5px solid var(--border-dark);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--heading);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s;
}

.add-cat-input:focus {
  border-color: var(--accent);
}

.add-cat-confirm {
  padding: 0.45rem 0.85rem;
  background: var(--accent);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.add-cat-confirm:hover {
  background: var(--accent-hover);
}

.add-cat-cancel {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem;
  transition: color 0.15s;
}

.add-cat-cancel:hover {
  color: var(--heading);
}

/* ── Recipe grid ── */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.875rem;
}

@media (min-width: 640px) {
  .recipe-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.1rem;
  }
}

@media (min-width: 1024px) {
  .recipe-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ── Cards ── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.card:hover,
.card:focus-visible {
  border-color: var(--border-dark);
  outline: none;
}

.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-img-wrap {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--input-bg);
}

.card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}

.card:hover .card-img-wrap img {
  transform: scale(1.03);
}

.card-body {
  padding: 0.75rem 0.875rem 0.875rem;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--heading);
  margin-bottom: 0.5rem;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

@media (min-width: 640px) {
  .card-title {
    font-size: 0.95rem;
  }
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

/* ── Tags ── */
.tag {
  display: inline-block;
  font-size: 0.65rem;
  font-family: inherit;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  background: var(--input-bg);
  color: var(--text-light);
}

/* ── No results ── */
.no-results {
  text-align: center;
  color: var(--text-light);
  padding: 4rem 1rem;
  font-size: 0.95rem;
}

.hidden {
  display: none;
}

/* ── Detail view ── */
.detail-view {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}

.detail-hidden {
  transform: translateX(100%);
}

.detail-visible {
  transform: translateX(0);
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 1.25rem 1.25rem 0;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--text-light);
  cursor: pointer;
  transition: color 0.15s;
  position: sticky;
  top: 0;
  z-index: 10;
}

.back-btn:hover {
  color: var(--heading);
}

.detail-photo-wrap {
  width: 100%;
  height: 260px;
  overflow: hidden;
  background: var(--input-bg);
  margin-top: 1rem;
}

@media (min-width: 640px) {
  .detail-photo-wrap {
    height: 380px;
  }
}

.detail-photo-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.detail-content {
  max-width: 680px;
  margin: 0 auto;
  padding: 2rem 1.25rem 5rem;
}

.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.detail-title {
  font-size: clamp(1.6rem, 5vw, 2.25rem);
  font-weight: 600;
  color: var(--heading);
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 0;
}

.edit-btn {
  flex-shrink: 0;
  align-self: center;
  background: none;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  padding: 0.4rem 0.9rem;
  transition: border-color 0.15s, color 0.15s;
}

.edit-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 2.5rem;
}

.detail-section {
  margin-top: 2.25rem;
}

.detail-section h3 {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-light);
  padding-bottom: 0.75rem;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
}

.ingredients-list {
  list-style: none;
  padding: 0;
}

.ingredients-list li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
}

.steps-list {
  padding-left: 1.5rem;
}

.steps-list li {
  padding: 0.9rem 0;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.8;
  border-bottom: 1px solid var(--border);
}

.steps-list li::marker {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
}

/* ── Floating action button ── */
.fab {
  position: fixed;
  bottom: 1.75rem;
  right: 1.5rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--white);
  font-size: 1.5rem;
  font-weight: 300;
  line-height: 1;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: background 0.15s ease, transform 0.15s ease;
  box-shadow: 0 2px 12px rgba(91, 127, 166, 0.3);
}

.fab:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.fab:active {
  transform: scale(0.95);
}

/* ── Modal overlay ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.modal-open {
  opacity: 1;
  pointer-events: all;
}

/* ── Modal sheet ── */
.modal {
  width: 100%;
  max-height: 92vh;
  background: var(--white);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
    justify-content: center;
  }
  .modal {
    max-width: 520px;
    border-radius: 16px;
    max-height: 90vh;
  }
}

.modal-overlay.modal-open .modal {
  transform: translateY(0);
}

.modal-header {
  position: relative;
  padding: 0.75rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  text-align: center;
}

.modal-handle {
  width: 32px;
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  margin: 0 auto 0.85rem;
}

@media (min-width: 640px) {
  .modal-handle { display: none; }
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--heading);
  letter-spacing: -0.01em;
}

.modal-close {
  position: absolute;
  top: 50%;
  right: 1.25rem;
  transform: translateY(-30%);
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--text-light);
  cursor: pointer;
  padding: 0.3rem;
  line-height: 1;
  border-radius: 50%;
  transition: color 0.15s;
}

.modal-close:hover {
  color: var(--heading);
}

.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.5rem 1.5rem 2.5rem;
  flex: 1;
}

/* ── Form fields ── */
.field {
  margin-bottom: 1.75rem;
}

.field > label:first-child {
  display: block;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--heading);
  margin-bottom: 0.6rem;
  letter-spacing: 0.01em;
}

.req {
  color: var(--accent);
  margin-left: 2px;
}

.field-hint {
  font-weight: 400;
  color: var(--text-light);
  font-size: 0.75rem;
}

.field input[type="text"] {
  width: 100%;
  padding: 0.5rem 0;
  border: none;
  border-bottom: 1.5px solid var(--border);
  border-radius: 0;
  font-size: 1rem;
  font-family: inherit;
  color: var(--heading);
  background: transparent;
  outline: none;
  transition: border-color 0.18s;
}

.field input[type="text"]:focus {
  border-bottom-color: var(--accent);
}

.field input[type="text"]::placeholder {
  color: var(--text-light);
  font-weight: 300;
}

/* Select wrapper for custom arrow */
.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: '';
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23999' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  pointer-events: none;
}

.field select {
  width: 100%;
  padding: 0.5rem 1.5rem 0.5rem 0;
  border: none;
  border-bottom: 1.5px solid var(--border);
  border-radius: 0;
  font-size: 1rem;
  font-family: inherit;
  color: var(--heading);
  background: transparent;
  outline: none;
  appearance: none;
  cursor: pointer;
  transition: border-color 0.18s;
}

.field select:focus {
  border-bottom-color: var(--accent);
}

.field input.invalid,
.field select.invalid {
  border-bottom-color: #D94F3A;
}

.field-error {
  font-size: 0.78rem;
  font-family: inherit;
  color: #D94F3A;
  margin-top: 0.4rem;
}

/* ── File / photo ── */
.file-drop {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border: 1.5px dashed var(--border-dark);
  border-radius: var(--radius);
  background: var(--input-bg);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-light);
  transition: border-color 0.18s, background 0.18s;
}

.file-drop:hover {
  border-color: var(--accent);
  background: var(--accent-faint);
}

.file-icon {
  font-size: 1.1rem;
}

input[type="file"] {
  display: none;
}

.photo-preview {
  display: none;
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-top: 0.75rem;
}

/* ── Dynamic ingredient / step lists ── */
.dyn-list {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin-bottom: 0.5rem;
}

.dyn-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dyn-row input {
  flex: 1;
  padding: 0.5rem 0;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--heading);
  background: transparent;
  outline: none;
  transition: border-color 0.18s;
}

.dyn-row input:focus {
  border-bottom-color: var(--accent);
}

.dyn-row input::placeholder {
  color: var(--text-light);
  font-weight: 300;
}

.remove-row {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--text-light);
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.remove-row:hover {
  background: #E8EEF5;
  color: var(--accent);
}

.add-row-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.35rem 0;
  transition: color 0.15s;
}

.add-row-btn:hover {
  color: var(--accent-hover);
}

/* ── Save button ── */
.save-btn {
  display: block;
  width: 100%;
  margin-top: 2rem;
  padding: 0.9rem;
  background: var(--accent);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  letter-spacing: 0.01em;
}

.save-btn:hover {
  background: var(--accent-hover);
}

.save-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ── Empty state ── */
.empty-state {
  grid-column: 1 / -1;
  padding: 4rem 1rem;
  text-align: center;
}

.empty-state-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.empty-state-sub {
  font-size: 0.85rem;
  color: var(--text-light);
}

/* ── Grid status (loading / error) ── */
.grid-status {
  grid-column: 1 / -1;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-light);
  font-size: 0.95rem;
}

.grid-status--error {
  color: var(--accent);
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-light);
  border-top: 1px solid var(--border);
}
