:root {
  color-scheme: dark;
  --bg: #101415;
  --panel: #191e20;
  --raised: #23292b;
  --raised-2: #292f31;
  --line: rgba(248, 250, 252, 0.14);
  --line-strong: rgba(248, 250, 252, 0.23);
  --cream: #f5f0e7;
  --muted: rgba(248, 250, 252, 0.65);
  --tomato: #df673d;
  --basil: #8aa85f;
  --steel: #447589;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(circle at 0 0, rgba(216, 93, 54, 0.09), transparent 26%),
    var(--bg);
  color: var(--cream);
  font: 14px/1.42 Inter, system-ui, sans-serif;
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.shell { width: min(1500px, 100%); min-height: 100vh; margin: auto; }
.app-view {
  height: 100vh;
  min-height: 680px;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
  overflow: hidden;
}
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 22px; }
.login-card {
  width: min(430px, 100%);
  display: grid;
  gap: 16px;
  padding: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
}
.brand-logo { width: 176px; max-height: 42px; object-fit: contain; object-position: left center; }
.login-card h1 { font-size: 36px; line-height: 1.02; }
.login-card > p:not(.eyebrow, .auth-message) { color: var(--muted); }

.eyebrow {
  color: var(--tomato);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 850; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: #111617;
  color: var(--cream);
}
input:focus, select:focus { border-color: var(--tomato); box-shadow: 0 0 0 3px rgba(216, 93, 54, 0.13); }
input[readonly] { color: var(--muted); background: rgba(255, 255, 255, 0.035); }

.primary-button, .ghost-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  border-radius: 8px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}
.primary-button { border: 1px solid var(--tomato); background: var(--tomato); color: white; }
.primary-button:hover { background: #ed7448; }
.ghost-button { border: 1px solid var(--line); background: rgba(255, 255, 255, 0.025); color: var(--cream); }
.ghost-button:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.065); }

.topbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(23, 18, 17, 0.92);
}
.brand-lockup, .top-actions { display: flex; align-items: center; gap: 12px; color: var(--cream); text-decoration: none; font-weight: 900; }
.top-actions { justify-content: flex-end; }
.topbar .brand-logo { width: 176px; }
.status-pill {
  max-width: 150px;
  overflow: hidden;
  padding: 5px 9px;
  border: 1px solid rgba(138, 168, 95, 0.45);
  border-radius: 999px;
  color: #b7d58a;
  font-size: 10px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-pill.missing { border-color: rgba(223, 103, 61, 0.54); color: #ff9a75; }

.operations-bar {
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(200px, 0.7fr) minmax(320px, 1.4fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.operations-bar h1 { font-size: 20px; line-height: 1.05; }
.global-search { grid-template-columns: auto minmax(0, 1fr); align-items: center; }
.global-search span { padding: 0 4px; }

.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.summary-card {
  min-width: 0;
  min-height: 60px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--steel);
  border-radius: 10px;
  background: var(--panel);
}
.summary-card.basil { border-left-color: var(--basil); }
.summary-card.tomato { border-left-color: var(--tomato); }
.summary-card span, .summary-card small { color: var(--muted); font-size: 11px; font-weight: 800; }
.summary-card strong { grid-row: 1 / 3; grid-column: 2; font-size: 25px; }

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
}
.component-list-panel, .recipe-workspace {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.component-list-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.panel-head, .editor-head, .section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-head { min-height: 54px; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 18px; }
.count-badge {
  min-width: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--raised-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}
.filter-row { display: flex; gap: 5px; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.filter-chip {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}
.filter-chip.active { border-color: rgba(223, 103, 61, 0.45); background: rgba(223, 103, 61, 0.13); color: var(--cream); }
.component-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 8px;
  overflow: auto;
  scrollbar-width: thin;
}
.component-card {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--tone, var(--steel));
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--cream);
  text-align: left;
}
.component-card:hover { background: rgba(255, 255, 255, 0.06); }
.component-card.active { border-color: rgba(223, 103, 61, 0.5); border-left-color: var(--tomato); background: rgba(223, 103, 61, 0.1); }
.component-card > div { min-width: 0; }
.component-card h3 { overflow: hidden; font-size: 15px; line-height: 1.15; overflow-wrap: anywhere; }
.component-card .component-sku { overflow: hidden; color: var(--muted); font: 800 10px/1.2 Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }
.component-card .component-meta { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.component-meta span { min-width: 0; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.component-meta strong { display: block; overflow: hidden; margin-top: 1px; color: var(--cream); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.empty-list { padding: 28px 14px; color: var(--muted); text-align: center; }

.recipe-workspace { position: relative; }
.editor-empty { height: 100%; display: grid; place-content: center; justify-items: center; gap: 6px; padding: 30px; color: var(--muted); text-align: center; }
.editor-empty h2 { color: var(--cream); }
.empty-icon { width: 48px; height: 48px; display: grid; place-items: center; margin-bottom: 5px; border: 1px solid var(--line-strong); border-radius: 12px; color: var(--tomato); font-size: 22px; font-weight: 950; }
.editor-panel { height: 100%; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.editor-head { min-height: 66px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.editor-head > div:first-child { min-width: 0; }
.editor-head h2 { font-size: 21px; }
.editor-head p { max-width: 740px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.title-line, .editor-head-actions { display: flex; align-items: center; gap: 8px; }
.editor-head-actions { justify-content: flex-end; }
#recipeForm { min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; overflow: hidden; }
.recipe-basics {
  display: grid;
  grid-template-columns: minmax(190px, 1.2fr) repeat(3, minmax(120px, 0.7fr));
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.special-fields {
  display: grid;
  grid-template-columns: auto repeat(4, minmax(120px, 1fr));
  align-items: end;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(223, 103, 61, 0.055);
}
.section-label { align-self: center; padding-right: 8px; }
.ingredient-section { min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); overflow: hidden; }
.section-head { min-height: 52px; padding: 8px 14px; }
.section-head h3 { font-size: 17px; }
.recipe-totals { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.recipe-totals span { padding: 5px 8px; border-radius: 6px; background: var(--raised); color: var(--muted); font-size: 10px; }
.recipe-totals strong { margin-left: 3px; color: var(--cream); }
.ingredient-table-head, .ingredient-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.7fr) minmax(100px, 0.55fr) minmax(90px, 0.45fr) 72px 36px;
  gap: 7px;
  align-items: center;
}
.ingredient-table-head { padding: 5px 14px; border-block: 1px solid var(--line); color: var(--muted); font-size: 10px; font-weight: 900; text-transform: uppercase; }
.ingredient-rows { min-height: 0; display: grid; align-content: start; gap: 5px; padding: 7px 14px 12px; overflow: auto; scrollbar-width: thin; }
.ingredient-row { min-width: 0; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 255, 255, 0.025); }
.ingredient-row label { min-width: 0; }
.mobile-label { display: none; }
.ingredient-row input, .ingredient-row select { min-height: 34px; padding-block: 5px; }
.ingredient-ratio { color: var(--muted); font-size: 11px; font-weight: 900; text-align: right; }
.remove-row { width: 34px; min-height: 34px; padding: 0; color: #ff9a75; }
.editor-actions {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  background: rgba(15, 19, 20, 0.96);
}
.editor-actions > div { display: grid; }
.editor-actions span { color: var(--muted); font-size: 10px; }

dialog {
  width: min(560px, calc(100% - 30px));
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--panel);
  color: var(--cream);
  box-shadow: 0 30px 90px #000;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(5px); }
dialog form { display: grid; gap: 15px; }
.dialog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; z-index: 40; right: 18px; bottom: 18px; max-width: 420px; padding: 12px 16px; border: 1px solid var(--line-strong); border-radius: 9px; background: #252c2d; box-shadow: 0 16px 44px #000; font-weight: 800; }
.auth-message { min-height: 20px; color: #ff9a75; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 260px minmax(0, 1fr); }
  .recipe-basics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .special-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-label { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .app-view { height: auto; min-height: 100vh; overflow: visible; }
  .topbar, .operations-bar { grid-template-columns: 1fr; flex-wrap: wrap; }
  .top-actions { flex-wrap: wrap; }
  .operations-bar { display: grid; }
  .global-search { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .workspace { grid-template-columns: 1fr; overflow: visible; }
  .component-list-panel { max-height: 390px; }
  .recipe-workspace { min-height: 620px; }
  .ingredient-table-head { display: none; }
  .ingredient-row { grid-template-columns: 1fr 1fr 70px 36px; }
  .ingredient-row label:first-child { grid-column: 1 / -1; }
  .mobile-label { display: inline; }
}
