* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  width: 380px;
  height: 520px;
  background-color: #f4f6f8;
  color: #333;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.header {
  background-color: #4f46e5;
  color: white;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.logo-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: bold;
  font-size: 16px;
}

.logo-img {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.user-status {
  font-size: 12px;
  opacity: 0.9;
  background: rgba(255,255,255,0.2);
  padding: 2px 8px;
  border-radius: 12px;
}

.hidden {
  display: none !important;
}

/* Auth Card */
.auth-card {
  margin: 32px 16px;
  padding: 24px 20px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}

.auth-card h2 {
  font-size: 18px;
  color: #1f2937;
}

.subtitle {
  font-size: 13px;
  color: #6b7280;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background-color: white;
  color: #374151;
  border: 1px solid #d1d5db;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: background-color 0.2s;
  margin-top: 8px;
}

.btn-google:hover {
  background-color: #f9fafb;
}

.google-icon {
  width: 18px;
  height: 18px;
}

.tab-link-container {
  margin-top: 8px;
  text-align: center;
}

.tab-link {
  font-size: 12px;
  color: #4f46e5;
  text-decoration: none;
}

.tab-link:hover {
  text-decoration: underline;
}

.error-msg {
  color: #ef4444;
  font-size: 12px;
  text-align: left;
}

/* Tab Navigation */
.tabs-bar {
  display: flex;
  background: white;
  border-bottom: 1px solid #e5e7eb;
}

.tab-btn {
  flex: 1;
  padding: 10px 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-btn.active {
  color: #4f46e5;
  border-bottom-color: #4f46e5;
}

/* Settings View */
.settings-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #f9fafb;
}

.settings-group {
  background: white;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-group-title {
  font-size: 13px;
  font-weight: bold;
  color: #374151;
  border-bottom: 1px solid #f3f4f6;
  padding-bottom: 6px;
}

.settings-avatar-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 0;
}

.avatar-preview-container {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  overflow: hidden;
  background: #e0e7ff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 2px solid #c7d2fe;
}

.avatar-img-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-placeholder {
  font-size: 24px;
  color: #4f46e5;
  user-select: none;
}

.avatar-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-label {
  font-size: 11px;
  color: #6b7280;
  font-weight: 500;
}

.settings-value {
  font-size: 13px;
  color: #1f2937;
  word-break: break-all;
}

/* Notification Settings & Switches */
.notif-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.notif-toggle-row.master-toggle {
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
  margin-bottom: 6px;
  font-weight: 600;
}

.notif-toggle-label {
  font-size: 12px;
  color: #374151;
}

.master-toggle .notif-toggle-label {
  font-size: 13px;
  color: #111827;
}

.notif-section-label {
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 2px;
}

.notif-sub-settings {
  display: flex;
  flex-direction: column;
  transition: opacity 0.2s ease;
}

.notif-sub-settings.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* Switch Toggle Component */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: .3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
}

input:checked + .slider {
  background-color: #4f46e5;
}

input:focus + .slider {
  box-shadow: 0 0 1px #4f46e5;
}

input:checked + .slider:before {
  transform: translateX(16px);
}

.slider.round {
  border-radius: 20px;
}

.slider.round:before {
  border-radius: 50%;
}

/* Friend Requests */
.requests-section {
  background: #fdf2f8;
  border-bottom: 1px solid #fbcfe8;
  padding: 8px 12px;
}

.requests-title {
  font-size: 11px;
  font-weight: bold;
  color: #be185d;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.request-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  border: 1px solid #fce7f3;
}

.request-info {
  display: flex;
  flex-direction: column;
}

.request-name {
  font-size: 13px;
  font-weight: 600;
  color: #1f2937;
}

.request-username {
  font-size: 11px;
  color: #6b7280;
}

.request-actions {
  display: flex;
  gap: 6px;
}

.btn-accept {
  background-color: #10b981;
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
}

.btn-reject {
  background-color: #f3f4f6;
  color: #6b7280;
  border: 1px solid #d1d5db;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}

.btn-delete-friend {
  background: none;
  border: 1px solid #fecaca;
  color: #ef4444;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  margin-left: 8px;
  transition: all 0.15s;
}

.btn-delete-friend:hover {
  background-color: #fee2e2;
}




.list-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: white;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  transition: background-color 0.15s;
}

.list-item:hover {
  background-color: #f3f4f6;
}

.list-item-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e0e7ff;
  color: #4f46e5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 16px;
  margin-right: 12px;
  flex-shrink: 0;
  overflow: hidden;
}

