:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f172a;
  --accent: #2563eb;
  --ok: #059669;
  --warn: #b45309;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: .2px; }
.logo { font-size: 20px; }

main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px); }

/* ---------- cards & fields ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 14px; font-size: 18px; }

.field { display: block; margin-bottom: 16px; }
.field:last-of-type { margin-bottom: 8px; }
.label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.label em { font-style: normal; text-transform: none; font-weight: 400; letter-spacing: 0; }

.control {
  width: 100%;
  padding: 13px 12px;
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  appearance: none;
}
select.control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2364748b'%3E%3Cpath d='M5.5 7.5 10 12l4.5-4.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 20px;
  padding-right: 36px;
}
.control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
textarea.control { resize: vertical; }

/* ---------- buttons ---------- */
.primary-btn {
  width: 100%;
  min-height: 52px;
  border: 0; border-radius: 12px;
  background: var(--accent); color: #fff;
  font-size: 17px; font-weight: 600; font-family: inherit;
  cursor: pointer;
}
.primary-btn:disabled { opacity: .55; cursor: default; }
.primary-btn.leave { background: var(--warn); }

.ghost-btn {
  border: 1px solid rgba(255,255,255,.35);
  background: transparent; color: inherit;
  padding: 8px 12px; border-radius: 999px;
  font-size: 14px; font-family: inherit; cursor: pointer;
}
.ghost-btn.small { border-color: var(--line); color: var(--accent); padding: 7px 12px; white-space: nowrap; }

.link-btn {
  border: 0; background: none; padding: 4px 0;
  color: var(--accent); font-size: 14px; font-family: inherit; cursor: pointer;
}

/* ---------- status banner ---------- */
.status {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 14px 16px; margin-bottom: 14px;
  border-radius: var(--radius);
  background: #ecfdf5; color: #065f46;
  box-shadow: var(--shadow);
  font-size: 15px;
}
.status.idle { background: #eff6ff; color: #1e3a8a; }
.status strong { display: block; }

/* ---------- location ---------- */
.loc-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px; border: 1px dashed var(--line); border-radius: 10px;
  font-size: 14px; color: var(--muted);
}
.loc-box.ok { border-style: solid; border-color: #a7f3d0; background: #f0fdf4; color: #065f46; }
.loc-box.err { border-color: #fecaca; background: #fef2f2; color: var(--danger); }

/* ---------- uploads ---------- */
.upload-row { display: flex; gap: 10px; }
.upload-btn {
  flex: 1; text-align: center;
  padding: 14px 10px; border-radius: 10px;
  background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe;
  font-size: 15px; font-weight: 500; cursor: pointer;
}
.upload-btn.secondary { background: #f8fafc; color: var(--muted); border-color: var(--line); }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 10px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #e2e8f0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px; border: 0; border-radius: 50%;
  background: rgba(15,23,42,.7); color: #fff; font-size: 15px; line-height: 1; cursor: pointer;
}

/* ---------- history ---------- */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.filters .field { margin-bottom: 0; }
.filters .link-btn { grid-column: 1 / -1; justify-self: start; }

.history { display: grid; gap: 12px; }
.entry { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.entry-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.entry-head .name { font-weight: 600; }
.pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: #dcfce7; color: #166534; white-space: nowrap; }
.pill.open { background: #fef3c7; color: #92400e; }

.leg { padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.leg-title { font-weight: 600; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.leg a { color: var(--accent); }
.leg .note { color: var(--muted); font-style: italic; margin-top: 4px; }
.leg-thumbs { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.leg-thumbs img { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; cursor: pointer; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------- misc ---------- */
.error { color: var(--danger); font-size: 14px; margin: 0 0 10px; }
.hidden { display: none !important; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: 999px;
  font-size: 15px; box-shadow: var(--shadow); z-index: 50;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.err { background: var(--danger); }

.lightbox {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15,23,42,.92);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

@media (min-width: 560px) {
  .filters { grid-template-columns: 1fr 1fr auto; }
}

.loc-box code { background: rgba(15,23,42,.06); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.loc-box { line-height: 1.45; }
.ghost-btn.small:disabled { opacity: .5; }

/* ---------- PIN gate ---------- */
.pin-gate {
  position: fixed; inset: 0; z-index: 70;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.pin-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  width: 100%; max-width: 360px;
  text-align: center;
}
.pin-card h2 { margin: 0 0 6px; font-size: 20px; }
.pin-card p { margin: 0 0 18px; color: var(--muted); font-size: 15px; }
.pin-input {
  text-align: center;
  font-size: 28px !important;
  letter-spacing: .4em;
  padding: 14px 12px;
  margin-bottom: 14px;
}

/* ---------- shift type selector ---------- */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span {
  display: block; text-align: center;
  padding: 14px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: #f8fafc;
  font-size: 15px; font-weight: 500; color: var(--muted);
  cursor: pointer;
}
.seg-opt input:checked + span {
  background: #eff6ff; border-color: var(--accent); color: #1d4ed8;
  box-shadow: 0 0 0 1px var(--accent) inset;
}

/* ---------- start time confirmation ---------- */
.time-confirm {
  background: #f0fdf4; border: 1px solid #a7f3d0; color: #065f46;
  border-radius: 10px; padding: 12px 14px; margin-bottom: 16px;
  font-size: 15px;
}
.time-confirm strong { display: block; font-size: 17px; margin-top: 2px; }

/* ---------- two-column numeric rows ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two-col .label { margin-bottom: 6px; }
@media (max-width: 400px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- report figures in history ---------- */
.figures {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px; margin-top: 8px;
}
.figure {
  background: #f8fafc; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px;
}
.figure dt { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0; }
.figure dd { margin: 2px 0 0; font-size: 15px; font-weight: 600; }

.shift-tag { font-size: 13px; }

/* ---------- history summary ---------- */
.summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
  background: var(--brand); color: #fff;
  border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow);
}
.summary-cell dt {
  margin: 0; font-size: 11px; letter-spacing: .05em;
  text-transform: uppercase; opacity: .7;
}
.summary-cell dd { margin: 3px 0 0; font-size: 18px; font-weight: 600; }

.breakdown {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px 14px;
}
.breakdown > div {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 9px 0; font-size: 15px;
  border-bottom: 1px solid var(--line);
}
.breakdown > div:last-child { border-bottom: 0; }
.breakdown strong { font-variant-numeric: tabular-nums; }

.status.blocked { background: #fef2f2; color: #991b1b; }
