:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --ink: #2b2320;
  --muted: #8a7d75;
  --line: #ece4db;
  --brand: #b4533a;
  --brand-soft: #f6e8e3;
  --gold: #c98a2d;
  --ok: #2e7d4f;
  --ok-soft: #e4f3ea;
  --warn: #9a6b08;
  --warn-soft: #fdf3dc;
  --bad: #b3261e;
  --bad-soft: #fdecea;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1.2rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--brand);
  text-decoration: none;
  letter-spacing: 0.2px;
}

nav { display: flex; gap: 0.6rem; align-items: center; }

nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
}

nav a.active { background: var(--brand-soft); color: var(--brand); }

.btn-new {
  background: var(--brand) !important;
  color: #fff !important;
}

main { max-width: 1100px; margin: 0 auto; padding: 1.2rem; }

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 2rem 0 1rem;
}

.flash {
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid #cfe8d8;
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.8rem;
  font-weight: 600;
}

.stats { display: flex; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 1rem; }

.stat {
  flex: 1;
  min-width: 140px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.stat .num { font-size: 1.5rem; font-weight: 800; }
.stat span:last-child { color: var(--muted); font-size: 0.85rem; }
.stat.warn .num { color: var(--warn); }
.stat.danger .num { color: var(--bad); }

.filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.filters input[type="search"] {
  flex: 1;
  min-width: 180px;
}

.filters input, .filters select, .form input, .form select, .form textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: var(--card);
  color: var(--ink);
}

.filters button {
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.9rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.card:hover { box-shadow: 0 6px 18px rgba(43, 35, 32, 0.08); transform: translateY(-2px); }

.thumb {
  aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, var(--brand-soft), #fff8ec);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; }

.thumb .ph { font-size: 3.4rem; opacity: 0.85; }

.body { padding: 0.8rem 0.9rem 0.9rem; display: flex; flex-direction: column; gap: 0.45rem; flex: 1; }

.row { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }

.name { font-size: 0.98rem; line-height: 1.3; }

.chip {
  flex-shrink: 0;
  background: var(--gold);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.price { font-size: 1.15rem; font-weight: 800; color: var(--brand); }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}

.badge.in { background: var(--ok-soft); color: var(--ok); }
.badge.low { background: var(--warn-soft); color: var(--warn); }
.badge.out { background: var(--bad-soft); color: var(--bad); }

.actions {
  margin-top: auto;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.actions form { display: inline; }

.actions button {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--ink);
  line-height: 1;
}

.actions button:hover { background: var(--brand-soft); }

.actions .del { width: auto; padding: 0 0.6rem; font-size: 0.78rem; color: var(--bad); height: 2rem; }
.actions .del:hover { background: var(--bad-soft); }

.actions .enhance {
  width: auto;
  padding: 0 0.7rem;
  height: 2rem;
  font-size: 0.78rem;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #c98a2d, #e0a84f);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(201, 138, 45, 0.35);
}

.actions .enhance:disabled { opacity: 0.65; cursor: wait; }

.actions .enhance.match {
  background: linear-gradient(135deg, #6b4fa0, #8e6fc4);
  box-shadow: 0 2px 6px rgba(107, 79, 160, 0.35);
}

.refbar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.refthumb {
  width: 54px;
  height: 54px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.refthumb.refph {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: var(--brand-soft);
}

.reftext { display: flex; flex-direction: column; gap: 0.1rem; flex: 1; min-width: 200px; }
.reftext strong { font-size: 0.95rem; }
.reftext span { color: var(--muted); font-size: 0.8rem; }

.refform { display: flex; gap: 0.5rem; align-items: center; }
.refform input {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: var(--bg);
  max-width: 220px;
  font-size: 0.85rem;
}

.small-btn { padding: 0.5rem 0.9rem; font-size: 0.85rem; }

.link { color: var(--brand); text-decoration: none; font-weight: 600; font-size: 0.88rem; }
.link:hover { text-decoration: underline; }

.empty {
  text-align: center;
  padding: 3rem 1rem;
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
}

.btn {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.4rem;
  max-width: 560px;
  margin: 0 auto;
}

.panel h1 { margin: 0 0 1rem; font-size: 1.3rem; }

.form { display: flex; flex-direction: column; gap: 0.9rem; }

.form label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.9rem; }
.form label small { color: var(--muted); font-weight: 400; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }

.form-actions { display: flex; gap: 0.9rem; align-items: center; margin-top: 0.3rem; }

.current-photo { display: flex; align-items: center; gap: 0.7rem; color: var(--muted); font-size: 0.85rem; }
.current-photo img { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; }

@media (max-width: 560px) {
  .two { grid-template-columns: 1fr; }
  .stats { flex-direction: column; }
}
