@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,300&family=DM+Mono:wght@400;500&display=swap');

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --accent:        #3b82f6;
  --accent-glow:   rgba(59,130,246,.18);
  --accent-hover:  #2563eb;
  --danger:        #ef4444;
  --warning:       #f59e0b;
  --success:       #22c55e;
  --info:          #06b6d4;
  --radius:        10px;
  --radius-lg:     16px;
  --sidebar-w:     240px;
  --topbar-h:      56px;
  --mobile-nav-h:  64px;
  --transition:    .18s ease;
  --font:          'DM Sans', sans-serif;
  --mono:          'DM Mono', monospace;
}

/* LIGHT theme (default) */
[data-theme="light"] {
  --bg:            #f5f5f7;
  --bg-card:       #ffffff;
  --bg-sidebar:    #fafafa;
  --bg-hover:      #f0f0f5;
  --bg-input:      #f7f7fa;
  --bg-modal:      #ffffff;
  --border:        rgba(0,0,0,.08);
  --border-strong: rgba(0,0,0,.14);
  --text:          #111116;
  --text-muted:    #666680;
  --text-faint:    #aaaabd;
  --scrollbar:     #d5d5e2;
  --shadow:        0 1px 4px rgba(0,0,0,.08);
  --shadow-lg:     0 8px 32px rgba(0,0,0,.12);
}

/* DARK theme */
[data-theme="dark"] {
  --bg:            #0d0d0f;
  --bg-card:       #161618;
  --bg-sidebar:    #111113;
  --bg-hover:      #1e1e22;
  --bg-input:      #1a1a1e;
  --bg-modal:      #18181b;
  --border:        rgba(255,255,255,.07);
  --border-strong: rgba(255,255,255,.13);
  --text:          #e8e8ed;
  --text-muted:    #8888a0;
  --text-faint:    #555565;
  --scrollbar:     #2a2a35;
  --shadow:        0 1px 4px rgba(0,0,0,.3);
  --shadow-lg:     0 8px 32px rgba(0,0,0,.5);
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: var(--font); cursor: pointer; border: none; outline: none; }
input, select, textarea { font-family: var(--font); outline: none; border: none; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 99px; }

/* ── Login ───────────────────────────────────────────────────────────────── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
  position: fixed; inset: 0; z-index: 9999; padding: 1rem;
}
#login-screen.hidden { display: none; }
.login-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 2.2rem 1.8rem;
  width: 100%; max-width: 360px;
  box-shadow: var(--shadow-lg);
  animation: fadeUp .4s ease;
}
.login-logo { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.8rem; }
.login-logo-icon {
  width: 36px; height: 36px; background: var(--accent);
  border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.login-logo-text { font-size: 1.1rem; font-weight: 700; letter-spacing: -.02em; }
.login-logo-sub { font-size: .72rem; color: var(--text-muted); }
.login-card h2 { font-size: 1.3rem; font-weight: 600; margin-bottom: .25rem; letter-spacing: -.02em; }
.login-card > p { color: var(--text-muted); font-size: .83rem; margin-bottom: 1.5rem; }
.form-group { margin-bottom: .9rem; }
.form-group label { display: block; font-size: .72rem; font-weight: 600; color: var(--text-muted); margin-bottom: .35rem; letter-spacing: .04em; text-transform: uppercase; }
.form-group input {
  width: 100%; padding: .75rem .9rem;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .9rem; transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
}
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.btn-login {
  width: 100%; padding: .85rem; margin-top: .5rem;
  background: var(--accent); color: #fff;
  border-radius: var(--radius); font-size: .95rem; font-weight: 600;
  transition: background var(--transition); display: flex; align-items: center; justify-content: center; gap: .5rem;
}
.btn-login:hover { background: var(--accent-hover); }
.btn-login:active { transform: scale(.98); }
.login-error { color: var(--danger); font-size: .8rem; margin-top: .6rem; text-align: center; min-height: 1.2em; }

/* ── App layout ──────────────────────────────────────────────────────────── */
#app { display: flex; min-height: 100vh; }
#app.hidden { display: none; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 200;
  overflow: hidden; /* Prevent sidebar itself from scrolling */
  transition: transform var(--transition), background var(--transition);
}
.sidebar-header {
  padding: 1rem 1.1rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .6rem; height: var(--topbar-h);
}
.sidebar-logo-icon {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0; color: #fff;
}
.sidebar-logo-text { font-size: .95rem; font-weight: 700; letter-spacing: -.02em; }
.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: .7rem .55rem; min-height: 0; }
.nav-section { margin-bottom: 1.2rem; }
.nav-section-label {
  font-size: .65rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-faint);
  padding: 0 .55rem; margin-bottom: .35rem;
}
.nav-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .6rem .7rem; border-radius: 8px;
  font-size: .855rem; font-weight: 500; color: var(--text-muted);
  cursor: pointer; position: relative;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px; -webkit-tap-highlight-color: transparent;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); }
