:root {
  --bg: #F5F3EF;
  --panel: #ffffff;
  --border: #e2e6ea;
  --text: #1a1d23;
  --muted: #6b7280;
  --primary: #E04A20;
  --primary-dark: #c43d18;
  --primary-bg: #fdf0ec;
  --navy: #1B2137;
  --navy-light: #2a3350;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);
  /* Accent set for stat tiles, chips, and other spot color - a wider,
     livelier palette than the core brand pair, used deliberately (never
     cycled at random) so each metric keeps a stable identity. */
  --accent-blue: #2a78d6;
  --accent-aqua: #1093a3;
  --accent-violet: #6440c9;
  --accent-magenta: #c23d7a;
  --accent-teal: #0f9e7a;
}

* { 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);
}

a { color: var(--primary); }

.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(560px circle at 12% 8%, rgba(224,74,32,.35), transparent 60%),
    radial-gradient(620px circle at 92% 88%, rgba(42,120,214,.30), transparent 60%),
    linear-gradient(160deg, var(--navy) 0%, #232b48 55%, #2f2350 100%);
}
.center-page::before {
  /* faint dot-grid texture for depth, purely decorative */
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 26px 26px;
  pointer-events: none;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  /* Lets a wide table scroll inside its own card on a narrow phone instead
     of blowing out the page width. */
  overflow-x: auto;
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  position: relative;
  z-index: 1;
  border: none;
  border-radius: 16px;
  padding: 36px 32px 32px;
  box-shadow: 0 24px 60px -12px rgba(10, 12, 30, .55);
  background:
    linear-gradient(#fff, #fff) padding-box,
    linear-gradient(135deg, var(--primary), var(--accent-blue)) border-box;
  border: 3px solid transparent;
  /* .card sets overflow-x: auto for scrollable tables, which also forces
     overflow-y to clip - override so the floating logo badge above the
     card (negative margin) doesn't get cut off. */
  overflow: visible;
}
.login-logo-wrap {
  width: 76px;
  height: 76px;
  margin: -60px auto 18px;
  border-radius: 20px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px -6px rgba(10,12,30,.35), 0 0 0 6px rgba(255,255,255,.15);
}
.login-logo { height: 40px; width: auto; }
.login-card h1 {
  font-size: 21px;
  margin-bottom: 4px;
  background: linear-gradient(100deg, var(--navy), var(--accent-blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 800;
}
.login-card p.sub { color: var(--muted); margin-top: 0; margin-bottom: 22px; font-size: 14px; }
.login-card form { text-align: left; }
.login-card button[type="submit"] {
  background: linear-gradient(100deg, var(--primary), var(--primary-dark));
  box-shadow: 0 8px 20px -6px rgba(224,74,32,.55);
}
.login-card button[type="submit"]:hover { box-shadow: 0 10px 24px -6px rgba(224,74,32,.65); transform: translateY(-1px); }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 14px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

textarea { min-height: 60px; resize: vertical; }

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  transition: background .15s, box-shadow .15s, transform .15s;
}
button:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 10px -3px rgba(224,74,32,.4); }
button:active { transform: translateY(0); }
button.secondary { background: #fff; border: 1px solid var(--border); color: var(--text); box-shadow: none; }
button.secondary:hover { background: #f3f4f6; box-shadow: var(--shadow); }
button.danger { background: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.error-box {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.error-box.show { display: block; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  background: linear-gradient(100deg, var(--navy) 0%, var(--navy-light) 100%);
  border-bottom: 3px solid var(--primary);
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: var(--shadow-md);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; color: #fff; }
.topbar .brand img { height: 30px; width: auto; display: block; border-radius: 6px; box-shadow: 0 0 0 2px rgba(255,255,255,.12); }
.topbar .who { color: rgba(255,255,255,.65); font-size: 13px; }
.topbar .actions { display: flex; align-items: center; gap: 12px; }
.topbar button.secondary {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
}
.topbar button.secondary:hover { background: rgba(255,255,255,.18); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 800px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.cols-5 { grid-template-columns: 1fr; }
}
@media (max-width: 1000px) and (min-width: 801px) {
  .grid.cols-5 { grid-template-columns: repeat(3, 1fr); }
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat::after {
  /* soft tint wash in the accent color, bleeding from the top-right corner */
  content: '';
  position: absolute;
  top: -30px;
  right: -30px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: var(--stat-accent, var(--primary));
  opacity: .08;
}
.stat .icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  background: rgba(0,0,0,.045);
  margin-bottom: 10px;
  position: relative;
}
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; color: var(--navy); }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 28px 0 12px;
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::before {
  content: '';
  width: 4px;
  height: 16px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--primary), var(--accent-blue));
  display: inline-block;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tbody tr:hover td { background: #fafafa; }
tr.low-stock td { background: var(--warning-bg); }
tr.low-stock td:first-child { border-left: 3px solid var(--warning); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}
.badge.INWARD { background: var(--success-bg); color: var(--success); }
.badge.USAGE { background: var(--primary-bg); color: var(--primary); }
.badge.WASTAGE { background: var(--danger-bg); color: var(--danger); }
.badge.SALE_DEDUCTION { background: #f5f3ff; color: #7c3aed; }
.badge.ADJUSTMENT { background: #f1f5f9; color: #475569; }
.badge.BILL { background: var(--danger-bg); color: var(--danger); }
.badge.PAYMENT { background: var(--success-bg); color: var(--success); }

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  flex-wrap: wrap;
  background: #eceae4;
  padding: 5px;
  border-radius: 12px;
  width: fit-content;
  max-width: 100%;
}
.tabs button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-weight: 600;
  border-radius: 8px;
  transition: background .15s, color .15s, box-shadow .15s;
}
.tabs button:hover { color: var(--navy); background: rgba(255,255,255,.6); }
.tabs button.active {
  background: linear-gradient(100deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 12px -3px rgba(224,74,32,.5);
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--navy);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: all .2s;
  pointer-events: none;
  max-width: 320px;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters > div { min-width: 140px; }
.filters label { margin-bottom: 4px; }
.filters input, .filters select { margin-bottom: 0; }

.two-col { display: grid; grid-template-columns: 340px 1fr; gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

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

.checkbox-list { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.checkbox-list label { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 13px; color: var(--text); margin-bottom: 6px; }
.checkbox-list label:last-child { margin-bottom: 0; }
.checkbox-list input[type="checkbox"] { width: auto; margin: 0; }
.hint { font-size: 12px; color: var(--muted); margin: -10px 0 14px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(27, 33, 55, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.overlay-card {
  background: var(--panel);
  border-radius: var(--radius);
  border-top: 4px solid var(--primary);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.review-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  background: var(--warning-bg);
  color: var(--warning);
}
.review-badge.reviewed { background: var(--success-bg); color: var(--success); }

canvas { max-width: 100%; }

/* ---- Analytics tab: self-contained chart primitives (no external lib) --- */
.viz-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.viz-card h3 { margin: 0 0 2px; font-size: 14px; color: var(--navy); }
.viz-card .viz-sub { font-size: 12px; color: var(--muted); margin: 0 0 14px; }

.viz-hbar { display: flex; flex-direction: column; gap: 10px; }
.viz-hbar-row { display: grid; grid-template-columns: 140px 1fr 72px; align-items: center; gap: 10px; border-radius: 6px; }
.viz-hbar-row:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
.viz-hbar-label { font-size: 12.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-hbar-track { position: relative; height: 20px; background: #f1f1ef; border-radius: 4px; display: flex; gap: 2px; overflow: hidden; }
.viz-hbar-track-stacked .viz-hbar-fill:first-child { border-radius: 4px 0 0 4px; }
.viz-hbar-fill { height: 100%; border-radius: 0 4px 4px 0; transition: width .3s ease; min-width: 2px; }
.viz-hbar-value { font-size: 12.5px; font-weight: 600; color: var(--navy); text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .viz-hbar-row { grid-template-columns: 90px 1fr 60px; }
  .viz-hbar-label { font-size: 11.5px; }
}

.viz-columns { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 20px; }
.viz-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; min-width: 4px; border-radius: 4px; }
.viz-col:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
.viz-col-bar { width: 100%; max-width: 22px; border-radius: 4px 4px 0 0; transition: height .3s ease; }
.viz-col-tip { position: absolute; top: -18px; font-size: 11px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.viz-col-axislabel { font-size: 10px; color: var(--muted); margin-top: 6px; white-space: nowrap; }

.viz-legend { display: flex; gap: 16px; margin-bottom: 12px; }
.viz-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.viz-legend-item i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.viz-meter-track { height: 22px; background: var(--success-bg); border-radius: 6px; overflow: hidden; }
.viz-meter-fill { height: 100%; background: var(--warning); border-radius: 6px 0 0 6px; transition: width .3s ease; }
.viz-meter-caption { font-size: 12px; color: var(--muted); margin-top: 8px; }

.viz-tooltip {
  position: fixed;
  z-index: 200;
  background: var(--navy);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s, transform .12s;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 220px;
}
.viz-tooltip.show { opacity: 1; transform: translateY(0); }
.viz-tooltip strong { font-size: 13px; }
.viz-tooltip span { color: rgba(255,255,255,.7); }

.viz-funnel-note { font-size: 12px; color: var(--muted); margin-top: 10px; }

.viz-efficiency {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}
.viz-efficiency strong { font-size: 20px; color: var(--navy); margin: 0 4px; }
.viz-efficiency.muted { color: var(--muted); font-size: 12.5px; }

/* ---- Mobile ----------------------------------------------------------
   Staff and supervisors mostly use this on a phone; only admin is on a
   desktop. Tighter spacing, bigger tap targets, and inputs at 16px so
   iOS Safari doesn't zoom in on focus. */
@media (max-width: 700px) {
  .container { padding: 14px; }

  .topbar { flex-wrap: wrap; height: auto; min-height: 56px; padding: 10px 14px; gap: 8px 14px; }
  .topbar .brand { font-size: 14px; }
  .topbar .who { font-size: 12px; }
  .topbar .actions { gap: 8px; }

  button { padding: 13px 18px; font-size: 15px; min-height: 44px; }
  input, select, textarea { padding: 13px 14px; font-size: 16px; min-height: 44px; }
  textarea { min-height: 70px; }
  label { font-size: 13px; }

  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; margin-bottom: 14px; }
  .tabs button { flex: 0 0 auto; min-height: 40px; padding: 10px 14px; }

  .card { padding: 16px; }
  .two-col { gap: 14px; }
  .grid { gap: 12px; }

  .section-title { margin: 20px 0 10px; }

  table { font-size: 12.5px; }
  th, td { padding: 8px; }

  .overlay { padding: 10px; }
  .overlay-card { padding: 20px 16px; }

  .filters { gap: 8px; }
  .filters > div { min-width: 0; flex: 1 1 140px; }

  .viz-hbar-row { grid-template-columns: 92px 1fr 56px; gap: 8px; }
  .viz-hbar-label { font-size: 11px; }
}
