:root {
  --bg: #f3efe6;
  --bg-card: #fffcf7;
  --ink: #1c241c;
  --muted: #5c6759;
  --line: #e0d8c8;
  --green: #1f4d3a;
  --green-2: #2d6a4f;
  --green-3: #95d5b2;
  --in: #1b7a4a;
  --out: #8a3b22;
  --out-bg: #8a3b22;
  --amber: #b45309;
  --amber-bg: #fde7c7;
  --danger: #9b1c1c;
  --shadow: 0 8px 24px rgba(28, 36, 28, 0.08);
  --radius: 16px;
  --tab-h: 68px;
  --feedback-dock-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background:
    radial-gradient(1200px 400px at 50% -120px, #dce8dc 0%, transparent 70%),
    var(--bg);
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--tab-h) + var(--feedback-dock-h) + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) 16px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--green);
  color: #f4f1ea;
  display: grid;
  place-items: center;
}

h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.demo-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  user-select: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
}

.demo-toggle input {
  accent-color: var(--green);
  width: 16px;
  height: 16px;
  margin: 0;
}

.pending-bar {
  margin: 0 16px 8px;
  background: var(--amber-bg);
  color: #7a3e04;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pending-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 0 rgba(180, 83, 9, 0.6);
  animation: pulse 1.6s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(180, 83, 9, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(180, 83, 9, 0); }
  100% { box-shadow: 0 0 0 0 rgba(180, 83, 9, 0); }
}

.main {
  flex: 1;
  padding: 8px 16px 24px;
}

.view h2 {
  margin: 4px 0 6px;
  font-size: 1.6rem;
  letter-spacing: -0.03em;
}

.lede {
  margin: 0 0 18px;
  color: var(--muted);
}

.punch-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  font-size: 0.92rem;
}

select {
  appearance: none;
  width: 100%;
  font: inherit;
  font-weight: 500;
  padding: 14px 40px 14px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-card)
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%235c6759' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='5 8 10 13 15 8'/></svg>")
    right 12px center no-repeat;
  color: var(--ink);
  min-height: 52px;
}

select:focus, button:focus-visible {
  outline: 3px solid #95d5b2;
  outline-offset: 1px;
}

.btn {
  width: 100%;
  border: 0;
  border-radius: 14px;
  min-height: 56px;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  margin-top: 6px;
}

.btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.btn-in { background: var(--in); }
.btn-out { background: var(--out-bg); }

.result {
  margin-top: 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.result strong { display: block; font-size: 1.05rem; margin-bottom: 4px; }
.result .meta { color: var(--muted); font-size: 0.92rem; }
.result .gps { margin-top: 8px; font-size: 0.85rem; color: var(--muted); }
.result.error {
  border-color: #f0c0c0;
  background: #fff5f5;
  color: var(--danger);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.week-list { display: flex; flex-direction: column; gap: 8px; }
.week-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
}
.week-row .title { font-weight: 700; }
.week-row .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.week-row .actions { flex-shrink: 0; }
.week-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}
.week-metrics strong { color: var(--ink); font-weight: 700; }


table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 10px 0; }

.badge {
  display: inline-block;
  background: var(--amber-bg);
  color: #7a3e04;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
}

.badge-ok {
  background: #e9f6ee;
  color: #1b7a4a;
}

.bars { display: flex; flex-direction: column; gap: 8px; margin: 0 0 12px; }
.bar-row { display: grid; grid-template-columns: 1fr 48px; gap: 8px; align-items: center; font-size: 0.8rem; }
.bar-track { height: 10px; background: #ece6d8; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--green-2); border-radius: 99px; }
.bar-label { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 3px; }

.footnote { color: var(--muted); font-size: 0.8rem; margin: 8px 0 4px; }
.dash-status { margin: -8px 0 14px; color: var(--muted); font-size: 0.9rem; }

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding: 6px 8px var(--safe-bottom);
  background: rgba(255, 252, 247, 0.96);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  backdrop-filter: blur(10px);
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  cursor: pointer;
}

.tab.is-active { color: var(--green); }
.tab svg { display: block; }

