/* ===== iOS 風・洗練モバイルデザイン（グリーン×ホワイト・ライト固定） ===== */
:root {
  /* ライト（iOS グループ化リスト） */
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #e9e9ef;
  --text: #000000;
  --muted: #8e8e93;
  --muted-2: #aeaeb2;
  --sep: rgba(60, 60, 67, 0.18);
  --accent: #3e8a88;
  --accent-dark: #2c6462;
  --accent-light: #eaf5f4;
  --green: #34c759;
  --red: #ff3b30;
  --seg-bg: rgba(118, 118, 128, 0.12);
  --seg-active: #ffffff;
  --field: #ffffff;
  --header-bg: rgba(242, 242, 247, 0.8);
  --shadow: 0 0.5px 2px rgba(0, 0, 0, 0.12);
  --done-ring: rgba(60, 60, 67, 0.35);
  --done-check: #7a7a7f;
  --assignee-bg: rgba(255, 204, 0, 0.22);
  --assignee-fg: #9a6b00;

  --pri-s: #ff3b30;
  --pri-1: #ff9500;
  --pri-2: #007aff;
  --pri-3: #8e8e93;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  /* 表示領域の最大幅（広い画面ではここまで広がる） */
  --app-max: 900px;
  /* 左右の余白（狭めにして表示領域を広く） */
  --pad-x: 6px;
}

/* ポータル全体で採用しているグリーン×ホワイトのブランドに合わせ、
   ライトテーマ固定とする（ダークテーマへの切り替えは行わない）。 */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* ダブル/トリプルタップによるズームを無効化 */
html { touch-action: manipulation; }
button, input, textarea, .tab, .task-main { touch-action: manipulation; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
  overscroll-behavior-y: none;
  /* ページ(body)を完全にロック。iOS がフォーカス時に勝手にスクロールするのを防ぐ。
     スクロールは一覧(.list)の内部のみ。 */
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  /* 固定配置にして iOS がフォーカス時に勝手にスクロールしないようにする。
     高さはキーボードを除いた表示領域(--app-h)に合わせる。 */
  position: fixed;
  top: var(--app-top, 0px);
  left: 0; right: 0;
  margin: 0 auto;
  max-width: var(--app-max);
  height: var(--app-h, 100dvh);
}

/* ===== ヘッダー（ナビバー + セグメント） ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + var(--safe-top)) var(--pad-x) 8px;
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
}

/* 接続設定（初回ゲート）中はタブ操作をさせない */
.app.setup-mode .app-header { display: none; }

/* iOS セグメンテッドコントロール */
.tabs {
  display: flex;
  flex: 1;
  gap: 2px;
  padding: 2px;
  background: var(--seg-bg);
  border-radius: 9px;
}
.tab {
  flex: 1;
  padding: 6px 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  transition: background .18s ease;
  letter-spacing: -0.01em;
}
.tab.is-active {
  background: var(--seg-active);
  box-shadow: var(--shadow);
  font-weight: 600;
}
.tab-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 2px;
}
.tab.is-active .tab-count { color: var(--accent); }

.icon-btn {
  width: 30px; height: 30px;
  font-size: 16px;
  color: var(--accent);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
}
.icon-btn:active { opacity: .5; }

/* ===== リスト（グループ化インセット） ===== */
.list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px var(--pad-x) calc(28px + var(--safe-bottom));
}
.empty {
  padding: 60px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.group {
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

/* memory（M）区切り */
.memory-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 20px 6px 10px;
  color: var(--muted);
}
.memory-divider span {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.memory-divider::before,
.memory-divider::after {
  content: '';
  flex: 1;
  height: 0.5px;
  background: var(--sep);
}
/* インセットの区切り線（左を空けて iOS 風に） */
.group .task + .task::before {
  content: '';
  display: block;
  height: 0.5px;
  margin-left: 42px;
  background: var(--sep);
}

.task { background: transparent; }

.task-main {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  cursor: pointer;
}
.task-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 400;
  word-break: break-word;
}
.task.done .task-title { color: var(--muted); text-decoration: line-through; }

/* 優先度バッジ（淡いティント + カラー文字） */
.badge {
  flex: none;
  min-width: 22px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  color: var(--c, var(--accent));
  background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent);
}

