:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Noto Sans JP", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ---- 画面切替（① 合言葉 → ② 自分を選ぶ → ③ 本体） ---- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(120deg, #1e3a8a, #2563eb);
}
.hidden { display: none !important; }
.login-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-icon { font-size: 44px; }
.login-card h1 { margin: 8px 0 4px; font-size: 20px; }
.login-card p { margin: 0 0 18px; font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  margin-bottom: 12px;
}
.login-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  font-size: 13px;
  padding: 8px 10px;
  margin-bottom: 12px;
}
.login-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
  text-align: left;
}
.login-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.login-fields select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  background: #fff;
  cursor: pointer;
}
.identity-actions { display: flex; gap: 8px; }
.identity-actions .primary-btn { flex: 1; }

/* ---- トップバー ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 24px;
  background: linear-gradient(120deg, #1e3a8a, #2563eb);
  color: #fff;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 32px; }
.topbar h1 { margin: 0; font-size: 20px; }
.subtitle { margin: 0; font-size: 13px; opacity: 0.85; }
.account { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.current-user { display: flex; flex-direction: column; gap: 2px; margin-right: 4px; }
.current-user-label { font-size: 11px; opacity: 0.8; }
.current-user-value { display: flex; align-items: center; gap: 6px; }
.current-user-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.6);
}
.current-user-name { font-weight: 700; font-size: 15px; }
.logout-btn {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}
.logout-btn:hover { background: rgba(255, 255, 255, 0.28); }

/* ---- レイアウト ---- */
main {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
}
@media (max-width: 860px) {
  main { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.panel h2 { margin: 0 0 12px; font-size: 17px; }
.side { display: flex; flex-direction: column; gap: 20px; }

/* ---- カレンダー ---- */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.calendar-header h2 { margin: 0; font-size: 18px; }
.nav-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 20px;
  cursor: pointer;
  color: var(--accent);
}
.nav-btn:hover { background: #f1f5f9; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; }
.legend-members { color: var(--muted); font-size: 12px; }

.weekday-row, .calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.weekday {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 4px 0;
}
.weekday.sun { color: #dc2626; }
.weekday.sat { color: #2563eb; }

.calendar-grid { margin-top: 4px; }
.day {
  min-height: 78px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.day.empty { background: transparent; border: none; }
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.day-num { font-size: 12px; color: var(--muted); }
.day.today .day-num { color: var(--accent); font-weight: 700; }
.day-num.sun { color: #dc2626; }
.day-num.sat { color: #2563eb; }

.res-bar {
  font-size: 11px;
  color: #fff;
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- フォーム ---- */
#reservation-form { display: flex; flex-direction: column; gap: 12px; }
#reservation-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
#reservation-form input {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
}
.form-actions { display: flex; gap: 8px; }
.primary-btn {
  flex: 1;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:hover { background: #1d4ed8; }
.primary-btn:disabled { opacity: 0.6; cursor: default; }
.secondary-btn {
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.secondary-btn:hover { background: #f1f5f9; }

.form-message {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
}
.form-message.warn { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.form-message.error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.form-message.success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.form-message .confirm-actions { margin-top: 8px; display: flex; gap: 8px; }
.form-message button {
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.btn-confirm { background: #d97706; color: #fff; }
.btn-cancel { background: #e5e7eb; color: #374151; }

/* ---- 予約一覧 ---- */
.reservation-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.reservation-list:empty::after {
  content: "予約はまだありません";
  color: var(--muted);
  font-size: 14px;
}
.res-item {
  border: 1px solid var(--border);
  border-left-width: 5px;
  border-radius: 8px;
  padding: 10px 12px;
  position: relative;
}
.res-item.editing { box-shadow: 0 0 0 2px var(--accent); }
.res-item .res-house { font-weight: 700; font-size: 14px; }
.res-house-tag {
  font-weight: 600;
  font-size: 11px;
  color: var(--muted);
  background: #f1f5f9;
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 4px;
}
.res-item .res-dates { font-size: 13px; color: var(--text); }
.res-item .res-meta { font-size: 12px; color: var(--muted); }
.res-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
}
.edit-btn, .cancel-btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
}
.edit-btn { color: var(--accent); }
.edit-btn:hover { background: #eff6ff; }
.cancel-btn { color: #dc2626; }
.cancel-btn:hover { background: #fef2f2; }