@media (min-width: 720px) {
  body { background: #e7e1d4; }
  .app {
    min-height: calc(100dvh - 32px);
    margin: 16px auto;
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
  }
  .tabbar {
    position: absolute;
    transform: none;
    left: 0;
    border-radius: 0 0 24px 24px;
  }
  .feedback-dock {
    position: absolute;
    transform: none;
    left: 0;
  }
}

input[type="text"],
input[type="password"],
input[type="datetime-local"],
textarea {
  width: 100%;
  font: inherit;
  font-weight: 500;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--ink);
  min-height: 48px;
}

textarea { min-height: 88px; resize: vertical; }

.btn-secondary {
  background: #fff;
  color: var(--green);
  border: 1px solid var(--green);
  margin-top: 10px;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  margin-top: 8px;
}

.btn-small {
  border: 1px solid var(--green);
  background: #fff;
  color: var(--green);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

.btn-tiny {
  border: 0;
  background: #efe8d8;
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 5px 10px;
  cursor: pointer;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

.chip.is-active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.card-head h3 { margin: 0; }

.alert-card {
  border-color: #f0c9a0;
  background: #fff8ee;
}

.alert-card h3 { color: #7a3e04; }

.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.plain-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.plain-list li:last-child { border-bottom: 0; }

.stack-list { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 6px; }

.stack-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
}

.stack-item .row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.stack-item .title { font-weight: 700; }
.stack-item .meta { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.stack-item .actions { display: flex; gap: 6px; flex-shrink: 0; }
.inactive-tag { color: var(--muted); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }

.form-error { color: var(--danger); font-size: 0.88rem; margin: 8px 0 0; }
.form-ok { color: var(--in); font-size: 0.88rem; margin: 8px 0 0; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 36, 28, 0.48);
  z-index: 80;
  display: grid;
  place-items: end center;
  padding: 16px 16px calc(16px + var(--safe-bottom));
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-card);
  border-radius: 20px;
  padding: 20px 18px 16px;
  box-shadow: var(--shadow);
  max-height: min(86dvh, 720px);
  overflow: auto;
}

.modal-card h2 { margin: 0 0 8px; font-size: 1.3rem; }
.modal-card p { color: var(--ink); }
.modal-card .lede { margin-bottom: 12px; }
.modal-card form { display: flex; flex-direction: column; gap: 12px; }
.modal-card .btn { margin-top: 4px; }

.pin-gate {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
}

@media (min-width: 720px) {
  .modal { place-items: center; }
}

.tabbar { grid-template-columns: repeat(4, 1fr); }

.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: start center;
  padding: calc(24px + var(--safe-top)) 16px 32px;
  background:
    radial-gradient(1200px 400px at 50% -120px, #dce8dc 0%, transparent 70%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px 18px 18px;
  box-shadow: var(--shadow);
}

.brand-lg { margin-bottom: 16px; }
.chips-auth { margin-bottom: 14px; }

.auth-intro { margin: 0 0 12px; color: var(--muted); font-size: 0.95rem; }
.account-cards { display: grid; gap: 10px; margin-bottom: 16px; }
.account-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  text-align: left;
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  min-height: 64px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.account-card strong { font-size: 1.05rem; color: var(--green); }
.account-card span { color: var(--muted); font-size: 0.9rem; }
.account-card.is-active {
  border-color: var(--green);
  background: #eef6f0;
  box-shadow: 0 0 0 3px rgba(31, 77, 58, 0.12);
}
.btn-text {
  display: block;
  width: 100%;
  margin: 8px 0 10px;
  padding: 10px 8px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--green);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}
.clock-as {
  margin: 0 0 14px;
  padding: 12px 14px;
  background: #eef6f0;
  border: 1px solid #cfe0d4;
  border-radius: 12px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--green);
}
.field-hint { display: block; margin-top: 6px; color: var(--muted); font-size: 0.85rem; font-weight: 400; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.lang-row { display: flex; gap: 8px; margin-top: 12px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.btn-row { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.btn-row .btn { margin-top: 0; }

#whoami { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.geofence-flag {
  margin-top: 8px;
  background: #fff8ee;
  border: 1px solid #f0c9a0;
  color: #7a3e04;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.88rem;
}

.print-only { display: none; }

@media print {
  body * { visibility: hidden !important; }
  #print-root, #print-root * { visibility: visible !important; }
  #print-root {
    display: block !important;
    position: absolute;
    left: 0; top: 0;
    width: 100%;
    padding: 16px;
    background: #fff;
    color: #000;
  }
  .tabbar, .topbar, .modal, .pending-bar, .feedback-dock { display: none !important; }
}

input[type="number"],
input[type="email"],
input[type="file"] {
  width: 100%;
  font: inherit;
  font-weight: 500;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--ink);
  min-height: 48px;
}

