/* UP Packing ERP — look & feel follows the WHB ERP (Bootstrap DashForge admin
   theme): light UI, white top navbar, blue primary, white cards on a pale
   grey canvas, uppercase muted table headers, "No data found." empty states. */
:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #f5f6fa;
  --line: #e5e9f2;
  --line-2: #cdd4e0;
  --text: #001737;
  --heading: #1b2e4b;
  --muted: #8392a5;
  --primary: #0168fa;
  --primary-dark: #0153c7;
  --green: #10b759;
  --red: #dc3545;
  --orange: #fd7e14;
  --blue: #0168fa;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3, h4, h5 { color: var(--heading); }

/* ---- top navbar (WHB/DashForge style: brand · nav · company/user right) ---- */
.topbar {
  display: flex; align-items: center; gap: 8px 22px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 8px 20px; min-height: 58px;
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { font-size: 18px; letter-spacing: .2px; color: var(--heading); white-space: nowrap; }
.brand b { font-weight: 800; }
.brand span { font-weight: 300; color: var(--muted); }
.logo { color: var(--primary); margin-right: 6px; }
#nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
#nav button {
  display: flex; align-items: center; gap: 7px;
  background: transparent; color: var(--heading); border: 0;
  padding: 8px 13px; border-radius: 4px; cursor: pointer; font-size: 13.5px;
}
#nav button:hover { color: var(--primary); background: var(--panel-2); }
#nav button.active { color: var(--primary); font-weight: 600; }
#nav button .ico { width: 17px; text-align: center; opacity: .75; }
.top-right { display: flex; align-items: center; gap: 14px; }
.company { font-size: 12px; font-weight: 700; letter-spacing: .4px; color: var(--heading); text-transform: uppercase; }
.user-menu { position: relative; }
#user-btn { background: transparent; border: 0; cursor: pointer; font-size: 13.5px; color: var(--heading); padding: 8px 4px; }
#user-btn:hover { color: var(--primary); }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 6px 20px rgba(28, 39, 60, .12); padding: 8px; z-index: 20;
}
.dropdown .whoami { padding: 6px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.dropdown .whoami b { display: block; font-size: 13.5px; color: var(--heading); }
.dropdown button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 8px 10px; border-radius: 4px; cursor: pointer; font-size: 13.5px; color: var(--text); }
.dropdown button:hover { background: var(--panel-2); color: var(--primary); }

main { padding: 24px 28px; max-width: 1160px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

@media (max-width: 760px) {
  .topbar { height: auto; padding: 10px 14px; }
  .company { display: none; }
  main { padding: 16px; }
}

/* ---- login page (WHB pattern: centered card, welcome line, company select) -- */
.login-body { display: grid; place-items: center; min-height: 100vh; background: var(--bg); }
.login-wrap { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 34px 32px 26px; box-shadow: 0 2px 10px rgba(28, 39, 60, .06); }
.login-logo { font-size: 40px; color: var(--primary); text-align: center; margin-bottom: 6px; }
.login-brand { text-align: center; font-size: 20px; color: var(--heading); margin-bottom: 4px; }
.login-brand b { font-weight: 800; }
.login-brand span { font-weight: 300; color: var(--muted); }
.login-welcome { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.login-btn { width: 100%; margin-top: 20px; padding: 10px; font-size: 14px; }
.login-err { margin-top: 12px; color: var(--red); font-size: 13px; }
.login-copy { text-align: center; color: var(--muted); font-size: 11.5px; margin-top: 22px; }

/* ---- shared components ---- */
h2 { margin: 0 0 4px; font-size: 20px; }
.sub { color: var(--muted); margin: 0 0 20px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 16px; }
.card .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }
.card .v { font-size: 26px; font-weight: 700; margin-top: 6px; color: var(--heading); }
.card .v.warn { color: var(--orange); }

.welcome { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 18px 20px; margin-bottom: 20px; }
.welcome h3 { margin: 0 0 2px; font-size: 17px; }
.welcome .clock { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; background: var(--panel-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 3px; font-size: 11.5px; font-weight: 600; }
.pill.planned, .pill.open { background: rgba(1,104,250,.1); color: var(--blue); }
.pill.in_progress { background: rgba(253,126,20,.12); color: var(--orange); }
.pill.completed, .pill.fulfilled, .pill.ok { background: rgba(16,183,89,.12); color: var(--green); }
.pill.cancelled, .pill.closed, .pill.off { background: rgba(131,146,165,.15); color: var(--muted); }
.pill.warn { background: rgba(220,53,69,.1); color: var(--red); }
.low { color: var(--red); font-weight: 600; }

button.btn { background: var(--primary); color: #fff; border: 1px solid var(--primary); padding: 7px 14px; border-radius: 4px; font-weight: 500; cursor: pointer; font-size: 13.5px; }
button.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
button.btn.ghost { background: var(--panel); color: var(--heading); border: 1px solid var(--line-2); }
button.btn.ghost:hover { background: var(--panel-2); color: var(--primary); }
button.btn.danger { background: #fff; color: var(--red); border: 1px solid rgba(220,53,69,.4); }
button.btn.danger:hover { background: rgba(220,53,69,.08); }
button.btn.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.row { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.row > * { flex: 1 1 320px; }
.row > .tight { flex: 0 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 18px; margin-bottom: 20px; }
.panel h3 { margin: 0 0 14px; font-size: 15px; }
.panel table { border-left: 0; border-right: 0; border-radius: 0; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
input, select, textarea { width: 100%; background: #fff; border: 1px solid var(--line-2); color: var(--text); padding: 8px 10px; border-radius: 4px; font-size: 14px; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(1,104,250,.15); }
textarea { min-height: 110px; font-family: ui-monospace, monospace; font-size: 12px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 10px; flex-wrap: wrap; gap: 10px; }
.toolbar h3 { margin: 0; }

/* sub-tabs inside a panel (e.g. Stock → Products / Materials / Stock Log) */
.subtabs { display: flex; gap: 6px; margin: 0 0 16px; border-bottom: 2px solid var(--line); }
.subtabs button { background: transparent; border: 0; color: var(--muted); padding: 8px 14px; cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.subtabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* permission checkbox grid on the Users panel */
.perm-grid { display: flex; gap: 12px; flex-wrap: wrap; }
.perm-grid label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--text); font-weight: 400; }
.perm-grid input { width: auto; }

.progress { background: var(--line); border-radius: 3px; height: 8px; overflow: hidden; min-width: 90px; }
.progress i { display: block; height: 100%; background: var(--green); }
.progress i.part { background: var(--orange); }

.mono { font-family: ui-monospace, monospace; font-size: 12px; }
.kv { color: var(--muted); font-size: 12px; }

#toast { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 40; }
.msg { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--primary); padding: 10px 14px; border-radius: 4px; max-width: 340px; animation: slide .2s ease; box-shadow: 0 4px 14px rgba(28,39,60,.12); }
.msg.err { border-left-color: var(--red); }
.msg.ok { border-left-color: var(--green); }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } }
.empty { color: var(--muted); padding: 20px; text-align: center; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 22px; min-width: 340px; max-width: 480px; box-shadow: 0 10px 40px rgba(28,39,60,.2); }
dialog::backdrop { background: rgba(27,46,75,.45); }
