:root {
  --navy: #0F1729;
  --navy-light: #1B2A4A;
  --orange: #E8772E;
  --orange-dark: #D4651E;
  --bg: #F4F5F7;
  --card-bg: #FFFFFF;
  --border: #E3E5E9;
  --text: #1A1D29;
  --text-muted: #6B7280;
  --text-faint: #9CA3AF;
  --green: #1E8E5A;
  --red-bg: #FDEDEE;
  --red-text: #C0392B;
  --amber-bg: #FFF6E0;
  --radius: 8px;
  --mono: 'SF Mono', 'Consolas', 'Menlo', monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }

.topnav { background: var(--navy); border-bottom: 1px solid #000; }
.topnav-inner {
  max-width: 1400px; margin: 0 auto; display: flex; align-items: center;
  justify-content: space-between; padding: 0 24px; height: 52px;
}
.brand { font-weight: 800; font-size: 17px; letter-spacing: 0.5px; color: #fff; }
.brand-accent { color: var(--orange); }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-link {
  color: #C7CCD9; font-size: 13.5px; font-weight: 500; padding: 7px 14px;
  border-radius: 6px; transition: background 0.15s, color 0.15s; white-space: nowrap;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,0.06); }
.nav-link.active { background: var(--orange); color: #fff; }
.nav-muted { color: #6B7280; }
.nav-sep { width: 1px; height: 22px; background: rgba(255,255,255,0.12); margin: 0 6px; }
.nav-user { color: #9aa3b5; font-size: 12.5px; font-weight: 600; padding: 0 4px; }

.page { max-width: 1400px; margin: 0 auto; padding: 32px 24px 80px; }
.page-title { font-size: 26px; font-weight: 800; margin: 0 0 2px; color: var(--text); }
.page-subtitle { color: var(--text-muted); font-size: 14px; margin: 0 0 24px; }

.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; }
.filter-bar { padding: 20px 24px; display: flex; gap: 20px; align-items: flex-end; flex-wrap: wrap; }
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-group.grow { flex: 1; min-width: 260px; }
.filter-label { font-size: 11px; font-weight: 700; letter-spacing: 0.6px; color: var(--text-faint); text-transform: uppercase; }
.input, .select {
  border: 1px solid var(--border); border-radius: 6px; padding: 9px 12px; font-size: 13.5px;
  background: #fff; color: var(--text); font-family: inherit;
}
.input:focus, .select:focus { outline: 2px solid var(--orange); outline-offset: -1px; }
.input { width: 100%; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--text); font-size: 13px;
  font-weight: 600; padding: 8px 16px; border-radius: 6px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #F7F8FA; }
.btn-primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); border-color: var(--orange-dark); }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-outline-block { width: 100%; justify-content: center; }

.checkbox-row { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-muted); padding-bottom: 9px; }
.checkbox-row input { width: 15px; height: 15px; accent-color: var(--orange); }

