/* =====================================================================
   Microteck Quote — design system
   Brand: Microteck blue (#1570B8) on a deep navy shell.
   ===================================================================== */
:root {
  --brand: #1570b8;
  --brand-600: #105d9a;
  --brand-50: #eaf3fb;
  --brand-100: #d3e6f6;
  --navy: #0b1f33;
  --navy-2: #12304d;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e5e9f0;
  --line-2: #eef1f6;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ok: #0f9d6b;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow: 0 6px 24px -8px rgba(15, 23, 42, .12), 0 2px 6px rgba(15, 23, 42, .04);
  --sidebar-w: 256px;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;

  --bs-primary: var(--brand);
  --bs-primary-rgb: 21, 112, 184;
  --bs-body-font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--bg);
  --bs-border-color: var(--line);
  --bs-link-color: var(--brand);
  --bs-link-color-rgb: 21, 112, 184;
  --bs-link-hover-color: var(--brand-600);
}

* { -webkit-font-smoothing: antialiased; }
body { font-size: 14px; background: var(--bg); color: var(--ink); }
a { text-decoration: none; }
.num, .table td.num, .table th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.text-muted { color: var(--muted) !important; }
.fw-semi { font-weight: 600; }
::selection { background: var(--brand-100); }

/* ---------------------------------------------------------------- shell */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; position: fixed; inset: 0 auto 0 0; z-index: 1040;
  background: radial-gradient(120% 60% at 0% 0%, #164a78 0%, transparent 60%), linear-gradient(180deg, var(--navy) 0%, #081726 100%);
  color: #c9d6e3; display: flex; flex-direction: column; padding: 18px 14px; transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 14px; color: #fff; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0;
  background: #fff; box-shadow: 0 6px 16px -6px rgba(42, 143, 224, .8), inset 0 0 0 1px rgba(255,255,255,.6);
}
.brand-mark img { width: 30px; height: auto; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; letter-spacing: .2px; }
.brand-text small { font-size: 11.5px; color: #8fb0cf; letter-spacing: .3px; }
.btn-new {
  display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 4px 10px; padding: 9px; border-radius: 11px;
  background: var(--brand); color: #fff; font-weight: 600; border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 8px 20px -10px rgba(21, 112, 184, .9);
}
.btn-new:hover { background: #1d7fcd; color: #fff; }
/* Menu scrolls only on very short screens, with the scrollbar hidden (wheel/touch still work) */
.side-nav { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; -ms-overflow-style: none; margin: 0 -4px; padding: 0 4px; }
.side-nav::-webkit-scrollbar { width: 0; height: 0; }
.side-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.2px; color: #6f8aa5; padding: 12px 12px 4px; font-weight: 700; }
.side-nav a {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; margin: 1px 0; border-radius: 10px;
  color: #c3d1df; font-weight: 500; transition: background .15s, color .15s;
}
.side-nav a i { font-size: 17px; opacity: .85; }
.side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a.active { background: rgba(42, 143, 224, .18); color: #fff; box-shadow: inset 3px 0 0 #3aa0f0; }
.side-nav a.active i { color: #5fb4f5; opacity: 1; }
.side-foot { display: flex; align-items: center; gap: 8px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; margin-top: 10px; }
.me { flex: 1; display: flex; align-items: center; gap: 10px; color: #fff; min-width: 0; }
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.me-text strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { font-size: 11.5px; color: #8fb0cf; }
.logout { color: #8fb0cf; font-size: 18px; padding: 6px 8px; border-radius: 8px; }
.logout:hover { color: #fff; background: rgba(255,255,255,.08); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; flex-shrink: 0;
  background: linear-gradient(135deg, #3aa0f0, var(--brand)); color: #fff; font-weight: 700; font-size: 12.5px; border: 0;
}
.avatar-btn { cursor: pointer; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: 12px; padding: 12px 28px;
  background: rgba(245, 247, 251, .82); backdrop-filter: saturate(160%) blur(10px); border-bottom: 1px solid var(--line);
}
.search-trigger {
  flex: 1; max-width: 520px; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 11px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted); text-align: left; box-shadow: var(--shadow-sm);
}
.search-trigger span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-trigger:hover { border-color: var(--brand-100); }
kbd { background: var(--line-2); color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 11px; font-family: inherit; box-shadow: none; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.icon-btn { border: 0; background: transparent; font-size: 22px; color: var(--ink); padding: 2px 6px; border-radius: 8px; }
.content { padding: 24px 28px 48px; max-width: 1480px; width: 100%; }
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; box-shadow: 20px 0 60px rgba(0,0,0,.3); }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(8, 23, 38, .45); z-index: 1035; }
  .main { margin-left: 0; }
  .topbar { padding: 10px 16px; }
  .content { padding: 18px 16px 40px; }
  .search-trigger kbd { display: none; }
}

/* ---------------------------------------------------------------- page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; font-weight: 800; letter-spacing: -.4px; margin: 0; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--brand); }

/* ---------------------------------------------------------------- cards */
.card-x { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-x > .hd { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.card-x > .hd h2, .card-x > .hd h3 { font-size: 15px; font-weight: 700; margin: 0; }
.card-x > .hd .hint { font-size: 12.5px; color: var(--muted); }
.card-x > .bd { padding: 20px; }
.card-x > .bd.p0 { padding: 0; }

/* ---------------------------------------------------------------- KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 1199.98px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 575.98px) {
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .ic { display: none; }
  .kpi .val { font-size: 22px; margin: 6px 0 2px; }
  .kpi .meta { font-size: 11.5px; }
}
.kpi { position: relative; overflow: hidden; padding: 18px 20px; }
.kpi .lbl { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; font-size: 12.5px; }
.kpi .ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 15px; }
.kpi .val { font-size: 28px; font-weight: 800; letter-spacing: -.8px; margin: 10px 0 4px; font-variant-numeric: tabular-nums; }
.kpi .meta { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; padding: 1px 7px; border-radius: 99px; font-size: 11.5px; }
.delta.up { background: #e7f7f0; color: var(--ok); }
.delta.down { background: #fdecec; color: var(--bad); }
.delta.flat { background: var(--line-2); color: var(--muted); }
.ic-blue { background: var(--brand-50); color: var(--brand); }
.ic-green { background: #e7f7f0; color: var(--ok); }
.ic-amber { background: #fef3e2; color: var(--warn); }
.ic-violet { background: #f1ecfe; color: #6d4ee6; }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1199.98px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.grid-2 > *, .grid-3 > *, .kpis > *, .search-trigger, .main { min-width: 0; }
.min-w-0 { min-width: 0; }

.funnel { display: flex; flex-direction: column; gap: 12px; }
.funnel-row { display: grid; grid-template-columns: 90px 1fr auto; align-items: center; gap: 12px; font-size: 13px; }
.funnel-bar { height: 10px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.funnel-bar span { display: block; height: 100%; border-radius: 99px; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line-2); color: inherit; }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: #fafbfd; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .s { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank { width: 26px; height: 26px; border-radius: 8px; background: var(--brand-50); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 12px; flex-shrink: 0; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty i { font-size: 34px; color: #b6c4d4; display: block; margin-bottom: 8px; }

/* ---------------------------------------------------------------- tables */
.table-x { margin: 0; }
.table-x > :not(caption) > * > * { padding: 12px 16px; border-color: var(--line-2); vertical-align: middle; }
.table-x thead th { background: #f8fafc; font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; white-space: nowrap; border-bottom: 1px solid var(--line); }
.table-x tbody tr { transition: background .12s; }
.table-x tbody tr:hover { background: #fafcff; }
.table-x .row-link { color: var(--ink); font-weight: 600; }
.table-x .row-link:hover { color: var(--brand); }
.th-sort { color: inherit; }
.th-sort:hover { color: var(--brand); }
.table-x td .sub { font-size: 12.5px; color: var(--muted); }
.table-wrap { overflow-x: auto; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.toolbar .search { position: relative; flex: 1; min-width: 220px; max-width: 380px; }
.toolbar .search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.toolbar .search input { padding-left: 34px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-weight: 600; font-size: 12.5px; display: inline-flex; gap: 6px; align-items: center; }
.chip .n { background: var(--line-2); border-radius: 99px; padding: 0 7px; font-size: 11px; color: var(--muted); }
.chip:hover { border-color: var(--brand-100); color: var(--brand); }
.chip.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip.active .n { background: rgba(255,255,255,.18); color: #fff; }
.pager-wrap { display: flex; justify-content: flex-end; padding: 14px 16px; border-top: 1px solid var(--line-2); }
.pagination { --bs-pagination-border-radius: 8px; --bs-pagination-active-bg: var(--brand); --bs-pagination-active-border-color: var(--brand); --bs-pagination-color: var(--ink-2); gap: 4px; }
.pagination .page-link { border-radius: 8px !important; }

/* ---------------------------------------------------------------- badges */
.badge-status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-draft { background: #f1f4f8; color: #52637a; }
.s-sent { background: var(--brand-50); color: var(--brand); }
.s-accepted { background: #e7f7f0; color: var(--ok); }
.s-rejected { background: #fdecec; color: var(--bad); }
.s-expired { background: #fef3e2; color: #b45309; }
.ver { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--line-2); color: var(--ink-2); font-size: 11.5px; font-weight: 700; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--line-2); color: var(--ink-2); font-size: 12px; font-weight: 500; }
.stock-low { color: var(--bad); font-weight: 700; }

/* ---------------------------------------------------------------- forms */
.form-label { font-weight: 600; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; }
.form-control, .form-select { border-radius: var(--radius-sm); border-color: #dbe1ea; padding: .55rem .8rem; font-size: 14px; }
.form-control:focus, .form-select:focus { border-color: #7fb6e3; box-shadow: 0 0 0 4px rgba(21, 112, 184, .12); }
.form-text { color: var(--muted); }
.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: 13.5px; padding: .5rem 1rem; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn-sm { padding: .35rem .75rem; font-size: 12.5px; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-600); --bs-btn-hover-border-color: var(--brand-600); --bs-btn-active-bg: var(--brand-600); box-shadow: 0 6px 14px -8px rgba(21, 112, 184, .9); }
.btn-light { --bs-btn-bg: #fff; --bs-btn-border-color: var(--line); --bs-btn-hover-bg: #f6f8fb; --bs-btn-hover-border-color: #d5dce6; color: var(--ink-2); }
.btn-wa { background: #25d366; border-color: #25d366; color: #fff; box-shadow: 0 6px 16px -8px rgba(37, 211, 102, .9); }
.btn-wa:hover { background: #1ebe5a; border-color: #1ebe5a; color: #fff; }
.btn-ghost-danger { color: var(--bad); background: transparent; border: 1px solid transparent; }
.btn-ghost-danger:hover { background: #fdecec; color: var(--bad); }
.btn-ghost-danger:disabled { border-color: transparent; background: transparent; color: #cbd5e1; }
.form-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 700; margin: 4px 0 14px; }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.sticky-actions { position: sticky; bottom: 0; z-index: 10; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-top: 1px solid var(--line); padding: 12px 20px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; border-radius: 0 0 var(--radius) var(--radius); }

/* ---------------------------------------------------------------- quote builder */
.qb-customer { border: 1.5px dashed #c9d5e3; border-radius: var(--radius); padding: 14px 16px; background: #fbfcfe; }
.qb-customer.selected { border-style: solid; border-color: var(--brand-100); background: var(--brand-50); }
.combo { position: relative; }
.combo-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 1050; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; display: none; padding: 4px;
}
.combo-menu.open { display: block; }
.combo-opt { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.combo-opt.hl, .combo-opt:hover { background: var(--brand-50); }
.combo-opt .t { font-weight: 600; }
.combo-opt .s { font-size: 12px; color: var(--muted); }
.combo-opt .r { text-align: right; font-size: 12.5px; white-space: nowrap; }
.combo-empty { padding: 12px; color: var(--muted); font-size: 13px; }

.lines { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.lines .combo-menu { min-width: 440px; }
.lines th { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; padding: 10px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.lines td { padding: 8px 6px; vertical-align: top; border-bottom: 1px solid var(--line-2); }
.lines .form-control { padding: .4rem .55rem; font-size: 13.5px; }
.lines .num input { text-align: right; }
.lines .drag { cursor: grab; color: #a3b1c2; padding-top: 10px; text-align: center; }
.lines .lt { font-weight: 700; padding-top: 14px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lines .desc { margin-top: 6px; font-size: 12.5px; color: var(--ink-2); }
.lines tr.dragging { opacity: .4; }
.line-del { border: 0; background: transparent; color: #a3b1c2; padding: 8px 6px; border-radius: 8px; }
.line-del:hover { color: var(--bad); background: #fdecec; }
@media (max-width: 991.98px) {
  .lines thead { display: none; }
  .lines .combo-menu { min-width: 0; }
  .lines, .lines tbody, .lines tr, .lines td { display: block; width: 100%; }
  .lines tr { border: 1px solid var(--line); border-radius: 12px; padding: 8px; margin-bottom: 10px; position: relative; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .lines td[data-label]::before { text-align: left; }
  .lines td { border: 0; padding: 2px; }
  .lines td.c-item { grid-column: 1 / -1; }
  .lines td.drag { display: none; }
  .lines td.c-act { position: absolute; top: 4px; right: 4px; width: auto; }
  .lines td.lt { grid-column: 1 / -1; text-align: left; padding-top: 4px; }
  .lines td[data-label]::before { content: attr(data-label); display: block; font-size: 10.5px; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
}
.totals { width: 100%; }
.totals td { padding: 6px 0; }
.totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.totals tr.grand td { border-top: 1px solid var(--line); padding-top: 12px; font-size: 18px; font-weight: 800; color: var(--navy); }
.words { font-size: 12.5px; color: var(--muted); font-style: italic; }

/* ---------------------------------------------------------------- quote view / preview */
.doc-frame { width: 100%; border: 0; background: #fff; border-radius: 10px; min-height: 900px; display: block; }
.doc-stage { background: repeating-linear-gradient(45deg, #eef2f7, #eef2f7 10px, #f3f6fa 10px, #f3f6fa 20px); padding: 20px; border-radius: var(--radius); }
.doc-paper { max-width: 860px; margin: 0 auto; box-shadow: 0 20px 50px -20px rgba(15,23,42,.35); border-radius: 10px; background: #fff; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 26px; }
.timeline li::before { content: ''; position: absolute; left: 7px; top: 18px; bottom: 0; width: 2px; background: var(--line-2); }
.timeline li:last-child::before { display: none; }
.timeline .dot { position: absolute; left: 0; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--brand-50); border: 3px solid #fff; box-shadow: 0 0 0 1.5px var(--brand-100); }
.timeline .dot.wa { background: #25d366; box-shadow: 0 0 0 1.5px #b6efcc; }
.timeline .dot.ok { background: var(--ok); }
.timeline .dot.view { background: #6d4ee6; }
.timeline .what { font-weight: 600; font-size: 13px; }
.timeline .when { font-size: 12px; color: var(--muted); }
.ver-list a { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--line-2); color: inherit; gap: 10px; }
.ver-list a:hover { background: #fafcff; }
.ver-list a.cur { background: var(--brand-50); }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }

.wa-phone { display: flex; gap: 8px; }
.wa-bubble { background: #e7ffdb; border-radius: 12px 12px 12px 2px; padding: 12px 14px; white-space: pre-wrap; font-size: 13.5px; box-shadow: 0 1px 1px rgba(0,0,0,.08); position: relative; }
.wa-bg { background: #efeae2; border-radius: var(--radius); padding: 16px; }
.send-tabs { display: flex; gap: 4px; padding: 4px; background: #f1f5f9; border-radius: 10px; width: 100%; }
.send-tabs button { flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 8px 10px; font-weight: 600; font-size: 13.5px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.send-tabs button.active { background: #fff; color: var(--ink, #0f172a); box-shadow: 0 1px 2px rgba(15,23,42,.08); }
.send-tabs button[data-tab="wa"].active i { color: #25d366; }
.send-tabs button[data-tab="email"].active i { color: var(--brand); }
.timeline .dot.mail { background: var(--brand); }

/* ---------------------------------------------------------------- roles */
.perm-module { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.perm-module .mh { background: #f8fafc; padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; font-weight: 700; border-bottom: 1px solid var(--line-2); }
.perm-module .mb { padding: 10px 14px; display: grid; gap: 8px; }

/* ---------------------------------------------------------------- flash */
.toast-flash {
  position: fixed; right: 24px; bottom: 24px; z-index: 2000; display: flex; align-items: center; gap: 10px; padding: 12px 14px 12px 16px;
  border-radius: 12px; background: var(--navy); color: #fff; box-shadow: 0 16px 40px -12px rgba(8, 23, 38, .5); max-width: 420px;
  animation: toastIn .3s ease;
}
.toast-flash.ok i { color: #34d399; }
.toast-flash.err { background: #7f1d1d; }
.toast-flash .btn-close { filter: invert(1); opacity: .6; margin-left: 6px; }
.toast-flash + .toast-flash { bottom: 84px; }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------------- palette */
.palette { border: 0; border-radius: 16px; overflow: hidden; box-shadow: 0 30px 80px -20px rgba(8,23,38,.5); }
.palette-input { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.palette-input i { font-size: 18px; color: var(--muted); }
.palette-input input { flex: 1; border: 0; outline: 0; font-size: 16px; background: transparent; }
.palette-results { max-height: 420px; overflow-y: auto; padding: 6px; }
.palette-hint { padding: 22px; text-align: center; color: var(--muted); font-size: 13px; }
.pal-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink); }
.pal-item.hl, .pal-item:hover { background: var(--brand-50); }
.pal-item .pi { width: 34px; height: 34px; border-radius: 9px; background: var(--line-2); display: grid; place-items: center; color: var(--ink-2); }
.pal-item .t { font-weight: 600; }
.pal-item .s { font-size: 12.5px; color: var(--muted); }
.pal-item .ty { margin-left: auto; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }
mark { background: #fff3b0; padding: 0 1px; border-radius: 3px; }

/* ---------------------------------------------------------------- auth */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art {
  position: relative; overflow: hidden; color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(80% 60% at 20% 10%, #1f6fb0 0%, transparent 60%), radial-gradient(60% 50% at 90% 90%, #0e4c80 0%, transparent 60%), var(--navy);
}
.auth-art::after {
  content: ''; position: absolute; inset: 0; opacity: .12;
  background-image: linear-gradient(rgba(255,255,255,.5) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.5) 1px, transparent 1px);
  background-size: 44px 44px; mask-image: radial-gradient(70% 60% at 50% 40%, #000 30%, transparent 100%);
}
.auth-art > * { position: relative; z-index: 1; }
.auth-art h1 { font-size: 40px; font-weight: 800; letter-spacing: -1px; line-height: 1.1; max-width: 520px; }
.auth-art p { color: #b7cde2; max-width: 460px; font-size: 15px; }
.auth-feats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 560px; }
.auth-feats div { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); border-radius: 12px; padding: 14px; font-size: 12.5px; color: #cfe0f0; }
.auth-feats i { display: block; font-size: 20px; color: #6cc0ff; margin-bottom: 6px; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: #fff; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card img { max-width: 100%; height: auto; margin-bottom: 28px; }
@media (max-width: 991.98px) { .auth { grid-template-columns: 1fr; } .auth-art { display: none; } }

/* ---------------------------------------------------------------- misc */
.dropdown-menu { border-color: var(--line); border-radius: 12px; padding: 6px; }
.dropdown-item { border-radius: 8px; padding: 7px 10px; font-size: 13.5px; }
.modal-content { border-radius: 16px; border: 0; }
.chart-box { position: relative; height: 290px; }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
@media print { .sidebar, .topbar, .no-print { display: none !important; } .main { margin: 0; } }

/* ---------------------------------------------------------------- user → branches picker */
.branch-pick { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.branch-pick .bp-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line-2); }
.branch-pick .bp-row:first-child { border-top: 0; }
.branch-pick .bp-row.on { background: var(--brand-50); }
.branch-pick .bp-default { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.branch-pick .bp-row:not(.on) .bp-default { opacity: .4; cursor: default; }

/* =====================================================================
   Design pass 1 — identifiers, filters, actions, phone layouts
   ===================================================================== */

/* Document identifiers read like the serial labels on the devices Microteck sells:
   a mono face for quote numbers, SKUs, HSN, codes; tabular figures for money. */
.mono { font-family: var(--mono); font-size: .92em; letter-spacing: -.01em; }
.doc-id { font-family: var(--mono); font-weight: 600; letter-spacing: -.02em; display: inline-flex; align-items: stretch; white-space: nowrap; }
.doc-id .ver {
  font-family: var(--mono); margin-left: 6px; padding: 0 6px; border-radius: 5px;
  background: var(--brand-50); color: var(--brand-600); font-size: 11px; display: inline-flex; align-items: center;
}
.money, .kpi .val, .totals-box .v { font-variant-numeric: tabular-nums; }

/* Toolbars: selects never clip their label; date range reads as one labelled control */
.toolbar .form-select.w-auto { min-width: 150px; padding-right: 2.25rem; }
.date-range {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: #f8fafc;
}
.date-range:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(21,112,184,.12); background: #fff; }
.date-range .dr-lbl { font-size: 12px; font-weight: 600; color: var(--muted); padding-right: 4px; border-right: 1px solid var(--line); margin-right: 2px; }
.date-range input { border: 0; background: transparent; font: inherit; font-size: 13px; color: var(--ink); width: 122px; outline: none; }
.date-range .dr-sep { color: var(--muted); }

/* Destructive icons stay quiet until hovered — a list of red bins shouts */
.btn-ghost-danger { color: #94a3b8; }
.btn-ghost-danger:hover, .btn-ghost-danger:focus-visible { color: var(--bad); background: #fdecec; }

/* Visible keyboard focus everywhere */
a:focus-visible, button:focus-visible, .btn:focus-visible, .chip:focus-visible, .side-nav a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px; box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------------------------------------------------------------- phones */
@media (max-width: 767.98px) {
  /* Status chips: one swipeable row instead of three wrapped lines */
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; }

  /* Filters: search full width, the rest two per row */
  .toolbar { gap: 8px; }
  .toolbar .search { flex: 1 1 100%; max-width: none; }
  .toolbar > .form-select, .toolbar > select { flex: 1 1 calc(50% - 4px); min-width: 0 !important; width: auto; }
  .date-range { flex: 1 1 100%; }
  .date-range { min-width: 0; }
  .date-range input { flex: 1 1 0; width: 0; min-width: 0; font-size: 12.5px; }

  /* List tables become cards: title + actions on top, labelled values below */
  .table-x.stack thead { display: none; }
  .table-x.stack, .table-x.stack tbody, .table-x.stack tr, .table-x.stack td { display: block; width: 100%; }
  .table-x.stack tbody tr { position: relative; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
  .table-x.stack > :not(caption) > * > * { padding: 0; border: 0; background: transparent; box-shadow: none; }
  .table-x.stack td { padding: 3px 0 !important; text-align: right; min-height: 22px; }
  .table-x.stack td[data-label]::before { content: attr(data-label); float: left; margin-right: 12px; color: var(--muted); font-size: 12px; font-weight: 600; font-family: var(--bs-body-font-family); letter-spacing: 0; }
  .table-x.stack td:first-child { text-align: left; padding: 0 0 8px !important; margin-bottom: 4px; border-bottom: 1px dashed var(--line-2) !important; }
  .table-x.stack td:first-child::before { content: none; }
  .table-x.stack td:last-child:not([data-label]) { position: absolute; top: 10px; right: 12px; width: auto; padding: 0 !important; }
  .table-x.stack td:last-child:not([data-label]) ~ td, .table-x.stack tr:has(td:last-child:not([data-label])) td:first-child { padding-right: 0; }
  .table-x.stack tr:has(td:last-child:not([data-label])) td:first-child { padding-right: 110px !important; }
  .table-x.stack td[colspan] { text-align: center; }
  .table-x.stack td .sub { font-size: 12px; }
  .table-wrap:has(> .table-x.stack) { overflow-x: visible; }
}

/* =====================================================================
   Design pass 2 — page headers and documents on phones
   ===================================================================== */
@media (max-width: 575.98px) {
  .page-head { gap: 12px; margin-bottom: 16px; }
  .page-head h1 { font-size: 21px; }
  .page-head > div:first-child { width: 100%; }
  /* Actions share one row: primary stretches, secondary buttons stay compact */
  .page-head .actions { width: 100%; }
  .page-head .actions > .btn-primary, .page-head .actions > form, .page-head .actions > .btn-group:last-child { flex: 1 1 auto; }
  .page-head .actions > form .form-select { width: 100%; min-width: 0 !important; }
  .page-head .actions .btn { padding-left: 12px; padding-right: 12px; }
  .doc-stage { padding: 10px; }
  .kpi .ic { display: none; }
}

/* Inline code / placeholders in brand colours instead of Bootstrap pink */
code { color: var(--brand-600); background: var(--brand-50); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: .86em; }
.logo-field { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border: 1px dashed var(--line); border-radius: var(--radius-sm); background: #f8fafc; }
.logo-field img { max-height: 46px; max-width: 55%; }
.ph-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ph-chip {
  font-family: var(--mono); font-size: 11.5px; padding: 2px 8px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--brand-100); background: var(--brand-50); color: var(--brand-600);
}
.ph-chip:hover { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------------------------------------------------------------- customer contact people */
.contact-rows { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.contact-row {
  display: grid; grid-template-columns: 1.3fr 1.1fr 1fr 1fr 1.4fr auto; gap: 10px; align-items: end;
  padding: 12px 14px; border-top: 1px solid var(--line-2);
}
.contact-row:first-child { border-top: 0; }
.contact-row:not(:first-child) .form-label { display: none; }
.contact-row:has(input[name=primary]:checked) { background: var(--brand-50); }
.cr-act { display: flex; align-items: center; gap: 4px; height: 38px; }
.cr-main { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; padding: 0 6px; white-space: nowrap; }
.contact-row:has(input[name=primary]:checked) .cr-main { color: var(--brand-600); }
.qb-contact { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--brand-100); }
.contact-list .ct { display: flex; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--line-2); }
.contact-list .ct:first-child { border-top: 0; }
.contact-list .ct .links { display: flex; gap: 4px; flex-shrink: 0; align-items: flex-start; }
.contact-pick { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.contact-pick button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 3px 10px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.contact-pick button:hover, .contact-pick button.on { border-color: var(--brand); color: var(--brand-600); background: var(--brand-50); }
@media (max-width: 991.98px) {
  .contact-row { grid-template-columns: 1fr 1fr; }
  .contact-row .form-label { display: block !important; }
  .cr-name, .cr-email { grid-column: 1 / -1; }
  .cr-act { grid-column: 1 / -1; justify-content: space-between; height: auto; }
}
