/* ============================================================
   Shop Manager — shared stylesheet
   Palette: light bg #F7F6F4 · navy #1F1B0D · orange #FF6A1A
   Font: Poppins (Google Fonts)
   ============================================================ */

:root {
  --bg: #F7F6F4;
  --navy: #1F1B0D;
  --orange: #FF6A1A;
  --orange-dark: #E45A12;
  --orange-light: #FF8A3D;
  --text: #1F1B0D;
  --muted: #6f6a5e;
  --card: #ffffff;
  --border: #E5E1DC;
  --red: #d64545;
  --red-bg: #fdecec;
  --green: #2e7d32;
  --green-bg: #e9f5ea;
  --radius: 12px;
  --shadow: 0 2px 14px rgba(31, 27, 13, 0.08);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Poppins', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.65rem 1.25rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
}
.btn-primary:hover { background: var(--orange-dark); border-color: var(--orange-dark); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: #efece6; }

.btn-danger {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn-danger:hover { background: #b93636; }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; border-radius: 8px; }

.btn-block { width: 100%; }

/* ---------- Header / top bar ---------- */
.site-header,
.topbar {
  background: var(--navy);
  color: #fff;
}

.site-header {
  padding: 1rem 1.5rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.logo .accent { color: var(--orange-light); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
.user-email {
  font-size: 0.85rem;
  color: #d8d3c8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40vw;
}
.logout-btn {
  background: transparent;
  color: #fff;
  border: 1px solid #4a4436;
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.logout-btn:hover { background: rgba(255, 255, 255, 0.08); }

/* ---------- Landing / auth page ---------- */
.auth-layout {
  max-width: 1024px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 2.5rem;
}

.hero h1 {
  font-size: 2.4rem;
  margin: 0 0 0.5rem;
  line-height: 1.15;
}
.hero h1 .accent { color: var(--orange); }
.tagline {
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0 0 1.5rem;
  max-width: 34rem;
}
.benefits {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 1rem;
  max-width: 34rem;
}
.benefits li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  box-shadow: var(--shadow);
  font-size: 0.95rem;
}
.benefits li strong { display: block; margin-bottom: 0.15rem; }
.benefits li span { color: var(--muted); font-size: 0.88rem; }

.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.75rem;
  height: fit-content;
}

.tabs {
  display: flex;
  background: var(--bg);
  border-radius: 10px;
  padding: 0.3rem;
  margin-bottom: 1.5rem;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}
.tab.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.field { display: block; margin-bottom: 1rem; font-size: 0.9rem; font-weight: 500; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }

.input,
textarea.input,
select.input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.85rem;
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
.input:focus {
  outline: 2px solid var(--orange-light);
  border-color: var(--orange);
}
textarea.input { resize: vertical; }

.pw-wrap { position: relative; }
.pw-toggle {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 0;
  color: var(--orange-dark);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.25rem;
}

.auth-links {
  display: flex;
  justify-content: flex-end;
  margin: -0.4rem 0 1rem;
}
.link-btn {
  background: none;
  border: 0;
  color: var(--orange-dark);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }

.error-text {
  color: var(--red);
  font-size: 0.85rem;
  margin: 0 0 1rem;
  background: var(--red-bg);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
}
.success-text {
  color: var(--green);
  font-size: 0.85rem;
  margin: 0 0 1rem;
  background: var(--green-bg);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
}

.reset-box {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ---------- Dashboard ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.15rem;
}
.stat-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.25rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-value.warn { color: var(--red); }

.toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.search-input { flex: 1; min-width: 180px; margin-top: 0; }

/* Desktop table */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table.products { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.products th,
table.products td {
  text-align: left;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.products th {
  background: #faf8f5;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  white-space: nowrap;
}
table.products tr:last-child td { border-bottom: 0; }
table.products tr:hover td { background: #fdfcfa; }
.cell-sub { display: block; font-size: 0.78rem; color: var(--muted); font-weight: 400; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions-cell { white-space: nowrap; }
.actions-cell .btn { margin-right: 0.4rem; }
.actions-cell .btn:last-child { margin-right: 0; }

.qty-badge {
  display: inline-block;
  min-width: 2.2rem;
  text-align: center;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
  background: var(--green-bg);
  color: var(--green);
}
.qty-badge.low { background: var(--red-bg); color: var(--red); }

/* Mobile cards (hidden on desktop) */
.product-cards { display: none; }
.p-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.15rem;
  margin-bottom: 0.9rem;
}
.p-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}
.p-card-name { font-weight: 600; font-size: 1rem; }
.p-card-cat { font-size: 0.8rem; color: var(--muted); }
.p-card-rows {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 1rem;
  font-size: 0.88rem;
  margin-bottom: 0.75rem;
}
.p-card-rows .k { color: var(--muted); font-size: 0.76rem; display: block; }
.p-card-rows .v { font-weight: 500; font-variant-numeric: tabular-nums; }
.p-card-actions { display: flex; gap: 0.5rem; }
.p-card-actions .btn { flex: 1; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
}
.empty-state .big { font-size: 2.5rem; margin-bottom: 0.5rem; }
.empty-state h3 { color: var(--text); margin: 0 0 0.4rem; }
.empty-state p { margin: 0 0 1.25rem; font-size: 0.92rem; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 27, 13, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}
.modal {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 1.75rem;
}
.modal h2 { margin: 0 0 1.25rem; font-size: 1.25rem; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.9rem;
}
.form-grid .span2 { grid-column: span 2; }
.form-error {
  color: var(--red);
  background: var(--red-bg);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
  margin: 0.25rem 0 1rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 0.8rem 1.25rem;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 200;
  max-width: calc(100vw - 2.5rem);
  text-align: center;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

/* ---------- Responsive ---------- */
@media (max-width: 767px) {
  .table-wrap { display: none; }      /* cards take over on mobile */
  .product-cards { display: block; }
  .auth-layout { padding-top: 1.75rem; }
  .hero h1 { font-size: 2rem; }
  .user-email { display: none; }
  .toolbar .btn { flex: 1; }
}

@media (min-width: 768px) {
  .auth-layout { grid-template-columns: 1.1fr 0.9fr; align-items: center; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Product photo ---------- */
.photo-field { grid-column: span 2; margin-bottom: 1rem; }
.photo-field .field-label { display: block; font-size: 0.9rem; font-weight: 500; margin-bottom: 0.4rem; }
.photo-preview-wrap { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.6rem; }
.photo-preview {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}
.photo-buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Thumbnails in table + mobile cards */
.product-cell { display: flex; align-items: center; gap: 0.85rem; }
.p-thumb {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}
/* Rows / cards open the detail modal on click */
.products tbody tr { cursor: pointer; }
.p-card { cursor: pointer; }
.p-card-title { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }

/* ---------- Product detail modal ---------- */
.detail-modal { max-width: 560px; padding: 0; overflow: hidden; position: relative; }
.modal-x {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 2;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: none;
  background: rgba(31, 27, 13, 0.55);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.modal-x:hover { background: rgba(31, 27, 13, 0.75); }
.detail-photo {
  width: 100%;
  height: 260px;
  object-fit: cover;
  display: block;
  background: #fff;
}
.detail-main { padding: 1.25rem 1.5rem 1.5rem; }
.detail-main h2 { margin: 0 0 0.4rem; font-size: 1.35rem; }
.cat-badge {
  display: inline-block;
  background: #fff4ec;
  color: var(--orange-dark);
  border: 1px solid #ffd9bd;
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
}
.detail-barcode {
  margin: 1rem 0 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.5rem 0.5rem;
  text-align: center;
}
.detail-barcode svg { max-width: 100%; height: auto; }
.detail-code {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
  word-break: break-all;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin: 1rem 0 0;
}
.detail-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
}
.detail-item .k { display: block; font-size: 0.72rem; color: var(--muted); margin-bottom: 0.15rem; }
.detail-item .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.detail-notes {
  margin: 1rem 0 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  font-size: 0.88rem;
}
.detail-notes .k { display: block; font-size: 0.72rem; color: var(--muted); margin-bottom: 0.25rem; }
.detail-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.25rem;
}
.detail-actions .btn { flex: 1; }
@media (max-width: 560px) {
  .detail-modal { max-width: 100%; border-radius: 16px 16px 0 0; align-self: flex-end; }
  .detail-photo { height: 220px; }
}

/* ---------- Barcode / QR scanner ---------- */
.scan-btn svg { vertical-align: -3px; margin-right: 0.35rem; }
#qr-reader { width: 100%; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
#qr-reader video { border-radius: 12px; }
.scanner-hint { color: var(--muted); font-size: 0.85rem; text-align: center; margin: 0.75rem 0 0; }
