:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --border: #e2e6e4;
  --text: #1c2624;
  --text-muted: #64716d;
  --primary: #1f7a5c;
  --primary-dark: #145c44;
  --primary-light: #e5f3ee;
  --danger: #c4432b;
  --danger-light: #fbe8e4;
  --warning: #b8790a;
  --warning-light: #fdf1de;
  --success: #1f7a5c;
  --success-light: #e5f3ee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 27, 0.06), 0 1px 6px rgba(20, 30, 27, 0.05);
  --nav-width: 220px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 0.75em; }

.app-shell { display: flex; min-height: 100vh; }

/* --- Sidebar (desktop) --- */
.sidebar {
  width: var(--nav-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  color: var(--primary-dark);
  margin-bottom: 18px;
  padding: 0 6px;
}
.brand .mark {
  width: 28px; height: 28px; border-radius: 8px;
  display: block; flex-shrink: 0;
}

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--text-muted); font-weight: 500; font-size: 0.92rem;
}
.nav-link:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav-link.active { background: var(--primary-light); color: var(--primary-dark); }
.nav-section-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); margin: 14px 6px 4px;
}

.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.85rem; }
.context-switcher { font-size: 0.8rem; color: var(--text-muted); padding: 6px; }
.context-switcher select { width: 100%; margin-top: 4px; }

/* Same location switcher as the sidebar's .context-switcher, but compact
   for the mobile topbar (sidebar is display:none under 860px, so without
   this there was no way to switch locations at all on a phone). */
.topbar-switcher { flex: 1; min-width: 0; margin: 0 10px; }
.topbar-switcher select {
  width: 100%; max-width: 220px; font-size: 0.85rem; padding: 6px 8px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

.demo-banner {
  background: var(--warning-light); border: 1px solid #f0dcae;
}
.demo-banner strong { color: var(--warning); }

.onboarding-card { background: var(--primary-light); border: 1px solid #cfe7dc; }
.onboarding-progress {
  height: 6px; border-radius: 4px; background: rgba(31,122,92,0.15); margin: 12px 0 4px; overflow: hidden;
}
.onboarding-progress-bar { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.2s ease; }
.onboarding-list { list-style: none; margin: 10px 0 0; padding: 0; }
.onboarding-list li {
  display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; border-top: 1px solid rgba(31,122,92,0.12);
}
.onboarding-list li:first-child { border-top: none; }
.onboarding-check {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 0.72rem; color: #fff;
  margin-top: 1px;
}
.onboarding-list li.done .onboarding-check { background: var(--primary); }
.onboarding-list li.done .onboarding-label { color: var(--text-muted); }

.pwa-banner { background: var(--primary-light); border: 1px solid #cfe7dc; }

.impersonation-banner {
  background: #4a2b0a; color: #fff3d6; padding: 8px 16px; font-size: 0.85rem;
  text-align: center; position: sticky; top: 0; z-index: 20;
}
.impersonation-banner a { color: #fff; text-decoration: underline; margin-left: 10px; font-weight: 600; }

/* --- Main content --- */
.main { flex: 1; min-width: 0; }
.topbar {
  display: none;
  align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.content { padding: 24px 28px 90px; max-width: 1080px; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-header .subtitle { color: var(--text-muted); margin-top: -6px; }

/* --- Cards --- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

.stat-card { text-align: left; }
.stat-card .stat-value { font-size: 1.7rem; font-weight: 700; }
.stat-card .stat-label { color: var(--text-muted); font-size: 0.82rem; }
.stat-card.alert .stat-value { color: var(--danger); }
.stat-card.warn .stat-value { color: var(--warning); }
.stat-card.good .stat-value { color: var(--success); }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 0.88rem;
  cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }

/* --- Forms --- */
label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.help-text { color: var(--text-muted); font-size: 0.8rem; margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); font-size: 0.92rem; font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.checkbox-row input { width: auto; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 0 0 14px; }
legend { font-weight: 700; padding: 0 6px; }

/* --- Tables --- */
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

/* --- Badges / pills --- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 0.74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.02em;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-neutral { background: var(--bg); color: var(--text-muted); }
.badge-role { background: #ece7fb; color: #5b3fb8; }

/* --- Alerts / flash --- */
.flash { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 0.88rem; font-weight: 500; }
.flash-success { background: var(--success-light); color: var(--primary-dark); }
.flash-error { background: var(--danger-light); color: var(--danger); }

/* --- Empty state --- */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 2rem; margin-bottom: 8px; }

/* --- Auth pages --- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); }
.auth-brand {
  display: flex; align-items: center; gap: 10px; margin-bottom: 22px;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-weight: 700; font-size: 1.3rem; letter-spacing: -0.01em; color: var(--primary-dark);
}
.auth-brand .mark { width: 34px; height: 34px; border-radius: 9px; display: block; flex-shrink: 0; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 0.88rem; color: var(--text-muted); }

/* --- Steps / hazards / CCPs (HACCP plan builder) --- */
.step-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; background: var(--bg); }
.hazard-row { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.ccp-tag { display: inline-block; background: var(--primary); color: #fff; font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 6px; }

/* --- Bottom nav (mobile) --- */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
  justify-content: space-around;
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-muted); font-size: 0.65rem; font-weight: 600; padding: 4px 6px; border-radius: 8px;
  min-width: 56px; text-decoration: none;
}
.bottom-nav a .ic { font-size: 1.15rem; }
.bottom-nav a.active { color: var(--primary); background: var(--primary-light); }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .topbar { display: flex; }
  .content { padding: 16px 14px 90px; }
  .bottom-nav { display: flex; }
  .grid-4, .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.wrap { flex-wrap: wrap; }
