:root {
  color-scheme: light;
  --canvas: #eef2f7;
  --canvas-accent: #dbeafe;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-muted: #f1f5f9;
  --text: #172033;
  --text-soft: #5f6c82;
  --text-faint: #8b97aa;
  --border: #dfe6ef;
  --border-strong: #c8d3e1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eaf1ff;
  --profit: #b91c1c;
  --loss: #15803d;
  --warning: #b45309;
  --violet: #7c3aed;
  --shadow-sm: 0 2px 8px rgba(23, 32, 51, 0.04);
  --shadow-md: 0 14px 38px rgba(31, 48, 78, 0.08);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0a0f16;
  --surface: #111821;
  --surface-soft: #151e29;
  --surface-muted: #1b2633;
  --text: #e7edf7;
  --text-soft: #aab5c5;
  --text-faint: #7d8ca1;
  --border: #273241;
  --border-strong: #3a495e;
  --primary: #7da8ff;
  --primary-hover: #a5c1ff;
  --primary-soft: #172844;
  --profit: #ff7b83;
  --loss: #58d39f;
  --warning: #f7c45b;
  --violet: #c4a7ff;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 14px 38px rgba(0, 0, 0, 0.28);
}

.recipe-topnav,
.recipe-topnav *,
.recipe-topnav *::before,
.recipe-topnav *::after,
.page-main,
.page-main *,
.page-main *::before,
.page-main *::after,
.app-toast {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
  -webkit-text-size-adjust: 100%;
}

body {
  position: relative;
  min-height: 100vh;
  margin: 0;
  padding: 0 0 4px;
  overflow-x: hidden;
  color: var(--text);
  background: #f3f5f7;
  font-family: "Segoe UI", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  font-size: calc(15px + 2px);
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  -webkit-tap-highlight-color: transparent;
}

.recipe-topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  width: min(calc(100% - 32px), 1260px);
  margin: 16px auto;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.recipe-nav-inner {
  display: flex;
  min-height: 50px;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  padding: 8px 10px;
}

.recipe-nav-brand {
  padding: 5px 10px;
  color: var(--text);
  font-size: calc(0.78rem + 5px);
  font-weight: 780;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.recipe-nav-section {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
}

.recipe-nav-professions {
  min-width: 0;
  flex: 1 1 auto;
}

.side-nav-label {
  padding: 5px 7px;
  color: var(--text-faint);
  font-size: calc(0.62rem + 7px);
  font-weight: 700;
  white-space: nowrap;
  color: #ef654f;
}

.side-nav-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 9px;
  color: var(--text-soft);
  border-radius: 7px;
  font-size: calc(0.7rem + 5px);
  font-weight: 600;
  line-height: 1.35;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.16s ease, background 0.16s ease;
}

.side-nav-group {
  position: relative;
  display: inline-flex;
}

.side-nav-parent {
  display: flex;
  width: auto;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  text-align: left;
  cursor: pointer;
  appearance: none;
  background: transparent;
  border: 0;
}

.side-nav-chevron {
  display: inline-flex;
  width: 10px;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: calc(0.58rem + 5px);
  line-height: 1;
  transition: color 0.16s ease, transform 0.16s ease;
}

.side-nav-group.is-open .side-nav-chevron {
  color: var(--primary);
  transform: rotate(180deg);
}

.side-nav-submenu {
  position: absolute;
  top: 100%;
  left: 50%;
  z-index: 60;
  width: min(420px, calc(100vw - 20px));
  padding-top: 8px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, -6px);
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
}

.side-nav-group.is-open .side-nav-submenu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.side-nav-submenu-panel {
  display: grid;
  max-height: min(70vh, 440px);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  padding: 10px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  scrollbar-width: thin;
}

.side-nav-child {
  width: 100%;
  white-space: normal;
}

.side-nav-link:hover {
  color: var(--primary);
  background: var(--surface-soft);
}

.side-nav-link.is-active {
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 750;
}

.side-nav-divider {
  width: 1px;
  height: 22px;
  margin: 0 5px;
  background: var(--border);
}

.container {
  display: block;
  width: min(100%, 1260px);
  margin: 0 auto;
}

