/* Cookbook web app styles.
   Carries over the look of recipe_manager.py (the read-only viewer) so the
   editing app feels familiar, and adds form / login / widget styles. */

:root {
  --bg: #f5f5f5;
  --ink: #2c3e50;
  --muted: #7f8c8d;
  --accent: #3498db;
  --accent-dark: #2980b9;
  --danger: #e74c3c;
  --ok: #27ae60;
  --card: #ffffff;
  --border: #dddddd;
  --radius: 8px;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 4px 8px rgba(0, 0, 0, 0.15);
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--ink);
}

.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* --- header / nav --- */
.site-header { background-color: var(--ink); color: #fff; }
.site-header__inner {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 14px; padding-bottom: 14px;
}
.site-header__brand { color: #fff; text-decoration: none; font-size: 1.4rem; font-weight: 700; }
.site-nav { display: flex; flex-wrap: wrap; gap: 4px; }
.site-nav a {
  color: #ecf0f1; text-decoration: none; padding: 6px 12px; border-radius: 4px;
}
.site-nav a:hover { background-color: var(--accent); color: #fff; }
.site-nav__logout { color: #f8c9c4; }

.page-title { color: var(--ink); margin: 8px 0 20px; }

/* --- cards --- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  margin-bottom: 20px; box-shadow: var(--shadow);
}

/* --- flash messages --- */
.flashes { margin: 16px 0; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 12px 16px; border-radius: 5px; border-left: 4px solid var(--muted); background: #fff; box-shadow: var(--shadow); }
.flash--error { border-left-color: var(--danger); background: #fdecea; }
.flash--info { border-left-color: var(--accent); background: #eaf4fd; }
.flash--success { border-left-color: var(--ok); background: #eafaf0; }
.flash--warning { border-left-color: #f39c12; background: #fef6e7; }

/* --- buttons --- */
.btn {
  display: inline-block; cursor: pointer; border: 1px solid var(--border);
  background: #fff; color: var(--ink); padding: 9px 16px; border-radius: 5px;
  font-size: 0.95rem; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: #f8f9fa; border-color: var(--accent); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { background: #c0392b; border-color: #c0392b; color: #fff; }
.btn--small { padding: 4px 10px; font-size: 0.85rem; }

/* --- forms --- */
.form { display: flex; flex-direction: column; gap: 6px; max-width: 640px; }
.form__label { font-weight: 600; margin-top: 10px; }
.form__input, .form__textarea, .form__select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 5px; font: inherit; background: #fff;
}
.form__input:focus, .form__textarea:focus, .form__select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}
.form__textarea { min-height: 120px; resize: vertical; }
.form__checkbox { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
.form__hint { color: var(--muted); font-size: 0.85rem; margin: 2px 0 0; }
.form__actions { display: flex; gap: 10px; margin-top: 18px; }

/* --- login --- */
.auth-card {
  background: var(--card); max-width: 380px; margin: 8vh auto 0; padding: 32px;
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.auth-card__title { margin: 0 0 4px; text-align: center; }
.auth-card__subtitle { margin: 0 0 20px; text-align: center; color: var(--muted); }
.auth-card .btn { margin-top: 16px; width: 100%; text-align: center; }

/* --- error page --- */
.error-page { text-align: center; padding: 8vh 20px; }
.error-page__code { font-size: 4rem; font-weight: 700; color: var(--muted); }
.error-page__message { font-size: 1.1rem; margin: 8px 0 24px; }

/* --- dynamic list widget (dynamic_list.js) --- */
.dynamic-list { margin: 6px 0 4px; }
.dynamic-list__rows { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.dynamic-list__row {
  display: flex; align-items: flex-start; gap: 8px; background: #fff;
  border: 1px solid var(--border); border-radius: 5px; padding: 8px;
}
.dynamic-list__row.dragging { opacity: 0.5; }
.dynamic-list__handle { cursor: grab; color: var(--muted); user-select: none; padding: 4px 2px; font-size: 1.1rem; line-height: 1; }
.dynamic-list__row .form__input,
.dynamic-list__row .form__textarea { flex: 1 1 auto; }
.dynamic-list__remove {
  cursor: pointer; border: none; background: transparent; color: var(--danger);
  font-size: 1.3rem; line-height: 1; padding: 0 6px;
}
.dynamic-list__remove:hover { color: #c0392b; }
.dynamic-list__add { margin-top: 8px; }
/* injected touch/keyboard move buttons */
.dynamic-list__move { display: inline-flex; flex-direction: column; gap: 2px; }
.dynamic-list__move button {
  cursor: pointer; border: 1px solid var(--border); background: #fff;
  color: var(--muted); border-radius: 4px; line-height: 1; padding: 1px 5px; font-size: 0.7rem;
}
.dynamic-list__move button:hover { border-color: var(--accent); color: var(--accent); }

/* --- reorderable lists/grids (reorder.js) --- */
[data-reorder] .reorder-item, .reorder-item { cursor: move; }
.reorder-item.dragging { opacity: 0.5; transform: rotate(1deg); }
/* injected touch/keyboard move buttons */
.reorder-controls { display: inline-flex; gap: 4px; margin-right: 10px; vertical-align: middle; }
.reorder-btn {
  cursor: pointer; border: 1px solid var(--border); background: #fff; color: var(--muted);
  border-radius: 4px; line-height: 1; padding: 4px 8px; font-size: 0.8rem;
}
.reorder-btn:hover { border-color: var(--accent); color: var(--accent); }
.reorder-btn:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- auto-save indicator --- */
.autosave-indicator {
  position: fixed; top: 20px; right: 20px; background-color: var(--ok);
  color: #fff; padding: 10px 15px; border-radius: 5px; opacity: 0;
  pointer-events: none; transition: opacity 0.3s; z-index: 1000;
}
.autosave-indicator.show { opacity: 1; }
.autosave-indicator--error { background-color: var(--danger); }

/* === Unit D: recipes (form + detail) === */
.form__req { color: var(--danger); font-weight: 700; }

/* Delete sits below the main form, visually separated. */
.recipe-form__delete { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); max-width: 640px; }

/* Recipe detail (read view) */
.recipe-detail__subtitle { font-size: 1.1rem; color: var(--muted); margin: 0 0 10px; }
.recipe-detail__meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 0 0 16px; color: var(--muted); }
.recipe-detail__category { background: #eaf4fd; color: var(--accent-dark); border-radius: 4px; padding: 2px 10px; font-size: 0.85rem; }
.recipe-detail__person { font-style: italic; }
.recipe-detail .form__actions { margin-top: 0; align-items: center; flex-wrap: wrap; }
.recipe-detail__delete { margin: 0; }
.recipe-detail__ingredients,
.recipe-detail__notes { padding-left: 20px; line-height: 1.6; }
.recipe-detail__instructions { padding-left: 22px; line-height: 1.7; }
.recipe-detail__instructions li { margin-bottom: 8px; }

/* === Unit E: people (index grid + form) === */
.people-actions { margin-bottom: 20px; }

.people-grid {
  list-style: none; padding: 0; margin: 0;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.people-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; transition: box-shadow 0.2s, transform 0.2s;
}
.people-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.people-card__link {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  text-decoration: none; color: var(--ink); padding: 16px 12px; height: 100%;
}
.people-card__photo {
  width: 96px; height: 96px; border-radius: 50%; overflow: hidden;
  background: var(--bg); margin-bottom: 12px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.people-card__photo img { width: 100%; height: 100%; object-fit: cover; }
.people-card__placeholder { font-size: 2.2rem; font-weight: 700; color: var(--muted); }
.people-card__name { font-weight: 600; }
.people-card__nickname { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }

/* person form: current-photo preview + delete block */
.person-form__photo { display: flex; flex-direction: column; gap: 6px; margin: 4px 0; }
.person-form__photo img {
  width: 120px; height: 120px; object-fit: cover; border-radius: var(--radius);
  border: 1px solid var(--border);
}
.person-form__delete {
  margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); max-width: 640px;
}
.person-form__delete-title { font-size: 1.1rem; margin: 0 0 8px; }
.person-form__refs { padding-left: 20px; line-height: 1.6; margin: 8px 0; }
.person-form__delete .form__actions { flex-wrap: wrap; }

/* === Unit F: sections (index + detail) === */
.section-add-card .form { max-width: none; }
.form__input--narrow { max-width: 120px; }
.section-reorder-hint { margin: 4px 0 12px; }

/* Section reorder list (index) */
.section-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.section-item {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
}
.section-item__order {
  flex: 0 0 auto; min-width: 1.6em; height: 1.6em; border-radius: 50%;
  background: var(--bg); color: var(--muted); font-size: 0.85rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; margin-top: 2px;
}
.section-item__body { flex: 1 1 auto; min-width: 0; }
.section-item__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.section-item__title { font-weight: 600; font-size: 1.05rem; text-decoration: none; color: var(--ink); }
.section-item__title:hover { color: var(--accent); }
.section-item__count { color: var(--muted); font-size: 0.85rem; }
.section-item__desc { color: var(--muted); margin: 6px 0 0; }
.section-item__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* Per-section "Manage" disclosure with edit/rename/delete forms */
.section-item__manage { margin-top: 12px; }
.section-item__manage > summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; width: fit-content; }
.section-manage__form { max-width: 480px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.section-manage__delete { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* Section detail */
.section-detail__desc { margin: 0 0 14px; }
.section-detail__actions { margin-top: 0; flex-wrap: wrap; }
.recipe-reorder-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.recipe-reorder-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 5px; box-shadow: var(--shadow); padding: 10px 14px;
}
.recipe-reorder-item__order {
  flex: 0 0 auto; min-width: 1.6em; height: 1.6em; border-radius: 50%;
  background: var(--bg); color: var(--muted); font-size: 0.8rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.recipe-reorder-item__title { flex: 1 1 auto; min-width: 0; }
.recipe-reorder-item__title a { text-decoration: none; color: var(--ink); font-weight: 600; }
.recipe-reorder-item__title a:hover { color: var(--accent); }
.recipe-reorder-item__person { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.recipe-reorder-item__delete { margin: 0; flex: 0 0 auto; }

/* Drag handle (reorder.js drags only from this when present, so the inline
   edit/rename inputs in a row stay text-selectable). Overrides the base
   `.reorder-item { cursor: move }` for rows that opt into a handle. */
.reorder-handle {
  flex: 0 0 auto; cursor: grab; color: var(--muted);
  font-size: 1rem; line-height: 1; padding: 2px 4px; user-select: none;
}
.reorder-handle:active { cursor: grabbing; }
.reorder-item:has(.reorder-handle) { cursor: default; }

/* Collapsible "Add a section" panel (kept below the list, collapsed by default) */
.section-add-details { margin-top: 18px; }
.section-add-summary { cursor: pointer; font-weight: 600; color: var(--accent); width: fit-content; }
.section-add-details[open] .section-add-summary { margin-bottom: 12px; }
.section-add-details .form { max-width: 480px; }

/* === Unit G: PDF generation === */
.pdf-card p { margin: 0 0 12px; }
.pdf-actions { align-items: center; flex-wrap: wrap; gap: 14px; }

/* Disabled/"generating" state for the link-styled generate button. */
.pdf-generate-btn.is-busy {
  opacity: 0.6; pointer-events: none; cursor: progress;
}

.pdf-status {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 0.9rem;
}
.pdf-status[hidden] { display: none; }

.pdf-spinner {
  width: 1em; height: 1em; flex: 0 0 auto;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: pdf-spin 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .pdf-spinner { animation: none; }
}
