:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --border: #dbe4ef;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --danger: #dc2626;
  --success: #16a34a;
  --cat-bg: #dbe9f7;
  --to-buy-bg: #fef3c7;
  --to-buy-border: #f59e0b;
  --ordered-bg: #dcfce7;
  --ordered-border: #22c55e;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 1.25rem; }

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge-guest { background: #e2e8f0; color: #334155; }
.badge-editor { background: #dcfce7; color: #166534; }

.editor-controls { display: flex; align-items: center; gap: 12px; }
.autosave-hint { font-size: 0.82rem; color: var(--success); font-weight: 600; }

.lock-banner {
  padding: 10px 24px;
  font-weight: 600;
  text-align: center;
  font-size: 0.95rem;
}
.lock-banner.other-locked { background: #fee2e2; color: #991b1b; border-bottom: 1px solid #fca5a5; }
.lock-banner.self-locked { background: #dbeafe; color: #1e40af; border-bottom: 1px solid #93c5fd; }

.container { max-width: 1540px; margin: 0 auto; padding: 18px 24px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.toolbar input, .toolbar select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  font-size: 0.9rem;
}
.toolbar input { flex: 1; min-width: 220px; }

.layout-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 18px;
  align-items: start;
}
@media (max-width: 1150px) {
  .layout-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.table-card { padding: 0; overflow: hidden; }
.table-wrapper { overflow-x: auto; max-height: 78vh; }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
thead th {
  position: sticky;
  top: 0;
  background: #f1f5f9;
  border-bottom: 2px solid var(--border);
  padding: 10px 8px;
  text-align: left;
  z-index: 10;
  white-space: nowrap;
}
th.num, td.num { text-align: center; width: 88px; }
th.total-col, td.total-col { font-weight: 700; background: #f8fafc; }

tbody tr { border-bottom: 1px solid #eef2f6; }
tbody td { padding: 6px 8px; }

tr.category-row td {
  background: var(--cat-bg);
  font-weight: 700;
  color: #0f172a;
  padding: 8px 12px;
  font-size: 0.9rem;
}

tr.status-to_buy { background-color: var(--to-buy-bg); }
tr.status-ordered { background-color: var(--ordered-bg); }

.cell-input {
  width: 58px;
  padding: 4px;
  text-align: center;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  font-size: 0.88rem;
  background: #fff;
}

.status-select {
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.status-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.pill-ok { background: #f1f5f9; color: #64748b; }
.pill-to_buy { background: #fde68a; color: #92400e; }
.pill-ordered { background: #bbf7d0; color: #166534; }

.offer-inline {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.offer-inline input {
  width: 95px;
  padding: 3px 5px;
  font-size: 0.78rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
}

.side-panel { display: flex; flex-direction: column; gap: 16px; }
.side-panel h2 { margin: 0 0 4px 0; font-size: 1.02rem; }
.subtext { margin: 0 0 10px 0; font-size: 0.8rem; color: var(--muted); }

.shopping-list { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; }
.shop-item {
  padding: 8px 10px;
  border-radius: 8px;
  border-left: 4px solid var(--to-buy-border);
  background: #fffbeb;
  font-size: 0.85rem;
}
.shop-item.ordered {
  border-left-color: var(--ordered-border);
  background: #f0fdf4;
}
.shop-item-meta { font-size: 0.78rem; color: var(--muted); margin-top: 3px; }

.audit-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 300px;
  overflow-y: auto;
  font-size: 0.8rem;
}
.audit-list li {
  padding: 6px 0;
  border-bottom: 1px solid #f1f5f9;
}
.audit-time { color: var(--muted); font-size: 0.74rem; display: block; }

.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-sm { padding: 4px 8px; font-size: 0.78rem; }

.hidden { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-content {
  background: #fff;
  padding: 20px;
  border-radius: 12px;
  width: 92%;
  max-width: 440px;
}
.modal-content h3 { margin-top: 0; }
.modal-content label { display: block; font-size: 0.82rem; font-weight: 600; margin: 10px 0 4px; }
.modal-content input, .modal-content select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.qty-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 6px;
}
.qty-grid.two-col { grid-template-columns: repeat(2, 1fr); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}