:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --border: #e6e6e9;
  --text: #1c1c1e;
  --muted: #6b6b72;
  --accent: #3b82f6;
  --accent-ink: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.12);
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center; font-size: 16px;
}
.btn {
  font: inherit; border: none; cursor: pointer; border-radius: 9px;
  padding: 10px 16px; font-weight: 600; font-size: 14px;
  transition: transform .05s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: #2f6fe0; }
.btn-ghost {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: #f0f0f2; }

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 26px 20px 60px; }

.intro { margin-bottom: 24px; }
.intro h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.intro p { color: var(--muted); font-size: 15px; }
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-top: 18px;
}
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 12px; min-width: 240px; flex: 1; max-width: 340px;
}
.search input { border: none; outline: none; font: inherit; width: 100%; background: transparent; }
.count { font-size: 13px; color: var(--muted); }

/* Product grid */
.grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  margin-top: 18px;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  transition: box-shadow .15s ease, transform .15s ease;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.thumb { height: 150px; display: grid; place-items: center; background: #fafafb; font-size: 56px; }
.card-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.name { font-weight: 650; font-size: 15px; }
.category { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.badge {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 20px; white-space: nowrap;
}
.badge-in { background: #e8f5ee; color: #1d7a4f; }
.badge-out { background: #fdecec; color: #b3372f; }
.price-row { display: flex; align-items: baseline; justify-content: space-between; margin-top: auto; padding-top: 10px; }
.price { font-size: 18px; font-weight: 700; }
.unit { font-size: 12px; color: var(--muted); font-weight: 500; }
.edit-link { font-size: 13px; color: var(--accent); background: none; border: none; cursor: pointer; font-weight: 600; }
.edit-link:hover { text-decoration: underline; }

.loading, .empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

/* Modal */
.overlay {
  position: fixed; inset: 0; background: rgba(20,20,24,.45);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 50; overflow-y: auto;
}
.overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 520px;
  padding: 24px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.close:hover { color: var(--text); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; font: inherit; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 9px; outline: none; background: var(--surface);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }
