:root {
  --bg: #f6f8f7;
  --surface: #ffffff;
  --border: #e3eae8;
  --text: #0f2a26;
  --text-soft: #5f726e;
  --text-mute: #5f726e;
  --primary: #0f766e;
  --primary-soft: #e6f4f1;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 8px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.6;
}
.cr-wrap { max-width: 880px; margin: 0 auto; padding: 16px; }
.cr-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 12px; }
.cr-header h1 { margin: 0; font-size: 1.4rem; }
.cr-sub { margin: 0; color: var(--text-soft); font-size: 0.9rem; }
.cr-account { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text-soft); }
.cr-status { min-height: 1.5em; margin: 0 0 8px; color: var(--text-soft); font-size: 0.9rem; }
.cr-status.is-error { color: var(--danger); }
.cr-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.cr-card h2, .cr-card h3 { margin: 0 0 12px; font-size: 1.1rem; }
.cr-form { display: grid; gap: 10px; }
.cr-form label { display: grid; gap: 4px; font-size: 14px; color: var(--text-soft); }
.cr-form input, .cr-form select, .cr-team-pick select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 1rem; color: var(--text); background: #fff;
}
.cr-inline { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; margin-bottom: 12px; }
.cr-btn {
  padding: 10px 16px; border: 1px solid var(--primary); border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px;
}
.cr-btn-ghost { background: #fff; color: var(--primary); }
.cr-btn-small { padding: 6px 10px; min-height: 36px; font-size: 14px; }
.cr-btn-danger { border-color: var(--danger); color: var(--danger); background: #fff; }
.cr-btn:disabled { opacity: 0.5; cursor: default; }
.cr-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.cr-row h3 { margin: 0; }
.cr-divider { display: flex; align-items: center; gap: 8px; margin: 16px 0 10px; color: var(--text-mute); font-size: 14px; }
.cr-divider::before, .cr-divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.cr-team-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.cr-team-head h2 { margin: 0; font-size: 1.25rem; }
.cr-team-pick { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-soft); }
.cr-res-form { margin: 12px 0; padding: 12px; background: var(--primary-soft); border-radius: var(--radius-sm); }
.cr-res-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.cr-res { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; min-width: 0; }
.cr-res-title { font-weight: 600; overflow-wrap: anywhere; }
.cr-res-note { color: var(--text-soft); font-size: 14px; overflow-wrap: anywhere; }
.cr-res-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cr-res-actions a { text-decoration: none; display: inline-flex; align-items: center; }
.cr-preview { width: 100%; height: 70vh; min-height: 360px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 8px; background: #fff; }
.cr-mute { color: var(--text-mute); font-size: 0.9rem; }
.cr-table-wrap { overflow-x: auto; }
.cr-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.cr-table th, .cr-table td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.cr-table td:last-child { display: flex; gap: 6px; }
.cr-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 14px; background: var(--primary-soft); color: var(--primary); }
.cr-badge.is-off { background: #fef2f2; color: var(--danger); }

/* Keep long titles, native file inputs and team pickers inside narrow screens. */
.cr-wrap, .cr-card, .cr-form, .cr-form label, .cr-team-pick { min-width: 0; }
.cr-form input, .cr-form select { min-width: 0; max-width: 100%; }
.cr-team-pick { max-width: 100%; }
.cr-team-pick select { min-width: 0; }
.cr-status, .cr-team-head h2, .cr-account, .cr-card h3 { overflow-wrap: anywhere; }
.cr-schedule-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; border-top: 1px solid var(--border); padding: 12px 0; }
.cr-schedule-text { flex: 1; min-width: 100px; overflow-wrap: anywhere; }
.cr-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.cr-placeholder { display: grid; place-items: center; background: var(--primary-soft); color: var(--text-soft); font-size: 14px; }
.cr-event-preview { max-width: 100%; max-height: 240px; object-fit: contain; }
.cr-images { display: flex; flex-wrap: wrap; gap: 8px; }
.cr-images button { max-width: 140px; overflow-wrap: anywhere; }
.cr-images img { display: block; width: 80px; height: 60px; object-fit: cover; }
.cr-btn:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }

