/* ===== Variables ===== */
:root {
  --line: #06C755;
  --line-dark: #04a847;
  --bg: #F7F8FA;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --warn: #f59e0b;
  --danger: #ef4444;
  --ok: #16a34a;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.06);
  --r: 12px;
  --appbar-h: 52px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  /* iOS の自動ズーム抑止のため touch-action 制限 */
  touch-action: pan-x pan-y;
}
body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
/* iOS は input の font-size が 16px 未満だと自動ズームが入る */
input, textarea, select, button { font-size: 16px; font-family: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }

#app {
  max-width: 480px; margin: 0 auto; min-height: 100vh;
  background: var(--bg); position: relative;
}

/* ===== App Bar ===== */
.appbar {
  position: sticky; top: 0; z-index: 50; height: var(--appbar-h);
  background: var(--line); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.appbar h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: .02em; }

main { padding: 16px 14px 28px; }

.view { display: none; }
.view.active { display: block; }

/* ===== Centered（ローディング・エラー画面共通） ===== */
.centered {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: calc(100vh - var(--appbar-h) - 48px);
  padding: 24px; text-align: center; gap: 14px;
}
.centered h2 { margin: 0; font-size: 18px; }
.centered .big-icon { font-size: 64px; line-height: 1; }
.centered .muted { color: var(--muted); font-size: 14px; line-height: 1.7; margin: 0; }
.centered .hint {
  background: #FEF3C7; color: #92400e; padding: 10px 14px; border-radius: 8px;
  font-size: 13px; max-width: 320px;
}

/* ===== Spinner ===== */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border); border-top-color: var(--line);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 24px; padding: 12px 22px; font-weight: 600;
  min-height: 48px; font-size: 15px;
}
.btn.primary { background: var(--line); color: #fff; }
.btn.primary:active { background: var(--line-dark); }
.btn.primary:disabled { background: #cbd5e1; color: #fff; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; border-radius: 12px; }
.btn.small { min-height: 40px; padding: 8px 16px; font-size: 14px; }

/* ===== Help details ===== */
.help-details {
  background: #fff; border-radius: 10px; padding: 12px 14px;
  max-width: 360px; width: 100%; text-align: left;
  box-shadow: var(--shadow); font-size: 13px;
}
.help-details summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.help-details .help-body { margin-top: 10px; color: var(--text); }
.help-details ol { padding-left: 20px; margin: 4px 0 12px; }
.help-details li { margin-bottom: 4px; }

/* ===== Employee Select（名前選択画面） ===== */
.employee-select-list {
  display: flex; flex-direction: column; gap: 12px;
  width: 100%; max-width: 320px; margin-top: 8px;
}
.employee-select-btn {
  background: #fff; border: 2px solid var(--border); border-radius: 14px;
  padding: 20px; font-size: 20px; font-weight: 700; color: var(--text);
  min-height: 64px; transition: transform 0.1s ease;
}
.employee-select-btn:active {
  background: var(--line); color: #fff; border-color: var(--line);
  transform: scale(0.98);
}
.employee-select-btn:disabled { opacity: 0.5; }

/* ===== Punch Screen ===== */
.punch-header {
  background: #fff; border-radius: var(--r); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.punch-header .greeting { font-size: 14px; }
.punch-header .greeting #employeeName { font-weight: 700; }
.state-badge {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 12px;
  background: #F3F4F6; color: var(--muted);
}
.state-badge.in { background: #DCFCE7; color: #166534; }
.state-badge.out { background: #FEE2E2; color: #991b1b; }

.location-card {
  background: #fff; border-radius: var(--r); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 12px;
}
.location-card.matched-office { border-left: 4px solid var(--line); }
.location-card.matched-field { border-left: 4px solid var(--accent); }
.location-card.unmatched { border-left: 4px solid var(--warn); }
.location-card.loading { opacity: 0.6; }
.location-icon { font-size: 24px; }
.location-body { flex: 1; }
.location-name { font-weight: 700; font-size: 15px; }
.location-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.today-logs {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px;
}
.today-log {
  background: #fff; border-radius: 8px; padding: 8px 12px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; border: 1px solid var(--border);
}
.today-log .badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 700;
}
.today-log .badge.IN { background: #DCFCE7; color: #166534; }
.today-log .badge.OUT { background: #FEE2E2; color: #991b1b; }
.today-log .time { font-weight: 700; }
.today-log .loc { color: var(--muted); font-size: 12px; margin-left: auto; }

.punch-area { margin: 18px 0; }
.punch-btn {
  width: 100%; min-height: 200px;
  border: 0; border-radius: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
  font-size: 36px; font-weight: 800; letter-spacing: 0.2em;
  color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.punch-btn:active:not(:disabled) {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.punch-btn:disabled { background: #cbd5e1; cursor: not-allowed; box-shadow: none; }
.punch-btn.punch-in { background: linear-gradient(135deg, #06C755, #04a847); }
.punch-btn.punch-out { background: linear-gradient(135deg, #ef4444, #dc2626); }
.punch-btn .punch-label { line-height: 1; }
.punch-btn .punch-sub {
  font-size: 13px; font-weight: 500; letter-spacing: 0; opacity: 0.9;
}

.footer-actions {
  display: flex; justify-content: center; gap: 8px; margin-top: 10px; flex-wrap: wrap;
}
.footer-actions .btn { text-decoration: none; }
.footer-actions a[hidden] { display: none; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: rgba(31, 35, 40, 0.92); color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
  z-index: 100; max-width: 90%;
}
.toast[hidden] { display: none; }

/* ===== Flash（打刻成功時の緑エフェクト） ===== */
.flash {
  position: fixed; inset: 0;
  background: rgba(6, 199, 85, 0.4);
  z-index: 99;
  pointer-events: none;
  animation: flashFade 0.6s ease-out;
}
.flash[hidden] { display: none; }
@keyframes flashFade {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-bg {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
}
.modal-body {
  position: relative; background: #fff; border-radius: 16px;
  padding: 20px; max-width: 360px; width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.modal-body h3 { margin: 0 0 8px; font-size: 16px; }
.modal-body .small { font-size: 12px; }
.modal-body input[type="text"] {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; margin: 12px 0;
}
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
}
.modal-actions .btn { min-height: 40px; padding: 8px 16px; font-size: 14px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ===== Rotate Warning ===== */
.rotate-warning { display: none; }
@media (orientation: landscape) and (max-height: 600px) {
  body > #app { display: none; }
  .rotate-warning {
    display: flex; position: fixed; inset: 0;
    background: var(--line); color: #fff;
    align-items: center; justify-content: center;
    z-index: 999; padding: 24px;
  }
  .rw-inner { text-align: center; }
  .rw-icon { font-size: 64px; }
  .rw-inner h2 { margin: 16px 0 8px; font-size: 18px; }
  .rw-inner p { margin: 0; opacity: 0.9; font-size: 14px; }
}
