/* Cow Dogging — mobile-first, outdoor-readable, light + dark */
:root {
  --bg: #f3f4f6; --surface: #ffffff; --surface2: #f8fafc; --border: #e2e8f0;
  --text: #0f172a; --muted: #64748b;
  --brand: #1e293b; --accent: #f59e0b; --primary: #2563eb; --primary-ink: #fff;
  --go: #16a34a; --stop: #dc2626; --warn: #d97706; --ok-bg: #dcfce7; --ok-fg: #166534;
  --bad-bg: #fee2e2; --bad-fg: #991b1b; --warn-bg: #fef3c7; --warn-fg: #92400e; --chip: #eef2f7;
  --radius: 14px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  --tabbar-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111a2e; --surface2: #0f172a; --border: #22304a;
    --text: #e5e9f0; --muted: #94a3b8; --brand: #0b1120; --primary: #3b82f6;
    --ok-bg: #0f2e1d; --ok-fg: #86efac; --bad-bg: #3a1010; --bad-fg: #fca5a5; --warn-bg: #3a2a08; --warn-fg: #fcd34d; --chip: #1b2741;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
}
body.no-scroll { overflow: hidden; }
a { color: var(--primary); }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; } h4 { font-size: .95rem; margin-top: 1.25rem; }
p { margin: .4rem 0 .8rem; }
code { background: var(--chip); padding: 1px 5px; border-radius: 5px; }
.small { font-size: .85rem; } .muted { color: var(--muted); } .center { text-align: center; }
.ic { flex: none; vertical-align: middle; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; } .row.gap, .gap { gap: .6rem; } .row.end { justify-content: flex-end; } .wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: .85rem; }
.nowrap { white-space: nowrap; }
.pad { padding: 0 1rem .75rem; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--brand); color: #fff; padding: calc(env(safe-area-inset-top, 0px) + .7rem) 1rem .7rem;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; letter-spacing: .01em; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand .ic { color: var(--accent); }
.who { opacity: .85; text-align: right; }
.who .badge { background: rgba(255,255,255,.15); color: #fff; }
main { max-width: 640px; margin: 0 auto; padding: 1rem; }
main.wide { max-width: 1200px; }
main:focus { outline: none; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border); height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.tabbar a.on { color: var(--primary); }
@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 88px; }
  .tabbar { top: 0; right: auto; width: 88px; height: 100vh; flex-direction: column; justify-content: flex-start; padding-top: 72px; border-top: 0; border-right: 1px solid var(--border); }
  .tabbar a { flex: 0 0 76px; }
  .topbar { margin-left: -88px; padding-left: calc(88px + 1rem); z-index: 40; }
}

