/* スマホ幅（360〜430px）を基準にしています。768px 以上で2列に広がります。 */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --line: #dfe3e8;
  --text: #1c2430;
  --sub: #5a6675;
  --accent: #1d6fd0;
  --warn-bg: #fdecec;
  --warn-line: #e79a9a;
  --todo-bg: #fff6e0;
  --todo-line: #e5bf6a;
  --caution-bg: #eef3fb;
  --caution-line: #a9c2e5;
  --danger: #b3261e;
  --tabbar-h: 56px;
  --actions-h: 108px; /* 下部の固定ボタン（スマホでは2段） */
}

* { box-sizing: border-box; }

/* ブラウザが「カーソルを見える位置へ」スクロールするとき、画面のいちばん下まで
   持っていこうとします。ところがこの画面は下部メニュー（と編集画面では固定ボタン）
   が重なっているため、そのままだとカーソルがその裏に隠れてしまいます。
   下にこれだけの余白を残すよう、ブラウザに伝えます。 */
html {
  scroll-padding-bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}

/* hidden 属性は、下の display 指定より優先します */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
body.plain { padding-bottom: 16px; }

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

/* --- 上部 --------------------------------------------------------------- */
.head {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px 8px;
}
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.head-title { font-weight: 700; font-size: 17px; }
.back { text-decoration: none; font-weight: 700; }
.role { font-size: 12px; color: var(--sub); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }
.logout { font-size: 12px; color: var(--sub); text-decoration: none; white-space: nowrap; }

.picker { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.picker-label { font-size: 12px; color: var(--sub); }
.picker select {
  flex: 1; min-height: 44px; font-size: 15px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
.picker.one { margin-top: 6px; font-size: 13px; color: var(--sub); }

.notice { margin-top: 8px; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.notice.batch { background: var(--todo-bg); border: 1px solid var(--todo-line); }
.notice.auth { background: var(--caution-bg); border: 1px solid var(--caution-line); }

.main { padding: 12px; max-width: 1100px; margin: 0 auto; }

/* --- 下部メニュー ------------------------------------------------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; min-height: var(--tabbar-h); display: flex; align-items: center; justify-content: center;
  text-decoration: none; color: var(--sub); font-size: 13px;
}
.tabbar a.on { color: var(--accent); font-weight: 700; border-top: 2px solid var(--accent); }

/* --- 一覧 --------------------------------------------------------------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.tab {
  flex: 0 0 auto; min-height: 40px; display: inline-flex; align-items: center; gap: 6px;
  padding: 0 12px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; text-decoration: none; color: var(--sub); font-size: 13px;
}
.tab.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.tab .count { font-size: 12px; opacity: .85; }

.cards { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.card {
  display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; text-decoration: none; color: inherit;
}
.card-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.date { font-size: 13px; color: var(--sub); }
.card-title { font-weight: 700; margin-top: 4px; }
.card-head { color: var(--sub); font-size: 13px; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.chip, .flag { font-size: 11px; border-radius: 999px; padding: 2px 8px; border: 1px solid var(--line); }
.chip.sns-instagram { background: #fdeef6; border-color: #efc0da; }
.chip.sns-facebook { background: #eaf1fd; border-color: #b6cdf2; }
.chip.sns-x { background: #eef0f2; }
.chip.type { background: #eef7ee; border-color: #b9ddb9; }
.chip.hold { background: var(--todo-bg); border-color: var(--todo-line); }
.chip.edited { background: #f0f0f5; }
.chip.status { background: #eef0f2; }
.flag.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.flag.todo { background: var(--todo-bg); border-color: var(--todo-line); }
.flag.caution { background: var(--caution-bg); border-color: var(--caution-line); }
.flag.posted { background: #eef7ee; border-color: #b9ddb9; }

.empty { color: var(--sub); text-align: center; padding: 24px 8px; }

/* --- 編集 --------------------------------------------------------------- */
.edit { padding-bottom: calc(var(--actions-h) + 12px); }
.event, .body, .warnings, .history {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin-bottom: 10px;
}
.event-title { font-weight: 700; }
.event-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.event-sub { color: var(--sub); font-size: 13px; margin-top: 4px; }
.photos { display: flex; gap: 8px; overflow-x: auto; margin-top: 10px; padding-bottom: 4px; }
.photos img { height: 96px; width: auto; border-radius: 8px; border: 1px solid var(--line); }

.save-row { display: flex; justify-content: space-between; align-items: center; min-height: 24px; }
.save-state { font-size: 12px; color: var(--sub); }
.editor-warn { font-size: 12px; color: var(--danger); }
textarea#text {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  font-family: inherit; font-size: 16px; line-height: 1.8; color: var(--text);
  min-height: 240px; resize: none; overflow: hidden;
}

.box { border-radius: 8px; padding: 10px; margin-bottom: 8px; font-size: 13px; }
.box:last-child { margin-bottom: 0; }
.box ul { margin: 6px 0 0; padding-left: 18px; }
.box-title { font-weight: 700; }
.box.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); }
.box.todo { background: var(--todo-bg); border: 1px solid var(--todo-line); }
.box.caution { background: var(--caution-bg); border: 1px solid var(--caution-line); }
.box.material { background: #f3f4f6; border: 1px solid var(--line); }
.jump { background: none; border: none; color: var(--accent); text-decoration: underline;
  font: inherit; padding: 4px 0; min-height: 32px; cursor: pointer; text-align: left; }

.history summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.history table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history td { border-top: 1px solid var(--line); padding: 6px 4px; vertical-align: top; }

/* --- 保留・プロファイル ------------------------------------------------- */
.section-title { font-size: 15px; margin: 16px 0 8px; }
.box-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin-bottom: 10px;
}
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.section-head .section-title { margin: 0; }
.section-body {
  white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 14px;
  margin: 8px 0 0; color: var(--text);
}
.section-edit textarea {
  width: 100%; min-height: 200px; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; font: inherit; font-size: 16px; line-height: 1.8; resize: vertical;
}

