/*
 * The admin panel's styling: a desktop tool, laid out as one — a fixed sidebar, a topbar, and a
 * main column that uses the width it is given. Dense enough to work with hundreds of recipes,
 * calm enough to write one in.
 */

:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #fbfbfa;
  --border: #e3e5e0;
  --border-strong: #cfd2ca;
  --text: #1c1f1a;
  --text-dim: #6b7166;
  --text-faint: #939a8e;
  --accent: #3f7d4e;
  --accent-dark: #305f3c;
  --accent-soft: #eaf2ec;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --warn: #8a6100;
  --warn-soft: #fdf4e0;
  --ok: #2f6b3f;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(28, 31, 26, 0.06), 0 6px 20px rgba(28, 31, 26, 0.05);
  --sidebar-w: 232px;
  --topbar-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14160f;
    --surface: #1c1f19;
    --surface-2: #22261f;
    --border: #2f342b;
    --border-strong: #454b40;
    --text: #e9ece5;
    --text-dim: #a6ad9f;
    --text-faint: #7c8377;
    --accent: #7bb98c;
    --accent-dark: #a2d3af;
    --accent-soft: #23301f;
    --danger: #f2b8b5;
    --danger-soft: #3a1f1d;
    --warn: #e9c46a;
    --warn-soft: #33290f;
    --ok: #7bb98c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-dark); }

.app-loading { display: grid; place-items: center; height: 100vh; color: var(--text-dim); }

/* ------------------------------------------------------------------ shell */

.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--topbar-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 650;
  letter-spacing: 0.04em;
}

.brand small { color: var(--text-faint); font-weight: 500; letter-spacing: 0; }

.nav { padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }

.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 500;
}

.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-dark); }
.nav .count { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text-faint); }
.nav .section { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-dim); }
.sidebar-foot strong { display: block; color: var(--text); font-weight: 600; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 { font-size: 16px; margin: 0; font-weight: 650; }
.topbar .spacer { flex: 1; }
.topbar .crumb { color: var(--text-faint); }

.content { padding: 20px; max-width: 1500px; width: 100%; }

/* ---------------------------------------------------------------- controls */

button, .btn {
  font: inherit;
  font-weight: 550;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
button.danger { color: var(--danger); border-color: var(--border-strong); }
button.danger:hover { background: var(--danger-soft); }
button.ghost { border-color: transparent; background: transparent; color: var(--text-dim); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.small { padding: 4px 8px; font-size: 12px; }
button.icon { padding: 4px 7px; line-height: 1; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
input[type="checkbox"], input[type="radio"] { width: auto; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 4px; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card > header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.card > header h2 { font-size: 14px; margin: 0; font-weight: 650; }
.card > header .spacer { flex: 1; }
.card .body { padding: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .k { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.stat.accent .n { color: var(--accent-dark); }
.stat.warn .n { color: var(--warn); }

/* ------------------------------------------------------------------ table */

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { flex: 1; min-width: 220px; max-width: 420px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 12px;
  font-weight: 550;
  cursor: pointer;
  color: var(--text-dim);
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }

table { width: 100%; border-collapse: collapse; background: var(--surface); }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 650;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: var(--topbar-h);
  background: var(--surface);
  z-index: 5;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.selected { background: var(--accent-soft); }
td.thumb { width: 56px; padding: 6px 12px; }
td.thumb img, .thumb-empty { width: 46px; height: 36px; border-radius: 4px; object-fit: cover; display: block; background: var(--surface-2); border: 1px solid var(--border); }
.thumb-empty { display: grid; place-items: center; font-size: 15px; color: var(--text-faint); }
td.actions { text-align: right; white-space: nowrap; }
td .title-link { font-weight: 600; color: var(--text); text-decoration: none; }
td .title-link:hover { color: var(--accent-dark); text-decoration: underline; }
td .sub { font-size: 12px; color: var(--text-faint); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 650; }
.badge.published { background: var(--accent-soft); color: var(--accent-dark); }
.badge.draft { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }
.badge.archived { background: var(--warn-soft); color: var(--warn); }
.badge.issues { background: var(--danger-soft); color: var(--danger); }

.pager { display: flex; align-items: center; gap: 10px; padding: 12px 16px; color: var(--text-dim); font-size: 13px; }
.bulkbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--accent-soft); border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 550; color: var(--accent-dark);
}

.empty { padding: 48px 16px; text-align: center; color: var(--text-dim); }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 15px; }

/* ----------------------------------------------------------------- editor */

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.editor-sections { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.editor-aside { position: sticky; top: calc(var(--topbar-h) + 20px); display: flex; flex-direction: column; gap: 16px; }

.section-nav { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 4px; }
.section-nav a { font-size: 12px; padding: 5px 10px; border-radius: 999px; color: var(--text-dim); text-decoration: none; border: 1px solid transparent; }
.section-nav a:hover { background: var(--surface-2); color: var(--text); }

.issue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.issue-list li { display: flex; gap: 8px; font-size: 13px; line-height: 1.35; }
.issue-list li.error { color: var(--danger); }
.issue-list li.warning { color: var(--warn); }
.issue-list .mark { flex: none; }

/* Ingredient rows */
.lines { display: flex; flex-direction: column; gap: 6px; }
.line {
  display: grid;
  grid-template-columns: 22px minmax(140px, 2.2fr) 78px 92px 78px 118px 22px 62px;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.line.dragging { opacity: 0.45; }
.line.over { border-color: var(--accent); }
.line .handle { cursor: grab; color: var(--text-faint); text-align: center; user-select: none; }
.line .warnmark { color: var(--warn); font-size: 12px; }
.line input, .line select { padding: 5px 7px; font-size: 13px; }
.line .name-cell { position: relative; }
.line-head {
  display: grid;
  grid-template-columns: 22px minmax(140px, 2.2fr) 78px 92px 78px 118px 22px 62px;
  gap: 6px;
  padding: 0 6px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 650;
}
.line-extra { padding: 8px 10px 10px 34px; display: grid; gap: 8px; border-left: 2px solid var(--accent-soft); margin: -2px 0 6px 12px; }

/* Ingredient picker */
.picker { position: relative; }
.picker-results {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 3px);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); max-height: 290px; overflow-y: auto;
}
.picker-results button {
  display: block; width: 100%; text-align: left; border: 0; border-radius: 0; background: transparent;
  padding: 7px 10px; font-weight: 500;
}
.picker-results button:hover, .picker-results button.on { background: var(--accent-soft); }
.picker-results .meta { font-size: 11px; color: var(--text-faint); }
.picker-results .create { border-top: 1px solid var(--border); color: var(--accent-dark); font-weight: 600; }
.linked { font-size: 11px; color: var(--ok); }
.unlinked { font-size: 11px; color: var(--warn); }

/* Steps */
.steps { display: flex; flex-direction: column; gap: 10px; }
.step { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); padding: 10px; }
.step.dragging { opacity: 0.45; }
.step > header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.step .num { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 650; flex: none; }
.step .handle { cursor: grab; color: var(--text-faint); }
.step .spacer { flex: 1; }

/* Pick lists (categories, tags, equipment) */
.picklist { display: flex; flex-wrap: wrap; gap: 6px; }
.picklist label {
  margin: 0; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: 12px; font-weight: 550; color: var(--text-dim); cursor: pointer; background: var(--surface);
}
.picklist label:hover { background: var(--surface-2); }
.picklist label.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }
.picklist input { display: none; }
.picklist .group-label { width: 100%; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin: 8px 0 0; }

/* Image upload */
.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 18px;
  text-align: center; color: var(--text-dim); cursor: pointer; background: var(--surface-2);
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.cover-preview { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.cover-preview img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.cover-preview .over-actions { position: absolute; right: 8px; top: 8px; display: flex; gap: 6px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 8px; }
.gallery figure { margin: 0; position: relative; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; }
.gallery button { position: absolute; top: 3px; right: 3px; padding: 1px 6px; font-size: 11px; }

/* Nutrition */
.nutrition-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px 12px; align-items: center; }
.nutrition-grid .head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); font-weight: 650; }
.nutrition-grid .computed { font-variant-numeric: tabular-nums; color: var(--text-dim); }
.nutrition-grid input { text-align: right; font-variant-numeric: tabular-nums; }
.coverage { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.coverage span { display: block; height: 100%; background: var(--accent); }

/* --------------------------------------------------------------- preview */

.preview-phone {
  width: 360px; margin: 0 auto; border: 10px solid #23261f; border-radius: 34px;
  background: var(--surface); overflow: hidden; box-shadow: var(--shadow);
}
.preview-phone .hero { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--surface-2); }
.preview-body { padding: 14px 16px 22px; }
.preview-body h3 { margin: 0 0 4px; font-size: 19px; line-height: 1.25; }
.preview-body .desc { color: var(--text-dim); font-size: 13px; margin: 0 0 12px; }
.preview-facts { display: flex; gap: 14px; padding: 10px 0; border-block: 1px solid var(--border); font-size: 12px; }
.preview-facts div { text-align: center; flex: 1; }
.preview-facts b { display: block; font-size: 14px; }
.preview-list { list-style: none; padding: 0; margin: 10px 0 0; }
.preview-list li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.preview-list li span:last-child { color: var(--text-dim); white-space: nowrap; }
.preview-steps { padding-left: 18px; margin: 8px 0 0; font-size: 13px; line-height: 1.5; }
.preview-steps li { margin-bottom: 8px; }
.preview-steps b { display: block; }

/* --------------------------------------------------------------- overlays */

.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 22, 15, 0.45); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); width: min(560px, 100%); max-height: 88vh; overflow: auto; }
.modal > header { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 650; }
.modal .body { padding: 18px; }
.modal > footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--surface); border: 1px solid var(--border-strong); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 10px 14px; max-width: 380px; font-size: 13px;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

/* ------------------------------------------------------------------ login */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: min(380px, 100%); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: 0.04em; }
.login-card p.sub { color: var(--text-dim); margin: 0 0 20px; font-size: 13px; }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; }

.saving { font-size: 12px; color: var(--text-faint); }
.saving.dirty { color: var(--warn); }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-dim); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.stack { display: flex; flex-direction: column; gap: 12px; }