.nav-icon { width: 18px; text-align: center; font-size: .9rem; flex-shrink: 0; }
.nav-badge {
  margin-left: auto; background: var(--danger);
  color: #fff; font-size: .62rem; font-weight: 700;
  padding: .1rem .4rem; border-radius: 99px; min-width: 18px; text-align: center;
}
.sidebar-footer { padding: .7rem .55rem; border-top: 1px solid var(--border); flex-shrink: 0; background: var(--bg-sidebar); }
.user-pill {
  display: flex; align-items: center; gap: .55rem;
  padding: .45rem .6rem; border-radius: 8px; cursor: default;
  min-width: 0; /* Allow children to shrink */
}
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .68rem; color: var(--text-muted); text-transform: capitalize; }
.btn-logout {
  padding: .32rem .65rem; border-radius: 7px;
  background: rgba(239,68,68,.08); color: var(--danger);
  border: 1px solid rgba(239,68,68,.18);
  font-size: .72rem; font-weight: 600;
  transition: all var(--transition); white-space: nowrap; flex-shrink: 0;
}
.btn-logout:hover { background: rgba(239,68,68,.15); border-color: rgba(239,68,68,.35); }

/* ── Main content area ───────────────────────────────────────────────────── */
#main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
#topbar {
  height: var(--topbar-h); background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .8rem; padding: 0 1.2rem;
  position: sticky; top: 0; z-index: 100;
}
.topbar-title { font-size: .95rem; font-weight: 600; flex: 1; letter-spacing: -.01em; }
.topbar-actions { display: flex; align-items: center; gap: .4rem; }
.btn-icon {
  width: 36px; height: 36px; border-radius: 8px;
  background: transparent; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.hamburger { display: none; }
#content { flex: 1; padding: 1.4rem; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.1rem 1.3rem;
  transition: background var(--transition), border-color var(--transition);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.card-title { font-size: .9rem; font-weight: 600; letter-spacing: -.01em; }

/* ── KPI Stats ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: .9rem; margin-bottom: 1.2rem;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem 1.1rem;
  position: relative; overflow: hidden;
  transition: border-color var(--transition), transform var(--transition);
  animation: fadeUp .4s ease both;
}
.stat-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--stat-accent, var(--accent));
}
.stat-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--stat-bg, var(--accent-glow));
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; margin-bottom: .7rem; color: var(--stat-accent, var(--accent));
}
.stat-value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.03em; line-height: 1; margin-bottom: .18rem; }
.stat-label { font-size: .7rem; color: var(--text-muted); font-weight: 500; }

/* ── Desktop table ───────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .835rem; }
thead th {
  text-align: left; padding: .65rem .9rem;
  font-size: .68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: .75rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--bg-hover); }

/* ── MOBILE CARD LIST — replaces table rows on small screens ─────────────── */
/* Orders card */
.order-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem 1.1rem;
  margin-bottom: .7rem; transition: border-color var(--transition);
  animation: fadeUp .25s ease;
}
.order-card:hover { border-color: var(--border-strong); }
.order-card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .6rem; gap: .5rem;
}
.order-card-ref { font-family: var(--mono); font-size: .85rem; font-weight: 600; }
.order-card-badges { display: flex; gap: .35rem; flex-wrap: wrap; }
.order-card-body { font-size: .82rem; color: var(--text-muted); margin-bottom: .7rem; line-height: 1.6; }
.order-card-body strong { color: var(--text); }
.order-card-actions { display: flex; gap: .45rem; flex-wrap: wrap; }