.page-main .container > .page-header {
  margin: 0 0 8px;
  background: transparent;
}

.page-main .container > .subtitle {
  margin: 0 0 20px;
  background: rgba(255, 255, 255, 0.7);
}

.page-main .container > .progress-bar {
  margin: 0;
  background: #dce5f0;
}

.page-main .container > #recipeList {
  margin: 0;
  background: transparent;
}

.page-main {
  padding: 4px 16px 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
  background: transparent;
}

h1 {
  margin: 0 0 8px;
  color: #111827;
  font-size: calc(clamp(1.45rem, 2.2vw, 2rem) + 2px);
  font-weight: 750;
  letter-spacing: -0.025em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.page-header h1 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
}

.subtitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 14px 0 14px 16px;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(223, 230, 239, 0.9);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
}

#subtitleText {
  flex: 1 1 420px;
  min-width: 0;
  font-size: calc(0.88rem + 2px);
}

.progress-bar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 100;
  height: 6px;
  margin: 0;
  overflow: hidden;
  display: none;
  pointer-events: none;
  background: #dce5f0;
  border-radius: 0;
  box-shadow: 0 1px 8px rgba(23, 32, 51, 0.18);
}

.progress-bar .bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #60a5fa);
  border-radius: inherit;
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.45);
  transition: width 0.2s ease;
}

.recipe-row {
  position: relative;
  display: grid;
  grid-template-columns: 272px 760px 196px;
  gap: 0;
  align-items: stretch;
  margin-bottom: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: none;
  transition: border-color 0.2s ease;
}

.recipe-row:hover {
  border-color: #c5cfdb;
}

.row-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 14px;
}

.favorite-action {
  appearance: none;
  padding: 0;
  color: var(--text-soft);
  background: transparent;
  border: 0;
  font-size: calc(0.75rem + 2px);
  font-weight: 650;
  line-height: 1.35;
  white-space: nowrap;
  cursor: pointer;
  margin-right: 26px;
}

