/* ── Variables ───────────────────────────────────────────────────────────── */

:root {
  --brand-header: #111827;
  --brand-border: #374151;

  --bg:           #f4f6f9;
  --surface:      #ffffff;
  --border:       #e2e6ed;
  --text-primary: #111827;
  --text-secondary:#5a6479;
  --text-muted:   #9ca3af;
  --accent:       var(--brand-header);

  --radius:       10px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
}

/* ── Reset ───────────────────────────────────────────────────────────────── */

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Fullscreen Center ───────────────────────────────────────────────────── */

.fullscreen-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ── Error Screen ────────────────────────────────────────────────────────── */

.error-box {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 48px;
  box-shadow: var(--shadow-md);
  max-width: 360px;
}

.error-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #fee2e2;
  color: #dc2626;
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.error-box p {
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ── Login Card ──────────────────────────────────────────────────────────── */

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  max-height: 52px;
  max-width: 180px;
  object-fit: contain;
  margin: 0 auto 14px;
  display: block;
}

.login-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.login-header p {
  font-size: 0.84rem;
  color: var(--text-secondary);
}

/* ── Forms ───────────────────────────────────────────────────────────────── */

form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field-group input {
  padding: 10px 13px;
  font-family: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
  width: 100%;
}

.field-group input:focus {
  border-color: var(--brand-border);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-header) 12%, transparent);
}

.form-error {
  font-size: 0.8rem;
  color: #dc2626;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 9px 12px;
}

button[type="submit"] {
  padding: 11px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--brand-header);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.18s, transform 0.1s;
  margin-top: 4px;
}

button[type="submit"]:hover { opacity: 0.88; }
button[type="submit"]:active { transform: scale(0.99); }
button[type="submit"]:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Header ──────────────────────────────────────────────────────────────── */

.shop-header {
  background: var(--brand-header);
  border-bottom: 2px solid var(--brand-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.header-logo {
  max-height: 36px;
  max-width: 120px;
  object-fit: contain;
  flex-shrink: 0;
}

.header-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.header-user {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.65);
  font-family: 'DM Mono', monospace;
}

.btn-logout {
  padding: 6px 14px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  background: transparent;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.btn-logout:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

/* ── Toolbar ─────────────────────────────────────────────────────────────── */

.shop-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.toolbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  font-family: inherit;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.search-input:focus {
  border-color: var(--brand-border);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-header) 10%, transparent);
}

.group-filter {
  padding: 8px 32px 8px 12px;
  font-family: inherit;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.18s;
}

.group-filter:focus { border-color: var(--brand-border); }

.product-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Main ────────────────────────────────────────────────────────────────── */

.shop-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

/* ── State Boxes ─────────────────────────────────────────────────────────── */

.state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 80px 24px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--brand-header);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Groups Container ────────────────────────────────────────────────────── */

#groupsContainer {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.group-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.group-name {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
}

.group-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--border);
  border-radius: 20px;
  padding: 2px 8px;
}

/* ── Product List ─────────────────────────────────────────────────────────── */

.product-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1px;
  background: var(--border);
}

.product-item {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  padding: 14px;
  gap: 10px;
  transition: background 0.12s;
  cursor: default;
}

.product-item:hover {
  background: #f8fafc;
}

/* ── Product Image ───────────────────────────────────────────────────────── */

.product-img-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.product-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.product-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.product-img-placeholder svg {
  width: 40%;
  height: 40%;
  opacity: 0.4;
}

/* ── Product Info ────────────────────────────────────────────────────────── */

.product-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.product-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Product Meta ────────────────────────────────────────────────────────── */

.product-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: auto;
}

.product-unit {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.product-price {
  font-family: 'DM Mono', monospace;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .login-card { padding: 32px 24px; }
  .header-inner { padding: 0 16px; }
  .toolbar-inner { padding: 10px 16px; }
  .shop-main { padding: 16px; }
  .product-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
