:root {
  --bg: #faf7f2;
  --panel: #ffffff;
  --ink: #2a201a;
  --ink-soft: #6b5d52;
  --line: #e7ddd0;
  --accent: #8113e2;
  --accent-hover: #6b0fc0;
  --accent-ink: #ffffff;
  --accent-soft: #f1e5fc;
  --good: #4c7a4c;
  --bad: #b1442e;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

.muted { color: var(--ink-soft); }
.pad { padding: 20px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { height: 58px; width: auto; display: block; flex-shrink: 0; }
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--ink-soft); }

.tabs { display: flex; gap: 6px; }
.tab {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
}
.tab:hover { border-color: var(--accent); }
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.logout-link {
  text-decoration: none; margin-left: 8px; color: var(--ink-soft);
  border-color: transparent; background: transparent;
}
.logout-link:hover { color: var(--bad); border-color: var(--bad); }

/* ---------- Views ---------- */
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; flex-direction: column; }

/* ---------- Lessons ---------- */
.lessons-layout { display: flex; flex: 1; min-height: 0; }
.lessons-list {
  width: 280px; flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
}
.lesson-item {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.lesson-item:hover { background: var(--accent-soft); }
.lesson-item.active { background: var(--accent-soft); border-left: 3px solid var(--accent); }
.lesson-badge {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.lesson-item.active .lesson-badge { background: var(--accent); color: #fff; }
.lesson-title { font-weight: 600; font-size: 14px; }

.lesson-main { flex: 1; padding: 24px; overflow-y: auto; }
.lesson-main video {
  width: 100%; max-width: 980px; max-height: 65vh;
  background: #000; border-radius: var(--radius);
  display: block;
}
.lesson-main h2 { margin: 18px 0 6px; }
.lesson-notes {
  margin-top: 16px; max-width: 980px;
}
.lesson-notes textarea {
  width: 100%; min-height: 120px; padding: 12px; border-radius: var(--radius);
  border: 1px solid var(--line); font-family: inherit; font-size: 14px; resize: vertical;
}
.lesson-notes .save-hint { font-size: 12px; color: var(--ink-soft); margin-top: 6px; }

/* ---------- Panels shared ---------- */
.panel-head {
  display: flex; gap: 10px; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  background: var(--panel); flex-wrap: wrap;
}
.panel-head input[type=search], .panel-head select {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13.5px;
}
.panel-head input[type=search] { flex: 1; min-width: 180px; }

.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13.5px; font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--bad); border-color: var(--bad); background: #fff; }
.btn-danger:hover { background: #fdeeea; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ---------- Recipes ---------- */
.recipes-layout { display: flex; flex: 1; min-height: 0; }
.recipes-list { width: 320px; flex-shrink: 0; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
#recipes-groups { overflow-y: auto; flex: 1; }
.recipe-group-label {
  padding: 10px 16px 4px; font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-soft);
}
.recipe-item {
  padding: 10px 18px; cursor: pointer; font-size: 13.5px; border-left: 3px solid transparent;
}
.recipe-item:hover { background: var(--accent-soft); }
.recipe-item.active { background: var(--accent-soft); border-left-color: var(--accent); font-weight: 700; }

.recipe-main { flex: 1; padding: 22px 26px; overflow-y: auto; }
.recipe-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.recipe-header h2 { margin: 0 0 4px; }
.recipe-header .tag { display: inline-block; background: var(--accent-soft); color: var(--accent); padding: 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; margin-right: 6px; }
.recipe-actions { display: flex; gap: 8px; }

.weight-row { display: flex; align-items: center; gap: 10px; margin: 16px 0; }
.weight-row label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.weight-row input { width: 120px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }

.stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 18px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 16px; min-width: 108px;
}
.stat-card .v { font-size: 18px; font-weight: 700; }
.stat-card .l { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--panel); font-size: 13.5px; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); background: #fdfbf8; position: sticky; top: 0; }
tr.total-row { font-weight: 700; background: var(--accent-soft); }
td.cell-num { text-align: right; font-variant-numeric: tabular-nums; }
td[contenteditable="true"]:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: #fffdf9; }

.item-row .rm-btn { color: var(--bad); cursor: pointer; font-size: 13px; }
.recipe-notes { margin-top: 18px; }
.recipe-notes textarea { width: 100%; min-height: 70px; padding: 10px; border-radius: var(--radius); border: 1px solid var(--line); font-family: inherit; }

.add-item-row { display: flex; gap: 8px; margin: 14px 0; align-items: center; flex-wrap: wrap; }
.add-item-row input { flex: 1; min-width: 200px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.autocomplete { position: relative; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; max-height: 220px; overflow-y: auto; z-index: 30; box-shadow: 0 8px 20px rgba(0,0,0,.08);
}
.autocomplete-list div { padding: 8px 12px; cursor: pointer; font-size: 13.5px; }
.autocomplete-list div:hover { background: var(--accent-soft); }
.autocomplete-list .ac-type { font-size: 10px; text-transform: uppercase; color: var(--ink-soft); margin-left: 6px; }

.msg { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin: 10px 0; }
.msg.err { background: #fdeeea; color: var(--bad); border: 1px solid #f3c9bd; }
.msg.ok { background: #eaf4ea; color: var(--good); border: 1px solid #c8e2c8; }

.field-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.field-row .fg { display: flex; flex-direction: column; gap: 4px; }
.field-row label { font-size: 11px; text-transform: uppercase; color: var(--ink-soft); letter-spacing: .04em; }
.field-row input, .field-row select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13.5px;
}

@media (max-width: 820px) {
  .lessons-layout, .recipes-layout { flex-direction: column; }
  .lessons-list, .recipes-list { width: 100%; max-height: 220px; border-right: none; border-bottom: 1px solid var(--line); }
}
