:root {
  --blue: #2f6fed;
  --blue-dark: #2457c5;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #eef1f6;
  --card: #ffffff;
  --green: #15803d;
  --red: #b91c1c;
  --amber: #92400e;
  --amber-bg: #fffbeb;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body { min-height: 100vh; }

.hidden { display: none !important; }

.view {
  max-width: 680px;
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 14px calc(28px + var(--safe-bottom));
}

h1, h2, p { margin: 0; }
h1 { font-size: 22px; letter-spacing: .5px; }
h2 { font-size: 16px; margin-bottom: 10px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.foot-gap { margin-top: 12px; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 26px 4px 20px;
}
.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--blue);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(47, 111, 237, .28);
}
.brand p { color: var(--muted); font-size: 13px; margin-top: 2px; }

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 4px 18px rgba(17, 24, 39, .05);
}

.login-card { margin-top: 0; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 13px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: #fff;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, .12);
}
textarea { min-height: 96px; resize: vertical; }

.inline-input { display: flex; gap: 8px; }
.inline-input input { flex: 1; min-width: 0; }

.hint {
  min-height: 20px;
  font-size: 13px;
  color: var(--muted);
  white-space: pre-line;
  margin: 2px 0 12px;
}
.hint.error { color: var(--red); }
.hint.ok { color: var(--green); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 11px 16px;
  cursor: pointer;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:active { background: var(--blue-dark); }
.btn.ghost { background: #f8fafc; }
.btn.full { width: 100%; }
.btn.big { height: 56px; font-size: 19px; border-radius: 13px; }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 9px; }
.btn.tiny { padding: 4px 9px; font-size: 12px; border-radius: 8px; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }

.footnote {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.65;
  margin: 14px 4px 0;
}

.banner {
  border-radius: 11px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
  line-height: 1.5;
}
.banner.danger { background: #fef2f2; color: var(--red); border: 1px solid #fecaca; }
.banner.info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  margin: calc(-18px - var(--safe-top)) -14px 12px;
  background: rgba(238, 241, 246, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(229, 231, 235, .8);
}
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

.status-card { padding-bottom: 14px; }
.status-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.clock-now {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  background: #ecfdf5;
  color: var(--green);
  white-space: nowrap;
}
.pill.gray { background: #f3f4f6; color: var(--muted); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.red { background: #fef2f2; color: var(--red); }

.punch-card .punch-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.punch-card h2 { margin-bottom: 0; }
.punch-card #punchHint { margin: 6px 0 12px; }
.punch-sub { text-align: center; margin-top: 10px; }

.gate { border: 1px solid #fde68a; background: var(--amber-bg); }
.gate h2 { color: var(--amber); }
.gate p { margin-bottom: 12px; }

.list-item {
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.list-item:first-child { border-top: 0; padding-top: 2px; }
.list-item .row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.list-item .tag { font-size: 12px; color: var(--muted); }
.list-item .msg { font-size: 13px; color: var(--muted); margin-top: 3px; white-space: pre-line; }
.list-item .ops { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }
.empty { color: var(--muted); font-size: 13px; padding: 4px 0; }

.rules { font-size: 13px; color: #374151; }
.rules p { margin: 0 0 6px; }
.rules .rule-line { display: flex; gap: 8px; }
.rules .rule-key { color: var(--muted); min-width: 74px; }

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}
.actions .btn { width: 100%; padding: 12px 8px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(17, 24, 39, .42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-sheet {
  width: 100%;
  max-width: 680px;
  max-height: 88vh;
  background: #fff;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  animation: sheet-in .18s ease-out;
}
@keyframes sheet-in { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 14px;
}
.modal-body p { margin: 0 0 10px; }
.modal-body .doc { white-space: pre-line; font-size: 13px; line-height: 1.7; color: #374151; }
.modal-foot {
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
}
.modal-foot .btn { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(88vw, 520px);
  background: rgba(17, 24, 39, .92);
  color: #fff;
  border-radius: 11px;
  padding: 10px 15px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  white-space: pre-line;
}

@media (min-width: 720px) {
  .modal { align-items: center; padding: 20px; }
  .modal-sheet { border-radius: 18px; max-height: 82vh; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e5e7eb;
    --muted: #9ca3af;
    --line: #374151;
    --bg: #0f172a;
    --card: #1e293b;
    --amber-bg: #332a12;
  }
  body { background: var(--bg); }
  input, textarea, select { background: #0f172a; color: var(--ink); }
  .topbar { background: rgba(15, 23, 42, .92); border-bottom-color: #1f2937; }
  .btn.ghost { background: #0f172a; color: var(--ink); }
  .list-item { border-top-color: #334155; }
  .modal-sheet { background: #1e293b; }
  .rules { color: #cbd5e1; }
  .banner.info { background: #172554; border-color: #1e40af; color: #bfdbfe; }
}