/* Stock card */
.stock-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: .9rem 1rem;
  margin-bottom: .6rem; display: flex; align-items: center; gap: .9rem;
  animation: fadeUp .2s ease;
}
.stock-card-icon {
  width: 42px; height: 42px; border-radius: 10px;
  background: var(--bg-hover); display: flex; align-items: center;
  justify-content: center; font-size: 1.2rem; flex-shrink: 0;
}
.stock-card-info { flex: 1; min-width: 0; overflow: hidden; }
.stock-card-name { font-size: .85rem; font-weight: 600; margin-bottom: .18rem;
  white-space: normal; word-break: break-word; line-height: 1.3; }
.stock-card-meta { font-size: .7rem; color: var(--text-muted); white-space: normal; word-break: break-word; }
.stock-card-qty { text-align: right; flex-shrink: 0; min-width: 60px; }
.stock-card-qty-val { font-size: 1.2rem; font-weight: 700; letter-spacing: -.02em; }
.stock-card-qty-unit { font-size: .68rem; color: var(--text-muted); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: .2rem .6rem; border-radius: 99px;
  font-size: .7rem; font-weight: 600; white-space: nowrap;
}
.badge-blue   { background: rgba(59,130,246,.12); color: #2563eb; }
.badge-green  { background: rgba(34,197,94,.12);  color: #16a34a; }
.badge-yellow { background: rgba(245,158,11,.12); color: #d97706; }
.badge-red    { background: rgba(239,68,68,.12);  color: #dc2626; }
.badge-cyan   { background: rgba(6,182,212,.12);  color: #0891b2; }
.badge-purple { background: rgba(139,92,246,.12); color: #7c3aed; }
.badge-gray   { background: rgba(128,128,160,.1); color: var(--text-muted); }
[data-theme="dark"] .badge-blue   { color: #60a5fa; }
[data-theme="dark"] .badge-green  { color: #4ade80; }
[data-theme="dark"] .badge-yellow { color: #fbbf24; }
[data-theme="dark"] .badge-red    { color: #f87171; }
[data-theme="dark"] .badge-cyan   { color: #22d3ee; }
[data-theme="dark"] .badge-purple { color: #a78bfa; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: var(--radius);
  font-size: .83rem; font-weight: 600;
  transition: all var(--transition); cursor: pointer; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 14px var(--accent-glow); }
.btn-ghost    { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-strong); }
.btn-danger   { background: transparent; color: var(--danger); border: 1px solid rgba(239,68,68,.2); }
.btn-danger:hover { background: rgba(239,68,68,.08); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.08); }
.btn-sm { padding: .38rem .75rem; font-size: .77rem; border-radius: 7px; }
/* Touch-friendly buttons on mobile */
.btn-touch { min-height: 44px; padding: .6rem 1.1rem; font-size: .88rem; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-row { display: grid; gap: .9rem; margin-bottom: .9rem; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.field label { display: block; font-size: .72rem; font-weight: 600; color: var(--text-muted); margin-bottom: .35rem; text-transform: uppercase; letter-spacing: .04em; }
.field input, .field select, .field textarea {
  width: 100%; padding: .7rem .88rem;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .88rem; transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow);
}
.field select { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .8rem center; padding-right: 2rem; }
.field textarea { resize: vertical; min-height: 70px; }
.field-check { display: flex; align-items: center; gap: .5rem; cursor: pointer; padding-top: 1.2rem; }
.field-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg-modal); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); width: 100%; max-width: 540px;
  max-height: 92vh; overflow-y: auto;
  transform: scale(.96) translateY(10px); transition: transform .2s;
  box-shadow: var(--shadow-lg);
}
.modal-overlay.open .modal { transform: none; }
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 960px; }
.modal-header {
  padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--bg-modal); z-index: 1;
}
.modal-title { font-size: .95rem; font-weight: 700; }
.modal-close {
  width: 28px; height: 28px; border-radius: 6px;
  background: transparent; color: var(--text-muted);
  font-size: 1rem; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text); }
.modal-body { padding: 1.3rem; }
.modal-footer {
  padding: .9rem 1.3rem; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: .55rem;
  position: sticky; bottom: 0; background: var(--bg-modal); z-index: 1;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 9999;
  display: flex; flex-direction: column; gap: .45rem;
  max-width: calc(100vw - 2rem);
}
.toast {
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: .7rem .95rem;
  font-size: .83rem; font-weight: 500;
  display: flex; align-items: center; gap: .55rem;
  box-shadow: var(--shadow-lg); animation: slideIn .25s ease; max-width: 320px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--accent); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast-icon { font-size: .95rem; }
.toast.fade-out { animation: fadeOut .25s ease forwards; }

/* ── Search bar ──────────────────────────────────────────────────────────── */
.search-bar {
  display: flex; align-items: center; gap: .45rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .5rem .8rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.search-bar input { background: transparent; color: var(--text); font-size: .86rem; flex: 1; }
.search-bar input::placeholder { color: var(--text-faint); }

/* ── Product dropdown ────────────────────────────────────────────────────── */
.prod-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--radius); z-index: 500;
  max-height: 240px; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.prod-option {
  padding: .6rem .85rem; cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.prod-option:last-child { border-bottom: none; }
.prod-option:hover, .prod-option:active { background: var(--bg-hover); }

/* ── Item builder ────────────────────────────────────────────────────────── */
.item-builder-row { position: relative; }

/* ── Stock indicators ────────────────────────────────────────────────────── */
.stock-bar { display: flex; align-items: center; gap: .55rem; }
.stock-progress { flex: 1; height: 4px; background: var(--border); border-radius: 99px; overflow: hidden; min-width: 50px; }
.stock-progress-fill { height: 100%; border-radius: 99px; transition: width .3s; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 3.5rem 2rem; color: var(--text-faint); text-align: center;
}
.empty-state .empty-icon { font-size: 2.2rem; margin-bottom: .8rem; opacity: .5; }
.empty-state p { font-size: .88rem; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .6s linear infinite; flex-shrink: 0;
}
.page-loader { display: flex; align-items: center; justify-content: center; gap: .8rem; height: 200px; color: var(--text-muted); }

/* ── Dashboard grid ──────────────────────────────────────────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.col-span-2 { grid-column: 1 / -1; }

/* ── Transit steps ───────────────────────────────────────────────────────── */
.transit-steps { display: flex; align-items: center; margin: .9rem 0; }
.transit-step { display: flex; flex-direction: column; align-items: center; gap: .28rem; flex: 1; position: relative; }
.transit-step::after { content: ''; position: absolute; top: 13px; left: 50%; width: 100%; height: 2px; background: var(--border); z-index: 0; }
.transit-step:last-child::after { display: none; }
.transit-dot {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--bg-hover); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: .65rem; position: relative; z-index: 1; transition: all var(--transition);
}
.transit-step.done .transit-dot  { background: var(--success); border-color: var(--success); color: #fff; }
.transit-step.active .transit-dot { background: var(--accent); border-color: var(--accent); color: #fff; animation: pulse 1.5s infinite; }
.transit-step.done::after { background: var(--success); }
.transit-label { font-size: .62rem; color: var(--text-muted); text-align: center; line-height: 1.2; }

/* ── Animations ──────────────────────────────────────────────────────────── */
@keyframes fadeUp  { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }
@keyframes fadeOut { to { opacity:0; transform:translateX(20px); } }
@keyframes slideIn { from { opacity:0; transform:translateX(20px); } to { opacity:1; } }
@keyframes spin    { to { transform:rotate(360deg); } }
@keyframes pulse   { 0%,100% { box-shadow:0 0 0 0 rgba(59,130,246,.4); } 50% { box-shadow:0 0 0 6px rgba(59,130,246,0); } }

/* ── Mobile bottom nav ───────────────────────────────────────────────────── */
#mobile-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: var(--bg-card); border-top: 1px solid var(--border);
  padding: .35rem .4rem;
  padding-bottom: max(.35rem, env(safe-area-inset-bottom));
}
.mobile-nav-items { display: flex; justify-content: space-around; }
.mobile-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: .18rem;
  padding: .45rem .6rem; border-radius: 8px; cursor: pointer;
  transition: all var(--transition); font-size: .58rem; color: var(--text-muted);
  min-width: 54px; -webkit-tap-highlight-color: transparent;
}
.mobile-nav-item .mn-icon { font-size: 1.25rem; line-height: 1; }
.mobile-nav-item.active { color: var(--accent); background: var(--accent-glow); }

/* ── Sidebar overlay ─────────────────────────────────────────────────────── */
#sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 199;
  background: rgba(0,0,0,.45); backdrop-filter: blur(2px);
}

/* ── Page toolbar (filters + actions) ───────────────────────────────────── */
.page-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: .7rem; margin-bottom: 1.1rem; flex-wrap: wrap;
}
.toolbar-filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; flex: 1; }
.toolbar-actions { display: flex; gap: .4rem; flex-shrink: 0; }
.filter-select {
  padding: .5rem .85rem; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: .83rem; font-family: var(--font);
  cursor: pointer; -webkit-appearance: none; min-width: 0;
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .82rem; }
.text-xs { font-size: .72rem; }
.font-mono { font-family: var(--mono); }
.text-right { text-align: right; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.section-title { font-size: 1.15rem; font-weight: 700; letter-spacing: -.02em; margin-bottom: 1.1rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: .9rem 0; }

/* ── Wh access matrix ────────────────────────────────────────────────────── */
.field-check { display: flex; align-items: center; gap: .5rem; cursor: pointer; }
.field-check input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet (≤900px)
═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: none; box-shadow: 4px 0 30px rgba(0,0,0,.3); }
  #sidebar-overlay { display: block; }
  #main { margin-left: 0; }
  .hamburger { display: flex !important; }
  #mobile-nav { display: block; }
  #content { padding: 1rem; padding-bottom: calc(var(--mobile-nav-h) + 1rem); }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  /* Switch orders/stock from table to cards */
  .desktop-table { display: none !important; }
  .mobile-cards  { display: block !important; }
  /* Toolbar stacks */
  .page-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-filters { flex-direction: column; }
  .toolbar-actions { justify-content: flex-end; }
  .filter-select { width: 100%; }
  /* Modal slides up from bottom */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 88vh;
  }
  /* Topbar */
  #topbar { padding: 0 .9rem; }
  .topbar-title { font-size: .88rem; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile (≤600px)
═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  :root { --topbar-h: 52px; }
  #content { padding: .75rem; padding-bottom: calc(var(--mobile-nav-h) + .75rem); }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .stat-card { padding: .8rem .9rem; }
  .stat-value { font-size: 1.35rem; }
  .stat-label { font-size: .65rem; }
  .stat-icon { width: 28px; height: 28px; font-size: .8rem; margin-bottom: .5rem; }
  .card { padding: .85rem 1rem; }
  .section-title { font-size: 1rem; }
  /* Touch-friendly tap targets */
  .btn-sm { min-height: 36px; }
  .order-card-actions .btn { min-height: 40px; flex: 1; justify-content: center; }
  .field input, .field select, .field textarea { font-size: 16px; } /* prevents iOS zoom */
  .search-bar input { font-size: 16px; }
  .filter-select { font-size: 16px; }
  #toast-container { bottom: calc(var(--mobile-nav-h) + .5rem); }
}

