:root {
  --gold: #D89A2C;
  --gold-light: #FBEFD8;
  --charcoal: #2B2A28;
  --charcoal-light: #EFECE6;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --gray-bg: #FAF7F1;
  --gray-border: #EAE3D3;
  --text: #2B2A28;
  --text-muted: #7A7267;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--gray-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='126.00' height='145.49' viewBox='0 0 126.00 145.49'%3E%3Cg fill='none' stroke='%23D89A2C' stroke-width='1.2' opacity='0.1'%3E%3Cpath d='M 42.00 0.00 L 21.00 36.37 L -21.00 36.37 L -42.00 0.00 L -21.00 -36.37 L 21.00 -36.37 Z' /%3E%3Cpath d='M 42.00 72.75 L 21.00 109.12 L -21.00 109.12 L -42.00 72.75 L -21.00 36.37 L 21.00 36.37 Z' /%3E%3Cpath d='M 105.00 36.37 L 84.00 72.75 L 42.00 72.75 L 21.00 36.37 L 42.00 0.00 L 84.00 0.00 Z' /%3E%3Cpath d='M 105.00 109.12 L 84.00 145.49 L 42.00 145.49 L 21.00 109.12 L 42.00 72.75 L 84.00 72.75 Z' /%3E%3Cpath d='M 168.00 0.00 L 147.00 36.37 L 105.00 36.37 L 84.00 0.00 L 105.00 -36.37 L 147.00 -36.37 Z' /%3E%3Cpath d='M 168.00 72.75 L 147.00 109.12 L 105.00 109.12 L 84.00 72.75 L 105.00 36.37 L 147.00 36.37 Z' /%3E%3C/g%3E%3C/svg%3E");
  background-repeat: repeat;
  background-attachment: fixed;
  color: var(--text);
  padding-bottom: 150px; /* room for bottom nav (~76px) + floating + button which sits above it */
}

a { color: var(--gold); text-decoration: none; }

.topbar {
  background-color: var(--charcoal);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='78.00' height='90.07' viewBox='0 0 78.00 90.07'%3E%3Cg fill='none' stroke='%23FFFFFF' stroke-width='1.2' opacity='0.06'%3E%3Cpath d='M 26.00 0.00 L 13.00 22.52 L -13.00 22.52 L -26.00 0.00 L -13.00 -22.52 L 13.00 -22.52 Z' /%3E%3Cpath d='M 26.00 45.03 L 13.00 67.55 L -13.00 67.55 L -26.00 45.03 L -13.00 22.52 L 13.00 22.52 Z' /%3E%3Cpath d='M 65.00 22.52 L 52.00 45.03 L 26.00 45.03 L 13.00 22.52 L 26.00 0.00 L 52.00 0.00 Z' /%3E%3Cpath d='M 65.00 67.55 L 52.00 90.07 L 26.00 90.07 L 13.00 67.55 L 26.00 45.03 L 52.00 45.03 Z' /%3E%3Cpath d='M 104.00 0.00 L 91.00 22.52 L 65.00 22.52 L 52.00 0.00 L 65.00 -22.52 L 91.00 -22.52 Z' /%3E%3Cpath d='M 104.00 45.03 L 91.00 67.55 L 65.00 67.55 L 52.00 45.03 L 65.00 22.52 L 91.00 22.52 Z' /%3E%3C/g%3E%3C/svg%3E");
  background-repeat: repeat;
  color: white;
  padding: 10px 18px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  padding: 2px;
}
.topbar-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
}
.topbar-logo-fallback {
  font-size: 20px;
  line-height: 1;
}
.topbar-title { font-size: 18px; font-weight: 800; }
.env-badge {
  background: #dc2626;
  color: white;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* A big, unmissable "this isn't the real data" watermark for a non-production
   copy of the app (see ENV_LABEL in app.py) - fixed so it stays in view
   while scrolling, tiled across the whole viewport, and pointer-events:none
   so it never blocks a click even though it sits on top of everything. */
.env-watermark {
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  background-repeat: repeat;
}

.content { padding: 16px; max-width: 640px; margin: 0 auto; }

.flash-stack { margin-bottom: 14px; }
.flash {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}
.flash-ok { background: #dcfce7; color: #166534; }
.flash-warn { background: #fef3c7; color: #92400e; }

/* ---- bottom nav ---- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-top: 1px solid var(--gray-border);
  display: flex;
  justify-content: space-around;
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  z-index: 20;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 6px 5px;
  border-radius: 10px;
}
.nav-item.active { color: var(--gold); background: var(--gold-light); }
.nav-icon { font-size: 20px; margin-bottom: 2px; }

/* ---- cards / summary ---- */
.card {
  background: white;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  margin-bottom: 14px;
}

.summary-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.summary-card {
  background: white;
  border-radius: 14px;
  padding: 14px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  flex: 1 1 calc(50% - 5px);
  min-width: 140px;
}
.summary-num { font-size: 24px; font-weight: 800; color: var(--gold); }
.summary-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; margin-top: 2px; }

.section-title {
  font-size: 15px;
  font-weight: 800;
  margin: 20px 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ---- buttons ---- */
.btn {
  display: inline-block;
  background: var(--gold);
  color: var(--charcoal);
  border: none;
  padding: 13px 18px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
  width: 100%;
}
.btn:active { opacity: 0.85; }
.btn-secondary { background: white; color: var(--gold); border: 2px solid var(--gold); }
.btn-sm { width: auto; padding: 8px 14px; font-size: 13px; }
.fab-link {
  display: block;
  text-align: center;
  background: var(--gold);
  color: var(--charcoal);
  padding: 12px;
  border-radius: 12px;
  font-weight: 800;
  margin-bottom: 14px;
}

/* ---- forms ---- */
.form-group { margin-bottom: 14px; }
label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 5px; color: var(--text-muted); }
input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--gray-border);
  font-size: 15px;
  background: white;
  color: var(--text);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }
