/* ================================================================
   recipeDB — Stylesheet
   ================================================================ */

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: #222;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: #fafafa;
}

/* ── Header ────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.2rem;
  background: #2c5f2e;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  z-index: 10;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.app-version {
  font-size: 0.62rem;
  font-weight: 400;
  opacity: 0.55;
  letter-spacing: normal;
  margin-left: 0.5rem;
  vertical-align: middle;
}

#btn-new-recipe,
#btn-import-recipe,
#btn-logout {
  background: #fff;
  color: #2c5f2e;
  border: none;
  padding: 0.35rem 0.9rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}

#btn-new-recipe:hover,
#btn-import-recipe:hover,
#btn-logout:hover { background: #e8f5e9; }

#btn-import-recipe:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#btn-login {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.6);
  padding: 0.35rem 0.9rem;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
#btn-login:hover { background: rgba(255,255,255,0.15); border-color: #fff; }

/* ── App layout ─────────────────────────────────────────────────── */
#app {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
#sidebar {
  width: 230px;
  min-width: 180px;
  border-right: 1px solid #ddd;
  overflow-y: auto;
  background: #fff;
  flex-shrink: 0;
}

/* ── Sidebar search ──────────────────────────────────────────────── */
#sidebar-search-wrap {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #eee;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

#sidebar-search {
  width: 100%;
  padding: 0.3rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.85rem;
  background: #fff;
}

#sidebar-search:focus {
  outline: none;
  border-color: #2c5f2e;
  box-shadow: 0 0 0 2px rgba(44,95,46,0.15);
}

.cat-group { border-bottom: 1px solid #eee; }

.cat-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  color: #2c5f2e;
  user-select: none;
  background: #f5f5f5;
  transition: background 0.1s;
}

.cat-header:hover { background: #e8f5e9; }

.cat-arrow {
  font-size: 0.7rem;
  transition: transform 0.15s ease;
  display: inline-block;
}

.cat-header.open .cat-arrow { transform: rotate(90deg); }

.cat-name { flex: 1; }

.cat-count {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 400;
  color: #888;
  background: #e8e8e8;
  border-radius: 10px;
  padding: 0.05rem 0.45rem;
  min-width: 1.2rem;
  text-align: center;
  flex-shrink: 0;
}

.cat-recipes { display: none; }
.cat-recipes.open { display: block; }

.cat-recipes a {
  display: block;
  padding: 0.3rem 0.9rem 0.3rem 1.8rem;
  color: #333;
  text-decoration: none;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}

.cat-recipes a:hover { background: #f0f8f0; }

.cat-recipes a.active {
  background: #e8f5e9;
  border-left-color: #2c5f2e;
  font-weight: 600;
  color: #1b3e1c;
}

/* ── Main content area ───────────────────────────────────────────── */
#main-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.4rem 2rem;
  background: #fafafa;
}

#welcome-msg {
  color: #888;
  margin-top: 2rem;
  font-size: 0.95rem;
}

/* ── Utility ─────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid #bbb;
  border-radius: 4px;
  font-size: 0.88rem;
  cursor: pointer;
  background: #f5f5f5;
  color: #333;
  transition: background 0.1s, border-color 0.1s;
}

.btn:hover { background: #eaeaea; }

.btn-primary {
  background: #2c5f2e;
  color: #fff;
  border-color: #2c5f2e;
}

.btn-primary:hover { background: #1e4420; }

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

.btn-danger:hover { background: #9b1d1d; }

/* ── Recipe view ─────────────────────────────────────────────────── */
.recipe-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

#recipe-view h2 {
  font-size: 1.4rem;
  margin-bottom: 0.2rem;
}

.recipe-meta {
  font-size: 0.88rem;
  color: #666;
  margin-bottom: 1.2rem;
}

/* Ingredient table */
.recipe-table {
  border-collapse: collapse;
  margin-bottom: 0.6rem;
}

.recipe-table td {
  padding: 0.1rem 0.6rem 0.1rem 0;
  vertical-align: top;
}

.recipe-table td:first-child {
  text-align: right;
  white-space: nowrap;
  min-width: 3rem;
  color: #444;
}

.recipe-table td:nth-child(2) {
  white-space: nowrap;
  color: #444;
  min-width: 2.5rem;
}

.recipe-table td:nth-child(3) {
  font-weight: 500;
}

.recipe-table td:nth-child(4) {
  color: #555;
  max-width: 38rem;
}

/* Text rows (instructions / section headers) */
.text-row {
  margin: 0.6rem 0;
  line-height: 1.6;
  max-width: 60rem;
}

.text-row.section-header {
  font-weight: 700;
  margin-top: 1rem;
  margin-bottom: 0.2rem;
  color: #1b3e1c;
}

/* ── Recipe form ─────────────────────────────────────────────────── */
#recipe-form h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  color: #2c5f2e;
}

.form-field {
  margin-bottom: 0.8rem;
}

.form-field label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
  color: #444;
}

