/* Apex Solutions brand: charcoal #35393A and teal #31B4AA, sampled from the company logo artwork. */
:root {
  --charcoal: #35393a; --charcoal-2: #464b4d; --teal: #31b4aa; --teal-dark: #17786f;
  --bg: #f2f3f3; --card: #ffffff; --line: #dfe2e3; --text: #1f2324; --muted: #5d6466;
  --green: #17794a; --green-bg: #e3f4ea; --red: #b3261e; --red-bg: #fbe9e7; --blue: #1d5fa8; --blue-bg: #e6f0fb;
  --radius: 14px; --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--teal-dark); }
button, input, select, textarea { font: inherit; color: inherit; }

.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; background: var(--charcoal); color: #fff; text-align: center; padding: 24px; }
.boot .muted { color: #b9bdbe; }
.logo { display: block; width: 100%; max-width: 300px; height: auto; }   /* logo artwork has its own charcoal background: only use on charcoal */
.mark { color: var(--teal); flex: 0 0 auto; }

/* ---------- shell ---------- */
.shell { min-height: 100vh; }
.main { padding-bottom: calc(68px + var(--safe-b)); }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  background: var(--charcoal); color: #fff; padding: calc(10px + var(--safe-t)) 16px 10px; min-height: 56px;
}
.top h1 { font-size: 19px; font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .who { font-size: 13px; color: #c9cdce; }
.top .mark { margin-right: 2px; }
.top .back { color: #fff; display: grid; place-items: center; width: 40px; height: 40px; margin-left: -10px; }
.banner { font-size: 13px; padding: 6px 16px; text-align: center; }
.banner.demo { background: #fff4d6; color: #6b4a00; }
.banner.offline { background: var(--red-bg); color: var(--red); font-weight: 600; }
.content { padding: 14px 14px 24px; max-width: 980px; margin: 0 auto; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.nav .brand, .nav .nav-foot, .nav .desk-only { display: none; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; text-decoration: none; color: var(--muted); font-size: 11.500px; font-weight: 600;
}
.tab.on, .tab.on-phone { color: var(--charcoal); }
.tab.on .icon, .tab.on-phone .icon { color: var(--teal-dark); }
.tab-icon { position: relative; display: grid; place-items: center; }
.count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; font-size: 11.5px; font-weight: 800; line-height: 1; }
.tab-icon .count { position: absolute; top: -7px; left: 12px; }
.nav .tab-icon .count.desk-only { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 220px 1fr; }
  .nav {
    position: sticky; top: 0; height: 100vh; flex-direction: column; border-top: 0; border-right: 1px solid var(--line);
    background: var(--charcoal); padding: 16px 10px; gap: 4px; right: auto;
  }
  .nav .brand { display: block; padding: 6px 8px 20px; }
  .nav .brand small { display: block; color: #a4a9ab; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; margin-top: 8px; }
  .nav .desk-only { display: flex; }
  .nav .nav-foot { display: block; margin-top: auto; color: #a4a9ab; font-size: 13px; padding: 8px; }
  .tab { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 10px; color: #c9cdce; font-size: 15px; }
  .tab.on-phone { color: #c9cdce; }
  .tab.on-phone .icon { color: inherit; }
  .tab.on { background: var(--charcoal-2); color: #fff; }
  .tab.on .icon { color: var(--teal); }
  .nav { overflow-y: auto; }
  .tab { min-height: 40px; }
  .nav .tab-icon .count.desk-only { display: inline-grid; }
  .nav .tab-icon .count.phone-only { display: none; }
  .main { padding-bottom: 0; }
  .top { background: var(--bg); color: var(--text); padding: 20px 28px 6px; position: static; }
  .top h1 { font-size: 26px; }
  .top .who, .top .mark { display: none; }
  .top .back { color: var(--text); }
  .content { padding: 14px 28px 40px; margin: 0; }
}

/* ---------- building blocks ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2, .section-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.section-title { margin: 18px 2px 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-size: 12.500px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 16px 4px; }
.error { color: var(--red); }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack > * + * { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 700; cursor: pointer; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--charcoal); border-color: var(--charcoal); color: #fff; }
.btn.accent { background: var(--teal); border-color: var(--teal); color: #1f2324; }
.btn.danger { color: var(--red); border-color: #e7b8b3; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 10px; font-size: 18px; cursor: pointer; color: var(--muted); }
.fab {
  position: fixed; right: 16px; bottom: calc(76px + var(--safe-b)); z-index: 8; width: 56px; height: 56px; border-radius: 50%;
  background: var(--teal); color: #1f2324; border: 0; display: grid; place-items: center; box-shadow: 0 6px 16px rgba(31, 35, 36, .3); cursor: pointer;
}
@media (min-width: 900px) { .fab { bottom: 28px; right: 28px; } }

.field { display: block; margin-bottom: 12px; }
.field-label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.field-hint { display: block; font-size: 12.500px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=search], input[type=tel], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border: 1px solid #c6cacb; border-radius: 10px; background: #fff;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible { outline: 3px solid rgba(49, 180, 170, .6); outline-offset: 1px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; background: #e9ebeb; color: #44494b; }
.s-survey, .s-quoted { background: #ecebfa; color: #45409a; }
.s-approved { background: var(--blue-bg); color: var(--blue); }
.s-in_progress { background: #fff0cf; color: #7a4a00; }
.s-snagging { background: #fde5d4; color: #9a4310; }
.s-complete, .s-invoiced, .s-approved-time { background: var(--green-bg); color: var(--green); }
.s-open { background: #fff0cf; color: #7a4a00; }
.s-submitted { background: var(--blue-bg); color: var(--blue); }
.flag { color: var(--red); font-weight: 700; font-size: 12.500px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; }
.chip { flex: 0 0 auto; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--charcoal); border-color: var(--charcoal); color: #fff; }

.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 56px; }
.item:first-child { border-top: 0; }
a.item:active, button.item:active { background: #f4f5f5; }
button.item { width: 100%; border-left: 0; border-right: 0; border-bottom: 0; background: none; text-align: left; cursor: pointer; }
.item-title { font-weight: 700; }
.item-sub { font-size: 13px; color: var(--muted); }
.avatar { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--charcoal); color: #fff; font-weight: 700; font-size: 14px; }

.stat { text-align: center; padding: 10px 6px; }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.500px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.stats .card { margin: 0; padding: 6px; }

/* time clock */
.clock-face { text-align: center; padding: 22px 14px; }
.clock-time { font-size: 46px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.clock-btn { width: 100%; min-height: 76px; font-size: 22px; border-radius: 18px; margin-top: 14px; }
.clock-btn.in { background: var(--green); border-color: var(--green); color: #fff; }
.clock-btn.out { background: var(--red); border-color: var(--red); color: #fff; }
.steps { display: flex; gap: 8px; flex-wrap: wrap; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 8px 6px; border-top: 1px solid var(--line); text-align: left; }
table.t th { font-size: 12px; color: var(--muted); border-top: 0; font-weight: 700; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tfoot td { font-weight: 800; }

.entry { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.entry.tap { cursor: pointer; }
.entry.tap:active { background: #f4f5f5; }
.week-nav .btn { font-size: 24px; line-height: 1; padding: 0 14px; min-height: 44px; }

/* schedule */
.sched-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
table.sched { border-collapse: collapse; width: 100%; min-width: 760px; table-layout: fixed; }
.sched th, .sched td { border-top: 1px solid var(--line); border-left: 1px solid var(--line); padding: 0; vertical-align: top; }
.sched thead th { border-top: 0; padding: 8px 4px; font-size: 12.5px; color: var(--muted); text-align: center; font-weight: 700; }
.sched thead th span { font-size: 17px; color: var(--text); }
.sched th.who { position: sticky; left: 0; z-index: 2; width: 104px; background: var(--card); border-left: 0; text-align: left; padding: 8px 10px; font-size: 13.5px; font-weight: 700; overflow-wrap: anywhere; }
.sched .today { background: #e4f5f3; }
.sched thead th.today span { color: var(--teal-dark); }
.cell { display: flex; flex-direction: column; gap: 4px; width: 100%; min-height: 58px; padding: 4px; border: 0; background: none; cursor: pointer; text-align: left; }
.cell:hover, .cell:focus-visible { background: rgba(31, 35, 36, .05); outline: none; }
.cell .plus { margin: auto; color: #bcc0c1; font-size: 20px; }
.sh { display: block; border-radius: 7px; padding: 3px 6px; font-size: 12px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.sh small { display: block; font-weight: 500; font-size: 11px; opacity: .85; }
.sh.off { background: var(--green-bg); color: var(--green); }
.sh.c0 { background: #dbeafe; color: #1e3a8a; } .sh.c1 { background: #fde8c8; color: #7a3d00; } .sh.c2 { background: #e5defc; color: #46348f; }
.sh.c3 { background: #d5f0ea; color: #0c5a4c; } .sh.c4 { background: #fbdbe4; color: #8a1c3c; } .sh.c5 { background: #e6e9ee; color: #334155; }
.today-card { border-color: var(--teal); box-shadow: inset 4px 0 0 var(--teal); }
.s-declined { background: var(--red-bg); color: var(--red); }

/* job P&L */
.kv.pnl { grid-template-columns: 1fr auto; }
.kv.pnl dd { text-align: right; }
.receipt { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; display: block; background: #e5e7e8; }
table.pnl-table { min-width: 720px; }
table.pnl-table th, table.pnl-table td { padding: 10px 10px; }
table.pnl-table a { text-decoration: none; }

/* chat */
.avatar.teal { background: var(--teal); color: var(--charcoal); }
.avatar .icon { color: inherit; }
.clip { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.chat-head { display: flex; flex-direction: column; padding: 2px 2px 10px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.msgs { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; min-height: 40vh; }
.day { align-self: center; font-size: 12px; font-weight: 700; color: var(--muted); background: #e5e7e8; border-radius: 999px; padding: 2px 10px; margin: 6px 0; }
.msg { align-self: flex-start; max-width: 84%; background: var(--card); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 8px 12px; }
.msg.own { align-self: flex-end; background: #d9f1ee; border-color: #bfe6e1; border-radius: 16px 16px 4px 16px; }
.msg-who { font-size: 12.5px; font-weight: 800; color: var(--teal-dark); margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-time { font-size: 11.5px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg .shot { display: block; width: 220px; max-width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; background: #e5e7e8; margin-bottom: 6px; }
.link { border: 0; background: none; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font-size: inherit; }
.composer { position: sticky; bottom: calc(60px + var(--safe-b)); display: flex; align-items: center; gap: 8px; background: var(--bg); padding: 8px 0 10px; margin-top: 4px; }
.composer input[type=text] { border-radius: 999px; padding-left: 16px; }
.composer .btn { min-height: var(--tap); border-radius: 999px; }
@media (min-width: 900px) { .composer { bottom: 0; } .msg { max-width: 62%; } }

/* forms */
.fld { padding: 12px 0; border-top: 1px solid var(--line); }
.fld:first-child, .fld-head + .fld { border-top: 0; }
.fld-head { margin: 14px 0 0; }
.fld-head:first-child { margin-top: 0; }
.fld-label { font-weight: 700; margin-bottom: 8px; }
.chip.yn { min-width: 76px; min-height: 44px; font-size: 15px; }
.chip.yn.on { background: var(--green); border-color: var(--green); }
.chip.yn.on.bad { background: var(--red); border-color: var(--red); }
.sig canvas { display: block; width: 100%; height: 150px; border: 1px dashed #9aa0a2; border-radius: 10px; background: #fff; touch-action: none; margin-bottom: 6px; }
.sig-view img { max-width: 280px; width: 100%; border: 1px solid var(--line); border-radius: 10px; display: block; }
.ph { position: relative; }
.ph button { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(31, 35, 36, .75); color: #fff; cursor: pointer; }
.fld-edit .task { min-height: 40px; }

/* files */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 2px 12px; font-size: 14.5px; }
.crumbs a { text-decoration: none; font-weight: 600; }
.ftag { flex: 0 0 auto; width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 11px; font-weight: 800; letter-spacing: .02em; background: #e9ebeb; color: #44494b; }
.ftag.k-folder { background: #fff0cf; color: #9a6400; font-size: 20px; }
.ftag.k-pdf { background: var(--red-bg); color: var(--red); }
.ftag.k-xls { background: var(--green-bg); color: var(--green); }
.ftag.k-doc { background: var(--blue-bg); color: var(--blue); }
.ftag.k-img { background: #ecebfa; color: #45409a; }
.item-title { overflow-wrap: anywhere; }
.sheet-head h2 { overflow-wrap: anywhere; }
.preview { display: block; width: 100%; max-height: 46vh; object-fit: contain; background: #e5e7e8; border-radius: 10px; margin-bottom: 10px; }
.preview.pdf { height: 46vh; border: 1px solid var(--line); }

.bar { height: 10px; border-radius: 99px; background: #e5e7e8; overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; background: var(--green); }
.bar i.over { background: var(--red); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: #e5e7e8; display: block; }
.task { display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 4px 0; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.task input { width: 24px; height: 24px; accent-color: var(--green); flex: 0 0 auto; }
.task.done span { text-decoration: line-through; color: var(--muted); }
.note { padding: 10px 0; border-top: 1px solid var(--line); }
.note:first-child { border-top: 0; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; font-size: 14.500px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* sheet / dialog */
.sheet-back { position: fixed; inset: 0; z-index: 30; background: rgba(10, 20, 32, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; padding: 12px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; font-size: 18px; }
.sheet-body { padding: 14px 16px calc(18px + var(--safe-b)); overflow-y: auto; }
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: 18px; } }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translate(-50%, 20px); z-index: 50; opacity: 0; pointer-events: none;
  background: var(--charcoal); color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600; max-width: 90vw; transition: all .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--red); }

/* login */
.login { min-height: 100vh; background: var(--charcoal); display: grid; place-items: center; padding: 20px; }
.login-box { background: var(--card); border-radius: 20px; padding: 22px; }
.login-box h1 { font-size: 24px; margin: 10px 0 2px; }
.login-inner { width: 100%; max-width: 400px; }
.login-inner .logo { margin: 0 auto 22px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