.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.25rem; margin-bottom: calc(-1 * (var(--tabbar-h) + var(--safe-b))); }
.center-pad { display: flex; justify-content: center; padding: 3rem 0; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.narrow { width: 100%; max-width: 400px; }
.card.flush { padding: 0; overflow: hidden; }
.card.hl { border-color: var(--accent); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .85rem 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h3 { margin: 0; }
details.card > summary { list-style: none; cursor: pointer; }
details.card > summary::-webkit-details-marker { display: none; }
details.card:not([open]) > summary { border-bottom: 0; }

.auth { text-align: center; }
.auth form { text-align: left; }
.auth-brand { margin-bottom: 1rem; }
.auth-brand .logo { width: 56px; height: 56px; margin: 0 auto .5rem; border-radius: 16px; display: grid; place-items: center; background: var(--brand); color: var(--accent); }
.auth-brand h1 { font-size: 1.5rem; margin: 0; }

/* ---------- forms ---------- */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
.lbl { display: block; margin-bottom: .35rem; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: .65rem .75rem; width: 100%; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--primary); flex: none; margin: 2px 0 0; }
input[type=range] { padding: 0; min-height: 32px; accent-color: var(--primary); background: none; border: 0; }
select.lg { font-weight: 600; }
label.check { flex-direction: row; align-items: flex-start; gap: .6rem; color: var(--text); font-weight: 500; }
.req { color: var(--stop); font-weight: 500; font-size: .75rem; }
textarea { resize: vertical; }
.note-wrap summary { cursor: pointer; color: var(--muted); font-size: .9rem; margin-top: .75rem; }
details.card.note-wrap summary { margin: 0; }
.note-wrap textarea { margin-top: .5rem; }
.help summary { cursor: pointer; font-size: .85rem; color: var(--primary); margin-top: .5rem; }
.help p { font-size: .85rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; font: inherit; font-weight: 600;
  min-height: 44px; padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .06s, filter .15s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:hover:not(:disabled) { filter: brightness(.97); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.go { background: var(--go); color: #fff; border-color: transparent; }
.btn.stop { background: var(--stop); color: #fff; border-color: transparent; }
.btn.warn { background: var(--warn); color: #fff; border-color: transparent; }
.btn.danger { background: var(--stop); color: #fff; border-color: transparent; }
.btn.danger.ghost { background: transparent; color: var(--stop); border-color: currentColor; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: .6rem; }
.btn.lg { min-height: 52px; font-size: 1.05rem; }
.btn.xl { min-height: 72px; font-size: 1.25rem; border-radius: 16px; width: 100%; }
.btn.sm { min-height: 36px; padding: .35rem .75rem; font-size: .88rem; }
.btn.busy { position: relative; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.icon-btn.disabled { opacity: .35; pointer-events: none; }
.link { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: .25rem; align-self: center; }
.seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; margin-bottom: 1rem; }
.seg button { flex: 1; border: 0; background: none; font: inherit; font-weight: 600; padding: .55rem; border-radius: 8px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- clock screen ---------- */
.status-card { border-radius: 20px; padding: 1.25rem; margin-bottom: 1rem; color: #fff; background: #475569; box-shadow: var(--shadow); }
.status-card.on { background: linear-gradient(135deg, #15803d, #16a34a); }
.status-card.break { background: linear-gradient(135deg, #b45309, #d97706); }
.status-line { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.15rem; }
.status-card .dot { width: 12px; height: 12px; border-radius: 50%; background: rgba(255,255,255,.55); }
.status-card.on .dot { background: #fff; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.7); } 70% { box-shadow: 0 0 0 10px rgba(255,255,255,0); } 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); } }
.timer { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin: .25rem 0 0; }
.status-sub { opacity: .92; margin-top: .25rem; }
.loc-card { padding: .85rem 1rem; }
.loc { display: flex; gap: .7rem; align-items: flex-start; }
.loc .ic { margin-top: 2px; }
.loc.ok .ic { color: var(--go); } .loc.bad .ic { color: var(--stop); }
.loc.bad b { color: var(--stop); }
.actions { display: grid; gap: .75rem; margin-bottom: 1rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1rem; }
.stats.three { grid-template-columns: 1fr 1fr 1fr; }
.stats > div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; display: flex; flex-direction: column; }
.stats b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.ot { color: var(--warn); }
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; align-items: center; gap: .6rem; padding: .55rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.plist li:first-child { border-top: 0; }
.plist .t { font-weight: 700; font-variant-numeric: tabular-nums; margin-right: auto; }
.k { font-weight: 600; font-size: .9rem; }
.k-in { color: var(--go); } .k-out { color: var(--stop); } .k-break_start, .k-break_end { color: var(--warn); }

.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; text-align: center; }
.day-head { display: flex; justify-content: space-between; margin-bottom: .25rem; }
.shift { display: flex; justify-content: space-between; gap: 1rem; padding: .6rem 0; border-top: 1px solid var(--border); }
.shift .hrs { font-weight: 700; font-variant-numeric: tabular-nums; }
.flags { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .3rem; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 3px; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.pill { display: inline-block; font-size: .75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.pill.on { background: var(--ok-bg); color: var(--ok-fg); } .pill.break { background: var(--warn-bg); color: var(--warn-fg); }
.dotflag { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; }
.dotflag.bad { background: var(--stop); } .dotflag.warn { background: var(--warn); }

/* ---------- admin ---------- */
.subnav { display: flex; gap: .35rem; overflow-x: auto; margin: -.25rem -1rem 1rem; padding: .25rem 1rem; scrollbar-width: none; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .85rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .9rem; background: var(--surface); border: 1px solid var(--border); white-space: nowrap; }
.subnav a.on { background: var(--brand); color: #fff; border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .subnav a.on { background: var(--primary); border-color: var(--primary); } }
.banner { display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; border-radius: 12px; margin-bottom: 1rem; background: #dbeafe; color: #1e40af; text-decoration: none; font-weight: 600; }
.banner.warn { background: var(--warn-bg); color: var(--warn-fg); }
.banner.bad { background: var(--bad-bg); color: var(--bad-fg); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media (max-width: 640px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; display: flex; flex-direction: column; text-decoration: none; color: var(--text); }
.kpi b { font-size: 1.8rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: .85rem; }
.kpi.on b { color: var(--go); } .kpi.break b { color: var(--warn); } .kpi.bad b { color: var(--stop); }
.grid2 { display: grid; gap: 1rem; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; align-items: start; } }
.crew, .list { list-style: none; margin: 0; padding: 0; }
.crew li, .list li { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-top: 1px solid var(--border); }
.crew li:first-child, .list li:first-child { border-top: 0; }
.list li.clickable, tr.clickable { cursor: pointer; }
.list li.clickable:hover, tr.clickable:hover { background: var(--surface2); }
.crew .right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 700; font-size: .85rem; background: var(--chip); color: var(--muted); }
.avatar.on { background: var(--go); color: #fff; } .avatar.break { background: var(--warn); color: #fff; }
.map { height: 360px; background: var(--surface2); }
.small-map { height: 220px; border-radius: 10px; margin: .5rem 0; overflow: hidden; }
#jMap { height: 300px; border-radius: 10px; overflow: hidden; }
.map-fallback { padding: 1rem; }
.pin { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font: 700 10px/1 sans-serif; color: #fff; background: #475569; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.pin.on, .pin.inside { background: var(--go); } .pin.break { background: var(--warn); } .pin.outside { background: var(--stop); } .pin.job { background: var(--primary); }
.toolbar { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar h2 { margin: 0; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { padding: .45rem .8rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: .88rem; font-weight: 600; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.range { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.range input { width: auto; min-height: 38px; padding: .35rem .5rem; }
.filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; align-items: flex-end; }
.filters label { flex: 1 1 140px; }
.filters label.check { flex: 0 0 auto; align-items: center; min-height: 44px; }
.filters input, .filters select { min-height: 38px; padding: .4rem .55rem; }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { padding: .6rem .75rem; text-align: left; border-top: 1px solid var(--border); vertical-align: middle; }
.tbl th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface2); border-top: 0; white-space: nowrap; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tfoot td { font-weight: 700; background: var(--surface2); }
.tbl tr.dim td { color: var(--muted); }
.tbl tr.open td { background: var(--surface2); }
.tbl tr.voided td { opacity: .55; text-decoration: line-through; }
.tbl tr.voided td .badge { text-decoration: none; }
.tbl tr.detail > td { background: var(--surface2); padding: .5rem .75rem 1rem; }
.tbl.inner { font-size: .85rem; background: var(--surface); border-radius: 10px; overflow: hidden; }
.punch-meta { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .35rem; }
.audit { padding-left: 1.1rem; margin: 0; }
.audit li { margin-bottom: .6rem; color: var(--text); }
.diff { color: var(--muted); }

/* ---------- modal / toast / spinner ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 100; background: rgba(15,23,42,.55); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding-bottom: var(--safe-b); animation: up .18s ease-out; }
.modal.wide { max-width: 760px; }
@media (min-width: 640px) { .modal-wrap { align-items: center; padding: 1rem; } .modal { border-radius: 18px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1rem .5rem; background: var(--surface); }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-body { padding: .5rem 1rem 1.25rem; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); transform: translate(-50%, 20px); z-index: 200;
  background: #0f172a; color: #fff; padding: .8rem 1.1rem; border-radius: 12px; max-width: min(92vw, 520px); font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.3); opacity: 0; pointer-events: none; transition: all .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: #166534; } .toast.error { background: #b91c1c; } .toast.warn { background: #b45309; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- print (timesheets) ---------- */
@media print {
  body { background: #fff; padding: 0; color: #000; }
  .topbar, .tabbar, .subnav, .toolbar, .card-head .row, .banner, #toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; }
  .tbl tr.detail[hidden] { display: none; }
}
