:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #111827;
  --muted: #687385;
  --line: #dde3ea;
  --accent: #1677a8;
  --accent-dark: #0f587d;
  --good: #25825f;
  --warn: #a65f00;
  --shadow: 0 10px 28px rgba(16, 24, 40, 0.08);
}

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

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(760px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 17px;
  line-height: 1.25;
}

.count-pill,
.badge,
.section-title span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e8f4fa;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.search-panel,
.selected-panel,
.list-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.search-panel {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  padding: 10px;
  margin-bottom: 12px;
}

.category-tabs {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 1px;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.category-tab {
  min-height: 34px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.category-tab.is-active {
  border-color: var(--accent);
  background: #e8f4fa;
  color: var(--accent-dark);
}

.search-field {
  display: grid;
  gap: 5px;
}

.search-field span,
.field span,
.meta,
.need-meta {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

.icon-button {
  width: 44px;
  min-height: 44px;
  align-self: end;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.selected-panel {
  padding: 14px;
  margin-bottom: 12px;
}

.selected-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.selected-title {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.selected-title h2,
.craft-card strong,
.need-name {
  overflow-wrap: anywhere;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.recipe-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
  margin-top: 14px;
}

.recipe-controls.single {
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 5px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.stats-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.stat-card span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.stat-card strong {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.needs-title {
  margin: 16px 0 8px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
}

.need-list {
  display: grid;
  gap: 8px;
}

.need-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.need-name {
  font-weight: 700;
}

.need-amount {
  color: var(--accent-dark);
  font-weight: 800;
  white-space: nowrap;
}

.list-panel {
  padding: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.craft-list {
  display: grid;
  gap: 8px;
}

.craft-card {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 72px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.craft-card.is-active {
  border-color: var(--accent);
  background: #f0f8fc;
  box-shadow: inset 4px 0 0 var(--accent);
}

.empty-state,
.error-state {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

.error-state {
  color: #9b2d26;
}

@media (min-width: 860px) {
  .app-shell {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    grid-template-areas:
      "header header"
      "search details"
      "list details";
    gap: 14px;
    align-content: start;
    padding: 22px;
  }

  .app-header {
    grid-area: header;
    margin-bottom: 0;
  }

  .search-panel {
    grid-area: search;
    position: static;
    margin-bottom: 0;
  }

  .selected-panel {
    grid-area: details;
    position: sticky;
    top: 22px;
    margin-bottom: 0;
  }

  .list-panel {
    grid-area: list;
  }

  .craft-list {
    max-height: calc(100vh - 220px);
    overflow: auto;
    padding-right: 3px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding-inline: 10px;
  }

  .selected-head,
  .recipe-controls,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .badge {
    width: max-content;
  }

  .need-row {
    grid-template-columns: 1fr;
  }

  .need-amount {
    justify-self: start;
  }
}
