/* Boston Erp - shared design tokens & components (back office + mobile) */
:root {
  --brand: #262845;
  --brand-ink: #1b1d33;
  --brand-2: #3a3d6b;
  --primary: #3b4fb8;
  --primary-hover: #3142a0;
  --primary-soft: #eceffb;
  --accent: #d63a2f;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e2e5ea;
  --border-strong: #cdd2da;
  --text: #16191f;
  --text-2: #4d5562;
  --muted: #7d8592;
  --success: #0b7a3e;
  --success-soft: #e3f4ea;
  --warning: #8a5a00;
  --warning-soft: #fff3d6;
  --danger: #b42828;
  --danger-soft: #fbe5e5;
  --info: #4a3aa7;
  --info-soft: #ecebfb;
  --orange: #a8461c;
  --orange-soft: #fde9df;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 8px; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.between { justify-content: space-between; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer;
  text-decoration: none !important; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: #b9c0ca; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.warn { background: #c06a12; border-color: #c06a12; color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0, 0, 0, .05); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.lg { min-height: 48px; padding: 0 18px; font-size: 16px; }
.btn.block { width: 100%; }
.btn svg { width: 16px; height: 16px; flex: none; }

/* ---------- forms ---------- */
label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; color: var(--text-2); }
label.field > span.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 10px; min-height: 38px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
input[type=checkbox], input[type=radio] { width: 17px; height: 17px; min-height: 0; accent-color: var(--primary); }
.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; color: var(--text); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 4px 0; }
.req::after { content: " *"; color: var(--danger); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-b { padding: 16px; }
.card-b.flush { padding: 0; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: #eceef2; color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.b-pending, .b-requested, .b-moi-pending { background: var(--warning-soft); color: var(--warning); }
.b-assigned, .b-scheduled, .b-approved-blue, .b-prepared, .b-sent { background: var(--primary-soft); color: #3142a0; }
.b-in_progress, .b-submitted, .b-ordered { background: var(--info-soft); color: var(--info); }
.b-rescheduled, .b-high { background: var(--orange-soft); color: var(--orange); }
.b-completed, .b-approved, .b-received { background: var(--success-soft); color: var(--success); }
.b-cancelled, .b-not_required, .b-low, .b-normal { background: #eceae6; color: #52514e; }
.b-rejected, .b-urgent { background: var(--danger-soft); color: var(--danger); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); white-space: nowrap; }
.tbl tbody tr:hover { background: #fafbfd; }
.tbl tr.click { cursor: pointer; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 100; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; }
.modal.wide { max-width: 820px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-b { padding: 20px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.modal .err { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: var(--radius-sm); margin-bottom: 12px; }

/* ---------- toast ---------- */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: #1f2630; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); font-weight: 500; animation: toast-in .18s ease-out; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- misc ---------- */
.stars { color: #e3a008; letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: #d5d8de; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; }
.kv > dt { color: var(--muted); font-size: 13px; }
.kv > dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 20px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline li::after { content: ""; position: absolute; left: 7.5px; top: 16px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #e9ecf0; border: 1px solid var(--border); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .x { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; font-size: 15px; line-height: 1; }
.photo.file { display: flex; align-items: center; justify-content: center; padding: 8px; text-align: center; font-size: 12px; word-break: break-all; }
/* Branded loader: the Boston Erp mark with a turning ring */
.spinner { position: relative; width: 48px; height: 48px; margin: 48px auto; background: url("logo-mark.png") center / 26px no-repeat; }
.spinner::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 3px solid var(--primary-soft); border-top-color: var(--primary); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--warning-soft); color: var(--warning); font-weight: 500; }
.alert.info { background: var(--primary-soft); color: #3142a0; }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.success { background: var(--success-soft); color: var(--success); }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .9); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sig-pad { width: 100%; height: 180px; border: 1px dashed var(--border-strong); border-radius: 8px; background: #fff; touch-action: none; display: block; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv > dd { margin-bottom: 8px; }
  .modal-bg { padding: 0; align-items: stretch; }
  .modal { border-radius: 0; min-height: 100%; max-width: none; display: flex; flex-direction: column; }
  .modal-b { flex: 1; }
  .modal-f { border-radius: 0; position: sticky; bottom: 0; }
}

/* ---------- projects: progress bars, step lists ---------- */
.progress { height: 8px; background: #e7e9f2; border-radius: 99px; overflow: hidden; min-width: 60px; }
.progress > span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary), #7b8cff); transition: width .7s cubic-bezier(.2, .7, .2, 1); }
.progress.lg { height: 12px; }
.progress.moi > span { background: linear-gradient(90deg, #0b7a3e, #3cc47c); }
.b-pending-step { background: #eef0f4; color: #5b6270; }
.step-list { list-style: none; margin: 0; padding: 0; }
.step-list li { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: start; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.step-list li:last-child { border-bottom: 0; }
.step-list li.clickable { cursor: pointer; border-radius: 8px; }
.step-list li.clickable:hover { background: var(--surface-2); }
.step-list .num { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12.5px; background: #eef0f4; color: #5b6270; }
.step-list li.done .num { background: var(--success); color: #fff; }
.step-list li.in_progress .num { background: var(--primary); color: #fff; }
.step-list li.na .num { background: #f2f2f2; color: #aaa; }
.step-list li.na .lbl { color: var(--muted); text-decoration: line-through; }
.step-list li.current { background: #f5f6ff; border-radius: 8px; }
.step-list .lbl { font-weight: 600; }
.step-list .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.update-card { padding: 14px 0; border-bottom: 1px solid var(--border); }
.update-card:last-child { border-bottom: 0; }
.update-card .who { font-weight: 600; }
.update-card .issue { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 6px 10px; margin-top: 6px; }
.update-card .photos { margin-top: 8px; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.b-new { background: var(--primary-soft); color: #3142a0; }
.b-running { background: var(--info-soft); color: var(--info); }
.b-on_hold { background: var(--warning-soft); color: var(--warning); }
.b-draft { background: var(--warning-soft); color: var(--warning); }
.b-active { background: var(--success-soft); color: var(--success); }
.b-expired { background: var(--danger-soft); color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 7px 13px; font: inherit; font-size: 13.5px; cursor: pointer; }
.chips button.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- customer search box (shared/customers.js) ---------- */
.picker { position: relative; }
.picker .results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow-lg); max-height: 260px; overflow-y: auto; z-index: 10; }
.picker .results div { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.picker .results div:hover, .picker .results div.hl { background: var(--primary-soft); }
.picker .results small { color: var(--muted); display: block; }
