:root {
  color-scheme: light;
  --color-bg: #f7f7f9;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-muted: #6b6b70;
  --color-primary: #2b6cb0;
  --color-primary-dark: #204e82;
  --color-border: #d8d8de;
  --color-error: #c0392b;
  --color-success: #1e7a34;
  --nav-height: 56px;
}

* {
  box-sizing: border-box;
}

/* [hidden]属性はどのクラスのdisplay指定よりも優先させる
   （author stylesheet同士は詳細度が同じ場合は後勝ちのため、.buttonのdisplay:inline-block等に
   負けてhidden要素が表示されてしまう事故を防ぐ）。 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

a {
  color: var(--color-primary);
}

button {
  font-family: inherit;
}

.error {
  color: var(--color-error);
  font-size: 0.85rem;
  min-height: 1.2em;
}

.success {
  color: var(--color-success);
  font-size: 0.85rem;
}

/* --- ログイン画面 --- */
.auth-page {
  max-width: 360px;
  margin: 10vh auto;
  padding: 2rem;
  background: var(--color-surface);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.auth-page h1 {
  font-size: 1.25rem;
  margin-top: 0;
}

.auth-page label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.auth-page input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 1rem;
}

.auth-page button {
  width: 100%;
  padding: 0.7rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
}

.auth-page button:hover {
  background: var(--color-primary-dark);
}

/* --- 共通レイアウト（支援者・管理者） --- */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  font-size: 1rem;
  margin: 0;
}

.app-main {
  flex: 1;
  padding: 1rem;
  padding-bottom: calc(var(--nav-height) + 1rem);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.app-main.with-chat-input {
  padding-bottom: calc(var(--nav-height) + 4rem);
}

.logout-link {
  font-size: 0.85rem;
  color: var(--color-muted);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
}

/* --- 管理者側：ヘッダーナビ --- */
.app-main.admin-wide {
  max-width: 1100px;
}

.admin-nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.admin-nav a {
  font-size: 0.9rem;
  color: var(--color-muted);
  text-decoration: none;
}

.admin-nav a:hover {
  color: var(--color-primary);
}

.filter-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.filter-row .field {
  margin-bottom: 0;
  min-width: 160px;
}

.status-badge.active {
  background: #e3f4e6;
  color: var(--color-success);
}

.status-badge.suspended {
  background: #fbe4e1;
  color: var(--color-error);
}

.status-badge.deleted {
  background: var(--color-border);
  color: var(--color-muted);
}

/* --- 支援者側：データ送信/チャット タブ切り替え --- */
.hub-tabs {
  display: flex;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.hub-tabs button {
  flex: 1;
  padding: 0.75rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 0.9rem;
  color: var(--color-muted);
  cursor: pointer;
}

.hub-tabs button.active {
  color: var(--color-primary);
  font-weight: bold;
  border-bottom-color: var(--color-primary);
}

/* --- 支援者側：下部タブナビゲーション --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}

.bottom-nav a,
.bottom-nav button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  text-decoration: none;
  color: var(--color-muted);
  background: none;
  border: none;
  cursor: pointer;
}

.bottom-nav a.active {
  color: var(--color-primary);
  font-weight: bold;
}

/* --- カード・ボタン --- */
.card h2 {
  margin-top: 0;
  font-size: 1rem;
}

.face-photo-preview {
  margin-bottom: 1rem;
}

.face-photo-preview img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-border);
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.button {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

.button:hover {
  background: var(--color-primary-dark);
}

.button.secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}

.button.danger {
  background: var(--color-error);
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.button.block {
  display: block;
  width: 100%;
  padding: 1rem;
  font-size: 1.05rem;
}

.data-send-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* --- 一覧・表 --- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
}

table th,
table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  font-size: 0.9rem;
}

table th {
  color: var(--color-muted);
  font-weight: 600;
}

table tr:hover td {
  background: rgba(43, 108, 176, 0.05);
}

/* --- フォーム全般 --- */
.field {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.field input,
.field select,
.field textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
}

/* --- チャット --- */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-bottom: 1rem;
}

.chat-bubble {
  max-width: 75%;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.own {
  align-self: flex-end;
  background: var(--color-primary);
  color: #fff;
}

.chat-bubble.other {
  align-self: flex-start;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.chat-meta {
    font-size: 0.7rem;
    color: var(--color-muted);
    margin-top: 0.15rem;
}

.chat-input-row {
  position: fixed;
  bottom: var(--nav-height);
  left: 0;
  right: 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}

.chat-input-row textarea {
  flex: 1;
  resize: none;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: inherit;
}

/* --- 管理者側チャット（下部固定ではなく通常フロー） --- */
.chat-thread.admin-thread {
  max-height: 60vh;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem;
  background: var(--color-bg);
}

.chat-input-row-static {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.chat-input-row-static textarea {
  flex: 1;
  resize: none;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: inherit;
}

/* --- 画像・動画送信 --- */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.85rem;
}

.file-item.failed {
  border-color: var(--color-error);
}

.file-item .thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--color-border);
  flex-shrink: 0;
}

.file-item .file-info {
  flex: 1;
  min-width: 0;
}

.file-item .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item .file-status {
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-top: 0.2rem;
}

.file-item.failed .file-status {
  color: var(--color-error);
}

.file-item-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.button.small {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--color-border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--color-primary);
}

.notice {
  padding: 0.75rem;
  border-radius: 4px;
  background: #fff8e1;
  border: 1px solid #f0e0a0;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* --- 送信履歴 --- */
.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--color-border);
  color: var(--color-text);
  margin-left: 0.4rem;
}

.status-badge.completed {
  background: #e3f4e6;
  color: var(--color-success);
}

.status-badge.failed,
.status-badge.partially_failed {
  background: #fbe4e1;
  color: var(--color-error);
}

.history-meta {
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-top: 0.4rem;
}

.media-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.media-preview-grid img,
.media-preview-grid video {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--color-border);
  cursor: pointer;
}

.media-preview-cell {
  position: relative;
}

.media-preview-checkbox {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 1;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 4px;
}

.media-preview-checkbox input {
  width: 16px;
  height: 16px;
  margin: 0;
}

/* --- 拡大表示（ライトボックス） --- */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.lightbox-content img,
.lightbox-content video {
  max-width: 90vw;
  max-height: 90vh;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
}
