:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --ink: #1b2422;
  --ink-soft: #5b6865;
  --line: #dfe5e2;
  --primary: #0f6b5c;
  --primary-ink: #ffffff;
  --primary-soft: #e2f1ed;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --info: #2b4fa8;
  --info-soft: #e6ecfb;
  --returned: #7a3aa0;
  --returned-soft: #f3e8fa;
  --done: #2e6b34;
  --done-soft: #e5f3e6;
  --muted-soft: #eceeed;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 40, 35, 0.06), 0 4px 14px rgba(20, 40, 35, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121816;
    --surface: #1b2321;
    --ink: #e8eeec;
    --ink-soft: #9fb0ab;
    --line: #2d3936;
    --primary: #54c2ad;
    --primary-ink: #06221d;
    --primary-soft: #16332d;
    --danger: #ff8a80;
    --danger-soft: #3b1b19;
    --warn: #ffc56b;
    --warn-soft: #3a2b10;
    --info: #9db7ff;
    --info-soft: #1c2745;
    --returned: #d8a6f5;
    --returned-soft: #2f1f3b;
    --done: #8fd497;
    --done-soft: #1a2f1d;
    --muted-soft: #262f2d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

button, input, select, textarea { font: inherit; color: inherit; }

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
}

/* ---- 上部バー ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -16px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .who { font-size: 0.8rem; color: var(--ink-soft); white-space: nowrap; }

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
}
.icon-btn:hover { background: var(--primary-soft); }

.sync {
  height: 3px;
  margin: 0 -16px;
  background: transparent;
  overflow: hidden;
}
.sync.on::before {
  content: "";
  display: block;
  width: 40%;
  height: 100%;
  background: var(--primary);
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}
@media (prefers-reduced-motion: reduce) {
  .sync.on::before { animation: none; width: 100%; opacity: 0.5; }
}

/* ---- メニュー ---- */
.menu {
  position: absolute;
  right: 12px;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 10;
  min-width: 200px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.menu button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.menu button:hover { background: var(--muted-soft); }

/* ---- タブと絞り込み ---- */
.tabs {
  display: flex;
  gap: 4px;
  margin: 14px 0 10px;
  padding: 4px;
  background: var(--muted-soft);
  border-radius: 12px;
}
.tabs button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
  cursor: pointer;
}
.tabs button[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.tabs .count { margin-left: 4px; font-weight: 400; font-size: 0.85em; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.875rem;
  cursor: pointer;
}
.chip b { font-size: 1rem; }
.chip[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); }
.chip.zero { color: var(--ink-soft); }
.chip.overdue:not(.zero) b { color: var(--danger); }
.chip.help:not(.zero) b { color: var(--warn); }
.chip.review:not(.zero) b { color: var(--info); }

.section-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 18px 2px 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.section-title span { font-weight: 400; }

/* ---- タスクのカード ---- */
.card {
  display: block;
  margin: 0 0 10px;
  padding: 14px 14px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
}
a.card:hover { border-color: var(--primary); }
.card.alert, a.card.alert:hover { border-left: 4px solid var(--danger); }
.card.attention, a.card.attention:hover { border-left: 4px solid var(--warn); }
.card.closed { opacity: 0.7; }

.card-head { display: flex; align-items: flex-start; gap: 8px; }
.card-title { flex: 1; margin: 0; font-size: 1rem; font-weight: 700; overflow-wrap: anywhere; }
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.card-meta .late { color: var(--danger); font-weight: 700; }
.card-meta .soon { color: var(--warn); font-weight: 700; }

.pill {
  flex: none;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  background: var(--muted-soft);
  color: var(--ink-soft);
}
.pill.s-doing { background: var(--primary-soft); color: var(--primary); }
.pill.s-help { background: var(--warn-soft); color: var(--warn); }
.pill.s-review { background: var(--info-soft); color: var(--info); }
.pill.s-returned { background: var(--returned-soft); color: var(--returned); }
.pill.s-done { background: var(--done-soft); color: var(--done); }
.pill.p-high { background: var(--danger-soft); color: var(--danger); }

.bar { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.bar progress { flex: 1; }
.bar .pct { min-width: 3.2em; text-align: right; font-size: 0.85rem; font-weight: 700; font-variant-numeric: tabular-nums; }

progress {
  appearance: none;
  -webkit-appearance: none;
  height: 8px;
  border: 0;
  border-radius: 999px;
  background: var(--muted-soft);
  overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--muted-soft); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 999px; }

