/* Touch Med — employee app. Mobile-first, RTL. */

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

/**
 * `hidden` gets its display:none from the UA stylesheet, which any class
 * selector outranks — .btn { display: flex } silently un-hides every hidden
 * button. This puts the attribute back in charge.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px; /* anything smaller makes iOS zoom on focus */
  -webkit-font-smoothing: antialiased;
}

.app { min-height: 100dvh; display: flex; flex-direction: column; }

.boot { flex: 1; display: grid; place-items: center; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- screens -- */

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
}
.screen--center { justify-content: center; align-items: center; text-align: center; gap: 0.25rem; }
.screen--app { padding: 0; gap: 0; }

.logo { width: 96px; height: 96px; border-radius: 22px; margin-bottom: 1rem; }
.logo--sm { width: 64px; height: 64px; border-radius: 16px; }

h1 { font-size: 1.3rem; margin: 0 0 0.35rem; font-weight: 700; }
.muted { color: var(--ink-muted); }
.small { font-size: 0.8rem; }
.hint { margin-top: 1.5rem; font-size: 0.8rem; color: var(--ink-muted); }

/* --------------------------------------------------------------- forms -- */

.form { width: 100%; margin-top: 1.5rem; display: flex; flex-direction: column; gap: 0.85rem; }

.field { display: flex; flex-direction: column; gap: 0.4rem; text-align: start; }
.field > span { font-size: 0.85rem; font-weight: 600; color: var(--ink-muted); }
.field input {
  font: inherit;
  font-family: var(--font-num);
  padding: 0.85rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--brand); }
.input--code { text-align: center; letter-spacing: 0.5em; font-size: 1.5rem; font-weight: 700; }

/* -------------------------------------------------------------- buttons -- */

.btn {
  font: inherit; font-weight: 600;
  padding: 0.95rem 1.25rem;
  border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 52px; /* comfortable thumb target */
  transition: opacity 0.15s, transform 0.06s;
}
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: 0.55; pointer-events: none; }

