/* Matrix Piping — Operations theme */
:root {
  --bg: #f3f4f7;
  --panel: #ffffff;
  --panel-alt: #fafbfc;
  --line: #dde0e6;
  --line-strong: #c8ccd4;
  --text: #1f2330;
  --muted: #5b6478;
  --muted-2: #8189a0;

  --brand: #ff6b1a;
  --brand-dark: #d8531a;
  --brand-tint: #fff1e6;

  --link: #1d6fc1;
  --link-dark: #155596;
  --header: #1a2541;
  --header-2: #243759;
  --header-3: #0f1729;

  --green: #1f9d55;
  --red: #d12a3a;
  --amber: #c97a00;

  --radius: 4px;
  --radius-lg: 6px;
  --shadow: 0 1px 2px rgba(20,30,50,.06), 0 1px 1px rgba(20,30,50,.04);
  --shadow-md: 0 4px 12px rgba(20,30,50,.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-dark); text-decoration: underline; }
code { font-family: ui-monospace, SF Mono, Menlo, Consolas, monospace; font-size: 12px; color: var(--text); }

svg { display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* ---------- App layout ---------- */
.app { display: grid; grid-template-rows: auto 1fr; min-height: 100vh; }

aside.sidebar {
  background: var(--header);
  color: #e8edf7;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: 0 2px 6px rgba(0,0,0,.10);
}

/* Header brand row */
.brand-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 8px 24px;
  background: linear-gradient(180deg, var(--header) 0%, var(--header-3) 100%);
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none;
  color: #fff;
}
.brand:hover { text-decoration: none; }
.logo-mark {
  width: 32px; height: 32px;
  border-radius: var(--radius);
  background: var(--brand);
  display: grid; place-items: center;
  color: #1a1006;
  font-weight: 800;
  font-size: 15px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.18), 0 1px 2px rgba(255,107,26,.4);
  font-family: 'Inter', system-ui, sans-serif;
}
.brand-name {
  display: flex; flex-direction: column; line-height: 1.1;
  font-weight: 700; font-size: 15px; letter-spacing: -.005em;
}
.brand-sub {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(255,255,255,.5);
  margin-top: 2px;
}

/* Header search */
.header-search {
  position: relative;
  max-width: 460px;
  width: 100%;
  justify-self: center;
}
.header-search .hs-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: rgba(255,255,255,.7);
  display: inline-flex; pointer-events: none;
  z-index: 1;
}
.header-search input[type="text"] {
  width: 100%;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.14);
  color: #fff;
  padding: 7px 12px 7px 32px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-family: inherit;
  min-width: 0;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.header-search input[type="text"]::placeholder { color: rgba(255,255,255,.50); }
.header-search input[type="text"]:focus {
  outline: none;
  background: rgba(255,255,255,.14);
  border-color: rgba(255,255,255,.34);
  box-shadow: none;
}
.hs-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: 420px; overflow-y: auto;
  z-index: 50;
  padding: 4px 0;
}
.hs-h { padding: 6px 14px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-2); font-weight: 700; }
.hs-item { display: block; padding: 8px 14px; color: var(--text); }
.hs-item:hover { background: var(--panel-alt); text-decoration: none; }
.hs-item .hs-sub { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.hs-empty { padding: 16px 14px; color: var(--muted); font-size: 12px; }

/* User pill */
.header-user { display: flex; align-items: center; gap: 10px; }
.hu-info { text-align: right; }
.hu-name { font-size: 12.5px; font-weight: 600; color: #fff; line-height: 1.2; }
.hu-role { font-size: 10.5px; color: rgba(255,255,255,.5); margin-top: 1px; letter-spacing: .02em; }
.hu-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4570c4, #2d4a87);
  color: #fff;
  font-weight: 700; font-size: 11.5px; letter-spacing: .04em;
  display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,.18);
}