textarea { min-height: 70px; resize: vertical; }

.line-item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 6px;
  align-items: end;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--gray-border);
}
.line-item-row label { font-size: 10px; }
.remove-line-btn {
  background: #fee2e2;
  color: var(--red);
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
}
.add-line-btn {
  background: var(--gold-light);
  color: var(--gold);
  border: none;
  border-radius: 10px;
  padding: 10px;
  width: 100%;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 16px;
}
.add-line-btn:disabled {
  background: #f0f0f3;
  color: #999;
  cursor: not-allowed;
}

/* ---- lists ---- */
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  border-radius: 12px;
  padding: 13px 14px;
  margin-bottom: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.list-row-main { font-weight: 700; font-size: 14px; }
.list-row-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.list-row-right { text-align: right; font-size: 13px; font-weight: 700; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f0f0f3; color: #555; }
.inactive-row { opacity: 0.55; }
.badge-gold { background: var(--gold-light); color: var(--gold); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px;
  font-size: 14px;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  margin-bottom: 8px;
}
table.simple-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  font-size: 13px;
}
table.simple-table th, table.simple-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--gray-border);
}
table.simple-table th {
  background: var(--gold-light);
  color: var(--gold);
  font-size: 11px;
  text-transform: uppercase;
}
table.simple-table th.sortable-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
table.simple-table th.sortable-th .sort-arrow {
  display: inline-block;
  width: 10px;
  opacity: 0.6;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-border);
  font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text-muted); }
.detail-value { font-weight: 700; }

.type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.type-toggle a {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  border: 2px solid var(--gray-border);
  color: var(--text-muted);
}
.type-toggle a.active-pull { border-color: var(--gold); color: var(--gold); background: var(--gold-light); }
.type-toggle a.active-return { border-color: var(--green); color: var(--green); background: #dcfce7; }

/* ---- global floating action button (mobile-first quick actions) ---- */
.fab-main {
  position: fixed;
  right: 18px;
  bottom: 84px; /* sits just above the bottom nav */
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--charcoal);
  border: none;
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}
.fab-main.open { background: var(--charcoal); color: white; }

.fab-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.fab-backdrop.open { opacity: 1; pointer-events: auto; }

.fab-menu {
  position: fixed;
  right: 18px;
  bottom: 152px; /* stacks upward from just above the main FAB */
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}
.fab-menu.open { pointer-events: auto; }

.fab-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.fab-menu.open .fab-menu-item { opacity: 1; transform: translateY(0); }
/* stagger the pop-in slightly so it doesn't feel like one flat block */
.fab-menu.open .fab-menu-item:nth-child(1) { transition-delay: 0.02s; }
.fab-menu.open .fab-menu-item:nth-child(2) { transition-delay: 0.05s; }
.fab-menu.open .fab-menu-item:nth-child(3) { transition-delay: 0.08s; }
.fab-menu.open .fab-menu-item:nth-child(4) { transition-delay: 0.11s; }
.fab-menu.open .fab-menu-item:nth-child(5) { transition-delay: 0.14s; }

.fab-menu-label {
  background: white;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.15);
  white-space: nowrap;
}
.fab-menu-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: white;
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
  flex-shrink: 0;
}

/* ---- inventory table grouping ---- */
.product-group-row.expandable { cursor: pointer; }
.product-group-row.expandable:active { background: var(--gold-light); }
.expand-arrow {
  display: inline-block;
  font-size: 11px;
  color: var(--gold);
  transition: transform 0.15s ease;
}
.batch-detail-row { background: #FAFAF7; }
.batch-detail-row td { font-size: 12px; color: var(--text-muted); }

/* ---- consistent action grid (replaces mismatched stacked buttons) ---- */
.action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: white;
  border: 2px solid var(--action-color, var(--gray-border));
  color: var(--action-color, var(--text));
  border-radius: 14px;
  padding: 14px 8px;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  flex: 1 1 calc(50% - 5px);
  min-width: 140px;
}
.action-btn:active { background: var(--gold-light); }
.action-btn .action-icon { font-size: 22px; }