/* Individual applications and member cards share the existing mobile layout. */
.cr-form .cr-check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.cr-check input[type="checkbox"] { width: 20px; height: 20px; flex: 0 0 20px; }
.cr-person-card { overflow-wrap: anywhere; }
.cr-person-card h3 { margin: 0 0 6px; }
.cr-person-card p { margin: 2px 0; color: var(--text-soft); }
.cr-person-card p:has(a) { margin-block: 6px; }
.cr-person-card fieldset { min-width: 0; margin: 0; padding: 10px; border: 1px solid var(--border); }
.cr-wrap nav { margin-bottom: 16px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; }
.cr-wrap nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border: 1.5px solid var(--primary); border-radius: 999px; background: var(--surface); color: var(--primary); font-weight: 700; text-decoration: none; }
.cr-wrap nav a:hover { background: var(--primary-soft); }
.cr-wrap nav a:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.cr-team-pick { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.cr-team-pick select { min-width: 0; flex: 1; }

/* Resource groups and import preview stay readable on narrow screens. */
.cr-resource-group { min-width: 0; margin-top: 12px; }
.cr-resource-group summary { min-height: 44px; padding: 10px 0; cursor: pointer; font-weight: 600; overflow-wrap: anywhere; }
.cr-form textarea { width: 100%; min-width: 0; max-width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; font-size: 16px; resize: vertical; }
.cr-form label, .cr-res-note, .cr-btn-small { font-size: 14px; }
.cr-btn-small { min-height: 44px; }
.cr-import-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 14px; }
.cr-import-table th, .cr-import-table td { padding: 6px 3px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.cr-import-table .is-invalid { background: #fef2f2; color: #991b1b; }
.cr-import-table p { margin: 4px 0; }
summary:focus-visible, textarea:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }

/* プレビューの URL は1行に縮めて「…」で省略（全文は title で確認できる） */
#cr-import-rows td:nth-child(3) { max-width: 7.5em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cr-legacy-login summary { padding-block: 12px; cursor: pointer; overflow-wrap: anywhere; }
.cr-id-edit { justify-self: start; border: 0; text-decoration: underline; }

/* 申請後の「受け付けました」と管理者向けの案内 */
.cr-done { display: grid; gap: 10px; margin: 8px 0 16px; padding: 14px 16px; border: 1.5px solid var(--primary); border-radius: var(--radius); background: var(--primary-soft); }
.cr-done p { margin: 0; }
.cr-done-title { font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.cr-done .cr-btn { justify-self: start; text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; }
.cr-done:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* 処理中の表示（上部のバーとボタンのくるくる） */
.cr-busy { position: fixed; top: calc(8px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); z-index: 1000; display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 999px; background: var(--primary); color: #fff; font-weight: 700; font-size: 15px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.18); }
.cr-spinner { width: 16px; height: 16px; border: 2.5px solid rgb(255 255 255 / 0.4); border-top-color: #fff; border-radius: 50%; animation: cr-spin 0.8s linear infinite; }
.cr-btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.cr-btn.is-busy::after { content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border: 2.5px solid currentColor; border-color: var(--primary) transparent var(--primary) var(--primary); border-radius: 50%; animation: cr-spin 0.8s linear infinite; }
.cr-btn:not(.cr-btn-ghost).is-busy::after { border-color: #fff transparent #fff #fff; }
@keyframes cr-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cr-spinner, .cr-btn.is-busy::after { animation-duration: 2.4s; } }
.cr-pw-form { padding: 8px 0; }
.cr-pw-form .cr-row { justify-content: flex-start; }
/* スマホではチーム表をカード状に縦積みし、操作ボタンが切れないようにする */
@media (max-width: 600px) {
  #cr-admin .cr-table thead { display: none; }
  #cr-admin .cr-table, #cr-admin .cr-table tbody, #cr-admin .cr-table tr, #cr-admin .cr-table td { display: block; width: 100%; }
  #cr-team-rows tr:not(.cr-pw-row) { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  #cr-team-rows tr:not(.cr-pw-row) td { padding: 0; border: 0; width: auto; }
  #cr-team-rows tr:not(.cr-pw-row) td:first-child { font-weight: 700; }
  #cr-team-rows tr:not(.cr-pw-row) td:last-child { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; }
}

.cr-in-line #cr-person-google, .cr-in-line #cr-person-gsi,
.cr-in-line #cr-google, .cr-in-line #cr-google-button { display: none !important; }
.cr-line-guard { border: 2px solid #b45309; }
.cr-line-guard .cr-btn { margin: 4px; white-space: normal; }
.cr-line-guard input { width: 100%; min-width: 0; box-sizing: border-box; }
.cr-pending-badge { border-radius: 999px; padding: 4px 10px; background: #fef3c7; color: #78350f; }
.cr-group-tools { display: inline-flex; flex-wrap: wrap; gap: 6px; margin: 6px; max-width: calc(100% - 12px); }
.cr-group-tools input { min-width: 0; width: 100%; box-sizing: border-box; }

/* 資料見出し。開閉状態は既存の details に任せる。件数は見出しの横に小さく出す */
.cr-card { box-shadow: 0 1px 3px rgb(15 42 38 / 0.04); }
.cr-count { margin-left: 4px; color: var(--text-soft); font-size: 14px; font-weight: 400; font-variant-numeric: tabular-nums; }
.cr-resource-group { border: 1px solid var(--border); border-radius: var(--radius); padding-inline: 12px; }
.cr-resource-group summary { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; list-style: none; }
.cr-resource-group summary::-webkit-details-marker { display: none; }
.cr-resource-group summary::after { content: "›"; color: var(--text-soft); }
.cr-resource-group[open] > summary::after { transform: rotate(90deg); }
.cr-group-name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cr-group-count { color: var(--text-soft); font-weight: 400; white-space: nowrap; }
.cr-group-tools { flex-basis: 100%; order: 1; }
.cr-btn:active, .cr-wrap a:active, summary:active { transform: scale(.98); }
@media (prefers-reduced-motion: reduce) {
  .cr-btn:active, .cr-wrap a:active, summary:active { transform: none; }
}

/* アカウントの編集欄は狭い画面でも折り返す */
.cr-account { flex-wrap: wrap; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
/* 個人ログインは操作ボタンがあるので見出しの下に1段で置く（PCで右半分に寄せない） */
.cr-account:has(.cr-profile) { flex-basis: 100%; margin-left: 0; }
.cr-profile { flex-basis: 100%; width: 100%; min-width: 0; font-size: 14px; overflow-wrap: anywhere; }
/* 名前の変更・チームの変更・ログアウトは小さいボタンを横に並べる。開いた入力欄は1行使う */
.cr-profile, .cr-profile > .cr-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cr-profile > .cr-form { display: contents; }
.cr-profile form, .cr-profile p { flex-basis: 100%; margin: 0; }
/* 見出し下では「名前 / 操作ボタン＋ログアウト」の2段にする。入力欄を開いたときだけ全幅 */
.cr-account:has(.cr-profile) > #cr-account-name { flex-basis: 100%; }
.cr-account .cr-profile { flex-basis: auto; width: auto; }
.cr-account .cr-profile:has(form:not([hidden])) { flex-basis: 100%; width: 100%; }
.cr-profile input, .cr-profile select { min-width: 0; min-height: 44px; }
.cr-profile .cr-row { justify-content: flex-start; }
.cr-profile button, .cr-person-card button { min-width: 44px; min-height: 44px; }

/* メンバー紹介の承認 */
#cr-intros .cr-person-card { overflow-wrap: anywhere; min-width: 0; }
.cr-intro-dialog { width: min(520px, calc(100% - 24px)); max-height: calc(100dvh - 32px); overflow-y: auto; margin: auto; box-sizing: border-box; }
.cr-intro-dialog::backdrop { background: rgb(0 0 0 / .5); }

/* 資料は1件1行。名前を押すと新しいタブで開き、ページ内表示・編集ボタンは右側に小さく並べる */
.cr-res-list .cr-res { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 8px 12px; }
.cr-res-main { flex: 1 1 12em; min-width: 0; }
a.cr-res-title { display: inline-flex; align-items: center; min-height: 44px; color: var(--text); text-decoration: none; }
a.cr-res-title::after { content: "↗"; margin-left: 6px; color: var(--text-soft); font-weight: 400; }
a.cr-res-title:hover { color: var(--primary); text-decoration: underline; }
a.cr-res-title:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.cr-res-main .cr-res-note { margin-top: -6px; }
.cr-res-list .cr-res-actions { margin-top: 0; }
.cr-res .cr-preview { flex-basis: 100%; }

/* ログイン: 以前の方法はたたんだ中に置く */
.cr-legacy-login { margin-top: 12px; border-top: 1px solid var(--border); }
.cr-legacy-login > summary { color: var(--text-soft); font-size: 14px; }
.cr-legacy-login .cr-res-note { margin: 0; }

/* チーム発行: 入力欄を並べ、「自動作成」はパスワード欄の横、「チームを発行」はその下 */
.cr-new-team { margin-bottom: 12px; }
.cr-new-team-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 10px; align-items: end; }
.cr-pw-field { display: flex; align-items: flex-end; gap: 6px; min-width: 0; }
.cr-pw-field label { flex: 1; min-width: 0; }
.cr-pw-field .cr-btn { flex-shrink: 0; }
.cr-new-team-submit { justify-self: start; }