/* Desktop: hide mobile cards, show table */
.mobile-cards { display: none; }
.desktop-table { display: block; }

/* ── PWA Install Banner ──────────────────────────────────────────────────── */
#pwa-banner {
  position: fixed; bottom: calc(var(--mobile-nav-h) + .5rem); left: .75rem; right: .75rem;
  z-index: 500; background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); padding: .85rem 1rem;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: .8rem;
  animation: slideUp .3s ease;
  transition: transform .3s;
}
#pwa-banner.dismissed { transform: translateY(200px); }
.pwa-banner-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.pwa-banner-text { flex: 1; min-width: 0; }
.pwa-banner-title { font-size: .85rem; font-weight: 600; }
.pwa-banner-sub { font-size: .72rem; color: var(--text-muted); }
@keyframes slideUp { from { transform: translateY(100px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Error toast — larger for important failures ─────────────────────────── */
.toast.error-big {
  border-left: 3px solid var(--danger);
  background: var(--bg-card);
  max-width: 380px;
  padding: .85rem 1.1rem;
}
.toast-error-title { font-weight: 700; font-size: .88rem; margin-bottom: .2rem; color: var(--danger); }
.toast-error-body  { font-size: .8rem; color: var(--text-muted); }

/* ── Stock card mobile improvements ──────────────────────────────────────── */
@media (max-width: 600px) {
  .stock-card { padding: .75rem .85rem; gap: .65rem; }
  .stock-card-icon { width: 36px; height: 36px; font-size: 1rem; border-radius: 8px; }
  .stock-card-name { font-size: .82rem; }
  .stock-card-qty-val { font-size: 1.05rem; }
  /* Page toolbar on very small screens */
  .page-toolbar { gap: .5rem; }
  .toolbar-filters { gap: .4rem; }
  .filter-select { font-size: 15px; padding: .45rem .65rem; }
  /* Warehouse dropdown full width on mobile */
  #stock-wh { width: 100%; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE FIXES v1.4.1
═══════════════════════════════════════════════════════════════════════════ */

/* ── Sidebar footer — always visible ────────────────────────────────────── */
/* (Rules already set above in primary sidebar styles) */

/* ── Dashboard responsive ──────────────────────────────────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.col-span-2 { grid-column: 1 / -1; }

@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .col-span-2 { grid-column: 1; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: .65rem; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: .5rem; }
  .stat-card { padding: .75rem .85rem; }
  .stat-value { font-size: 1.25rem; }
}

/* ── Users table — responsive card on mobile ───────────────────────────── */
.users-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 700px) {
  /* Hide less important columns */
  .users-table th:nth-child(5),
  .users-table td:nth-child(5) { display: none; } /* Status */
  /* Shrink warehouse access column */
  .users-table th:nth-child(4),
  .users-table td:nth-child(4) { max-width: 110px; overflow: hidden; }
}

/* ── Activity log — responsive ─────────────────────────────────────────── */
@media (max-width: 700px) {
  /* Hide less critical columns on small screens */
  .activity-table th:nth-child(4),
  .activity-table td:nth-child(4),
  .activity-table th:nth-child(5),
  .activity-table td:nth-child(5) { display: none; }
  /* Make action column wrap */
  .activity-table td:nth-child(3) { 
    font-size: .72rem; word-break: break-all; max-width: 120px;
  }
}

/* ── Order timeline audit table ────────────────────────────────────────── */
.step-audit-row {
  display: flex; align-items: baseline; gap: .6rem;
  padding: .42rem .75rem; font-size: .75rem;
  border-top: 1px solid var(--border);
}
.step-audit-row:first-child { border-top: none; }
.step-audit-icon { color: var(--success); font-size: .7rem; flex-shrink: 0; width: 12px; }
.step-audit-label { font-weight: 600; min-width: 70px; color: var(--text); flex-shrink: 0; }
.step-audit-time { color: var(--text-muted); flex: 1; }
.step-audit-by { color: var(--text-muted); text-align: right; font-size: .72rem; }

@media (max-width: 500px) {
  .step-audit-row { flex-wrap: wrap; gap: .25rem; padding: .5rem .75rem; }
  .step-audit-by { width: 100%; text-align: left; padding-left: 22px; }
}

/* ── Topbar on mobile — tighten ─────────────────────────────────────────── */
@media (max-width: 400px) {
  #topbar { padding: 0 .65rem; gap: .4rem; }
  .topbar-title { font-size: .82rem; }
  .btn-icon { width: 32px; height: 32px; }
}

/* ── Movements table — hide SKU on small screens ────────────────────────── */
@media (max-width: 700px) {
  .movements-table th:nth-child(2),
  .movements-table td:nth-child(2),
  .movements-table th:nth-child(6),
  .movements-table td:nth-child(6) { display: none; }
}

/* ── Dashboard Recent Orders table on mobile ────────────────────────────── */
@media (max-width: 600px) {
  /* Stack KPI cards in single column on very small screens */
  .stats-grid { gap: .5rem; }
  /* Recent orders: hide status col to fit */
  .dashboard-grid .card table th:last-child,
  .dashboard-grid .card table td:last-child { display: none; }
}

/* ── Barcode display ─────────────────────────────────────────────────────── */
.barcode-tag {
  display: inline-flex; align-items: center; gap: .25rem;
  font-family: var(--mono); font-size: .68rem; color: var(--text-muted);
  background: var(--bg-hover); border: 1px solid var(--border);
  padding: .1rem .4rem; border-radius: 4px; margin-top: 2px;
}

/* ── Change Password button in sidebar footer ────────────────────────────── */
.btn-change-pw {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .28rem .45rem;
  font-size: .8rem;
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.btn-change-pw:hover { background: var(--bg-hover); color: var(--text); }
