* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #fbfbfb;
  --panel: #fff;
  --sidebar: #f5f5f4;
  --border: #e5e5e3;
  --border-strong: #d6d6d4;
  --text: #1c1c1a;
  --text-2: #6b6b68;
  --text-3: #9b9b98;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --danger: #dc2626;
  --green: #16a34a;
  --radius: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
#app { height: 100vh; display: flex; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ---------- login ---------- */
.login-wrap { margin: auto; width: 340px; padding: 20px; }
.login-logo { width: 52px; height: 52px; border-radius: 12px; background: #222; color: #fff; font-weight: 700; font-size: 22px; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.login-wrap h1 { font-size: 19px; text-align: center; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--text-2); margin-bottom: 22px; }
.login-wrap input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); margin-bottom: 10px; background: #fff; }
.login-wrap input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.btn-primary { background: #222; color: #fff; border-radius: var(--radius); padding: 10px 16px; font-weight: 600; width: 100%; }
.btn-primary:hover { background: #000; }
.login-err { color: var(--danger); text-align: center; margin-top: 10px; min-height: 18px; }

/* ---------- layout ---------- */
.sidebar { width: 220px; min-width: 220px; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 12px 8px; }
.ws { display: flex; align-items: center; gap: 8px; padding: 6px 8px 14px; font-weight: 700; font-size: 14px; }
.ws-logo { width: 24px; height: 24px; border-radius: 6px; background: #222; color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 7px; color: var(--text-2); font-weight: 500; width: 100%; text-align: left; }
.nav-item svg { width: 16px; height: 16px; flex: none; }
.nav-item:hover { background: rgba(0,0,0,.05); }
.nav-item.active { background: rgba(0,0,0,.07); color: var(--text); }
.nav-count { margin-left: auto; color: var(--text-3); font-size: 12px; }
.nav-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); padding: 16px 10px 6px; }
.sidebar-bottom { margin-top: auto; border-top: 1px solid var(--border); padding-top: 8px; }
.me-block { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; width: 100%; text-align: left; }
.me-block:hover { background: rgba(0,0,0,.05); }
.me-name { font-weight: 600; line-height: 1.2; }
.me-role { font-size: 11px; color: var(--text-3); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--panel); }
.topbar h2 { font-size: 15px; font-weight: 700; margin-right: auto; display: flex; align-items: center; gap: 8px; }
.topbar h2 .cnt { color: var(--text-3); font-weight: 500; font-size: 13px; }
.search { position: relative; }
.search input { border: 1px solid var(--border-strong); border-radius: 7px; padding: 7px 10px 7px 30px; width: 220px; background: var(--bg); }
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-3); }
.btn-new { background: #222; color: #fff; border-radius: 7px; padding: 7px 14px; font-weight: 600; white-space: nowrap; }
.btn-new:hover { background: #000; }
.view { flex: 1; overflow: auto; }

/* ---------- filter chips ---------- */
.chips { display: flex; gap: 6px; padding: 12px 20px 0; flex-wrap: wrap; }
.chip { border: 1px solid var(--border-strong); border-radius: 99px; padding: 4px 12px; font-size: 12.5px; color: var(--text-2); background: #fff; }
.chip:hover { border-color: var(--text-3); }
.chip.on { background: #222; color: #fff; border-color: #222; }
.chip .n { opacity: .6; margin-left: 4px; }

/* ---------- table ---------- */
.tbl-wrap { padding: 14px 20px 30px; overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3); padding: 9px 12px; border-bottom: 1px solid var(--border); background: #fafaf9; white-space: nowrap; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: #f7f7f6; }
.rec-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--text-3); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- pills & avatars ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 99px; background: currentColor; }
.av { width: 22px; height: 22px; min-width: 22px; border-radius: 99px; color: #fff; font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.av.lg { width: 34px; height: 34px; min-width: 34px; font-size: 13px; border-radius: 10px; }
.owner-cell { display: flex; align-items: center; gap: 7px; }
.co-logo { width: 20px; height: 20px; min-width: 20px; border-radius: 5px; border: 1px solid var(--border); background: #fff; object-fit: contain; }
.co-logo-fallback { width: 20px; height: 20px; min-width: 20px; border-radius: 5px; background: var(--sidebar); border: 1px solid var(--border); color: var(--text-2); font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- kanban ---------- */
.board { display: flex; gap: 12px; padding: 16px 20px 30px; overflow-x: auto; align-items: flex-start; min-height: calc(100% - 10px); }
.col { min-width: 250px; width: 250px; background: var(--sidebar); border-radius: 10px; padding: 8px; }
.col-head { display: flex; align-items: center; gap: 7px; padding: 4px 6px 8px; font-weight: 700; font-size: 12.5px; }
.col-head .n { color: var(--text-3); font-weight: 500; }
.col-head .sum { margin-left: auto; color: var(--text-2); font-weight: 600; font-size: 12px; }
.col-cards { display: flex; flex-direction: column; gap: 8px; min-height: 30px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 11px; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card:hover { border-color: var(--border-strong); }
.card.dragging { opacity: .4; }
.card-name { font-weight: 600; margin-bottom: 5px; }
.card-co { color: var(--text-2); font-size: 12.5px; display: flex; align-items: center; gap: 6px; margin-bottom: 7px; }
.card-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.card-amt { font-weight: 700; color: var(--text); }
.card-foot .av { margin-left: auto; }
.col.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }

/* ---------- drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 660px; max-width: 96vw; background: var(--panel); z-index: 50; box-shadow: -8px 0 30px rgba(0,0,0,.12); display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-title { font-size: 16px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 30px; height: 30px; border-radius: 7px; display: flex; align-items: center; justify-content: center; color: var(--text-2); }
.icon-btn:hover { background: var(--sidebar); color: var(--text); }
.drawer-body { flex: 1; overflow: auto; display: flex; }
.drawer-fields { width: 46%; min-width: 270px; border-right: 1px solid var(--border); padding: 16px 18px; overflow: auto; }
.drawer-side { flex: 1; padding: 16px 18px; overflow: auto; background: #fafaf9; }
.fld { margin-bottom: 12px; }
.fld label { display: block; font-size: 11.5px; color: var(--text-3); font-weight: 600; margin-bottom: 3px; }
.fld input, .fld select, .fld textarea { width: 100%; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 5px 7px; margin-left: -7px; }
.fld textarea { resize: vertical; min-height: 54px; }
.fld input:hover, .fld select:hover, .fld textarea:hover { background: var(--sidebar); }
.fld input:focus, .fld select:focus, .fld textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
.drawer-actions { display: flex; gap: 8px; padding: 0 0 14px; }
.btn { border: 1px solid var(--border-strong); background: #fff; border-radius: 7px; padding: 6px 12px; font-weight: 600; font-size: 12.5px; }
.btn:hover { background: var(--sidebar); }
.btn.primary { background: #222; border-color: #222; color: #fff; }
.btn.primary:hover { background: #000; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fef2f2; border-color: #fecaca; }
.side-sec { font-size: 12px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; margin: 14px 0 8px; }
.side-sec:first-child { margin-top: 0; }
.mini-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; cursor: pointer; }
.mini-card:hover { border-color: var(--border-strong); }
.mini-card .t { font-weight: 600; }
.mini-card .s { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.note-box { display: flex; gap: 8px; margin-bottom: 12px; }
.note-box textarea { flex: 1; border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; resize: vertical; min-height: 38px; background: #fff; }
.note-box textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.tl-item { display: flex; gap: 9px; margin-bottom: 12px; }
.tl-body { flex: 1; }
.tl-meta { font-size: 11.5px; color: var(--text-3); margin-bottom: 2px; }
.tl-meta b { color: var(--text-2); }
.tl-text { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; white-space: pre-wrap; }
.tl-sys { color: var(--text-2); font-size: 12.5px; padding-top: 2px; }
.linklike { color: var(--accent); cursor: pointer; font-weight: 600; font-size: 12.5px; background: none; padding: 0; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.3); padding: 16px; }
.modal-box { background: #fff; border-radius: 12px; width: 430px; max-width: 100%; max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 15px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 16px 18px; }
.modal-body .fld input, .modal-body .fld select { border-color: var(--border-strong); background: #fff; margin-left: 0; padding: 8px 10px; }
.modal-body .fld input:focus, .modal-body .fld select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 16px; }
.form-err { color: var(--danger); font-size: 12.5px; min-height: 16px; margin-bottom: 6px; }

/* ---------- users view ---------- */
.badge { font-size: 11px; font-weight: 700; border-radius: 5px; padding: 2px 7px; }
.badge.admin { background: #fef3c7; color: #92400e; }
.badge.member { background: var(--sidebar); color: var(--text-2); }
.badge.inactive { background: #fee2e2; color: #991b1b; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 9px 18px; border-radius: 9px; z-index: 100; font-weight: 600; box-shadow: var(--shadow); }

.empty { padding: 60px 20px; text-align: center; color: var(--text-3); }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 30; height: 100%; left: -230px; transition: left .18s; box-shadow: none; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .burger { display: flex !important; }
  .search input { width: 130px; }
  .drawer-body { flex-direction: column; }
  .drawer-fields { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .topbar { padding: 10px 12px; }
  .tbl-wrap, .chips { padding-left: 12px; padding-right: 12px; }
  .board { padding: 12px; }
}
.burger { display: none; }

/* ---------- dispatch additions ---------- */
.grid { display: grid; gap: 10px; }
.g4 { grid-template-columns: repeat(4, 1fr); } .g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 760px) { .g4, .g3 { grid-template-columns: repeat(2, 1fr); } }
.modal-box.wide { width: 780px; }
.modal-body .fld textarea { border: 1px solid var(--border-strong); background: #fff; margin-left: 0; padding: 8px 10px; width: 100%; border-radius: 6px; }
.modal-body .fld textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
table.lines { width: 100%; border-collapse: collapse; margin-top: 4px; }
table.lines th { text-align: left; font-size: 11.5px; color: var(--text-3); font-weight: 600; padding: 4px 6px 4px 0; }
table.lines td { padding: 3px 6px 3px 0; vertical-align: top; }
table.lines input, table.lines select { width: 100%; border: 1px solid var(--border-strong); border-radius: 6px; padding: 6px 8px; background: #fff; min-width: 52px; }
table.lines input:focus, table.lines select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.stats { display: flex; gap: 12px; padding: 14px 20px 0; flex-wrap: wrap; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 16px; min-width: 160px; }
.stat .lbl { font-size: 12px; color: var(--text-3); font-weight: 600; }
.stat .val { font-size: 17px; font-weight: 700; margin-top: 2px; }
.stat .val .sub { font-size: 12.5px; color: var(--text-3); font-weight: 500; }
tr.overdue-row td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.row-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.mail-frame { width: 100%; height: 380px; background: #fff; border: 1px solid var(--border-strong); border-radius: 8px; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 8px; }
.tbl td.wrap { white-space: normal; }
@media (max-width: 760px) { .stats { padding: 12px 12px 0; } }

/* overview (admin) */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; padding: 14px 20px 4px; }
.kpi-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 13px 15px; cursor: pointer; transition: box-shadow .12s; }
.kpi-card:hover { box-shadow: var(--shadow); }
.kpi-card .k-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
.kpi-card .k-value { font-size: 24px; font-weight: 700; margin-top: 3px; }
.kpi-card .k-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.ov-warn { color: var(--danger); font-weight: 600; }
.ov-cols { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); padding: 6px 20px 20px; align-items: start; }
.ov-tbl { padding: 8px 0 0; }
.ov-tbl .hint { margin-top: 4px; }
.rowlink { cursor: pointer; }
.rowlink:hover td { background: var(--hover, #f6f6f4); }
@media (max-width: 760px) {
  .kpi-grid { padding: 12px 12px 4px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .ov-cols { padding: 6px 12px 16px; }
}

/* ---------- returnable material still out with the customer ---------- */
tr.returnable-row td { background: #fffbeb; }
tr.returnable-row td:first-child { box-shadow: inset 3px 0 0 #d97706; }
tr.returnable-row.overdue-row td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

/* ---------- per-view filters & column picker ---------- */
.chips select.chip-filter { margin-left: auto; border: 1px solid var(--border-strong); border-radius: 6px; padding: 4px 8px; background: #fff; font-size: 12.5px; max-width: 240px; }
.chips .colpick { margin-left: auto; }
.chips select.chip-filter ~ .colpick, .chips select.chip-filter + .colpick { margin-left: 8px; }
.colpick-line { display: flex; align-items: center; gap: 8px; padding: 5px 2px; font-size: 13.5px; cursor: pointer; }
.colpick-line input { accent-color: #222; }

/* ---------- expense payment reminders strip (shared ledger with purchase) ---------- */
.rem-box { margin: 14px 20px 0; border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 10px 14px; }
.rem-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 12.5px; margin-bottom: 6px; }
.rem-line { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; flex-wrap: wrap; }
.rem-due { font-weight: 600; }
.rem-due.overdue { color: var(--danger); }
.rem-due.soon { color: #d97706; }
@media (max-width: 760px) { .rem-box { margin: 14px 12px 0; } }

/* searchable customer picker */
.cpick { position: relative; }
.cpick .cp-list { display: none; position: absolute; z-index: 40; left: 0; right: 0; top: 100%; margin-top: 3px; background: #fff; border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow); max-height: 240px; overflow: auto; }
.cpick.open .cp-list { display: block; }
.cp-it { padding: 7px 10px; font-size: 13px; cursor: pointer; }
.cp-it:hover, .cp-it.hover { background: var(--sidebar); }
.cp-it.sel { font-weight: 600; }
.cp-none { padding: 7px 10px; color: var(--text-3); font-size: 13px; }

/* detail modals (PO / customer) */
.detail-kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 18px; margin-bottom: 4px; }
.detail-kv > div > div:last-child { margin-top: 1px; }
.modal-body .stats .stat { border: 1px solid var(--border-strong); }
.tag-pill { display: inline-block; border: 1px solid var(--border-strong); background: var(--sidebar); border-radius: 20px; padding: 1px 9px; font-size: 11.5px; font-weight: 600; color: var(--text-2, #444); cursor: pointer; vertical-align: 1px; }
.tag-pill:hover { border-color: var(--accent); color: var(--accent); }

/* overview: monthly revenue vs pending chart */
.ov-chart-wrap { padding-bottom: 8px; }
.ov-chart-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px; margin-bottom: 8px; }
.ov-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); }
.ov-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.ov-chart-scroll { overflow-x: auto; }
.ov-tip { position: fixed; display: none; z-index: 200; background: var(--text); color: #fff; font-size: 12px; padding: 4px 9px; border-radius: 6px; pointer-events: none; white-space: nowrap; box-shadow: var(--shadow); }
.linkpo-list { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }
.linkpo-row { display: flex; gap: 9px; align-items: flex-start; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.linkpo-row:hover { border-color: var(--border-strong); background: #fafaf9; }
.linkpo-row input { margin-top: 3px; }

/* ---- in-app PO document viewer ---- */
.pv-overlay { position: fixed; inset: 0; z-index: 300; background: rgba(15,23,42,.82); display: flex; flex-direction: column; }
.pv-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #0f172a; color: #fff; flex-shrink: 0; }
.pv-name { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-pages { flex: 1; overflow-y: auto; padding: 16px 8px; text-align: center; -webkit-overflow-scrolling: touch; }
.pv-page { display: block; margin: 0 auto 12px; max-width: min(900px, 100%); width: 100%; background: #fff; border-radius: 4px; box-shadow: 0 2px 12px rgba(0,0,0,.4); }