.btn--primary { background: var(--brand); color: #fff; }
.btn--ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.btn--link { background: none; color: var(--ink-muted); font-weight: 400; min-height: 40px; padding: 0.4rem; }

.btn--punch { font-size: 1.05rem; min-height: 64px; border-radius: var(--radius); }
.btn--in { background: var(--brand); color: #fff; }
.btn--out { background: #b45309; color: #fff; }

.btn .spin {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 40%); border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

.iconbtn {
  background: none; border: none; font-size: 1.25rem; color: var(--ink-muted);
  width: 2.25rem; height: 2.25rem; border-radius: 50%; cursor: pointer;
}

/* -------------------------------------------------------------- notices -- */

.error, .ok {
  margin: 0.75rem 0 0; padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm); font-size: 0.875rem; line-height: 1.6;
}
.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .error { background: #2a1315; color: #fca5a5; border-color: #4c1d1d; }
  :root:not([data-theme="light"]) .ok { background: #0f2318; color: #86efac; border-color: #14532d; }
}

/* -------------------------------------------------------------- consent -- */

.consent { display: flex; flex-direction: column; gap: 0.9rem; }
.consent h1 { margin-bottom: 0; }
.consent p { margin: 0; line-height: 1.8; font-size: 0.925rem; }
.list { margin: 0; padding-inline-start: 1.1rem; display: flex; flex-direction: column; gap: 0.6rem; line-height: 1.7; font-size: 0.9rem; }
.note {
  background: var(--brand-light); border-radius: var(--radius-sm);
  padding: 0.9rem 1rem; font-size: 0.875rem; line-height: 1.7;
}
.note ul { margin: 0.5rem 0 0; padding-inline-start: 1.1rem; display: flex; flex-direction: column; gap: 0.35rem; }

/* --------------------------------------------------------------- topbar -- */

.topbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: max(0.85rem, env(safe-area-inset-top)) 1rem 0.85rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar__logo { width: 36px; height: 36px; border-radius: 10px; }
.topbar__who { flex: 1; display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.topbar__who b { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------ statecard -- */

.statecard {
  margin: 1rem; padding: 1.5rem 1rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); text-align: center;
}
.statecard--in { background: var(--brand); border-color: var(--brand); color: #fff; }
.statecard--in .muted { color: rgb(255 255 255 / 75%); }
.statecard__label { font-size: 0.85rem; font-weight: 600; opacity: 0.85; }
.statecard__clock {
  font-family: var(--font-num); font-size: 2.75rem; font-weight: 700;
  line-height: 1.15; margin: 0.3rem 0; font-variant-numeric: tabular-nums;
}
.statecard__sub { font-size: 0.85rem; }

/* ------------------------------------------------------------------ geo -- */

.geo { margin: 0 1rem; }
.geo__row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; }
.geo__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-muted); flex: none; }
.geo__dot--ok { background: #16a34a; }
.geo__dot--warn { background: #d97706; }
.geo__dot--bad { background: #dc2626; }
.map {
  height: 160px; margin-top: 0.75rem;
  border-radius: var(--radius-sm); border: 1px solid var(--line); overflow: hidden;
}

/* -------------------------------------------------------------- actions -- */

.actions { margin: 1.25rem 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.done { text-align: center; padding: 1rem; color: #16a34a; font-weight: 600; }

.tabs {
  margin-top: auto; display: flex;
  border-top: 1px solid var(--line); background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
  position: sticky; bottom: 0;
}
.tab {
  flex: 1; padding: 0.9rem; background: none; border: none;
  font: inherit; font-size: 0.875rem; color: var(--ink-muted); cursor: pointer;
}
.tab--active { color: var(--brand); font-weight: 700; }

/* -------------------------------------------------------------- history -- */

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; padding: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.8rem 0.5rem; text-align: center; }
.stat b { display: block; font-size: 1.35rem; font-family: var(--font-num); }
.stat span { font-size: 0.72rem; color: var(--ink-muted); }

.days { padding: 0 1rem 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.day {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 0.8rem 0.9rem;
  display: flex; align-items: center; gap: 0.75rem;
}
.day__date { font-family: var(--font-num); font-weight: 700; font-size: 0.9rem; min-width: 3.5rem; }
.day__times { flex: 1; font-size: 0.8rem; color: var(--ink-muted); font-family: var(--font-num); }
.badge { font-size: 0.72rem; padding: 0.2rem 0.5rem; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.badge--ok { background: #dcfce7; color: #166534; }
.badge--late { background: #fef3c7; color: #92400e; }
.badge--out { background: #fee2e2; color: #991b1b; }
.badge--open { background: var(--brand-light); color: var(--brand); }
.empty { text-align: center; color: var(--ink-muted); padding: 2.5rem 1rem; font-size: 0.9rem; }

/* --------------------------------------------------------------- camera -- */

.camera {
  position: fixed; inset: 0; z-index: 50;
  background: #000; color: #fff;
  display: flex; flex-direction: column;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  gap: 0.75rem;
}
.camera__head { display: flex; align-items: center; justify-content: space-between; }
.camera__head .iconbtn { color: #fff; }
.camera__video {
  flex: 1; width: 100%; object-fit: cover; border-radius: var(--radius);
  background: #111; transform: scaleX(-1); /* mirror, so it reads like a mirror */
  min-height: 0;
}
.camera__hint { color: rgb(255 255 255 / 70%); text-align: center; font-size: 0.85rem; margin: 0; }
.btn--shutter { background: #fff; color: #000; }

/* -------------------------------------------------------------- install -- */

[data-install-android], [data-install-ios] { width: 100%; margin-top: 1.5rem; }
[data-install-android-manual] { width: 100%; }
[data-install-android] .btn { width: 100%; }
[data-action="install-skip"] { width: 100%; margin-top: 0.5rem; }

.steps {
  margin: 0; padding: 0; list-style: none; counter-reset: step;
  text-align: start; display: flex; flex-direction: column; gap: 0.85rem;
}
.steps li { position: relative; padding-inline-start: 2.25rem; font-size: 0.95rem; line-height: 1.5; }
.steps li::before {
  content: counter(step); counter-increment: step;
  position: absolute; inset-inline-start: 0; top: 0.1rem;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--surface); border: 1.5px solid var(--line);
  font-family: var(--font-num); font-weight: 700; font-size: 0.85rem;
  display: grid; place-items: center;
}

/* ---------------------------------------------------------- permissions -- */

.permwrap { padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.permform { margin-top: 0; }
.field select,
.field textarea {
  font: inherit;
  font-family: var(--font);
  padding: 0.85rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  outline: none;
  resize: vertical;
}
.field select:focus, .field textarea:focus { border-color: var(--brand); }
/* Safari renders date inputs right-aligned in RTL and clips the picker. */
.field input[type="datetime-local"] { direction: ltr; text-align: start; }

.perm {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 0.85rem 0.95rem;
  display: flex; flex-direction: column; gap: 0.35rem;
}
.perm__head { display: flex; align-items: center; gap: 0.5rem; }
.perm__type { font-weight: 700; font-size: 0.925rem; flex: 1; }
.perm__when { font-size: 0.8rem; color: var(--ink-muted); font-family: var(--font-num); }
.perm__reason { font-size: 0.85rem; color: var(--ink-muted); line-height: 1.6; }
.perm__note {
  font-size: 0.8rem; padding: 0.5rem 0.7rem; border-radius: 8px;
  background: var(--brand-light); color: var(--ink); line-height: 1.6;
}
.badge--pending { background: #fef3c7; color: #92400e; }
.badge--approved { background: #dcfce7; color: #166534; }
.badge--rejected { background: #fee2e2; color: #991b1b; }
.perm__cancel {
  align-self: flex-start; background: none; border: none; padding: 0;
  color: #b91c1c; font: inherit; font-size: 0.8rem; cursor: pointer; text-decoration: underline;
}

.reportlink {
  margin: 0 1rem 0.5rem; text-decoration: none; font-size: 0.9rem; min-height: 46px;
}