.favorite-action:hover {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.favorite-action:disabled {
  color: var(--text-faint);
  cursor: not-allowed;
  text-decoration: none;
}

.scan-btn {
  position: static;
  z-index: 3;
  min-height: 32px;
  padding: 6px 12px;
  color: #334155;
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  box-shadow: none;
  font-size: calc(0.75rem + 2px);
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.scan-btn:hover {
  color: var(--primary);
  background: #f8fafc;
  border-color: #91ade0;
  transform: none;
}

.scan-btn:active {
  transform: translateY(0);
}

.scan-btn:disabled {
  color: var(--text-faint);
  background: #f8fafc;
  border-color: var(--border);
  cursor: wait;
  transform: none;
}

.output-block {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0;
  padding: 0 18px 0 0;
  border-right: 1px solid var(--border);
}

.slot-label,
.profit-label,
.yield-label {
  color: var(--text-faint);
  font-size: calc(0.68rem + 2px);
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}

.output-product {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.output-summary {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  min-width: 0;
  align-items: start;
  gap: 10px;
}

.item-icon {
  position: relative;
  display: inline-flex;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--text-faint);
  background: #f3f5f7;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

.item-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.item-icon.is-empty::after,
.item-icon.is-missing::after {
  content: "?";
  color: #9aa5b5;
  font-size: calc(0.72rem + 2px);
  font-weight: 700;
}

.output-item-icon {
  flex-basis: 42px;
  width: 42px;
  height: 42px;
  border-radius: 8px;
}

.quality-select,
.reagent-inline select {
  min-width: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.quality-select {
  width: 100%;
  max-width: 100%;
  padding: 6px 8px;
  font-size: calc(0.78rem + 2px);
}

.quality-select:hover,
.quality-select:focus,
.reagent-inline select:hover,
.reagent-inline select:focus {
  background: #ffffff;
  border-color: #7fa7ef;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.output-name {
  min-width: 0;
  color: var(--text);
  font-size: calc(0.92rem + 2px);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.output-name .item-id {
  display: block;
  margin-top: 1px;
  margin-left: 0;
}

.item-id {
  color: var(--text-faint);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: calc(0.64rem + 2px);
  font-weight: 400;
  letter-spacing: 0.02em;
}

.output-meta-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.field-label,
.unit-label {
  color: var(--text-faint);
  font-size: calc(0.68rem + 2px);
  font-weight: 650;
  white-space: nowrap;
}

.quality-value {
  color: #3f4b5f;
  font-size: calc(0.8rem + 2px);
  font-weight: 650;
}

.output-price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.price-line {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 92px;
  color: var(--text);
  font-size: calc(0.9rem + 2px);
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.price-editable {
  border-radius: 4px;
  cursor: pointer;
  text-decoration: underline dotted transparent;
  text-underline-offset: 3px;
  transition: color 0.16s ease, text-decoration-color 0.16s ease;
}

.price-editable:hover,
.price-editable:focus-visible {
  color: var(--primary);
  text-decoration-color: currentColor;
}

.price-editable:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.price-line.manual .price-display,
.reagent-inline.manual .subtotal,
.mix-option-inline.manual .subtotal,
.mix-price-item.manual .subtotal {
  color: var(--warning);
}

.edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  color: #6b778c;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font-size: calc(0.72rem + 2px);
  line-height: 1;
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.edit-btn:hover {
  color: var(--primary);
  background: #ffffff;
  border-color: #8cb0ef;
}

.edit-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.price-input,
.yield-input {
  color: var(--text);
  background: #ffffff;
  border: 1px solid #6d9bea;
  border-radius: 7px;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  font-size: calc(0.8rem + 2px);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  outline: none;
}

.price-input {
  width: 78px;
  padding: 4px 6px;
}

.yield-input {
  width: 64px;
  padding: 3px 6px;
  color: var(--violet);
  border-color: #a78bfa;
  text-align: left;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.yield-line {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.yield-line .yield-value {
  min-width: 32px;
  color: var(--violet);
  font-size: calc(0.9rem + 2px);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: right;
}

.yield-line .edit-btn:hover {
  color: var(--violet);
  border-color: #b69aef;
}

.middle-area {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0;
  padding: 0 18px;
  border-right: 1px solid var(--border);
}

.column-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 9px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  font-size: calc(0.68rem + 2px);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.reagents-group {
  display: flex;
  width: 100%;
  flex-direction: column;
}

.mix-slot-heading {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  padding: 0;
  color: var(--text);
  font-size: calc(0.67rem + 2px);
  font-weight: 700;
  white-space: nowrap;
}

.mix-row .mix-slot-heading .reagent-item-icon {
  opacity: 1;
  filter: none;
}

.mix-optional-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-faint);
  white-space: nowrap;
  cursor: pointer;
}

.mix-optional-toggle input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.mix-options-inline {
  display: grid;
  grid-template-columns: repeat(2, 120px);
  flex: 0 0 250px;
  width: 250px;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.mix-option-inline {
  position: relative;
  display: grid;
  grid-template-columns: 30px 10px 44px 16px;
  width: 100%;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  white-space: nowrap;
}

.mix-option-inline + .mix-option-inline::before {
  position: absolute;
  top: 50%;
  left: -10px;
  content: "+";
  color: var(--text-faint);
  font-weight: 700;
  transform: translate(-50%, -50%);
}

.mix-option-inline.disabled {
  opacity: 0.55;
}

.mix-prices-inline {
  display: grid;
  grid-template-columns: repeat(2, 90px);
  flex: 0 0 190px;
  align-items: center;
  width: 190px;
  gap: 10px;
  margin-left: 10px;
}

.mix-price-item {
  display: flex;
  justify-content: flex-end;
  width: 90px;
  align-items: center;
  overflow: hidden;
}

.mix-price-item.disabled {
  opacity: 0.55;
}

.mix-level {
  min-width: 30px;
  color: var(--text-soft);
  font-size: calc(0.64rem + 2px);
  font-weight: 700;
  white-space: nowrap;
}

.reagent-inline {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #edf0f4;
  border-radius: 0;
  transition: opacity 0.16s ease;
}

.reagent-item-icon {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  margin-left: 0;
}

.reagent-inline:hover {
  background: transparent;
}

.reagent-inline.optional {
  border-left: 0;
}

.reagent-inline.disabled {
  opacity: 0.58;
}

.reagent-inline .slot-label {
  color: var(--text-faint);
  font-size: calc(0.66rem + 2px);
  letter-spacing: 0;
  text-transform: none;
}

.dropdown-selected-name {
  flex: 0 1 150px;
  min-width: 56px;
  overflow: hidden;
  color: var(--text);
  font-size: calc(0.73rem + 2px);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reagent-inline select {
  flex: 1 1 180px;
  max-width: 100%;
  padding: 5px 7px;
  font-size: calc(0.73rem + 2px);
}

.item-stack {
  display: flex;
  min-width: 0;
  max-width: none;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 1px;
}

.item-stack .item-name {
  max-width: none;
  overflow: hidden;
  color: var(--text);
  font-size: calc(0.77rem + 2px);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-stack .item-id {
  max-width: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reagent-inline input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0 1px;
  accent-color: var(--primary);
  cursor: pointer;
}

.reagent-inline .qty {
  min-width: 22px;
  color: #536173;
  font-size: calc(0.74rem + 2px);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

.material-qty-field {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
  color: var(--text-faint);
  font-size: calc(0.66rem + 2px);
  white-space: nowrap;
}

.material-qty-input {
  width: 54px;
  min-height: 30px;
  padding: 4px 5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font-size: calc(0.73rem + 2px);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: center;
  outline: none;
}

.material-qty-input:hover,
.material-qty-input:focus {
  background: var(--surface-muted);
  border-color: var(--primary);
}

.material-qty-unit {
  font-size: calc(0.64rem + 2px);
}

.material-qty-mark {
  color: var(--text-faint);
  font-size: calc(0.64rem + 2px);
}

.mix-option-inline .material-qty-field {
  gap: 2px;
}

.mix-option-inline .material-qty-input {
  width: 44px;
  min-height: 28px;
  padding: 3px 4px;
}

.mix-price-item .subtotal-wrap {
  flex: 0 0 56px;
  width: 56px;
  min-width: 56px;
  justify-content: flex-end;
}

.subtotal-wrap {
  display: flex;
  flex: 0 0 214px;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-width: 0;
}

.reagent-inline .subtotal {
  min-width: 72px;
  color: #334155;
  font-size: calc(0.76rem + 2px);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
}

.mix-price-item .subtotal {
  width: 100%;
  min-width: 0;
  overflow: hidden;
  font-size: calc(0.68rem + 2px);
  text-overflow: ellipsis;
}

.mix-price-item .price-input {
  width: 56px;
  padding: 3px 4px;
}

.reagent-inline .edit-btn {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  font-size: calc(0.65rem + 2px);
}

.reagent-inline .price-input {
  width: 78px;
  padding: 3px 5px;
  font-size: calc(0.73rem + 2px);
}

.profit-block {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 42px 0 0 18px;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.profit-metrics {
  display: flex;
  flex-direction: column;
}

.profit-item {
  display: flex;
  min-width: 0;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #edf0f4;
  border-radius: 0;
}

.profit-label {
  color: var(--text-faint);
  font-size: calc(0.68rem + 2px);
  letter-spacing: 0.04em;
}

.profit-value {
  overflow: hidden;
  color: var(--text);
  font-size: calc(clamp(0.8rem, 0.9vw, 0.92rem) + 2px);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profit-value.red {
  color: var(--profit);
}

.profit-value.green {
  color: var(--loss);
}

.profit-value.neutral {
  color: #a16207;
}

.refresh-btn {
  min-height: 38px;
  padding: 8px 16px;
  color: #ffffff;
  background: #253247;
  border: 1px solid #1d293b;
  border-radius: 999px;
  box-shadow: 0 3px 10px rgba(23, 32, 51, 0.16);
  font-size: calc(0.82rem + 2px);
  font-weight: 650;
  cursor: pointer;
  transition: background 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
  margin-right: 12px;
}

.refresh-btn:hover {
  background: #172033;
  box-shadow: 0 5px 14px rgba(23, 32, 51, 0.22);
  transform: translateY(-1px);
}

.refresh-btn:active {
  transform: translateY(0);
}

.loading,
.error {
  padding: 32px;
  border-radius: var(--radius-lg);
}

.loading {
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--border);
  text-align: center;
}

.error {
  color: #991b1b;
  background: #fff5f5;
  border: 1px solid #fecaca;
  border-left: 4px solid #ef4444;
}

.preview-login-hint {
  margin-top: 2px;
  padding: 14px 16px;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  font-size: calc(0.82rem + 2px);
  font-weight: 600;
  text-align: center;
}

.app-toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10001;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.24);
  font-size: calc(0.78rem + 2px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.app-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.app-toast.is-error {
  color: #b4232d;
  border-color: #e39aa1;
}

html[data-theme="dark"] .app-toast.is-error {
  color: #ffb1b8;
  background: #25171b;
  border-color: #6f343b;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.28);
  outline-offset: 2px;
}

html[data-theme="dark"] body {
  background: var(--canvas);
}

html[data-theme="dark"] h1 {
  color: #f3f7fc;
}

html[data-theme="dark"] .subtitle {
  background: rgba(17, 24, 33, 0.88);
  border-color: rgba(58, 73, 94, 0.82);
}

html[data-theme="dark"] .page-main .container > .subtitle {
  background: rgba(17, 24, 33, 0.88);
}

html[data-theme="dark"] .progress-bar {
  background: #263244;
}

html[data-theme="dark"] .page-main .container > .progress-bar {
  background: #263244;
}

html[data-theme="dark"] .progress-bar .bar {
  background: linear-gradient(90deg, #6f9cff, #a1c3ff);
}

html[data-theme="dark"] .recipe-row:hover {
  border-color: #40526a;
}

html[data-theme="dark"] .scan-btn {
  color: var(--text-soft);
  background: var(--surface-soft);
  border-color: var(--border-strong);
}

html[data-theme="dark"] .scan-btn:hover {
  color: var(--primary);
  background: var(--surface-muted);
  border-color: var(--primary);
}

html[data-theme="dark"] .scan-btn:disabled {
  color: var(--text-faint);
  background: #151d28;
  border-color: var(--border);
}

html[data-theme="dark"] .item-icon {
  background: #182230;
  border-color: var(--border-strong);
}

html[data-theme="dark"] .item-icon.is-empty::after,
html[data-theme="dark"] .item-icon.is-missing::after {
  color: #738197;
}

html[data-theme="dark"] .quality-select:hover,
html[data-theme="dark"] .quality-select:focus,
html[data-theme="dark"] .reagent-inline select:hover,
html[data-theme="dark"] .reagent-inline select:focus {
  background: var(--surface-muted);
  border-color: var(--primary);
}

html[data-theme="dark"] .quality-value,
html[data-theme="dark"] .reagent-inline .qty,
html[data-theme="dark"] .reagent-inline .subtotal,
html[data-theme="dark"] .mix-option-inline .subtotal,
html[data-theme="dark"] .mix-price-item .subtotal {
  color: #c5d0de;
}

html[data-theme="dark"] .edit-btn {
  color: var(--text-soft);
  background: var(--surface-soft);
  border-color: var(--border-strong);
}

html[data-theme="dark"] .edit-btn:hover {
  color: var(--primary);
  background: var(--surface-muted);
  border-color: var(--primary);
}

html[data-theme="dark"] .price-input,
html[data-theme="dark"] .yield-input {
  background: var(--surface-muted);
}

html[data-theme="dark"] .reagent-inline,
html[data-theme="dark"] .profit-item {
  border-bottom-color: #202b39;
}

html[data-theme="dark"] .profit-value.neutral {
  color: #f0bd4f;
}

html[data-theme="dark"] .refresh-btn {
  color: #111821;
  background: #dfe8f4;
  border-color: #dfe8f4;
  box-shadow: none;
}

html[data-theme="dark"] .refresh-btn:hover {
  color: #0a0f16;
  background: #ffffff;
  border-color: #ffffff;
  box-shadow: none;
  transform: none;
}

html[data-theme="dark"] .loading {
  background: rgba(17, 24, 33, 0.84);
  border-color: var(--border);
}

html[data-theme="dark"] .error {
  color: #ffadb4;
  background: #25171b;
  border-color: #5b2a31;
  border-left-color: #ef656e;
}

html[data-theme="dark"] button:focus-visible,
html[data-theme="dark"] select:focus-visible,
html[data-theme="dark"] input:focus-visible {
  outline-color: rgba(125, 168, 255, 0.46);
}

@media (max-width: 1439px) {
  .recipe-row {
    grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.7fr);
    padding-top: 56px;
  }

  .profit-block {
    grid-column: 1 / -1;
    margin-top: 16px;
    padding: 16px 0 0;
    border-top: 1px solid var(--border);
  }

  .middle-area {
    border-right: 0;
  }

  .profit-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0 22px;
  }
}

@media (max-width: 1000px) {
  body {
    padding: 0;
  }

  .page-main {
    padding: 18px 14px 36px;
  }

  .recipe-topnav {
    width: calc(100% - 20px);
    margin: 12px auto;
  }

  .recipe-nav-inner {
    gap: 2px;
    padding: 7px;
  }

  .recipe-nav-professions {
    flex-basis: 100%;
  }

  .side-nav-divider {
    display: none;
  }

  .side-nav-submenu-panel {
    max-height: min(60vh, 360px);
  }

  .side-nav-child {
    white-space: normal;
  }
}

@media (max-width: 840px) {
  body {
    padding: 0;
  }

  body > .navbartop2 {
    height: auto;
    min-height: 64px;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }

  body > .navbartop2 .logo2 {
    flex: 0 0 auto;
  }

  body > .navbartop2 .logo2 img {
    width: 42px;
    margin: 0;
  }

  body > .navbartop2 > div:nth-child(2) {
    display: flex;
    min-width: 0;
    flex: 1 1 200px;
    gap: 6px;
  }

  body > .navbartop2 .search-selector {
    width: 86px;
    height: 38px;
    padding: 4px 8px;
    font-size: 14px;
    letter-spacing: 0;
  }

  body > .navbartop2 .search-bar2 {
    width: auto;
    min-width: 0;
    height: 38px;
    flex: 1 1 auto;
    margin: 0;
    padding: 4px 10px;
    font-size: 14px;
    letter-spacing: 0;
  }

  body > .navbartop2 .avatar {
    max-height: 40px;
    margin: 0;
    border-radius: 10px;
  }

  body > .navbartop2 .userimg2 {
    flex: 0 0 auto;
  }

  .page-main {
    padding: 18px 14px 36px;
  }

  .recipe-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 56px 12px 12px;
    overflow: hidden;
  }

  .output-block {
    padding: 0 0 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .middle-area {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
  }

  .mix-row {
    flex-wrap: wrap;
  }

  .mix-options-inline {
    flex-basis: 100%;
    width: 100%;
    margin-top: 6px;
    margin-left: 0;
  }

  .mix-prices-inline {
    flex-basis: 100%;
    margin-top: 6px;
    margin-left: 0;
  }

  .profit-block {
    grid-column: auto;
    margin-top: 0;
    padding-top: 14px;
    border-top: 0;
  }

  .subtitle {
    align-items: flex-start;
  }

  #subtitleText {
    flex-basis: 100%;
  }

  .refresh-btn {
    width: auto;
  }

}

@media (max-width: 520px) {
  body {
    padding-right: 0;
    padding-left: 0;
  }

  .page-main {
    padding: 14px 10px 32px;
  }

  h1 {
    font-size: calc(1.35rem + 2px);
  }

  .subtitle {
    padding: 12px 0 12px 12px;
  }

  .quality-select {
    width: 100%;
  }

  .reagent-inline {
    width: 100%;
  }

  .item-stack {
    flex: 1 1 100px;
  }

  .reagent-inline select {
    flex: 1 1 140px;
    max-width: 100%;
  }

  .subtotal-wrap {
    flex-basis: 110px;
    margin-left: 0;
  }

  .profit-metrics {
    grid-template-columns: 1fr;
  }

  .side-nav-submenu-panel {
    grid-template-columns: 1fr;
  }

  .side-nav-child {
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
