/* 勤怠打刻 Web版 - 共通スタイル（WPF版のデザインを踏襲） */

:root {
  --bg: #f3f4f8;
  --surface: #ffffff;
  --text: #0f172a;
  --subtext: #64748b;
  --muted: #94a3b8;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --primary-gradient: linear-gradient(135deg, #6366f1, #4f46e5);
  --danger: #e11d48;
  --danger-soft: #ffe4e6;
  --success: #059669;
  --success-soft: #d1fae5;
  --warning: #d97706;
  --warning-soft: #fef3c7;

  --clock-in: linear-gradient(135deg, #34d399, #059669);
  --clock-out: linear-gradient(135deg, #fb7185, #e11d48);
  --break-start: linear-gradient(135deg, #fbbf24, #d97706);
  --break-end: linear-gradient(135deg, #38bdf8, #0284c7);

  --shadow: 0 4px 28px rgba(15, 23, 42, 0.07);
  --shadow-hover: 0 10px 36px rgba(15, 23, 42, 0.13);
  --shadow-color: 0 8px 28px rgba(15, 23, 42, 0.18);
  --font: "Segoe UI", "Yu Gothic UI", "Meiryo UI", "Hiragino Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

input { user-select: text; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { opacity: 0.45; cursor: default; }

.icon { width: 1em; height: 1em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

[hidden] { display: none !important; }

/* ---------- レイアウト ---------- */

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

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 24px 36px 0;
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.logo {
  width: 44px; height: 44px; border-radius: 14px; flex: none;
  display: grid; place-items: center;
  background: var(--primary-gradient); color: #fff; font-size: 22px;
}

.brand-title { font-size: 18px; font-weight: 600; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.clock { text-align: right; }
.clock-time { font-size: 34px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.clock-date { font-size: 13px; color: var(--subtext); }

main { flex: 1; min-height: 0; position: relative; padding: 20px 36px 24px; }

.view { position: absolute; inset: 20px 36px 24px; display: flex; flex-direction: column; animation: view-in 0.22s ease-out; }
.view.center { align-items: center; justify-content: center; text-align: center; overflow: auto; }

@keyframes view-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ---------- ボタン ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 56px; min-width: 140px; padding: 0 28px; border-radius: 14px;
  font-size: 18px; font-weight: 600;
  transition: transform 0.08s, filter 0.15s, box-shadow 0.15s;
}
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn-primary { background: var(--primary-gradient); color: #fff; box-shadow: var(--shadow-color); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger { background: var(--clock-out); color: #fff; box-shadow: var(--shadow-color); }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--surface); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #f8fafc; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 16px; border-radius: 22px;
  font-size: 15px; color: var(--subtext);
}
.btn-ghost:hover:not(:disabled) { background: rgba(0, 0, 0, 0.05); }
.btn-ghost.danger { color: var(--danger); font-weight: 600; }
.btn-ghost.danger:hover:not(:disabled) { background: rgba(225, 29, 72, 0.08); }

.btn-icon {
  width: 52px; height: 52px; border-radius: 26px; flex: none;
  display: grid; place-items: center; font-size: 20px;
  background: var(--surface); box-shadow: var(--shadow);
}
.btn-icon:active { transform: scale(0.94); }

/* ---------- ① スタッフ選択 ---------- */

.heading { padding: 0 10px 12px; }
.heading h1 { margin: 0; font-size: 34px; font-weight: 700; }
.heading p { margin: 4px 0 0; font-size: 17px; color: var(--subtext); }

.staff-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 0; }

.staff-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(188px, 1fr)); gap: 20px; padding: 10px;
}

.staff-card {
  position: relative; height: 212px; border-radius: 24px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  background: var(--surface); box-shadow: var(--shadow); padding: 16px 12px;
  border: 2px solid transparent;
  transition: transform 0.08s, box-shadow 0.15s;
}
.staff-card:hover { box-shadow: var(--shadow-hover); }
.staff-card:active { transform: scale(0.96); }
.staff-card.is-working { border-color: #a7f3d0; background: linear-gradient(180deg, #ffffff 60%, #f0fdf8); }
.staff-card.is-break { border-color: #fde68a; background: linear-gradient(180deg, #ffffff 60%, #fffbeb); }

.avatar {
  width: 84px; height: 84px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-size: 34px; font-weight: 600;
}
.staff-card .avatar { width: 80px; height: 80px; font-size: 32px; }

.staff-name {
  margin-top: 14px; max-width: 100%; font-size: 21px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* 状態表示（勤務中・休憩中のときだけ表示） */
.status {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
  height: 30px; padding: 0 12px; border-radius: 15px;
  font-size: 14px; font-weight: 700; white-space: nowrap;
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status .since { font-weight: 600; font-variant-numeric: tabular-nums; }
.status-working { color: #047857; background: var(--success-soft); }
.status-break { color: #b45309; background: var(--warning-soft); }
.status-working .dot { animation: pulse 2s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }

.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.empty-icon {
  width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-size: 36px;
}
.empty p { margin: 20px 0 0; font-size: 20px; line-height: 1.6; color: var(--subtext); white-space: pre-line; }

.bottombar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px;
}

.refresh { display: flex; align-items: center; gap: 14px; }

.btn-refresh {
  display: inline-flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 24px; border-radius: 26px;
  font-size: 17px; font-weight: 600; color: var(--primary);
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid #e0e7ff;
  transition: transform 0.08s, box-shadow 0.15s;
}
.btn-refresh:hover:not(:disabled) { box-shadow: var(--shadow-hover); }
.btn-refresh:active:not(:disabled) { transform: scale(0.96); }
.btn-refresh.loading .icon { animation: spin 0.9s linear infinite; }
.btn-refresh:disabled { opacity: 1; }

.updated-at { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- ② 打刻種別 ---------- */

.view-action { align-items: center; justify-content: center; overflow: auto; }
.view-action .back { position: absolute; left: 0; top: 0; }

.action-head { display: flex; flex-direction: column; align-items: center; }
.action-head .avatar { width: 96px; height: 96px; font-size: 40px; }
.action-name { margin-top: 16px; font-size: 38px; font-weight: 700; text-align: center; }
.action-current { margin-top: 10px; min-height: 30px; }
.action-hint { margin: 10px 0 20px; font-size: 17px; color: var(--subtext); }

.tiles { display: grid; grid-template-columns: repeat(2, 300px); gap: 20px; }

.tile {
  position: relative; height: 184px; border-radius: 28px; padding: 24px 28px;
  color: #fff; text-align: left; box-shadow: var(--shadow-color);
  display: flex; flex-direction: column; justify-content: space-between;
  transition: transform 0.08s, filter 0.15s;
}
.tile:hover { filter: brightness(1.06); }
.tile:active { transform: scale(0.96); }
.tile[data-action="CLOCK_IN"] { background: var(--clock-in); }
.tile[data-action="CLOCK_OUT"] { background: var(--clock-out); }
.tile[data-action="BREAK_START"] { background: var(--break-start); }
.tile[data-action="BREAK_END"] { background: var(--break-end); }
.tile-icon {
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.2); font-size: 26px;
}
.tile-label { font-size: 38px; font-weight: 700; line-height: 1.15; }
.tile-sub { font-size: 14px; opacity: 0.85; }

/* ---------- ③〜⑤ 送信中・完了・エラー ---------- */

.spinner {
  width: 64px; height: 64px; border-radius: 50%;
  border: 6px dashed var(--primary); animation: spin 1s linear infinite;
}
.processing-text { margin-top: 28px; font-size: 24px; font-weight: 600; }

.badge {
  width: 132px; height: 132px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-size: 60px; background: var(--clock-in);
  animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop { from { transform: scale(0.4); } to { transform: scale(1); } }
.success-name { margin-top: 28px; font-size: 26px; font-weight: 600; color: var(--subtext); }
.success-time { font-size: 96px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.success-label { font-size: 32px; font-weight: 700; }
.countdown { width: 220px; height: 6px; margin-top: 36px; border-radius: 3px; background: var(--border); overflow: hidden; }
.countdown div { height: 100%; background: var(--muted); transform-origin: left; animation: countdown 2s linear forwards; }
@keyframes countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.error-icon {
  width: 112px; height: 112px; border-radius: 50%; display: grid; place-items: center;
  background: var(--danger-soft); color: var(--danger); font-size: 48px;
}
.error-icon.warning { background: var(--warning-soft); color: var(--warning); }
.error-title { margin: 28px 0 0; font-size: 36px; font-weight: 700; }
.error-message { max-width: 760px; margin: 14px 0 0; font-size: 20px; line-height: 1.6; color: var(--subtext); white-space: pre-line; }
.button-row { display: flex; gap: 12px; justify-content: center; margin-top: 36px; }

/* ---------- カード・フォーム ---------- */

.card { background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 32px; }

.card-head { display: flex; align-items: center; gap: 14px; }
.card-head h2 { margin: 0; font-size: 21px; font-weight: 700; }
.card-icon {
  width: 44px; height: 44px; border-radius: 14px; flex: none; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-size: 20px;
}
.card-note { margin: 6px 0 12px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.pill { margin-left: auto; padding: 4px 12px; border-radius: 12px; font-size: 14px; font-weight: 600; color: var(--primary); background: var(--primary-soft); white-space: nowrap; }

.field-label { display: block; margin: 20px 0 8px; font-size: 14px; font-weight: 600; color: var(--subtext); }
.field-label .optional { font-weight: 400; color: var(--muted); }

.input {
  width: 100%; height: 56px; padding: 0 16px; border-radius: 14px;
  font: inherit; font-size: 20px; color: var(--text);
  background: #f8fafc; border: 1.5px solid var(--border); outline: none;
}
.input:focus { border-color: var(--primary); background: #fff; }

.message { margin-top: 14px; min-height: 22px; font-size: 14px; font-weight: 600; text-align: center; line-height: 1.5; }
.message.error { color: var(--danger); }
.message.info { color: var(--subtext); }

/* ---------- ⑥ 管理者PIN ---------- */

.pin-card { width: 400px; max-width: 100%; padding: 32px 36px; }
.pin-card.shake { animation: shake 0.4s; }
@keyframes shake {
  15% { transform: translateX(-14px); } 30% { transform: translateX(12px); } 45% { transform: translateX(-9px); }
  60% { transform: translateX(6px); } 75% { transform: translateX(-3px); }
}
.pin-card h2 { margin: 16px 0 0; font-size: 24px; }
.pin-card .sub { margin: 4px 0 0; font-size: 15px; color: var(--subtext); }
.pin-card .card-icon { width: 56px; height: 56px; border-radius: 18px; font-size: 24px; margin: 0 auto; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin-top: 22px; height: 16px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); }
.pin-dots span.filled { background: var(--primary); border-color: var(--primary); }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px 16px; justify-content: center; margin-top: 8px; }
.key {
  height: 76px; border-radius: 38px; font-size: 28px; font-weight: 600; background: #f1f5f9;
  display: grid; place-items: center; transition: transform 0.08s;
}
.key:active { transform: scale(0.94); }
.key.plain { background: transparent; font-size: 15px; }
.pin-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.pin-actions .btn { min-width: 0; padding: 0; }

/* ---------- ⑦ 管理画面 ---------- */

.view-admin { overflow-y: auto; }
.admin-head { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; }
.admin-head h1 { margin: 0; font-size: 28px; }
.admin-head p { margin: 0; font-size: 14px; color: var(--subtext); }

.admin-grid { display: grid; grid-template-columns: 5fr 6fr; gap: 24px; align-items: start; }
.admin-grid .wide { grid-column: 1 / -1; }

.list { margin: 0; padding: 0; list-style: none; }
.list li { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .avatar { width: 40px; height: 40px; font-size: 17px; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .meta { font-size: 12px; color: var(--muted); }
.list .empty-row { justify-content: center; color: var(--muted); font-size: 15px; padding: 20px 0; }
.staff-list { max-height: 360px; overflow-y: auto; padding-right: 8px; }
.tag { margin-left: 8px; padding: 2px 8px; border-radius: 8px; font-size: 12px; font-weight: 600; color: var(--success); background: var(--success-soft); vertical-align: middle; }
.device-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: #f1f5f9; color: var(--subtext); font-size: 20px; }

.admin-message {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 16px;
  padding: 10px 16px; border-radius: 12px; font-size: 15px; font-weight: 600;
  animation: view-in 0.2s ease-out;
}
.admin-message.ok { color: var(--success); background: var(--success-soft); }
.admin-message.error { color: var(--danger); background: var(--danger-soft); }

/* ---------- 確認ダイアログ・トースト ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px;
  background: rgba(15, 23, 42, 0.45); animation: fade 0.16s;
}
@keyframes fade { from { opacity: 0; } }
.dialog { width: 480px; max-width: 100%; padding: 36px; text-align: center; }
.dialog .error-icon { width: 64px; height: 64px; font-size: 28px; margin: 0 auto; }
.dialog h2 { margin: 20px 0 0; font-size: 22px; }
.dialog p { margin: 10px 0 0; font-size: 15px; line-height: 1.6; color: var(--subtext); white-space: pre-line; }
.dialog .button-row { display: grid; grid-template-columns: 1fr 1fr; margin-top: 28px; }
.dialog .btn { min-width: 0; }

.toast {
  position: fixed; left: 50%; bottom: 32px; z-index: 20; transform: translateX(-50%);
  padding: 12px 22px; border-radius: 22px; font-size: 15px; color: #fff;
  background: rgba(15, 23, 42, 0.9); pointer-events: none; opacity: 0; transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* ---------- ログイン画面 ---------- */

.login-page { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 440px; max-width: 100%; }
.login-card .logo { margin: 0 auto; width: 56px; height: 56px; border-radius: 18px; font-size: 28px; }
.login-card h1 { margin: 16px 0 0; font-size: 26px; text-align: center; }
.login-card .lead { margin: 6px 0 0; font-size: 14px; line-height: 1.6; color: var(--subtext); text-align: center; }
.login-card .btn { width: 100%; margin-top: 24px; }
.login-card .foot { margin: 16px 0 0; font-size: 12px; line-height: 1.6; color: var(--muted); text-align: center; }

/* ---------- 小さい画面 ---------- */

@media (max-width: 900px) {
  .topbar { padding: 16px 16px 0; }
  main { padding: 12px 16px 16px; }
  .view { inset: 12px 16px 16px; }
  .admin-grid { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 220px)); }
  .tile { height: 150px; padding: 18px 20px; }
  .tile-label { font-size: 30px; }
  .heading h1 { font-size: 28px; }
}

@media (max-height: 760px) {
  .action-head .avatar { width: 72px; height: 72px; font-size: 30px; }
  .action-name { font-size: 30px; margin-top: 10px; }
  .tile { height: 150px; }
}

/* ---------- 補助 ---------- */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon-lg { font-size: 24px; }
#addStaffBtn { width: 100%; margin-top: 20px; }
.center-note { text-align: center; margin-top: 12px; }