/* 完了トグル（透明な丸＋薄い輪郭＋白チェックのみ） */
.done-btn {
  flex: none;
  width: 24px; height: 24px;
  font-size: 12px;
  line-height: 1;
  color: var(--done-check);
  background: transparent;
  border: 1.5px solid var(--done-ring);
  border-radius: 50%;
  cursor: pointer;
  transition: opacity .1s ease;
}
.done-btn:active { opacity: .5; }

/* 確認先（完了ボタンのすぐ左に inline 表示） */
.task-assignees {
  display: flex;
  flex: none;
  gap: 4px;
  max-width: 46%;
  overflow: hidden;
}
.task-assignees .chip {
  white-space: nowrap;
  font-size: 10.5px;
  padding: 1px 6px;
  background: var(--assignee-bg);
  color: var(--assignee-fg);
  font-weight: 600;
}

/* メタ行（LINEメモ・完了日時） */
.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  padding: 0 12px 5px 42px;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: -2px;
}
.chip {
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--card-2);
  color: var(--muted);
}
.chip.line {
  background: var(--card-2);
  color: var(--muted);
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.done-time { color: var(--muted); }
.pending-chip {
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  color: #ff9500;
  background: color-mix(in srgb, #ff9500 16%, transparent);
  border-radius: 8px;
}

/* ===== 展開エリア（編集） ===== */
.task-edit {
  border-top: 0.5px solid var(--sep);
  padding: 12px 16px 16px;
  background: var(--bg);
  display: none;
  gap: 10px;
  flex-direction: column;
}
.task.expanded .task-edit { display: flex; }
/* 開いているタスク行（見出し＋詳細要約）を同じ色にして連続感を出す */
.task.expanded .task-main,
.task.expanded .task-meta { background: var(--card-2); }

.field-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: none;
}
.tag-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tag-row::-webkit-scrollbar { display: none; }
.tag-row .tag { flex: none; }
.tag {
  padding: 4px 11px;
  font-size: 12.5px;
  color: var(--text);
  background: var(--card-2);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: background .12s;
}
.tag.on { background: var(--accent); color: #fff; }

.memo {
  width: 100%;
  min-height: 92px;
  padding: 8px 10px;
  font-size: 15px;
  color: var(--text);
  background: var(--card-2);
  border: none;
  border-radius: 9px;
  resize: vertical;
  font-family: inherit;
}
.memo:focus, .composer-input:focus { outline: none; }
/* メモタブの入力欄・一覧 */
.memo-quick { min-height: 176px; margin-bottom: 10px; }
.memo-edit { min-height: 200px; }   /* メモ編集時の記入欄を広く */
.memo-text { white-space: pre-wrap; }

.save-btn {
  width: 100%;
  padding: 10px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.save-btn:active { opacity: .85; }

.edit-actions { display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.text-btn {
  padding: 6px 12px;
  font-size: 13px;
  background: var(--card-2);
  border: none;
  border-radius: 8px;
  color: var(--accent);
  cursor: pointer;
}
.text-btn.danger { color: var(--red); }

/* ===== 下部固定ドック（定期パネル + 入力バー） ===== */
/* 入力ドックはレイアウトの一番下に配置（固定配置にしない）。
   アプリ高さをキーボードの上に合わせるので、常にキーボード直上に収まる。 */
.dock {
  position: relative;   /* close-fab(absolute) の基準 */
  flex: none;
  z-index: 30;
  padding-bottom: var(--safe-bottom);
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
}
.composer { padding: 8px var(--pad-x) 10px; }

/* 折りたたみ時の丸ボタン（FAB） */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + var(--safe-bottom));
  z-index: 35;
  width: 56px; height: 56px;
  font-size: 30px;
  font-weight: 300;
  line-height: 1;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.38);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:active { opacity: .85; }

/* 入力を閉じるボタン（ドックの上・右） */
.close-fab {
  position: absolute;
  right: var(--pad-x);
  top: -52px;
  padding: 9px 20px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 20px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.close-fab:active { opacity: .85; }

.composer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 29;
  background: transparent;
  display: none;
}
.composer-backdrop.show { display: block; }
.composer-row { display: flex; gap: 8px; align-items: center; }
.composer-foot {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
.archive-btn {
  flex: none;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border: none;
  border-radius: 15px;
  cursor: pointer;
}
.archive-btn:active { opacity: .6; }
.archive-date-input {
  flex: none;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border: none;
  border-radius: 15px;
  font-family: inherit;
}
.repeat-btn {
  flex: none;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--seg-bg);
  border: none;
  border-radius: 15px;
  cursor: pointer;
  font-family: inherit;
}
.repeat-btn.on { color: #fff; background: var(--accent); }
.repeat-btn:active { opacity: .6; }
.repeat-tag {
  margin-left: 8px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-radius: 8px;
  vertical-align: middle;
}
.prio-btn {
  flex: none;
  min-width: 34px;
  padding: 8px 8px;
  font-size: 13px;
  font-weight: 700;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  color: var(--c, var(--accent));
  background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent);
}
.composer-input {
  flex: 1;
  min-width: 0;
  padding: 9px 14px;
  font-size: 16px; /* iOS ズーム防止 */
  color: var(--text);
  background: var(--field);
  border: 0.5px solid var(--sep);
  border-radius: 18px;
}
.add-btn {
  flex: none;
  width: 32px; height: 32px;
  font-size: 20px;
  font-weight: 400;
  line-height: 1;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: opacity .1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.add-btn:active { opacity: .6; }

.composer-tags {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.composer-tags::-webkit-scrollbar { display: none; }
.composer-tags .tag { flex: none; }

/* ===== 定期タスクフォーム ===== */
.recur-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  margin-bottom: 16px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.recur-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.recur-form .composer-input { border-radius: 10px; }
.recur-form .prio-btn { border-radius: 10px; min-width: 40px; }
.seg {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--seg-bg);
  border: none;
  border-radius: 9px;
  cursor: pointer;
}
.seg.on { color: #fff; background: var(--accent); }
.recur-add {
  padding: 11px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 11px;
  cursor: pointer;
}
.recur-add:active { opacity: .85; }

/* ===== 保管（スクロールカレンダー） ===== */
.arch-day {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin: 10px 4px 5px;
}
.arch-date {
  flex: none;
  font-size: 11px;
  color: var(--muted);
  background: transparent;
  border: none;
  font-family: inherit;
  padding: 2px 2px;
  min-width: 0;
}

/* ===== 優先度メニュー（上に開く選択リスト） ===== */
.menu-backdrop { position: fixed; inset: 0; z-index: 60; }
.prio-menu {
  position: fixed;
  z-index: 61;
  min-width: 148px;
  padding: 5px;
  background: var(--card);
  border: 0.5px solid var(--sep);
  border-radius: 13px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.32);
}
.prio-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 11px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.prio-item:active { background: var(--card-2); }
.prio-item.sel { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.prio-dot { width: 13px; height: 13px; border-radius: 50%; flex: none; }
.prio-item-label { flex: 1; text-align: left; font-weight: 600; }
.prio-check { color: var(--accent); font-size: 14px; font-weight: 700; }

/* ===== トースト ===== */
.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 64px);   /* 「取り消す」バーと同じ上部中央に表示 */
  bottom: auto;
  transform: translateX(-50%);
  z-index: 40;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: rgba(30, 30, 32, 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
}

/* 「取り消す」スナックバー */
.undo-bar {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 64px);
  bottom: auto;
  transform: translateX(-50%);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100% - 24px);
  padding: 9px 10px 9px 16px;
  white-space: nowrap;   /* メッセージとボタンを1段（横並び）で表示 */
  font-size: 13px;
  color: #fff;
  background: rgba(44, 44, 46, 0.98);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.undo-bar.show { opacity: 1; pointer-events: auto; }
.undo-btn {
  flex: none;
  padding: 4px 10px;
  font-size: 14px;
  font-weight: 700;
  /* undo-bar は常に濃色背景なので、視認性のため accent より明るいグリーンにする */
  color: color-mix(in srgb, var(--accent) 65%, white);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.undo-btn:active { opacity: .6; }

/* ローディングバー */
.loading-bar {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  z-index: 50;
  transition: width .2s ease, opacity .2s;
}
