:root {
  --bg: #f4f6fa; --panel: #fff; --text: #1b2333; --muted: #6b7489; --line: #e3e7ef;
  --brand: #1463ff; --brand-2: #0b47c4; --ok: #12a150; --warn: #d98a00; --bad: #d93838; --info: #6d4aff;
  --side: #0f1a2e; --side-text: #c7d0e3; --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Bengali", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d1220; --panel: #151c2e; --text: #e6eaf3; --muted: #8d97ad; --line: #26304a; --side: #0a0f1b; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 18px; margin: 0; flex: 1; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.err { color: var(--bad); margin-top: 8px; min-height: 18px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0f1a2e, #1463ff); }
.login-card { background: var(--panel); padding: 32px; border-radius: 14px; width: min(360px, 92vw); display: grid; gap: 12px; box-shadow: 0 20px 60px #0005; }
.brand-lg { font-size: 22px; font-weight: 700; }

/* layout */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; flex-shrink: 0; }
.brand { font-weight: 700; color: #fff; padding: 18px 18px 12px; font-size: 16px; }
nav a { display: block; color: var(--side-text); padding: 8px 18px; border-left: 3px solid transparent; }
nav a:hover { background: #ffffff10; }
nav a.active { background: #ffffff18; color: #fff; border-left-color: var(--brand); }
.nav-h { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .5; padding: 14px 18px 4px; }
.me { margin-top: auto; padding: 14px 18px; border-top: 1px solid #ffffff15; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.me .btn { color: var(--side-text); border-color: #ffffff30; }
main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
#menuBtn { display: none; }
.search input { width: 260px; }
#view { padding: 20px 24px 60px; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -240px; z-index: 20; transition: left .2s; }
  .sidebar.open { left: 0; }
  #menuBtn { display: inline-block; }
  .search input { width: 150px; }
  #view { padding: 16px; }
}

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: wait; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { min-height: 80px; resize: vertical; font-family: ui-monospace, monospace; }
input:focus, select:focus, textarea:focus { outline: 2px solid #1463ff40; border-color: var(--brand); }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check input { width: auto; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #1463ff0a; }
.mono { font-family: ui-monospace, monospace; font-size: 13px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: var(--line); white-space: nowrap; }
.b-ok { background: #12a15022; color: var(--ok); }
.b-warn { background: #d98a0022; color: var(--warn); }
.b-bad { background: #d9383822; color: var(--bad); }
.b-info { background: #6d4aff22; color: var(--info); }
.b-blue { background: #1463ff22; color: var(--brand); }

.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 120px 1fr 90px; gap: 8px; align-items: center; font-size: 13px; }
.bar .track { background: var(--line); border-radius: 4px; height: 10px; overflow: hidden; }
.bar .fill { background: var(--brand); height: 100%; }
.bar .n { text-align: right; font-variant-numeric: tabular-nums; }

.lines .line { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; align-items: start; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.lines .line textarea { min-height: 60px; }
@media (max-width: 700px) { .lines .line { grid-template-columns: 1fr; } }

.modal { position: fixed; inset: 0; background: #0008; display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 12px; padding: 22px; width: min(820px, 100%); max-height: 92vh; overflow: auto; position: relative; }
.modal-x { position: absolute; right: 12px; top: 8px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); }
.toast { position: fixed; bottom: 20px; right: 20px; background: #1b2333; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 420px; }
.toast.bad { background: var(--bad); }

/* chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 150px); }
.chat-log { flex: 1; overflow-y: auto; padding: 8px 4px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.bot table { margin: 8px 0; font-size: 13px; }
.msg.bot p { margin: 6px 0; }
.msg .tools { font-size: 11px; color: var(--muted); margin-top: 6px; }
.chat-input { display: flex; gap: 8px; padding-top: 10px; }
.chat-input textarea { min-height: 46px; height: 46px; font-family: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 13px; color: var(--text); }
.chip:hover { border-color: var(--brand); }
.md h3, .md h4 { margin: 10px 0 4px; font-size: 14px; }
.md code { background: var(--line); padding: 1px 4px; border-radius: 4px; }
.md ul, .md ol { margin: 4px 0; padding-left: 20px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font: inherit; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
pre.code { background: var(--bg); border: 1px solid var(--line); padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 12px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* barcode scanning */
.scanbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: #1463ff0d; border: 1px dashed var(--brand); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.scanbar .scan-ico { font-size: 20px; color: var(--brand); }
.scanbar input.scan { flex: 1; min-width: 220px; font-family: ui-monospace, monospace; font-size: 15px; }
.scanbar .scan-status { flex-basis: 100%; font-size: 13px; }
.scan-status.ok { color: var(--ok); }

/* stock level colour bars */
.lvl { min-width: 170px; }
.lvl-track { position: relative; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.lvl-fill { height: 100%; border-radius: 4px; }
.lvl-min { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: .35; }
.lvl-txt { font-size: 12px; margin-top: 3px; white-space: nowrap; }
.lvl-tag { font-size: 11px; padding: 0 6px; border-radius: 99px; }
.lvl-ok .lvl-fill { background: var(--ok); } .lvl-ok .lvl-tag { background: #12a15022; color: var(--ok); }
.lvl-low .lvl-fill { background: var(--warn); } .lvl-low .lvl-tag { background: #d98a0022; color: var(--warn); }
.lvl-critical .lvl-fill { background: var(--bad); } .lvl-critical .lvl-tag { background: #d9383822; color: var(--bad); }
.bell { position: relative; border: 0; background: none; font-size: 20px; cursor: pointer; padding: 4px 8px; }
.bell-n { position: absolute; top: -2px; right: -2px; background: var(--warn); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; min-width: 18px; height: 18px; line-height: 18px; text-align: center; padding: 0 4px; }
.bell-n.crit { background: var(--bad); }
