:root {
  --bg: #f0f9ff;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #64748b;
  --line: #cbd5e1;
  --accent: #f59e0b; /* ビタミン系オレンジでやる気UP */
  --ok: #16a34a;
  --danger: #dc2626;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.12), 0 12px 24px rgba(0, 0, 0, 0.08);
  --radius: 14px;
}

html,
body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden; /* 横スクロール抑止 */
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP",
    sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #fff7ed 0%, #f0f9ff 100%);
}

/* すべての幅計算をborder込みにして“はみ出し”を起こしにくく */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 中央カラム */
.container {
  max-width: 920px;
  margin: 24px auto;
  padding: 0 16px;
}

/* ヘッダー */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ボタン */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
}
.btn.primary {
  color: #fff;
  background: linear-gradient(180deg, #fdba74, var(--accent));
  border-color: #fdba74;
  box-shadow: 0 10px 22px rgba(245, 158, 11, 0.25);
}

/* 追加ボタン（少し控えめ） */
.btn.cta-add {
  font-weight: 800;
  font-size: 15px;
  padding: 10px 14px;
  min-width: 76px;
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.28);
}
.btn.cta-add:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 26px rgba(245, 158, 11, 0.36);
}
@media (min-width: 760px) {
  .btn.cta-add {
    font-size: 16px;
    padding: 11px 16px;
  }
}

/* リスト/行 */
.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: grab;
  max-width: 100%;
  overflow-x: hidden;
}
.row:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}
.row.dragging {
  opacity: 0.6;
  cursor: grabbing;
}
.row.drag-over {
  outline: 2px dashed #7fb4ff;
  outline-offset: 0;
} /* はみ出し防止 */

.rowHead input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.titleText {
  flex: 1;
  min-width: 0;
  font: 600 18px/1.5 inherit;
  color: var(--text);
  padding: 6px 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.muted {
  color: var(--muted);
  font-size: 12px;
}

/* 状態バッジ */
.pill {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
}
.pill.done {
  color: var(--ok);
  background: #f0fdf4;
  border-color: #bbf7d0;
}
.pill.overdue {
  color: #b91c1c;
  background: #fef2f2;
  border-color: #fecaca;
}

/* 詳細 */
details > summary {
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
details[open] > summary {
  color: var(--accent);
}

/* 詳細パネル */
.panel {
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
  background: var(--card);
  display: grid;
  gap: 14px;
  max-width: 100%;
}
.panel .grid {
  gap: 12px;
}
.quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* 操作チップ */
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.chip:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  transform: translateY(-1px);
}
.danger {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fef2f2;
}

/* ドラッグ用ハンドル */
.dragHandle {
  border: none;
  background: transparent;
  color: #2563eb;
  cursor: grab;
  font-size: 18px;
  padding: 6px 8px;
  border-radius: 8px;
}
.dragHandle:active {
  cursor: grabbing;
}

/* 入力系 */
textarea.input {
  padding: 14px 16px;
  line-height: 1.9;
  font-size: 15px;
  letter-spacing: 0.2px;
  min-height: 140px;
  resize: vertical;
  border-radius: calc(var(--radius) - 2px);
}
.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 0 12px;
  flex: 1;
  min-width: 0;
}
#search {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  outline: none;
  min-width: 0;
}
#search:focus {
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
}
.search-hint {
  font-size: 12px;
  color: var(--muted);
}
mark {
  background: #fde68a;
  padding: 0 2px;
  border-radius: 2px;
}

/* タグ */
.tag {
  display: inline-block;
  padding: 2px 8px;
  margin: 2px;
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--line);
}
.tag.active {
  outline: 2px solid var(--accent);
}