.table-wrap { overflow-x: auto; }
table.price-table { width: 100%; border-collapse: collapse; }
.price-table thead th {
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: 0.6px; color: var(--text-faint);
  text-transform: uppercase; padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.price-table thead th.num { text-align: right; }
.price-table tbody td { padding: 13px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
.price-table tbody td.num { text-align: right; font-family: var(--mono); font-size: 13px; }
.price-table tbody tr.product-row { cursor: pointer; transition: background 0.12s; }
.price-table tbody tr.product-row:hover { background: #FAFBFC; }

.product-name { font-weight: 600; }
.product-toggle {
  display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px;
  border: 1px solid var(--border); border-radius: 4px; font-size: 12px; color: var(--text-muted);
  margin-right: 8px; transition: transform 0.15s;
}
tr.expanded .product-toggle { transform: rotate(90deg); }
.unit-tag { font-size: 11px; color: var(--text-faint); font-style: italic; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 100px; font-size: 11.5px; font-weight: 700; }
.pill-alert { background: #FBE2E4; color: var(--red-text); }
.pill-flag { background: var(--amber-bg); color: #92660C; margin-left: 6px; }
.count-badge { font-size: 12px; color: var(--text-muted); background: #F0F1F4; padding: 2px 9px; border-radius: 100px; font-weight: 600; }

.history-row td { padding: 0; background: #FAFAFB; }
.history-panel { padding: 4px 14px 16px 46px; }
.history-table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.history-table th {
  text-align: left; font-size: 10.5px; font-weight: 700; color: var(--text-faint); text-transform: uppercase;
  letter-spacing: 0.5px; padding: 8px 12px; background: #F7F8FA; border-bottom: 1px solid var(--border);
}
.history-table th.num { text-align: right; }
.history-table td { padding: 8px 12px; font-size: 12.5px; border-bottom: 1px solid #F0F1F3; }
.history-table td.num { text-align: right; font-family: var(--mono); }
.history-table tr:last-child td { border-bottom: none; }
.history-loading { padding: 16px; color: var(--text-muted); font-size: 13px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }

.form-card { max-width: 560px; padding: 28px; }
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.error-banner { background: var(--red-bg); color: var(--red-text); padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 16px; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

.login-body { background: var(--navy); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: #fff; border-radius: var(--radius); padding: 36px 32px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,0.35); }
.login-brand { font-weight: 800; font-size: 20px; color: var(--navy); text-align: center; }
.login-sub { text-align: center; color: var(--text-muted); font-size: 13px; margin: 4px 0 22px; }

.flash-stack { margin-bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 11px 16px; border-radius: 6px; font-size: 13.5px; font-weight: 500; }
.flash-success { background: #E6F4EC; color: var(--green); }
.flash-error { background: var(--red-bg); color: var(--red-text); }

.role-badge { font-size: 10.5px; font-weight: 700; padding: 2px 9px; border-radius: 100px; text-transform: uppercase; }
.role-admin { background: #FDEEDD; color: var(--orange-dark); }
.role-user { background: #EEF1F8; color: var(--navy-light); }
.status-dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; }
.status-active { background: var(--green); }
.status-inactive { background: #C7CCD9; }
.activity-row { display: flex; gap: 14px; padding: 10px 14px; border-bottom: 1px solid #F0F1F3; font-size: 12.5px; align-items: baseline; }
.activity-row .time { color: var(--text-faint); width: 140px; flex-shrink: 0; font-family: var(--mono); }
.activity-row .who { font-weight: 600; width: 90px; flex-shrink: 0; }
.activity-row .what { color: var(--text-muted); }
.tag-action { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 100px; background: #EEF1F8; color: var(--navy-light); text-transform: uppercase; }
.admin-nav { display: flex; gap: 6px; margin-bottom: 20px; }
.admin-nav a { padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.admin-nav a.active { background: var(--navy); color: #fff; }
.admin-nav a:hover:not(.active) { background: #F0F1F4; }
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 24px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .big-num { font-size: 26px; font-weight: 800; color: var(--navy); font-family: var(--mono); }
.stat-card .label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.4px; margin-top: 4px; }

@media (max-width: 720px) {
  .topnav-inner { padding: 0 12px; }
  .page { padding: 20px 12px 60px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Responsive table -> cards ---------- */
/* Below the breakpoint, tables with .price-table stop being tables visually -
   each row becomes a stacked card, each cell becomes a labeled line. This
   avoids horizontal scrolling/page overflow entirely rather than just hiding
   columns (which loses information silently). */
@media (max-width: 700px) {
  .table-wrap { overflow-x: visible; }
  table.price-table, table.price-table tbody, table.price-table tr, table.price-table td {
    display: block;
    width: 100%;
  }
  table.price-table thead { display: none; }
  table.price-table tr.product-row {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    padding: 12px 14px 6px;
  }
  table.price-table tr.product-row td {
    padding: 6px 0;
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
  }
  table.price-table tr.product-row td.num { text-align: right; font-family: var(--mono); }
  table.price-table tr.product-row td:first-child {
    font-size: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid #F0F1F3;
    margin-bottom: 4px;
  }
  /* Label each value cell using a data attribute set in the template */
  table.price-table tr.product-row td[data-label]::before {
    content: attr(data-label);
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.4px;
  }
  tr.history-row td { display: block; padding: 0; }
  .history-panel { padding: 10px 4px 14px; }
  .history-table, .history-table thead, .history-table tbody, .history-table tr, .history-table td {
    display: block; width: 100%;
  }
  .history-table thead { display: none; }
  .history-table tr {
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 8px;
    padding: 8px 10px;
    background: #fff;
  }
  .history-table tr td {
    border-bottom: none;
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
  }
  .history-table tr td[data-label]::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 700;
    color: var(--text-faint);
    text-transform: uppercase;
  }
}

/* ---------- Mobile nav ---------- */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
}

@media (max-width: 860px) {
  .topnav { position: relative; }
  .nav-toggle { display: flex; }
  .nav-links {
    display: none;
    flex-direction: column;
    align-items: stretch;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    width: 100%;
    gap: 2px;
    padding: 10px 12px 14px;
    background: var(--navy);
    box-shadow: 0 12px 24px rgba(0,0,0,0.25);
    z-index: 50;
  }
  .nav-links.open { display: flex; }
  .nav-link { width: 100%; padding: 12px 10px; }
  .nav-sep { display: none; }
  .nav-user { padding: 10px 10px 0; }
}

.rename-form { display: inline; }
.rename-input { min-width: 220px; border-color: transparent; background: transparent; }
.rename-input:hover, .rename-input:focus { border-color: var(--border); background: #fff; }

@media (max-width: 700px) {
  table.price-table tr.product-row td[data-label=""]::before { content: none; }
  .rename-input { width: 100%; min-width: 0; }
  /* Inline settings forms (unit/reorder/recipe/save) need to stack and use
     full width on mobile - they have fixed pixel widths for desktop's
     single-line layout, which overflow a phone screen otherwise. */
  .adjust-form {
    flex-wrap: wrap;
    width: 100%;
  }
  .adjust-form input, .adjust-form select {
    width: 100% !important;
    flex: 1 1 100%;
  }
  .adjust-form button { flex: 1 1 100%; margin-top: 4px; }
  table.price-table tr.product-row td.settings-cell { display: block; }
  table.price-table tr.product-row td.settings-cell::before {
    display: block;
    margin-bottom: 6px;
  }
  /* :has() fallback for the same effect on any other form-containing cells */
  table.price-table tr.product-row td[data-label]:has(form) { display: block; }
  table.price-table tr.product-row td[data-label]:has(form)::before {
    display: block;
    margin-bottom: 6px;
  }
}

.edit-link {
  font-size: 11.5px;
  color: var(--text-faint);
  text-decoration: none;
  margin-left: 8px;
  font-weight: 600;
}
.edit-link:hover { color: var(--orange-dark); text-decoration: underline; }
