:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --ink: #1c1f23;
  --muted: #646b73;
  --line: #dcd8d0;
  --head: #23272e;
  --accent: #e8a317;
  --accent-ink: #1c1f23;
  --ok: #2f7d4a;
  --warn: #b7791f;
  --bad: #b3261e;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px 16px; text-align: center; color: var(--muted); }

/* Top bar */
.top { position: sticky; top: 0; z-index: 5; background: var(--head); color: #fff; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { font-size: 12px; opacity: .75; font-weight: 400; display: block; }
.top button.icon { background: transparent; border: 0; color: #fff; padding: 8px; font-size: 20px; line-height: 1; }
.net { font-size: 12px; padding: 3px 9px; border-radius: 99px; background: #3a414b; white-space: nowrap; }
.net.on::before, .net.off::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.net.on::before { background: #5ad17f; }
.net.off::before { background: #f0a43a; }

main { padding: 14px 16px 120px; max-width: 640px; margin: 0 auto; }

/* Controls */
label.f { display: block; margin: 0 0 14px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
label.f > span em { font-style: normal; color: var(--bad); }
input, select, textarea { width: 100%; min-height: 48px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: var(--radius); background: #fff; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(232,163,23,.2); }
input.err, select.err { border-color: var(--bad); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 13px; color: var(--muted); margin: -8px 0 14px; }
.errmsg { color: var(--bad); font-size: 14px; margin: 0 0 12px; }

.btn { display: block; width: 100%; min-height: 52px; border: 0; border-radius: var(--radius); font-weight: 650; font-size: 16px; padding: 12px 16px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--head); color: #fff; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.btn.danger { background: var(--bad); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn + .btn { margin-top: 10px; }
.linkbtn { background: none; border: 0; color: var(--ink); text-decoration: underline; padding: 6px 0; font-size: 14px; }

/* Panels / sections */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.section-title { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 18px 0 8px; }
.kv { display: grid; grid-template-columns: 42% 1fr; gap: 6px 10px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; word-break: break-word; }

/* Day bar */
.daybar { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; margin-bottom: 12px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: #e9e5dd; }
.chip.warn { background: #fbecd0; color: #7a4d0b; }
.chip.bad { background: #f6d6d3; color: #7d1a14; }
.chip.ok { background: #d8eedf; color: #1d5532; }

.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.banner.closed { background: #23272e; color: #fff; }
.banner.warn { background: #fbecd0; color: #5e3c09; }
.banner.bad { background: #f6d6d3; color: #6b1711; }

/* Challan cards */
.list { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-align: left; width: 100%; cursor: pointer; }
.card.synced { border-left-color: var(--ok); }
.card.pending { border-left-color: var(--accent); }
.card.error { border-left-color: var(--bad); }
.card .l1 { display: flex; justify-content: space-between; gap: 8px; font-weight: 650; }
.card .l2 { font-size: 14px; color: var(--muted); margin-top: 3px; }
.card .tag { font-size: 12px; font-weight: 600; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; border: 1.5px dashed var(--line); border-radius: var(--radius); }

/* Bottom action bar */
.actions { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(244,242,238,.96); border-top: 1px solid var(--line); padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px); display: grid; grid-template-columns: 1fr 1fr; gap: 10px; z-index: 5; }
.actions.one { grid-template-columns: 1fr; }
.actions .btn + .btn { margin-top: 0; }
.actions-inner { max-width: 640px; margin: 0 auto; width: 100%; }

/* Signature */
.sigwrap { border: 1.5px dashed #b9b3a8; border-radius: var(--radius); background: #fff; position: relative; touch-action: none; }
.sigwrap canvas { display: block; width: 100%; height: 170px; touch-action: none; }
.sigwrap .ph { position: absolute; inset: 0; display: grid; place-items: center; color: #b9b3a8; pointer-events: none; font-size: 15px; }
.sigtools { display: flex; justify-content: space-between; align-items: center; margin: 6px 0 14px; font-size: 13px; color: var(--muted); }
.sigimg { width: 100%; max-height: 170px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }

.calc { background: #f0ede6; border-radius: var(--radius); padding: 10px 12px; margin: -4px 0 14px; font-size: 15px; }
.calc b { font-size: 17px; }
.gps { font-size: 13px; color: var(--muted); margin-bottom: 14px; }

/* Activation */
.brand { text-align: center; padding: 34px 0 18px; }
.brand img { width: 72px; height: 72px; border-radius: 16px; }
.brand h2 { margin: 12px 0 4px; font-size: 22px; }
.brand p { margin: 0; color: var(--muted); font-size: 14px; }
.pin { letter-spacing: .5em; font-size: 22px; text-align: center; font-variant-numeric: tabular-nums; }

/* Modal + toast */
.modal-back { position: fixed; inset: 0; background: rgba(20,22,26,.55); z-index: 20; display: grid; align-items: end; }
.modal { background: var(--bg); border-radius: 16px 16px 0 0; padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px); max-width: 640px; width: 100%; margin: 0 auto; }
.modal h3 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 16px; color: #3b4148; }
.toast { position: fixed; left: 16px; right: 16px; top: calc(env(safe-area-inset-top) + 64px); max-width: 520px; margin: 0 auto; background: var(--head); color: #fff; padding: 12px 14px; border-radius: var(--radius); z-index: 30; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.25); pointer-events: none; }
.toast.bad { background: var(--bad); }

.menu { position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 54px); background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.18); min-width: 220px; z-index: 10; overflow: hidden; }
.menu .who { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.menu button { display: block; width: 100%; text-align: left; padding: 13px 14px; border: 0; background: #fff; font-size: 15px; }
.menu button + button { border-top: 1px solid #eee; }
.ver { font-size: 12px; color: var(--muted); padding: 8px 14px; border-top: 1px solid var(--line); }

/* Full day / Half day tick options */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; border-radius: var(--radius); }
.seg.err { outline: 2px solid var(--bad); outline-offset: 3px; }
.seg .opt { position: relative; display: block; }
.seg .opt input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg .opt span { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px; border: 1.5px solid var(--line); border-radius: var(--radius); background: #fff; font-weight: 650; font-size: 17px; }
.seg .opt span::before { content: ""; width: 20px; height: 20px; border-radius: 5px; border: 2px solid #b9b3a8; background: #fff; flex: none; }
.seg .opt input:checked + span { border-color: var(--accent); background: #fdf4e1; box-shadow: 0 0 0 3px rgba(232,163,23,.2); }
.seg .opt input:checked + span::before { border-color: var(--accent); background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 10.5l3.2 3.2L15 7' fill='none' stroke='%231c1f23' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/16px no-repeat; }
.seg .opt input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Start of day: machine type cards */
.types { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 18px; }
.typecard { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px 10px 14px; background: #fff; border: 1.5px solid var(--line); border-radius: 14px; cursor: pointer; color: var(--ink); }
.typecard svg { width: 64px; height: 42px; color: #4a515a; }
.typecard b { font-size: 17px; }
.typecard small { color: var(--muted); font-size: 13px; }
.typecard.on { border-color: var(--accent); background: #fdf4e1; box-shadow: 0 0 0 3px rgba(232,163,23,.25); }
.typecard.on svg { color: var(--ink); }

/* Entry: common details summary */
.common { display: flex; gap: 10px; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px; }
.common dl { flex: 1; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 14px; }
.common dt { color: var(--muted); }
.common dd { margin: 0; font-weight: 600; }
.common small { font-weight: 400; color: var(--muted); }
.daylink { display: flex; justify-content: space-between; gap: 8px; width: 100%; background: #e9e5dd; border: 0; border-radius: var(--radius); padding: 12px 14px; font-size: 14px; color: var(--ink); cursor: pointer; text-align: left; }
.daylink span:last-child { font-weight: 650; white-space: nowrap; }

/* Entry: vehicle dropdown */
.vhead { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 8px; }
.vcount { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: #d8eedf; color: #1d5532; }
.vselect { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 52px; padding: 10px 14px; background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius); font-size: 16px; font-weight: 650; color: var(--muted); cursor: pointer; text-align: left; margin-bottom: 8px; }
.vselect.chosen { color: var(--ink); border-color: var(--accent); }
.vselect.done { background: #e6f4ea; border-color: #9fd0ae; }
.vselect.err { border-color: var(--bad); }
.vselect small, .vopt small { font-weight: 400; color: var(--muted); }
.vselect .caret { color: var(--muted); font-size: 14px; }
.sheet { max-height: 82vh; display: flex; flex-direction: column; }
.sheet h3 { display: flex; justify-content: space-between; align-items: baseline; }
.sheet h3 small { font-size: 13px; font-weight: 600; color: #1d5532; }
.vlist { overflow-y: auto; margin: 4px 0 12px; display: flex; flex-direction: column; gap: 6px; }
.vgroup { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 8px 2px 2px; }
.vopt { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 50px; padding: 10px 14px; background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius); font-size: 16px; font-weight: 650; color: var(--ink); text-align: left; cursor: pointer; }
.vopt.done { background: #e6f4ea; border-color: #b9dcc4; }
.vopt .mark { font-size: 13px; font-weight: 700; color: var(--ok); white-space: nowrap; }
.vopt.on { box-shadow: 0 0 0 3px rgba(232,163,23,.35); border-color: var(--accent); }

/* Top bar refresh + footer */
#syncBtn { font-size: 22px; }
#syncBtn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ver-foot { text-align: center; font-size: 12px; color: var(--muted); margin: 18px 0 0; }

/* Page 1 calendar */
.flabel { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.flabel em { font-style: normal; color: var(--bad); }
.cal { background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius); padding: 8px 10px 10px; }
.calhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.calhead .icon { background: none; border: 0; font-size: 26px; line-height: 1; padding: 4px 12px; color: var(--ink); cursor: pointer; }
.calhead .icon:disabled { opacity: .25; cursor: default; }
.calgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.calgrid .wd { font-size: 11px; font-weight: 700; color: var(--muted); padding: 2px 0; }
.cd { height: 38px; border: 1.5px solid transparent; border-radius: 9px; background: #f4f2ee; font-size: 15px; font-weight: 600; color: var(--ink); display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.cd.future { background: transparent; color: #c9c4ba; cursor: default; font-weight: 400; }
.cd.closed { background: #cfe9d7; color: #154a29; }
.cd.open { background: #fbd9a8; color: #6b3d00; }
.cd.today { border-color: #8a8f96; }
.cd.sel { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink) inset; }
.calfoot { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.dot.closed { background: #8fcea3; } .dot.open { background: #f5b562; }
.calsel { font-size: 13px; margin-top: 6px; padding-top: 6px; border-top: 1px solid #eee; }

/* 10-day log */
.loglist { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.logrow { display: grid; grid-template-columns: 92px 84px 1fr; gap: 8px; align-items: center; padding: 12px 12px; border-top: 1px solid #eee; font-size: 14px; }
.logrow:first-child { border-top: 0; }
.logrow .ld { font-weight: 650; }
.logrow .ld small, .logrow .lt small { font-weight: 400; color: var(--muted); }
.logrow .lt { font-weight: 600; }
.logrow.total { background: #f4f2ee; }
.lst { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; text-align: center; }
.lst.closed { background: #cfe9d7; color: #154a29; }
.lst.open { background: #fbd9a8; color: #6b3d00; }
.lst.none { color: #b9b3a8; }
.top .icon svg { display: block; }

/* Collapsible date bar */
.datebar { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 50px; padding: 8px 14px; background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius); font-size: 16px; font-weight: 650; color: var(--ink); cursor: pointer; text-align: left; }
.datebar #dateBarText { flex: 1; }
.datebar .caret { color: var(--muted); font-size: 14px; transition: transform .15s; }
.datebar.open { border-color: var(--accent); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.datebar.open .caret { transform: rotate(180deg); }
.datebar + .cal { border-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; border-color: var(--accent); }
.monthnav { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 6px; margin-bottom: 10px; }