.list-item-avatar img,
.sender-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.list-item-avatar.keep {
  background: #fef3c7;
  color: #d97706;
}

.list-item-avatar.group {
  background: #dcfce7;
  color: #16a34a;
}

.list-item-info {
  flex: 1;
  min-width: 0;
}

.list-item-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.list-item-title {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-decoration: none;
  text-overflow: ellipsis;
}

.list-item-time {
  font-size: 11px;
  color: #9ca3af;
  margin-left: 8px;
  flex-shrink: 0;
}

.list-item-desc {
  font-size: 12px;
  color: #6b7280;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-item-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  margin-left: 10px;
  flex-shrink: 0;
}

.list-item-time {
  font-size: 11px;
  color: #9ca3af;
  white-space: nowrap;
}

.unread-count-badge {
  background-color: #dbeafe;
  color: #2563eb;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #3b82f6;
  opacity: 0.85;
  margin-left: 6px;
  flex-shrink: 0;
}

/* Main Section */
.main-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.channel-bar {
  background: white;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e5e7eb;
}

.channel-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.btn-back {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  color: #4b5563;
}

.btn-back:hover {
  background-color: #f3f4f6;
}

.channel-name {
  font-weight: bold;
  font-size: 14px;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-sm {
  background: none;
  border: 1px solid #d1d5db;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  color: #6b7280;
}

/* Chat Message Search Bar */
.chat-search-bar {
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  padding: 8px 12px;
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-search-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 4px 10px;
}

.chat-search-input-wrapper .search-icon {
  font-size: 13px;
  color: #9ca3af;
}

.chat-search-input-wrapper input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 13px;
  color: #1f2937;
  background: transparent;
}

.chat-search-results {
  max-height: 220px;
  overflow-y: auto;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
}

.search-result-item {
  padding: 8px 12px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background-color 0.15s ease;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background-color: #f3f4f6;
}

.search-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}

.search-result-sender {
  font-weight: 600;
  color: #4b5563;
}

.search-result-time {
  color: #9ca3af;
}

.search-result-snippet {
  font-size: 12px;
  color: #1f2937;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-match {
  background-color: #fef08a;
  font-weight: 600;
  color: #854d0e;
  border-radius: 2px;
  padding: 0 2px;
}

.search-empty-msg {
  padding: 12px;
  text-align: center;
  font-size: 12px;
  color: #9ca3af;
}

/* メッセージのハイライト点滅アニメーション */
@keyframes highlightFlash {
  0% { transform: scale(1); filter: brightness(1); }
  30% { transform: scale(1.04); filter: brightness(1.2); box-shadow: 0 0 10px rgba(79, 70, 229, 0.5); }
  60% { transform: scale(1); filter: brightness(1.1); box-shadow: 0 0 6px rgba(79, 70, 229, 0.3); }
  100% { transform: scale(1); filter: brightness(1); box-shadow: none; }
}

.highlight-msg {
  animation: highlightFlash 1.4s ease;
}

.messages-container {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 80%;
}

.message-group.my-group {
  align-self: flex-end;
  align-items: flex-end;
}

.message-group.other-group {
  align-self: flex-start;
  align-items: flex-start;
}

.sender-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  padding-left: 2px;
}

.sender-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e0e7ff;
  color: #4f46e5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.sender-name-text {
  font-size: 11px;
  font-weight: 600;
  color: #4b5563;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  width: fit-content;
  position: relative;
}

.msg-delete-btn {
  background: none;
  border: none;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.15s ease;
  user-select: none;
  border-radius: 4px;
}

.message-row:hover .msg-delete-btn {
  opacity: 0.6;
}

.msg-delete-btn:hover {
  opacity: 1 !important;
  transform: scale(1.15);
  background: rgba(0, 0, 0, 0.05);
}

