@font-face { font-family: 'Montserrat'; font-weight: 400; font-display: swap; src: url('/fonts/montserrat-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Montserrat'; font-weight: 600; font-display: swap; src: url('/fonts/montserrat-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Montserrat'; font-weight: 700; font-display: swap; src: url('/fonts/montserrat-latin-700-normal.woff2') format('woff2'); }

:root {
  /* Style Guide v1.0 */
  --orange: #E85324;      /* Primary Orange */
  --orange-2: #E0674B;    /* Secondary Orange */
  --orange-3: #DD9083;    /* Alternative Orange */
  --dark: #15162B;        /* Primary Dark Blue */
  --blue: #3D4172;        /* Secondary Blue */
  --grey: #C6C6C6;        /* Primary Gray */
  --bg: #F3F3F6;
  --card: #FFFFFF;
  --muted: #3D4172;       /* captions use Secondary Blue */
  --danger: #B3261E;
  --ok: #1E7A46;
  --tap: 52px;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Montserrat', system-ui, sans-serif;
  background: var(--bg);
  color: var(--dark);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

/* ---- Top & bottom bars */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: #fff; color: var(--dark);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 4px solid var(--orange);
}
.brand { display: block; line-height: 0; }
.brand img { height: 44px; width: auto; }
.save-state { font-size: 13px; font-weight: 600; color: var(--blue); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--dark);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  min-height: 64px; display: flex; align-items: center; justify-content: center;
  color: var(--grey); text-decoration: none; font-weight: 600; font-size: 13px;
  border-top: 4px solid transparent;
}
.tabbar a.active { color: #fff; border-top-color: var(--orange); }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
h1 { font-size: 26px; font-weight: 700; margin: 6px 0 16px; color: var(--orange); }   /* Main heading */
h2 { font-size: 18px; font-weight: 700; margin: 0 0 12px; color: var(--dark); }      /* Third heading */

/* ---- Cards & lists */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 3px rgba(21,22,43,.08); }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 10px;
  min-height: 72px; box-shadow: 0 1px 3px rgba(21,22,43,.08);
  text-decoration: none; color: inherit; width: 100%; border: 0; font: inherit; text-align: left; cursor: pointer;
}
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 14px; color: var(--muted); margin-top: 3px; }
.list-item .right { text-align: right; font-weight: 700; white-space: nowrap; }
.cat-head { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 18px 4px 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---- Buttons (big touch targets) */
.btn {
  min-height: var(--tap); padding: 0 20px; border-radius: 12px; border: 2px solid transparent;
  font: inherit; font-weight: 700; font-size: 16px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn-primary { background: var(--orange); color: var(--dark); }      /* orange buttons use dark blue text */
.btn-primary:active { filter: brightness(.92); }
.btn-secondary { background: var(--blue); color: #fff; }
.btn-ghost { background: #fff; color: var(--blue); border-color: var(--blue); }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-row.three { grid-template-columns: 1fr 1fr 1fr; }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap); border-radius: 12px; border: 2px solid var(--grey);
  background: #fff; font: inherit; font-size: 22px; font-weight: 700; color: var(--blue); cursor: pointer;
}

/* ---- Forms */
label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 12px 14px; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  border: 2px solid var(--grey); border-radius: 12px; background: #fff; color: var(--dark);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--orange); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---- Status chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 22px; border: 2px solid var(--grey);
  background: #fff; font: inherit; font-weight: 600; font-size: 14px; white-space: nowrap; cursor: pointer; color: var(--dark);
}
.chip.active { background: var(--dark); border-color: var(--dark); color: #fff; }
.status { display: inline-block; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 12px; }
.status-Draft { background: #E6E6EC; color: var(--blue); }
.status-Sent { background: #DCE0F7; color: var(--blue); }
.status-Accepted { background: #D6F0DF; color: var(--ok); }
.status-Declined { background: #F7DCDA; color: var(--danger); }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg .chip { border-radius: 10px; padding: 0 4px; min-height: var(--tap); }

/* ---- Quote lines */
.line { border: 2px solid #ECECF1; border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.line-top { display: flex; gap: 8px; align-items: flex-start; }
.line-top input { flex: 1; font-weight: 600; }
.line-remove { min-width: var(--tap); min-height: var(--tap); border: 0; background: none; font-size: 26px; color: var(--danger); cursor: pointer; }
.line-mid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; align-items: end; }
.line-mid label, .cost-field label { white-space: nowrap; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper input { flex: 1; min-width: 0; text-align: center; padding: 12px 2px; }
.stepper .icon-btn { min-width: 44px; }
.line-amt { text-align: right; font-weight: 700; font-size: 17px; margin-top: 10px; }
.line-unit { font-size: 13px; color: var(--muted); }
.cost-field { margin-top: 8px; }
.cost-field label { margin-top: 0; }
.private-tag { font-size: 11px; font-weight: 700; color: var(--danger); text-transform: uppercase; letter-spacing: .5px; }

/* ---- Totals & margin */
.totals .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 16px; }
.totals .row.total { font-size: 20px; font-weight: 700; border-top: 2px solid var(--grey); margin-top: 6px; padding-top: 12px; }
.totals .row.deposit { background: var(--orange); color: var(--dark); font-weight: 700; border-radius: 10px; padding: 12px; margin-top: 8px; }
.margin { border: 2px dashed var(--blue); }
.margin.low { border-color: var(--danger); background: #FFF6F5; }
.margin .big { font-size: 30px; font-weight: 700; }
.margin.low .big { color: var(--danger); }
.margin .warn { color: var(--danger); font-weight: 700; margin-top: 8px; }
.margin .note { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* ---- Bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet.hidden, .hidden { display: none !important; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(21,22,43,.55); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60;
  background: var(--dark); color: #fff; padding: 14px 20px; border-radius: 12px; font-weight: 600; max-width: 90vw;
}
.toast.error { background: var(--danger); }
/* ---- Job statuses */
.status-job-Unscheduled { background: #FBE3DB; color: #A23A17; }
.status-job-Scheduled { background: #DCE0F7; color: var(--blue); }
.status-job-In-progress { background: #FFF0C2; color: #7A5600; }
.status-job-Completed { background: #D6F0DF; color: var(--ok); }
.status-job-Cancelled { background: #E6E6EC; color: #5B5E7A; }
.seg.seg-job { grid-template-columns: repeat(3, 1fr); }
a.icon-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* ---- Team roles */
body.role-team .tabbar { grid-template-columns: repeat(3, 1fr); }
body.role-team .tabbar a[data-tab="quotes"], body.role-team .tabbar a[data-tab="invoices"] { display: none; }
.role-pick { display: grid; gap: 8px; }
.role-opt { display: flex; gap: 12px; align-items: flex-start; border: 2px solid var(--grey); border-radius: 12px; padding: 12px; margin: 0; color: var(--dark); font-weight: 400; cursor: pointer; }
.role-opt input { width: 24px; min-height: 24px; margin-top: 2px; flex: none; }
.role-opt small { color: var(--muted); font-size: 13px; }
.role-opt:has(input:checked) { border-color: var(--orange); background: #FFF6F2; }
.who { display: flex; gap: 8px; flex-wrap: wrap; }
.who-opt { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 14px; border: 2px solid var(--grey); border-radius: 24px; margin: 0; color: var(--dark); font-weight: 600; cursor: pointer; }
.who-opt input { width: 20px; min-height: 20px; }
.who-opt:has(input:checked) { border-color: var(--dark); background: var(--dark); color: #fff; }
.visit-who { font-size: 12px; font-weight: 700; color: var(--blue); margin-top: 3px; }

/* ---- Invoices */
.inv-Draft { background: #E6E6EC; color: var(--blue); }
.inv-Unpaid { background: #DCE0F7; color: var(--blue); }
.inv-Overdue { background: #F7DCDA; color: var(--danger); }
.inv-Part-paid { background: #FFF0C2; color: #7A5600; }
.inv-Paid { background: #D6F0DF; color: var(--ok); }
.inv-Void { background: #E6E6EC; color: #5B5E7A; text-decoration: line-through; }
h1 .status { vertical-align: middle; font-size: 13px; margin-left: 6px; }
.xero-badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; margin-left: 4px; }
.xero-badge.ok { background: #E3F3EA; color: var(--ok); }
.xero-badge.warn { background: #FFF0C2; color: #7A5600; }
.warn-text { color: var(--danger); font-weight: 600; }
.stat { margin-bottom: 0; }
.stat-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat-num { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat-bad .stat-num { color: var(--danger); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid #ECECF1; }
.kv span { color: var(--muted); }
.kv-link { display: inline-block; margin: 10px 14px 0 0; font-weight: 700; color: var(--blue); text-decoration: none; min-height: 44px; line-height: 44px; }
.inv-table { width: 100%; border-collapse: collapse; }
.inv-table td { padding: 10px 0; border-bottom: 1px solid #ECECF1; vertical-align: top; }
.inv-table td .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.inv-table td.amt { text-align: right; font-weight: 700; white-space: nowrap; padding-left: 12px; }

/* ---- Reports (chart colours validated for colour-blind separation: blue #257de0 / brand orange #E85324) */
:root { --s-income: #257de0; --s-expense: #E85324; --chart-grid: #e7e7e7; --chart-axis: #c2c2c2; --chart-ink2: #666666; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.stat-grid .stat { margin: 0; }
.stat-note { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.35; }
.fine { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.linkbtn { background: none; border: 0; font: inherit; font-weight: 700; font-size: 14px; color: var(--blue); cursor: pointer; min-height: 44px; padding: 0 4px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.legend { display: flex; gap: 16px; font-size: 14px; color: var(--chart-ink2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.sw.s-income { background: var(--s-income); } .sw.s-expense { background: var(--s-expense); }
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-wrap .grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart-wrap .axis { stroke: var(--chart-axis); stroke-width: 1; }
.chart-wrap .tick { fill: var(--chart-ink2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-wrap path.s-income { fill: var(--s-income); } .chart-wrap path.s-expense { fill: var(--s-expense); }
.chart-wrap .hit { fill: transparent; cursor: pointer; }
.chart-wrap .mgroup { outline: none; transition: opacity .12s; }
.chart-wrap .mgroup.dim { opacity: .35; }
.tip { position: absolute; z-index: 3; background: #fff; border: 1px solid rgba(11,11,11,.1); box-shadow: 0 4px 14px rgba(21,22,43,.15); border-radius: 10px; padding: 10px 12px; font-size: 13px; pointer-events: none; min-width: 170px; }
.tip div { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.tip b { margin-left: auto; font-variant-numeric: tabular-nums; }
.tip .tip-net { border-top: 1px solid #ECECF1; padding-top: 4px; }
table.rpt { width: 100%; border-collapse: collapse; font-size: 14px; }
table.rpt th { text-align: right; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 0 6px 8px; border-bottom: 1px solid #ECECF1; }
table.rpt th:first-child, table.rpt td:first-child { text-align: left; padding-left: 0; }
table.rpt td { text-align: right; padding: 9px 0 9px 8px; border-bottom: 1px solid #ECECF1; vertical-align: top; font-variant-numeric: tabular-nums; }
table.rpt td a { color: var(--blue); font-weight: 700; text-decoration: none; }
.late { color: var(--danger); font-weight: 700; white-space: nowrap; }
.aging { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 12px; }
.aging div { background: #F6F6F9; border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.aging span { font-size: 11px; color: var(--muted); font-weight: 600; } .aging b { font-size: 14px; }
details.pl summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; list-style: none; }
details.pl summary::after { content: '›'; margin-left: auto; font-size: 24px; color: var(--blue); transition: transform .15s; }
details.pl[open] summary::after { transform: rotate(90deg); }
.pl-head { font-weight: 700; color: var(--blue); margin: 16px 0 4px; }
.pl-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid #F0F0F4; font-size: 14px; font-variant-numeric: tabular-nums; }
.pl-total { font-weight: 700; border-bottom: 2px solid var(--grey); }
.pl-key { font-weight: 700; font-size: 16px; background: #F6F6F9; padding: 10px 8px; border-radius: 8px; margin-top: 10px; }
@media (max-width: 520px) { .aging { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { #view > .chips.chips-wrap { flex-wrap: wrap; max-width: none; } }
@media (min-width: 900px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

/* ---- Calendar */
.cal-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-week { flex: 1; text-align: center; font-weight: 700; }
.cal-today { min-height: 52px; padding: 0 14px; }
.day-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 4px;
  min-height: 64px; border-radius: 12px; background: #fff; color: var(--dark); text-decoration: none;
  border: 2px solid transparent;
}
.day-btn .dow { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.day-btn .dnum { font-size: 18px; font-weight: 700; }
.day-btn .dots { font-size: 12px; line-height: 1; color: var(--orange); letter-spacing: 1px; }
.day-btn.is-today { border-color: var(--orange); }
.day-btn.active { background: var(--dark); color: #fff; }
.day-btn.active .dow { color: var(--grey); }
.visit-card {
  display: block; background: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 10px;
  text-decoration: none; color: var(--dark); border-left: 6px solid var(--blue);
  box-shadow: 0 1px 3px rgba(21,22,43,.08); min-height: 64px;
}
.visit-time { font-weight: 700; color: var(--orange); font-size: 14px; }
.visit-title { font-weight: 700; margin-top: 2px; }
.visit-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.status-border-In-progress { border-left-color: #E0A800; }
.status-border-Completed { border-left-color: var(--ok); opacity: .75; }
.status-border-Cancelled { border-left-color: var(--grey); opacity: .6; text-decoration: line-through; }
.week-grid { display: none; }

/* ---- Desktop / wide screens */
@media (min-width: 900px) {
  .day-strip, .day-view { display: none; }
  .week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
  .week-col { background: #fff; border-radius: 12px; padding: 8px; min-height: 260px; display: flex; flex-direction: column; }
  .week-col.is-today { outline: 3px solid var(--orange); }
  .week-head { font-weight: 700; color: var(--dark); text-decoration: none; padding: 4px 4px 8px; border-bottom: 2px solid #ECECF1; margin-bottom: 8px; }
  .week-col .visit-card { padding: 8px 10px; font-size: 13px; box-shadow: none; background: #F6F6F9; }
  .week-add { margin-top: auto; min-height: 40px; border: 2px dashed var(--grey); background: none; border-radius: 10px; font: inherit; font-size: 20px; color: var(--blue); cursor: pointer; }
  .week-add:hover { border-color: var(--orange); color: var(--orange); }
  .tabbar a { font-size: 15px; }
  .seg.seg-job { grid-template-columns: repeat(5, 1fr); }
  body { padding-bottom: 24px; }
  .topbar { padding: 12px 32px; }
  /* menu moves from the bottom into the header area */
  .tabbar {
    position: sticky; top: 68px; bottom: auto; z-index: 9;
    display: flex; justify-content: flex-start; gap: 4px;
    padding: 0 24px; background: var(--dark);
  }
  .tabbar a { min-height: 52px; padding: 0 24px; border-top: 0; border-bottom: 4px solid transparent; }
  .tabbar a.active { border-bottom-color: var(--orange); }
  .tabbar a:hover { color: #fff; }
  main { max-width: 1180px; padding: 24px 32px; }
  #view > h1, #view > .btn-block, #view > .chips, #view > #pb-search { max-width: 760px; }
  #view > .list-item, #pb-list, #view > .empty, #view > form { max-width: 760px; }
  .editor { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
  .col-side { position: sticky; top: 140px; }
  /* bottom sheet becomes a centred dialog */
  .sheet-panel { top: 50%; bottom: auto; left: 50%; right: auto; transform: translate(-50%, -50%);
    width: 560px; max-height: 80vh; border-radius: 20px; }
  .list-item:hover { box-shadow: 0 2px 10px rgba(21,22,43,.15); }
}

.bar { height: 10px; border-radius: 5px; background: #ECECF1; overflow: hidden; }
.bar > div { height: 100%; background: var(--orange); transition: width .3s; }

/* ---- Job photos & notes */
.ph-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
@media (min-width: 900px) { .ph-grid { grid-template-columns: repeat(4, 1fr); } }
.ph-thumb { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 10px; overflow: hidden;
  background: #ECECF1; cursor: pointer; }
.ph-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-thumb:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.ph-cap-dot { position: absolute; right: 6px; bottom: 6px; background: rgba(21,22,43,.7); color: #fff;
  border-radius: 10px; font-size: 12px; padding: 1px 6px; }
.ph-progress { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: #FDEDE7; color: var(--dark); font-weight: 600; }
.ph-full-link { display: block; }
.ph-full { display: block; width: 100%; max-height: 60vh; object-fit: contain; background: #15162B; border-radius: 12px; }
.notes { margin-top: 14px; }
.note { border-top: 1px solid #ECECF1; padding: 12px 0; }
.note-body { white-space: pre-line; overflow-wrap: anywhere; }
.note-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); margin-top: 4px; }
.note-del { background: none; border: 0; color: var(--danger); font: inherit; font-weight: 600; min-height: 40px; padding: 0 4px; cursor: pointer; }

.sticky-actions { position: sticky; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 5; padding-top: 6px; }