.form-field input,
.form-field select {
  width: 100%;
  max-width: 400px;
  padding: 0.4rem 0.6rem;
  border: 1px solid #bbb;
  border-radius: 4px;
  font-size: 0.95rem;
  background: #fff;
  transition: border-color 0.15s;
}

.form-field input:focus,
.form-field select:focus {
  outline: none;
  border-color: #2c5f2e;
  box-shadow: 0 0 0 2px rgba(44,95,46,0.15);
}

/* ── Row preview list ────────────────────────────────────────────── */
#rows-preview {
  margin: 0.8rem 0;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  min-height: 2rem;
  max-height: 40vh;
  overflow-y: auto;
}

#rows-preview:empty::after {
  content: 'Noch keine Zutaten/Schritte eingegeben.';
  display: block;
  padding: 0.6rem 0.8rem;
  color: #aaa;
  font-size: 0.85rem;
  font-style: italic;
}

.preview-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.88rem;
}

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

.row-badge {
  font-size: 0.72rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.row-badge.ingredient { background: #e3f2fd; color: #1565c0; }
.row-badge.text       { background: #f3e5f5; color: #6a1b9a; }
.row-badge.header     { background: #fff8e1; color: #e65100; }

.preview-row-content { flex: 1; color: #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-actions {
  display: flex;
  align-items: center;
  gap: 0.05rem;
  margin-left: auto;
  flex-shrink: 0;
}

.btn-sort-row,
.btn-edit-row,
.btn-del-row {
  border: none;
  background: none;
  cursor: pointer;
  color: #bbb;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0.1rem 0.25rem;
  flex-shrink: 0;
  transition: color 0.1s;
}

.btn-sort-row:hover:not(:disabled) { color: #2c5f2e; }
.btn-sort-row:disabled { opacity: 0.25; cursor: default; }

.btn-edit-row:hover { color: #1565c0; }

.btn-del-row { font-size: 1rem; }
.btn-del-row:hover { color: #c62828; }

/* ── Inline row editing ──────────────────────────────────────────── */
.row-inline-edit {
  display: flex;
  flex: 1;
  gap: 0.3rem;
  align-items: center;
  min-width: 0;
}

.row-inline-edit input {
  padding: 0.15rem 0.35rem;
  border: 1px solid #2c5f2e;
  border-radius: 3px;
  font-size: 0.85rem;
  background: #f0f8f0;
  min-width: 0;
}

.row-inline-edit input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(44,95,46,0.2);
}

.row-inline-edit input[data-field="amount"]          { width: 4rem;  flex-shrink: 0; }
.row-inline-edit input[data-field="unit"]            { width: 4rem;  flex-shrink: 0; }
.row-inline-edit input[data-field="ingredient_name"] { flex: 1; }
.row-inline-edit input[data-field="instruction"]     { flex: 1; }
.row-inline-edit input[data-field="text_content"]    { flex: 1; }

.btn-confirm-edit {
  border: none;
  background: none;
  cursor: pointer;
  color: #2c5f2e;
  font-size: 1rem;
  padding: 0.1rem 0.25rem;
  flex-shrink: 0;
  transition: color 0.1s;
}
.btn-confirm-edit:hover { color: #1b3e1c; }

/* ── Import status panel ─────────────────────────────────────────── */
#import-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 4rem 2rem;
  text-align: center;
  color: #444;
}

.import-spinner {
  width: 2.8rem;
  height: 2.8rem;
  border: 3px solid #e0e0e0;
  border-top-color: #2c5f2e;
  border-radius: 50%;
  animation: import-spin 0.75s linear infinite;
}

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

.import-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #2c5f2e;
}

.import-filename {
  font-size: 0.82rem;
  color: #999;
  max-width: 28rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.import-progress-wrap {
  width: 22rem;
  max-width: 90%;
  height: 6px;
  background: #e8e8e8;
  border-radius: 3px;
  overflow: hidden;
}

.import-progress-bar {
  height: 100%;
  width: 0;
  background: #2c5f2e;
  border-radius: 3px;
  /* slow deceleration: reaches ~85% over 50s, then stalls */
  transition: width 50s cubic-bezier(0.05, 0.4, 0.4, 1);
}

.import-steps {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 18rem;
  max-width: 90%;
  text-align: left;
}

.import-step {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.88rem;
  color: #ccc;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.import-step-icon {
  width: 1rem;
  text-align: center;
  flex-shrink: 0;
}

.import-step[data-state="pending"] .import-step-icon::before { content: '○'; color: #ddd; }

.import-step[data-state="active"] {
  color: #2c5f2e;
  font-weight: 600;
  background: #f0f8f0;
}
.import-step[data-state="active"] .import-step-icon::before { content: '▶'; font-size: 0.7rem; }

.import-step[data-state="done"] { color: #aaa; }
.import-step[data-state="done"] .import-step-icon::before { content: '✓'; color: #2c5f2e; font-weight: 700; }

.import-page-info {
  font-size: 0.85rem;
  color: #888;
  font-weight: 600;
}

.import-elapsed {
  font-size: 0.78rem;
  color: #bbb;
  font-variant-numeric: tabular-nums;
}

/* ── Keyboard input area ─────────────────────────────────────────── */
.input-section {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
}

.input-section h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: #2c5f2e;
  margin-bottom: 0.7rem;
}

.ingredient-inputs {
  display: grid;
  grid-template-columns: 80px 80px 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.text-inputs {
  display: grid;
  grid-template-columns: 1fr;
  margin-bottom: 0.4rem;
}

.input-field-wrap input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid #bbb;
  border-radius: 4px;
  font-size: 0.9rem;
  background: #fff;
}

.input-field-wrap input:focus {
  outline: none;
  border-color: #2c5f2e;
  box-shadow: 0 0 0 2px rgba(44,95,46,0.15);
}

.input-field-wrap input.active-field {
  border-color: #2c5f2e;
  background: #f0f8f0;
}

.input-label {
  display: block;
  font-size: 0.72rem;
  color: #888;
  margin-bottom: 0.15rem;
}

.input-hint {
  font-size: 0.78rem;
  color: #999;
  margin-top: 0.4rem;
}

.input-hint kbd {
  background: #eee;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  font-family: monospace;
  font-size: 0.78rem;
}

/* ── Form actions ────────────────────────────────────────────────── */
.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  position: sticky;
  bottom: 0;
  background: #fafafa;
  padding: 0.75rem 0;
  border-top: 1px solid #e0e0e0;
  z-index: 1;
}

hr.form-divider {
  border: none;
  border-top: 1px solid #e0e0e0;
  margin: 1.2rem 0;
}

/* ── Login modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-box {
  background: #fff;
  border-radius: 8px;
  padding: 2rem;
  width: 22rem;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-box h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #2c5f2e;
}

.modal-box input[type="password"] {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}

.modal-box input[type="password"]:focus {
  outline: none;
  border-color: #2c5f2e;
  box-shadow: 0 0 0 2px rgba(44,95,46,0.15);
}

.login-error {
  color: #c0392b;
  font-size: 0.88rem;
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

.btn-secondary {
  background: #f0f0f0;
  color: #444;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: #e0e0e0; }

/* ── Servings scaler ─────────────────────────────────────────────── */
.servings-input {
  width: 3.2rem;
  padding: 0.1rem 0.3rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 0.88rem;
  text-align: center;
  color: #444;
  background: #fff;
  vertical-align: middle;
}

.servings-input:focus {
  outline: none;
  border-color: #2c5f2e;
  box-shadow: 0 0 0 2px rgba(44,95,46,0.15);
}

.btn-servings-reset {
  border: none;
  background: none;
  cursor: pointer;
  color: #aaa;
  font-size: 1rem;
  padding: 0 0.2rem;
  vertical-align: middle;
  transition: color 0.1s;
}

.btn-servings-reset:hover { color: #2c5f2e; }

/* ── Search highlight ────────────────────────────────────────────── */
mark.search-highlight {
  background: #fff176;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Share toast ─────────────────────────────────────────────────── */
.share-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(0.5rem);
  background: #333;
  color: #fff;
  padding: 0.5rem 1.2rem;
  border-radius: 20px;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}

.share-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Hamburger button (desktop: hidden) ──────────────────────────── */
.btn-menu {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.3rem;
  flex-shrink: 0;
}

/* ── Sidebar backdrop ────────────────────────────────────────────── */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
}

#sidebar-backdrop.visible { display: block; }

/* ── Mobile layout ───────────────────────────────────────────────── */
@media (max-width: 640px) {

  /* Header --------------------------------------------------------- */
  .btn-menu { display: block; }
  .app-version { display: none; }

  header { padding: 0.4rem 0.6rem; gap: 0.3rem; }
  header h1 { font-size: 1rem; flex: 1; }

  /* Icon-only buttons on mobile — hide text labels, keep all buttons visible */
  .btn-label { display: none; }

  #btn-import-recipe,
  #btn-new-recipe,
  #btn-logout { padding: 0.25rem 0.5rem; font-size: 0.82rem; }
  #btn-login  { padding: 0.25rem 0.5rem; font-size: 0.82rem; }

  /* App layout ----------------------------------------------------- */
  /* #app is the flex container that fills the remaining viewport.
     Position it relatively so the absolute sidebar is clipped inside. */
  #app { position: relative; overflow: hidden; }

  /* Sidebar becomes a slide-in drawer within #app (below the header) */
  #sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80vw;
    max-width: 300px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 3px 0 16px rgba(0,0,0,0.2);
  }

  #sidebar.open { transform: translateX(0); }

  /* Main area takes full width */
  #main-area { padding: 1rem; }

  /* Recipe view ---------------------------------------------------- */
  .recipe-actions { flex-wrap: wrap; }

  .recipe-table { width: 100%; }
  .recipe-table td { font-size: 0.88rem; padding: 0.2rem 0.4rem 0.2rem 0; }

  /* Servings input row: keep on one line */
  .recipe-meta { font-size: 0.85rem; }
}