.message-group.my-group .message-row {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.message-group.other-group .message-row {
  flex-direction: row;
  align-self: flex-start;
}

.msg-meta {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  font-size: 10px;
  line-height: 1.2;
  color: #9ca3af;
  flex-shrink: 0;
  user-select: none;
}

.message-group.my-group .msg-meta {
  align-items: flex-end;
  text-align: right;
}

.message-group.other-group .msg-meta {
  align-items: flex-start;
  text-align: left;
}

.msg-read-status {
  color: #4f46e5;
  font-weight: 600;
  font-size: 10px;
  cursor: default;
}

.msg-read-status.clickable {
  cursor: pointer;
  text-decoration: underline;
}

.msg-time-text {
  color: #9ca3af;
  font-size: 10px;
}

.message-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  position: relative;
  word-break: break-word;
  width: fit-content;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-bubble.my-msg {
  background-color: #4f46e5;
  color: white;
  border-bottom-right-radius: 2px;
}

.message-bubble.other-msg {
  background-color: white;
  color: #1f2937;
  border-bottom-left-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}



.password-card {
  background-color: #312e81;
  color: white;
  padding: 10px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.password-header {
  font-size: 11px;
  font-weight: bold;
  opacity: 0.9;
}

.password-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: monospace;
  font-size: 14px;
  font-weight: bold;
}

.copy-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
}

.media-preview {
  max-width: 100%;
  max-height: 180px;
  border-radius: 8px;
  margin-top: 4px;
}

.msg-time {
  font-size: 10px;
  opacity: 0.7;
  text-align: right;
  margin-top: 4px;
}

/* Input Bar */
.input-bar {
  background: white;
  border-top: 1px solid #e5e7eb;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.file-upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #6b7280;
  background: none;
  transition: all 0.2s;
  flex-shrink: 0;
  margin-bottom: 1px;
}

.file-upload-btn:hover {
  background: #f3f4f6;
  color: #4f46e5;
}

textarea {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 18px;
  padding: 8px 14px;
  font-size: 13px;
  line-height: 1.4;
  height: 36px;
  min-height: 36px;
  max-height: 96px; /* 約4行分 */
  resize: none;
  outline: none;
  box-sizing: border-box;
  overflow-y: auto;
}

textarea:focus {
  border-color: #4f46e5;
}

.btn-send {
  background-color: #4f46e5;
  color: white;
  padding: 0 16px;
  height: 36px;
  border-radius: 18px;
  flex-shrink: 0;
  margin-bottom: 1px;
}

/* Modal Dialogs */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

#addMemberModal,
#avatarCropModal {
  z-index: 120;
}

.modal-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 320px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-title {
  font-size: 15px;
  font-weight: bold;
  color: #1f2937;
}

.modal-input {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}

.modal-input:focus {
  border-color: #4f46e5;
}

.modal-list {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 4px;
}

.modal-list-item {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
}

.modal-list-item:hover {
  background: #f3f4f6;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.btn-primary {
  background-color: #4f46e5;
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary:hover {
  background-color: #4338ca;
}

.btn-secondary {
  background: none;
  border: 1px solid #d1d5db;
  color: #4b5563;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.btn-secondary:hover {
  background-color: #f9fafb;
}

.btn-delete-friend,
.btn-delete-group {
  background: none;
  border: 1px solid #fca5a5;
  color: #ef4444;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.btn-delete-friend:hover,
.btn-delete-group:hover {
  background-color: #fef2f2;
  border-color: #ef4444;
}

/* 友達詳細モーダル用ボタンスタイル */
.friend-modal-btn {
  width: 100%;
  height: 36px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition: all 0.2s;
}

.friend-modal-btn.btn-unfriend {
  background: none;
  border: 1px solid #fca5a5;
  color: #ef4444;
}

.friend-modal-btn.btn-unfriend:hover {
  background-color: #fef2f2;
  border-color: #ef4444;
}

/* アバター切り抜きモーダル */
.crop-area-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 12px 0;
}

.crop-viewport {
  position: relative;
  width: 220px;
  height: 220px;
  background-color: #111827;
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  cursor: grab;
}

.crop-viewport:active {
  cursor: grabbing;
}

.crop-target-image {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center center;
  pointer-events: none;
  max-width: none;
  max-height: none;
}

.crop-circle-mask {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 160px;
  height: 160px;
  margin-left: -80px;
  margin-top: -80px;
  border-radius: 50%;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  border: 2px dashed rgba(255, 255, 255, 0.85);
  pointer-events: none;
  box-sizing: border-box;
}

.crop-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  margin-top: 6px;
}

.crop-controls input[type="range"] {
  cursor: pointer;
  accent-color: #4f46e5;
}

/* P2P ファイルカード */
.p2p-file-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 190px;
  max-width: 260px;
}

.p2p-file-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.p2p-file-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.p2p-file-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.p2p-file-size {
  font-size: 11px;
  opacity: 0.8;
}

.p2p-download-btn {
  width: 100%;
  padding: 6px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.p2p-status-text {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.9;
  text-align: center;
  padding: 2px 0;
}

