/* ===== Brand theme: change these to re-colour the whole app ===== */
:root {
  --brand: #0f2742;          /* primary (sidebar, headings) */
  --brand-2: #1b3a5c;        /* primary hover */
  --accent: #f5a524;         /* highlights, primary buttons */
  --accent-ink: #1a1300;     /* text on accent */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #16202c;
  --muted: #5d6b7c;
  --line: #e2e7ee;
  --good: #16794c;
  --warn: #b25e00;
  --bad: #b42318;
  --info: #1d5fbf;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--brand); margin: 0 0 .5em; line-height: 1.2; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
pre { white-space: pre-wrap; }

/* Shell */
.shell { display: flex; min-height: 100vh; background: linear-gradient(to right, var(--brand) 232px, transparent 232px); }
.sidebar { width: 232px; background: var(--brand); color: #cfd8e3; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-size: 17px; }
.brand:hover { text-decoration: none; }
.wordmark { font-weight: 400; letter-spacing: -.01em; font-size: 20px; color: inherit; }
.wordmark strong { font-weight: 800; }
.wordmark-lg { font-size: 28px; color: var(--brand); }
.erp-tag { font-size: 11px; font-weight: 700; letter-spacing: .08em; padding: 2px 6px; border-radius: 4px; background: var(--accent); color: var(--accent-ink); }
.sidebar nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #cfd8e3; margin-bottom: 2px; }
.sidebar nav a:hover { background: var(--brand-2); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.1); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.1); padding: 12px 16px; }
.me { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.me img, .avatar { width: 32px; height: 32px; border-radius: 50%; }
.avatar { display: inline-grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.me-name { color: #fff; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .muted { color: #93a3b8; }
.link-btn { background: none; border: 0; color: #cfd8e3; padding: 0; cursor: pointer; font: inherit; }
.link-btn:hover { color: #fff; text-decoration: underline; }

.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 18px; cursor: pointer; }
.content { padding: 24px 28px 48px; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 20px; }
.card > h2:first-child { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 20px 0; }
.empty { text-align: center; padding: 40px 20px; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 20px; }

.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 700; color: var(--brand); margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.accent { border-top: 3px solid var(--accent); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #f8fafc; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 600; border-bottom: 0; }
tr.low td { background: #fff7ed; }

/* Forms */
form.form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
label .muted { font-weight: 400; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid #cdd5df; border-radius: 8px; font: inherit; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 36px; }
textarea { min-height: 80px; resize: vertical; }
.form-actions { display: flex; gap: 8px; align-items: center; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form > div { flex: 1; min-width: 120px; }
.inline-form .btn { flex: none; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters input, .filters select { width: auto; min-width: 160px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid #cdd5df; background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f3f5f8; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(.95); background: var(--accent); }
.btn-dark { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-dark:hover { background: var(--brand-2); }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-google { width: 100%; justify-content: center; padding: 10px; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef1f5; color: #3d4a5c; white-space: nowrap; }
.badge-new, .badge-lead, .badge-planning, .badge-draft, .badge-pending { background: #eef4ff; color: #1d4ed8; }
.badge-scheduled, .badge-prospect, .badge-sent { background: #f3e8ff; color: #6b21a8; }
.badge-in_progress, .badge-active, .badge-partial { background: #fff4e0; color: #9a5b00; }
.badge-completed, .badge-paid, .badge-customer, .badge-finalized, .badge-approved { background: #e7f6ee; color: #146c43; }
.badge-invoiced { background: #e0f2f1; color: #0f766e; }
.badge-on_hold, .badge-inactive, .badge-disabled { background: #f1f2f4; color: #59606b; }
.badge-cancelled, .badge-void, .badge-overdue { background: #fdecec; color: #b42318; }
.badge-emergency { background: #b42318; color: #fff; }
.badge-high { background: #fdecec; color: #b42318; }
.badge-low { background: #f1f2f4; color: #59606b; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; margin-right: 6px; }

.flash { margin: 16px 28px 0; padding: 10px 14px; border-radius: 8px; background: #e7f6ee; color: #145c3b; border: 1px solid #b7e2c8; }
.flash-error { background: #fdecec; color: #8a1c13; border-color: #f5c2bd; }
.login-card .flash { margin: 0 0 12px; }

.pager { display: flex; gap: 4px; padding: 12px; }
.pager a { padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line); }
.pager a.current { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Bars */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding-top: 10px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar span.fill { width: 100%; max-width: 44px; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar:last-child span.fill { background: var(--accent); }
.bar .bl { font-size: 11px; color: var(--muted); }
.bar .bv { font-size: 11px; color: var(--ink); }
.progress { height: 8px; background: #eef1f5; border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--good); }
.progress.over > span { background: var(--bad); }

/* Schedule */
.cal { display: grid; grid-template-columns: 160px repeat(7, minmax(110px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); min-width: 950px; }
.cal > div { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 8px; min-height: 64px; }
.cal .head { background: #f8fafc; font-weight: 600; font-size: 12px; min-height: 0; color: var(--muted); }
.cal .head.today { color: var(--brand); box-shadow: inset 0 -3px 0 var(--accent); }
.cal .who { font-weight: 600; display: flex; align-items: center; }
.cal .cell.today { background: #fffbf2; }
.ev { display: block; border-radius: 6px; padding: 4px 6px; font-size: 12px; margin-bottom: 4px; color: #fff; line-height: 1.3; }
.ev:hover { text-decoration: none; filter: brightness(1.08); }
.ev small { display: block; opacity: .9; }

/* Line items editor */
.items td { padding: 6px; }
.items input { padding: 6px 8px; }

/* Login */
body.plain { background: linear-gradient(160deg, var(--brand) 0%, var(--brand-2) 60%, #24486f 100%); min-height: 100vh; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: #fff; padding: 36px 32px; border-radius: 16px; width: 100%; max-width: 380px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { font-size: 20px; margin-top: 12px; }

.dev-login { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); display: grid; gap: 8px; }

/* Print (invoices, pay stubs) */
.doc { max-width: 820px; margin: 0 auto; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.doc-head h2 { font-size: 22px; }
@media print {
  .sidebar, .topbar, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 0; }
}

/* Responsive */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: -240px; z-index: 20; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: block; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .content { padding: 16px; }
  .flash { margin: 12px 16px 0; }
  .shell { background: none; }
  .grid-2, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; }
  .doc-head { flex-direction: column; }
}

/* Proposals */
.proposal { line-height: 1.6; font-size: 15px; }
.proposal h1 { font-size: 26px; margin: 8px 0 16px; }
.proposal h2 { font-size: 18px; margin: 28px 0 8px; padding-bottom: 6px; border-bottom: 2px solid var(--accent); display: block; }
.proposal h3 { font-size: 15px; margin: 18px 0 6px; }
.proposal table { margin: 10px 0 16px; font-size: 14px; }
.proposal ul, .proposal ol { padding-left: 22px; }
.proposal hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.badge-sent { background: #f3e8ff; color: #6b21a8; }
.badge-accepted { background: #e7f6ee; color: #146c43; }
.badge-declined { background: #fdecec; color: #b42318; }
@media print { .grid-main { display: block; } .proposal { font-size: 12pt; } }
.proposal.doc { max-width: none; margin: 0; }

/* ===== Help desk ticket statuses (portal and ERP) ===== */
.badge-t-open { background: #eef4ff; color: #1d4ed8; }
.badge-t-in_progress { background: #fff4e0; color: #9a5b00; }
.badge-t-waiting { background: #fdecec; color: #b42318; }
.badge-t-resolved { background: #e7f6ee; color: #146c43; }
.badge-t-closed { background: #f1f2f4; color: #59606b; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a.active { color: var(--brand); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--brand); }
.btn-block { width: 100%; justify-content: center; padding: 10px; }
.btn-lg { padding: 11px 18px; font-size: 15px; }
.thread-msg { padding: 12px 14px; border-radius: 10px; background: #f6f8fb; border: 1px solid var(--line); margin-bottom: 10px; }
.thread-msg.from-customer { background: #fff; }
.thread-msg.internal { background: #fff8e6; border-color: #f3d48a; }
.link-box { display: flex; gap: 6px; }
.link-box input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: 12px; }

/* ===== Customer portal (one.hsmglobal.ca) ===== */
body.portal { display: flex; flex-direction: column; min-height: 100vh; }
.p-header { background: var(--brand); color: #fff; }
.p-bar { max-width: 1160px; margin: 0 auto; padding: 14px 24px 10px; display: flex; align-items: center; gap: 16px; }
.p-brand { display: flex; align-items: center; gap: 12px; color: #fff; font-size: 20px; letter-spacing: -.01em; }
.p-brand:hover { text-decoration: none; }
.p-brand strong { font-weight: 800; }
.p-brand .one-mark { width: 44px; height: 32px; color: var(--accent); }
.p-me { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; flex-wrap: wrap; justify-content: flex-end; }
.p-me a { color: #fff; }
.p-company { color: #93a3b8; }
.p-nav { max-width: 1160px; margin: 0 auto; padding: 0 16px; display: flex; gap: 2px; overflow-x: auto; }
.p-nav a { color: #cfd8e3; padding: 10px 12px; border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 600; }
.p-nav a:hover { color: #fff; text-decoration: none; }
.p-nav a.active { color: #fff; border-color: var(--accent); }
.p-main { flex: 1; width: 100%; max-width: 1160px; margin: 0 auto; padding: 24px; }
.p-main > .flash { margin: 0 0 16px; }
.p-foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 16px 28px; }
.p-hero { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; }
.p-hero h1 { font-size: 26px; margin-bottom: 4px; }
.p-hero p { margin: 0; max-width: 640px; }
.p-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.p-head h1 { font-size: 22px; margin: 0 0 4px; }
.p-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.p-row:last-child { border-bottom: 0; }
.p-callout { border-left: 4px solid var(--accent); }
.p-narrow { max-width: 720px; }
.p-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 10px; }
.p-tile { display: flex; flex-direction: column; gap: 4px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fff; border-top: 4px solid var(--info); }
.p-tile:hover { text-decoration: none; box-shadow: var(--shadow); border-color: #cdd5df; }
.p-tile-security, .p-tile-cctv { border-top-color: #6b21a8; }
.p-tile-fire { border-top-color: var(--bad); }
.p-tile-energy { border-top-color: var(--good); }
.p-tile-bas { border-top-color: var(--accent); }
.p-tile-type { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.p-tile-open { color: var(--info); margin-top: auto; font-weight: 600; }
.p-thread { padding: 8px 20px; }
.p-msg { padding: 14px 0; border-bottom: 1px solid var(--line); }
.p-msg:last-child { border-bottom: 0; }
.p-msg-staff { border-left: 3px solid var(--accent); padding-left: 12px; }
.p-msg-who { margin-bottom: 6px; }
.p-msg-body { white-space: normal; overflow-wrap: anywhere; }
.p-progress { height: 10px; background: #eef1f5; border-radius: 99px; overflow: hidden; margin-bottom: 8px; }
.p-progress span { display: block; height: 100%; background: var(--accent); }
.p-proposal-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.p-decline { position: relative; }
.p-decline summary { list-style: none; }
.p-decline summary::-webkit-details-marker { display: none; }
.p-decline[open] form { position: absolute; right: 0; top: 110%; z-index: 5; width: min(320px, 80vw); background: #fff; padding: 14px; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.portal-plain { background: radial-gradient(circle at 30% 0%, var(--brand-2), var(--brand) 70%); }
.p-login-mark .one-mark { width: 72px; height: 52px; color: var(--brand); }
.login-card h1 strong { font-weight: 800; }
.p-login-form { text-align: left; margin: 18px 0 12px; }
@media (max-width: 760px) {
  .p-bar { padding: 12px 16px 8px; }
  .p-company { display: none; }
  .p-main { padding: 16px; }
  .p-hero .btn-lg { width: 100%; justify-content: center; }
}
@media print { .p-header, .p-foot { display: none !important; } .p-main { padding: 0; } }