.held-head { display: flex; gap: 10px; align-items: flex-start; }
.held-thumb { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.held-info { flex: 1; min-width: 0; }
.held-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.held-actions.column { flex-direction: column; align-items: stretch; }
.held-actions input[type=text], .held-actions input[type=date] {
  min-height: 44px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px;
  font: inherit; font-size: 15px; flex: 1 1 140px; min-width: 0; max-width: 100%;
}
/* 「日付を指定」の行。
   flex-basis が 0（flex: 1）だと、折り返しの判定でも幅0として数えられるため
   flex-wrap が働かず、日付入力の最小幅のぶんだけ画面からはみ出します。
   実寸に近い flex-basis を与えて、幅が足りなければボタンを次の行へ落とします。 */
.date-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.held-actions:not(.column) .date-pick { flex: 1 1 200px; }
.held-actions.column .date-pick { flex: 0 0 auto; }
.date-pick span { font-size: 13px; color: var(--sub); white-space: nowrap; }
.btn.small { min-height: 44px; flex: 0 0 auto; padding: 0 14px; font-size: 14px; }
/* 予定の候補名など、長い文字列のボタンは折り返して収めます。 */
.held-actions .btn.small { max-width: 100%; white-space: normal; }
.held-actions.column .btn.small { width: 100%; }
/* 「PXL_20260825_042227815.jpg」のような切れ目のないファイル名を折り返します。 */
.held-info .card-title { overflow-wrap: anywhere; }
.hint { font-size: 12px; color: var(--sub); margin: 8px 0 0; }
.card.held { display: block; }

.evidence { font-size: 13px; color: var(--sub); margin-top: 6px; }

/* --- 写真を追加 --------------------------------------------------------- */
.upload { padding-bottom: calc(var(--actions-h) + 12px); }
.upload section { margin-top: 12px; }
.file-btn { display: inline-flex; cursor: pointer; }

.picked-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
/* 枚数が増えても横に伸びず、折り返して収まるようにします */
.thumbs {
  list-style: none; margin: 8px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px;
}
.thumb { position: relative; min-width: 0; }
.thumb img {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line); display: block;
}
.thumb-name {
  display: block; font-size: 11px; color: var(--sub); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thumb-del {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px;
  border-radius: 999px; border: none; background: rgba(0, 0, 0, .55); color: #fff;
  font-size: 16px; line-height: 1; cursor: pointer;
}

.bar { height: 8px; border-radius: 999px; background: #e6e9ee; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.result ul { margin: 6px 0 0; padding-left: 18px; }
.result li.ng { color: var(--danger); }

/* 一覧・保留の上に出す入口 */
.add-photo {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; margin-bottom: 10px; border-radius: 8px;
  border: 1px dashed var(--accent); color: var(--accent);
  background: var(--card); text-decoration: none; font-weight: 700; font-size: 14px;
}

/* --- 運営 --------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px;
}
.stats .stat:first-child { grid-column: 1 / span 2; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-value.bad { color: var(--danger); }
.stat-label { font-size: 12px; color: var(--sub); margin-top: 2px; }
.stat-label .small { font-size: 11px; }
.flag.hold { background: var(--todo-bg); border-color: var(--todo-line); }

.prompt-text {
  width: 100%; min-height: 320px; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; font-family: ui-monospace, "Consolas", monospace; font-size: 13px;
  line-height: 1.7; resize: vertical;
}
.trial { margin-top: 10px; display: grid; gap: 10px; }
.trial-col { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fbfbfc; }
.run-detail { font-size: 13px; padding: 6px 0; border-top: 1px solid var(--line); }

.settings { padding-bottom: calc(var(--actions-h) + 12px); }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 13px; color: var(--sub); margin-bottom: 4px; }
.field input[type=text], .field input[type=number], .field select {
  width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 8px;
  padding: 0 10px; font: inherit; font-size: 16px; background: #fff; color: var(--text);
}
.field.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 15px; }
.check input[type=checkbox] { width: 22px; height: 22px; }
.per-week { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--sub); }
.per-week input { width: 72px; min-height: 44px; border: 1px solid var(--line);
  border-radius: 8px; padding: 0 8px; font: inherit; font-size: 16px; text-align: right; }
#check-result .box { margin-top: 8px; }
.settings code { background: #eef0f2; padding: 1px 4px; border-radius: 4px; font-size: 12px; }
.term-list { list-style: none; margin: 8px 0 0; padding: 0; }
.term-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border-top: 1px solid var(--line); padding: 8px 0;
}
.term-list .card-head { display: block; }

/* --- 下部の固定ボタン --------------------------------------------------- */
.actions {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  z-index: 25; display: flex; flex-direction: column; gap: 6px; padding: 8px 12px;
  background: var(--card); border-top: 1px solid var(--line);
}
.actions-row { display: flex; gap: 8px; }
.actions-row:empty { display: none; }

/* 本文を編集している間は、下部の固定ボタン（112px）と下部メニュー（56px）を
   引っ込めます。スマホではこの2つで画面下 168px が塞がっており、いちばん下の行を
   打つと、ブラウザがカーソルをその裏へ送り込んでしまうためです。
   入力欄から離れると戻ります。PC（768px以上）では隠しません。 */
@media (max-width: 767px) {
  body.typing .actions,
  body.typing .tabbar { display: none; }
}
.btn {
  flex: 1; min-height: 44px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.danger { color: var(--danger); border-color: #e0b4b1; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions input[type=date] {
  min-height: 44px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px;
  font: inherit; font-size: 14px; flex: 0 0 auto; width: 140px;
}

.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + var(--actions-h) + 16px);
  z-index: 40; background: #222c3a; color: #fff; border-radius: 8px; padding: 10px 12px;
  font-size: 14px; text-align: center;
}
.copied {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45);
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 12px;
  color: #fff; padding: 24px; text-align: center;
}
.copied .links { display: flex; gap: 16px; }
.copied .links a { color: #fff; }
.copied .btn { flex: 0 0 auto; width: 200px; }
.error-message { white-space: pre-wrap; }

/* --- PC（2列） ---------------------------------------------------------- */
@media (min-width: 768px) {
  :root { --actions-h: 64px; }
  .tabbar a { font-size: 14px; }
  .main { padding: 16px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .edit { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; padding-bottom: 80px; }
  .edit .event { grid-column: 1; grid-row: 1 / span 2; }
  .edit .body { grid-column: 2; grid-row: 1; margin-bottom: 0; }
  .edit .warnings { grid-column: 2; grid-row: 2; }
  .edit .history { grid-column: 1 / span 2; }
  .trial { grid-template-columns: 1fr 1fr; }
  .actions { flex-direction: row; justify-content: flex-end; align-items: center; }
  .actions .btn { flex: 0 0 auto; min-width: 150px; }
  .toast { left: auto; right: 16px; width: 320px; bottom: 88px; }
}

/* 「あと2ステップ」の案内（確認リンクの画面・共有待ちの画面） */
.box ol.setup-list { margin: 6px 0 0; padding-left: 20px; }
.box ol.setup-list li { margin: 2px 0; }
.setup-address { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.setup-address code { word-break: break-all; background: #fff; padding: 2px 6px; border-radius: 4px; }