/* Tab nav */
.nav {
  display: flex;
  flex-wrap: wrap;
  padding: 0 16px;
  gap: 0;
  background: var(--header-2);
  border-bottom: 2px solid var(--brand);
}
.nav a {
  color: rgba(255,255,255,.72);
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  position: relative;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  display: inline-flex; align-items: center; gap: 7px;
  transition: color .12s ease, background .12s ease;
}
.nav a .nav-ic { display: inline-flex; opacity: .85; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.05); text-decoration: none; }
.nav a:hover .nav-ic { opacity: 1; }
.nav a.active {
  color: #fff;
  background: rgba(255,255,255,.06);
  border-bottom-color: var(--brand);
}
.nav a.active .nav-ic { opacity: 1; color: var(--brand); }

/* ---------- Main ---------- */
.main {
  padding: 22px 28px 60px;
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
}
.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
}
.topbar h1 {
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -.01em;
  color: var(--header);
}
.topbar .subtitle { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.topbar .actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ---------- Cards / KPIs ---------- */
.cards { display: grid; gap: 12px; }
.cards.cols-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.cards.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.cards.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card h3 {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
  display: flex; align-items: center; gap: 6px;
}
.card h3 svg { color: var(--muted-2); }
.card .big {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--header);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.card .sub { color: var(--muted-2); font-size: 11px; margin-top: 3px; }
.card .change { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; }
.card .change.up { color: var(--green); }
.card .change.down { color: var(--red); }

/* ---------- Pipeline ---------- */
.pipeline {
  display: grid;
  grid-template-columns: repeat(9, minmax(108px, 1fr));
  gap: 6px;
  overflow-x: auto;
}
.pipeline .stage {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 12px;
  min-height: 80px;
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.pipeline .stage:hover { border-color: var(--link); background: #fff; text-decoration: none; transform: translateY(-1px); }
.pipeline .stage .name {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 700;
}
.pipeline .stage .count {
  font-size: 22px;
  font-weight: 600;
  margin-top: 4px;
  color: var(--header);
  font-variant-numeric: tabular-nums;
}
.pipeline .stage.empty .count { color: var(--muted-2); opacity: .45; }
.pipeline .stage.busy { border-top: 2px solid var(--brand); padding-top: 9px; }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--line-strong);
  padding-top: 10px; padding-bottom: 10px;
  white-space: nowrap;
}
tbody tr:nth-child(even) td { background: var(--panel-alt); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #eef4fb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-action { cursor: pointer; }
.row-action:hover { background: #eef4fb; }

.empty-state { padding: 32px 16px; text-align: center; color: var(--muted); }
.empty-state .ic { color: var(--muted-2); margin-bottom: 8px; display: inline-block; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: #e7eaf0;
  color: var(--muted);
  border: 1px solid transparent;
  line-height: 1.5;
}
.badge.stage-enquiry           { background: #e6f0fc; color: #1d4f86; }
.badge.stage-quoting           { background: #fff4d6; color: #8a5a00; }
.badge.stage-awaiting_approval { background: #ffe8c2; color: #8a5400; }
.badge.stage-materials         { background: #e0eefc; color: #1d6fc1; }
.badge.stage-fabrication       { background: #ffe2cc; color: #b8430c; }
.badge.stage-qa                { background: #d8f1e1; color: #126b3d; }
.badge.stage-coating           { background: #ece1fb; color: #5d2da6; }
.badge.stage-dispatch          { background: #fff4d6; color: #8a5a00; }
.badge.stage-invoiced          { background: #d8f1e1; color: #126b3d; }
.badge.stage-complete          { background: #e7eaf0; color: var(--muted); }

.badge.priority-urgent { background: #fde0e3; color: #a31a28; }
.badge.priority-high   { background: #ffe8c2; color: #8a5400; }
.badge.priority-normal { background: #e6f0fc; color: #1d4f86; }
.badge.priority-low    { background: #e7eaf0; color: var(--muted); }

.badge.role-admin       { background: #e0e4ec; color: #2c3653; }
.badge.role-sales       { background: #e6f0fc; color: #1d4f86; }
.badge.role-estimator   { background: #ece1fb; color: #5d2da6; }
.badge.role-purchasing  { background: #d6efea; color: #0f6b54; }
.badge.role-fabricator  { background: #ffe2cc; color: #b8430c; }
.badge.role-qa          { background: #d8f1e1; color: #126b3d; }
.badge.role-coatings    { background: #fce0f1; color: #8a2168; }
.badge.role-dispatch    { background: #fff4d6; color: #8a5a00; }
.badge.role-accounts    { background: #ddebf7; color: #1d4f86; }

.dot { width: 7px; height: 7px; border-radius: 999px; background: var(--muted); display: inline-block; margin-right: 5px; vertical-align: 0; }
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }

/* ---------- Buttons ---------- */
.btn {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  line-height: 1.4;
  font-family: inherit;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.btn:hover { background: var(--panel-alt); border-color: #a8aebc; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(29,111,193,.3); }
.btn.primary {
  background: var(--brand);
  border-color: var(--brand-dark);
  color: #fff;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.12);
}
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.btn-danger:hover { background: #b1212f; border-color: #b1212f; color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--link); }
.btn.ghost:hover { background: var(--panel-alt); }
.btn.sm { padding: 4px 9px; font-size: 11.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { display: inline-block; }

/* ---------- Inputs ---------- */
input.search, select.search, textarea.search,
input[type=date], input[type=text], input[type=search], input[type=email], input[type=tel], input[type=number] {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-family: inherit;
  min-width: 220px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input.search:focus, select.search:focus, textarea.search:focus,
input[type=date]:focus, input[type=text]:focus, input[type=search]:focus,
input[type=email]:focus, input[type=tel]:focus, input[type=number]:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 2px rgba(29,111,193,.18);
}
select.search { padding-right: 26px; }

/* ---------- Filter chips ---------- */
.filters {
  display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: fit-content;
  box-shadow: var(--shadow);
}
.filters .chip {
  background: transparent;
  border: 1px solid transparent;
  padding: 4px 12px;
  border-radius: 3px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  text-transform: capitalize;
  white-space: nowrap;
}
.filters .chip:hover { background: var(--panel-alt); color: var(--text); }
.filters .chip.active {
  background: var(--header);
  border-color: var(--header);
  color: #fff;
}

/* ---------- Activity feed ---------- */
.activity { display: flex; flex-direction: column; }
.activity .item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.activity .item:last-child { border-bottom: 0; }
.activity .ic {
  width: 26px; height: 26px; border-radius: 999px;
  background: var(--panel-alt); border: 1px solid var(--line);
  display: grid; place-items: center;
  color: var(--muted);
  flex-shrink: 0;
}
.activity .ic.green { background: #e7f5ec; border-color: #b9e1c8; color: var(--green); }
.activity .ic.brand { background: var(--brand-tint); border-color: #ffd1ae; color: var(--brand-dark); }
.activity .ic.amber { background: #fff4d6; border-color: #f5d98d; color: var(--amber); }
.activity .ic.red   { background: #fde0e3; border-color: #f4b8bf; color: var(--red); }
.activity .content { flex: 1; min-width: 0; }
.activity .who { color: var(--muted-2); font-size: 11.5px; margin-top: 1px; }
.activity .time { color: var(--muted-2); font-size: 11px; flex-shrink: 0; padding-top: 4px; font-variant-numeric: tabular-nums; }

/* ---------- Workflow rules diagram ---------- */
.workflow-diagram {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 8px 4px; overflow-x: auto;
}
.workflow-diagram .node {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  color: var(--header);
  display: inline-flex; flex-direction: column; gap: 2px;
  min-width: 92px;
}
.workflow-diagram .node .role {
  font-size: 10px; color: var(--muted); font-weight: 500;
  text-transform: uppercase; letter-spacing: .04em;
}
.workflow-diagram .arrow { color: var(--muted-2); display: inline-flex; }

/* ---------- Drawer ---------- */
.drawer-mask {
  position: fixed; inset: 0;
  background: rgba(15,23,41,.50);
  display: none; z-index: 50;
  backdrop-filter: blur(2px);
}
.drawer-mask.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(720px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 51;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.32,.72,0,1);
  display: flex; flex-direction: column;
  box-shadow: -10px 0 40px rgba(15,23,41,.18);
}
.drawer.open { transform: translateX(0); }
.drawer header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-alt);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.drawer header h2 { margin: 0 0 4px; font-size: 16px; color: var(--header); font-weight: 600; }
.drawer .body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.drawer .close {
  background: transparent; border: 0; color: var(--muted);
  cursor: pointer; padding: 4px;
  display: inline-flex; border-radius: var(--radius);
  transition: background .12s ease, color .12s ease;
}
.drawer .close:hover { color: var(--text); background: rgba(0,0,0,.05); }
.drawer footer {
  padding: 12px 22px;
  border-top: 1px solid var(--line);
  background: var(--panel-alt);
  display: flex; gap: 8px; justify-content: flex-end;
}

/* Form grid */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .ff { display: flex; flex-direction: column; }
.form-grid .ff.full { grid-column: 1 / -1; }
.form-grid .ff label {
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 4px; display: block;
}
.form-grid .ff input.search,
.form-grid .ff select.search,
.form-grid .ff textarea.search { min-width: 0; width: 100%; }

/* Quote line items */
.line-items { width: 100%; border-collapse: collapse; margin-top: 8px; }
.line-items th { background: var(--panel-alt); font-size: 10.5px; padding: 7px 8px; }
.line-items td { padding: 5px 6px; border-bottom: 1px solid var(--line); }
.line-items input { width: 100%; padding: 5px 8px; font-size: 12px; border: 1px solid var(--line); border-radius: 3px; background: #fff; font-family: inherit; min-width: 0; }
.line-items input:focus { outline: none; border-color: var(--link); box-shadow: 0 0 0 1px rgba(29,111,193,.2); }
.line-items td.num input { text-align: right; font-variant-numeric: tabular-nums; }
.line-items .del-row { background: transparent; border: 0; color: var(--muted-2); cursor: pointer; padding: 4px 6px; display: inline-flex; }
.line-items .del-row:hover { color: var(--red); }
.line-totals { margin-top: 12px; display: flex; flex-direction: column; gap: 3px; align-items: flex-end; font-size: 13px; font-variant-numeric: tabular-nums; }
.line-totals .total { font-weight: 700; color: var(--header); border-top: 1px solid var(--line-strong); padding-top: 6px; margin-top: 4px; font-size: 14px; }
.line-totals .row { display: flex; gap: 18px; min-width: 240px; justify-content: space-between; }
.section-h { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; margin: 20px 0 8px; }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 0; padding: 4px 0; }
.timeline .step { display: flex; gap: 12px; align-items: flex-start; padding: 9px 0; position: relative; }
.timeline .step + .step::before {
  content: ''; position: absolute; left: 10px; top: -7px; width: 1px; height: 16px; background: var(--line-strong);
}
.timeline .step .pin {
  width: 21px; height: 21px; border-radius: 999px; flex-shrink: 0;
  background: #fff; border: 2px solid var(--line-strong);
  display: grid; place-items: center; color: var(--muted);
}
.timeline .step.done .pin { background: var(--brand); border-color: var(--brand-dark); color: #fff; }
.timeline .step .body { font-size: 12.5px; flex: 1; min-width: 0; }
.timeline .step .body .when { color: var(--muted-2); font-size: 11.5px; margin-top: 2px; }

/* Spinner */
.spinner {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
.btn:not(.primary):not(.btn-danger) .spinner { border-color: var(--line-strong); border-top-color: var(--header); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Utility */
.muted { color: var(--muted); }
.muted-2 { color: var(--muted-2); }
.small { font-size: 11.5px; }
.right { text-align: right; }
.flex { display: flex; }
.flex.between { justify-content: space-between; }
.flex.center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 22px; }
.welcome { font-size: 13px; color: var(--muted); margin-bottom: 18px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow); }
.welcome strong { color: var(--header); font-weight: 600; }
.welcome .meta { margin-left: auto; color: var(--muted-2); font-size: 11.5px; }

@media (max-width: 1100px) {
  .header-search { max-width: 320px; }
}
@media (max-width: 900px) {
  .brand-row { grid-template-columns: auto 1fr; padding: 8px 16px; gap: 12px; }
  .header-search { display: none; }
  .header-user .hu-info { display: none; }
  .nav { padding: 0 8px; overflow-x: auto; flex-wrap: nowrap; }
  .nav a { padding: 9px 12px; font-size: 11.5px; }
  .main { padding: 16px 18px 60px; }
  .pipeline { grid-template-columns: repeat(5, minmax(108px, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
}