/* 優先度バッジ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  margin-right: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}
.badge.high {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}
.badge.medium {
  background: #eef2ff;
  color: #3730a3;
  border-color: #c7d2fe;
}
.badge.low {
  background: #ecfeff;
  color: #155e75;
  border-color: #a5f3fc;
}

/* ===================== モーダル（1系統に統一） ===================== */
.modal.hidden {
  display: none;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
}
.modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-width: 100vw;
  max-height: 100dvh; /* iPhoneの実表示高にフィット */
  overflow: auto; /* 中だけスクロール */
  margin: 0 auto;
  background: var(--card);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 12px;
  -webkit-overflow-scrolling: touch;
}
/* iOSの自動ズーム抑止（16px以上） */
.modal-panel input,
.modal-panel select,
.modal-panel textarea,
.modal-panel button,
.modal-panel label,
.modal-panel small {
  font-size: 16px;
  line-height: 1.4;
  max-width: 100%;
  min-width: 0;
}
/* 長文折返し */
.modal-panel .title,
.modal-panel .field {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* モーダル中は背景を固定 */
body.modal-open {
  overflow: hidden;
  touch-action: none;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.icon-btn {
  background: transparent;
  border: 0;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
}
.modal-body .field {
  display: block;
  margin: 12px 0;
}
.modal-body .field > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
}
.modal-body input[type="text"],
.modal-body input[type="datetime-local"],
.modal-body textarea,
.modal-body select {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

/* 入力系（ライト上書き） */
textarea.input,
input.input,
select.input {
  background: #fff !important;
  color: var(--text) !important;
  border: 1px solid var(--line) !important;
}
textarea.input:focus,
input.input:focus,
select.input:focus {
  background: #fff !important;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
  outline: none;
}

/* ===== Dashboard ===== */
.dashboard {
  margin: 14px 0 20px;
  display: grid;
  gap: 14px;
  color: var(--text);
}
.dash-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
@media (max-width: 860px) {
  .dash-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

.dash-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.dash-card h3 {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 6px;
}
.dash-card .num {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}
.chart {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.chart h4 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--text);
}
.chart svg {
  width: 100%;
  height: 160px;
  display: block;
}

.dash-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
}
.toggle-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}
.toggle-btn.active {
  outline: 2px solid var(--accent);
}

/* open/close 可視制御 */
#dashboard .dash-body {
  display: none;
}
#dashboard.open .dash-body {
  display: block;
}
#dashboard .dash-extras {
  display: none;
}
#dashboard.open .dash-extras {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* 日付ピッカー */
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.8;
}
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

/* --- Login Hero (light) --- */
.hero {
  display: grid;
  place-items: center;
  min-height: min(72vh, 720px);
  margin-top: 10px;
  position: relative;
}
.hero .orb {
  position: absolute;
  inset: -10% -10% auto auto;
  width: 560px;
  height: 560px;
  background: radial-gradient(
      circle at 35% 35%,
      rgba(253, 230, 138, 0.22),
      transparent 60%
    ),
    radial-gradient(
      circle at 70% 55%,
      rgba(147, 197, 253, 0.22),
      transparent 65%
    );
  filter: blur(6px);
  animation: float 14s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes float {
  from {
    transform: translateY(-8px) translateX(6px);
  }
  to {
    transform: translateY(8px) translateX(-6px);
  }
}

.login-card {
  width: min(680px, 92vw);
  border-radius: 22px;
  padding: 28px;
  color: var(--text);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.86),
    rgba(255, 255, 255, 0.78)
  );
  border: 1px solid rgba(148, 163, 184, 0.35);
  backdrop-filter: blur(10px) saturate(1.05);
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.1),
    0 10px 22px rgba(245, 158, 11, 0.12);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.brand .logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: conic-gradient(from 220deg, #60a5fa, #34d399, #60a5fa);
  filter: saturate(1.2);
}
.brand h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.02em;
  color: var(--text);
}
.hero-lead {
  color: var(--muted);
  margin: 6px 0 14px;
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 18px;
}
.hero-badge {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.login-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.btn.big {
  font-size: 16px;
  padding: 12px 16px;
  border-radius: 12px;
}
.muted-note {
  font-size: 12px;
  color: var(--muted);
}

/* ログイン状態クラス（保険） */
.hidden {
  display: none !important;
}
body.logged-out #appShell {
  display: none;
}
body.logged-in #hero {
  display: none;
}
html.booting #hero,
html.booting #appShell {
  display: none;
}

/* スマホ最適化：行の折返しと可読性 */
@media (max-width: 480px) {
  .rowHead {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }
  .rowHead input[type="checkbox"] {
    order: -2;
    flex: 0 0 auto;
  }
  .rowHead .titleText {
    order: -1;
    flex: 1 1 auto;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-break: loose;
    font-size: 16px;
  }
  .rowHead .muted {
    flex: 1 1 100%;
  }
  .rowHead .pill {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    max-width: max-content;
  }
  .rowHead .tagBox {
    flex: 1 1 100%;
    margin-bottom: 10px;
  }
  .row > details {
    margin-top: 6px;
  }
}

/* PC の背景（任意） */
@media (min-width: 861px) {
  body.desktop-bg {
    background: #e7f5ff no-repeat center/cover fixed;
    position: relative;
    overflow-x: hidden;
  }
  body.desktop-bg::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.55) 0%,
      rgba(255, 255, 255, 0.35) 30%,
      rgba(255, 255, 255, 0.25) 100%
    );
    z-index: -1;
  }
  .container {
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(4px);
  }
}