/* Extra contrast and target size for cheap Android phones */
.tab, .chip, .btn, .btn-small, .btn-tiny, select, .demo-toggle {
  min-height: 44px;
}
.chip, .btn-tiny, .btn-small, .demo-toggle { min-height: 44px; display: inline-flex; align-items: center; }
.tab { min-height: 52px; }

.clock-now {
  margin: 0 0 12px;
  padding: 10px 14px;
  background: #fff8ee;
  border: 1px solid #f0c9a0;
  border-radius: 12px;
  font-weight: 700;
  color: #7a3e04;
}
.segment-group { margin-bottom: 12px; }
.segment-group:last-child { margin-bottom: 0; }
.segment-group .group-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 6px;
}
.segment-item {
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
}
.segment-item .meta { color: var(--muted); }
.week-segments { margin-top: 8px; font-size: 0.85rem; color: var(--muted); }
.week-segments div { margin-top: 2px; }
#btn-switch { background: #2d6a4f; color: #fff; }

/* Beta mobile + feedback / recovery */
html, body {
  overflow-x: hidden;
  scroll-padding-bottom: 50vh;
}
.main {
  padding-bottom: calc(108px + var(--feedback-dock-h) + env(safe-area-inset-bottom, 0px));
}
input, select, textarea {
  font-size: 16px;
}
.btn-tiny, .btn-small, .chip, .account-card, .tab, .file-label {
  min-height: 44px;
  min-width: 44px;
}
.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}
.top-actions .btn-tiny {
  padding: 8px 10px;
}
.modal-card {
  max-height: min(90dvh, 720px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.recovery-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.25rem;
  letter-spacing: 0.06em;
  font-weight: 700;
  background: var(--paper, #f4efe3);
  border: 1px dashed var(--line, #d8d0c0);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  word-break: break-all;
}
.file-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
  font-weight: 600;
}
.file-label input[type="file"] {
  min-height: 44px;
}
#feedback-list .stack-item { margin-top: 8px; }
#pending-bar.is-auth { background: #7a3e04; color: #fff; }
.auth-screen { overflow-x: hidden; }
@media (max-width: 420px) {
  .topbar { align-items: flex-start; }
  .demo-toggle { font-size: 0.8rem; }
}

.draft-banner {
  background: #f6e4b5;
  color: #5c3b00;
  border: 1px solid #e0c37a;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 600;
  margin: 0 0 16px;
}
.legal-page { max-width: 40rem; margin: 0 auto; padding: 16px; }
.legal-card { background: var(--paper, #fffaf2); padding: 20px; border-radius: 12px; }
.legal-card h1 { margin: 0 0 12px; }
.legal-card h2 { margin: 20px 0 8px; font-size: 1.05rem; }
.legal-nav { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0; }
.legal-nav a { min-height: 44px; display: inline-flex; align-items: center; }

.feedback-dock {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  z-index: 6;
  padding: 6px 12px;
  background: rgba(255, 252, 247, 0.96);
  border-top: 1px solid var(--line);
  box-sizing: border-box;
}
.feedback-dock #btn-feedback {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--green);
  background: #fff;
  color: var(--green);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}
.score-row {
  border: 0;
  margin: 4px 0 8px;
  padding: 0;
  min-width: 0;
}
.score-row legend {
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0;
  margin-bottom: 4px;
}
.score-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.score-option {
  flex: 1 1 0;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-card);
  padding: 8px 6px;
  cursor: pointer;
}
.score-option:has(input:checked) {
  border-color: var(--green);
  background: #eef6f0;
  color: var(--green);
}
.score-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--green);
}