.empty {
  margin: 40px 0;
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.toggle-row { display: flex; justify-content: center; margin: 18px 0; }
.link-btn {
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.fab {
  position: fixed;
  right: max(16px, calc(50vw - 344px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 6;
  min-height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(15, 107, 92, 0.35);
  cursor: pointer;
}

/* ---- 詳細 ---- */
.panel {
  margin: 14px 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 12px; font-size: 0.95rem; }
.detail-title { margin: 0 0 8px; font-size: 1.25rem; line-height: 1.4; overflow-wrap: anywhere; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 0.92rem; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts .late { color: var(--danger); font-weight: 700; }

.body-text { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }

.quick { display: flex; gap: 10px; margin-bottom: 14px; }
.quick .btn { flex: 1; }

/* ---- フォーム ---- */
.field { margin: 0 0 16px; }
.field > label, .field > .label { display: block; margin-bottom: 6px; font-size: 0.88rem; font-weight: 700; }
.field .hint { margin: 6px 0 0; font-size: 0.8rem; color: var(--ink-soft); }

input[type="text"], input[type="password"], input[type="date"], select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
textarea { min-height: 96px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices button {
  min-height: 42px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}
.choices button[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 700;
}

.slider { display: flex; align-items: center; gap: 12px; }
.slider input[type="range"] { flex: 1; min-height: 44px; accent-color: var(--primary); }
.slider output { min-width: 3.4em; text-align: right; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
}
.btn.primary { border-color: var(--primary); background: var(--primary); color: var(--primary-ink); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }

.privacy {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.85rem;
  font-weight: 600;
}

.error-text { margin: 0 0 14px; color: var(--danger); font-weight: 600; }

/* ---- 履歴 ---- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 20px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
}
.timeline .when { font-size: 0.8rem; color: var(--ink-soft); }
.timeline .what { font-size: 0.9rem; font-weight: 600; }
.timeline .comment { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- ログイン ---- */
.login { max-width: 400px; margin: 0 auto; padding-top: 12vh; }
.login h1 { margin: 0 0 4px; font-size: 1.5rem; }
.login .lead { margin: 0 0 24px; color: var(--ink-soft); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); color: #fff; }

.loading { margin: 48px 0; text-align: center; color: var(--ink-soft); }

/* ---- グループ ---- */
.tabs .count { display: block; margin: 0; font-size: 0.75rem; line-height: 1.2; }
.tabs button { min-height: 48px; padding: 4px 2px; font-size: 0.88rem; line-height: 1.3; }

.stats { display: flex; flex-wrap: wrap; gap: 2px 12px; }

.checks { border: 1px solid var(--line); border-radius: 10px; padding: 2px 12px; }
.checks label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  border-bottom: 1px solid var(--line);
  font-weight: 400;
  cursor: pointer;
}
.checks label:last-child { border-bottom: 0; }
.checks input[type="checkbox"] { flex: none; width: 22px; height: 22px; accent-color: var(--primary); }
.checks .hint { margin: 0 0 0 auto; white-space: nowrap; }

.hint.center { text-align: center; color: var(--ink-soft); font-size: 0.85rem; }

/* ---- 利用者管理 ---- */
input[type="email"] { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.issued { border: 2px solid var(--primary); }
.code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 1.15rem; font-weight: 700; letter-spacing: 0.04em; user-select: all; -webkit-user-select: all; }
.facts.field { margin-bottom: 16px; }

/* ---- お知らせ ---- */
.notices {
  margin: 14px 0 0;
  padding: 10px 14px 6px;
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
}
.notices-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.notices-head h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 0.95rem; }
.notices-head .link-btn { min-height: 36px; padding: 4px 6px; font-size: 0.85rem; }
.badge {
  min-width: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.78rem;
  line-height: 22px;
  text-align: center;
}
.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}
.notice-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.notice-when { flex: none; font-size: 0.8rem; color: var(--ink-soft); }
.notices .hint { margin: 4px 0 6px; font-size: 0.8rem; color: var(--ink-soft); }

.plain-list { margin: 0; padding: 0; list-style: none; }
.plain-list li { padding: 10px 0; border-top: 1px solid var(--line); font-size: 0.92rem; }
.plain-list li:first-child { border-top: 0; padding-top: 0; }
.plain-list b { display: block; }
