/*
 * HomeCame Todo のスタイル。
 * 色は HomeCame 本体・お客様ページと同じトークンです（site/server/portal/styles.js）。
 * 書体は外部から読み込まず、端末にある日本語書体を使います。
 */

:root {
  --bg: #f7f5f0;
  --bg-subtle: #efebe3;
  --surface: #ffffff;
  --text: #272a27;
  --text-muted: #63675f;
  --border: #dbd7ce;
  --border-strong: #c3beb2;
  --accent: #4f6455;
  --accent-dark: #3b5044;
  --accent-light: #dce4dc;
  --focus: #1f4d8f;
  --alert: #97331f;
  --alert-bg: #fbe6e0;
  --warn: #7a4f0e;
  --warn-bg: #fbf0da;

  --c-green: #4f7a5a;
  --c-blue: #3a6ea5;
  --c-orange: #c27a2c;
  --c-red: #b4473a;
  --c-purple: #7a5a9a;
  --c-gray: #8a8d86;

  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, system-ui, sans-serif;
  --radius: 6px;
  --nav-width: 240px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1f1c;
    --bg-subtle: #252925;
    --surface: #232723;
    --text: #e8e6e0;
    --text-muted: #a3a79e;
    --border: #3a3f39;
    --border-strong: #4c524b;
    --accent: #8fb39a;
    --accent-dark: #a9c7b2;
    --accent-light: #2d3a31;
    --focus: #8ab4f0;
    --alert: #f0a08f;
    --alert-bg: #3e2621;
    --warn: #e8c27a;
    --warn-bg: #3a2f1c;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- 部品 ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn--primary { color: #12160f; } }
.btn--danger { color: var(--alert); border-color: transparent; background: transparent; padding-inline: 0.5rem; }
.btn--text { border-color: transparent; background: transparent; color: var(--text-muted); padding-inline: 0.5rem; }

input[type="text"], input[type="email"], input[type="search"], input[type="date"], input[type="time"], select, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.55rem 0.7rem;
  min-height: 2.75rem;
}
input:disabled { opacity: 0.5; }
textarea { resize: vertical; min-height: 6rem; }

.field { display: grid; gap: 0.3rem; border: 0; padding: 0; min-width: 0; }
.field__label { font-size: 0.85rem; color: var(--text-muted); padding: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.hint { font-size: 0.9rem; color: var(--text-muted); }

/* タグの入力欄：付けたタグと入力を1つの枠に並べる */
.tag-editor {
  display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface);
  padding: 0.35rem 0.5rem; min-height: 2.75rem; cursor: text;
}
.tag-editor:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.tag-chips { display: contents; list-style: none; }
.tag-chip { display: inline-flex; align-items: center; gap: 0.15rem; background: var(--accent-light); border-radius: 4px; padding: 0.1rem 0.15rem 0.1rem 0.5rem; font-size: 0.9rem; }
.tag-chip__remove { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; padding: 0 0.35rem; font-size: 1rem; line-height: 1; min-height: 1.6rem; }
.tag-editor input[type="text"] { flex: 1; min-width: 8rem; border: 0; background: transparent; padding: 0.2rem; min-height: 2rem; outline: none; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag-suggest__item { border: 1px dashed var(--border-strong); background: transparent; border-radius: 4px; padding: 0.2rem 0.6rem; font-size: 0.85rem; color: var(--text-muted); cursor: pointer; min-height: 2rem; }
.tag-suggest__item::before { content: "＋ "; }
.tag-suggest__item:hover { color: var(--text); border-color: var(--accent); }
.message { color: var(--alert); background: var(--alert-bg); border-radius: var(--radius); padding: 0.6rem 0.8rem; font-size: 0.9rem; }
.check { display: inline-flex; gap: 0.5rem; align-items: center; cursor: pointer; }
.check input { width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }
.spacer { flex: 1; }

.dot { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--c-gray); flex: none; }
.dot--lg { width: 1.6rem; height: 1.6rem; }
.dot--tag { background: transparent; border: 1.5px solid var(--accent); border-radius: 2px; }
.dot--green { background: var(--c-green); }
.dot--blue { background: var(--c-blue); }
.dot--orange { background: var(--c-orange); }
.dot--red { background: var(--c-red); }
.dot--purple { background: var(--c-purple); }
.dot--gray { background: var(--c-gray); }

/* ---------- 読み込み中・ログイン ---------- */

.splash { display: grid; place-items: center; min-height: 100dvh; color: var(--text-muted); }

.login { max-width: 400px; margin: 0 auto; padding: 12vh 16px 2rem; display: grid; gap: 1rem; }
.login__brand, .topbar__brand { font-size: 1.4rem; font-weight: 700; letter-spacing: 0.02em; }
.login__brand span, .topbar__brand span { color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem; display: grid; gap: 0.9rem; }
.code-input { font-size: 1.5rem; letter-spacing: 0.3em; text-align: center; }

/* ---------- 本体の枠 ---------- */

.app {
  display: grid;
  /* minmax(0, …) にしないと、中身の幅に押されて画面の外へはみ出します */
  grid-template-columns: var(--nav-width) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "nav main";
  min-height: 100dvh;
}
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 16px;
  padding-top: max(0.6rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar__brand { font-size: 1.1rem; margin-right: auto; white-space: nowrap; }
/* 幅が足りないときは、同期の表示だけを縮めて「…」で切ります（全文は title に入れてあります） */
.sync { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .btn { white-space: nowrap; flex-shrink: 0; }
.topbar__brand .topbar__maker { color: inherit; }
@media (max-width: 480px) {
  .topbar { gap: 0.4rem; }
  .topbar__brand { font-size: 1rem; }
  /* スマホでは「Todo」だけにして、同期の表示（オフライン・未送信）に幅を回します */
  .topbar__brand .topbar__maker { display: none; }
  .topbar .btn--text { font-size: 0.85rem; padding-inline: 0.3rem; }
}
.sync[data-state="offline"], .sync[data-state="pending"] { color: var(--warn); }
.sync[data-state="error"] { color: var(--alert); }

.nav { grid-area: nav; border-right: 1px solid var(--border); padding: 1rem 0.75rem; display: flex; flex-direction: column; gap: 0.25rem; }
.nav ul { list-style: none; padding: 0; display: grid; gap: 2px; }
.nav__heading { font-size: 0.75rem; color: var(--text-muted); margin: 1rem 0.5rem 0.25rem; }
.nav__item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 0;
  background: transparent;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
}
.nav__item:hover { background: var(--bg-subtle); }
.nav__item[aria-current="page"] { background: var(--accent-light); font-weight: 600; }
.nav__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav__count { font-size: 0.8rem; color: var(--text-muted); }
.nav__add { margin-top: 0.25rem; }
.nav__add input { border-style: dashed; background: transparent; min-height: 2.4rem; }

.main { grid-area: main; padding: 1.25rem clamp(16px, 3vw, 2.5rem) 4rem; max-width: 820px; width: 100%; }
.main__head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.main__title { font-size: 1.4rem; }

.toolbar { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.toolbar select { width: auto; }

.quick-add { margin-bottom: 0.75rem; }
.quick-add input { border-color: var(--accent); min-height: 3rem; }

/* ---------- Todo の一覧 ---------- */

.todos { list-style: none; padding: 0; display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.todos:empty { display: none; }
.todo { display: flex; align-items: flex-start; background: var(--surface); }
.todo__check {
  flex: none;
  width: 3rem;
  align-self: stretch;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: start center;
  padding-top: 0.85rem;
}
.todo__check::before {
  content: "";
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
}
.todo__check[aria-checked="true"]::before {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='white' stroke-width='2'/%3E%3C/svg%3E") center / 80% no-repeat;
  border-color: var(--accent);
}
.todo__body {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.75rem 1rem 0.75rem 0;
  cursor: pointer;
  display: grid;
  gap: 0.25rem;
}
.todo__title { overflow-wrap: anywhere; }
.todo--done .todo__title { color: var(--text-muted); text-decoration: line-through; }
.todo__meta { display: flex; flex-wrap: wrap; gap: 0.35rem 0.75rem; font-size: 0.8rem; color: var(--text-muted); align-items: center; }
.badge { border-radius: 999px; padding: 0 0.5rem; font-size: 0.75rem; border: 1px solid currentColor; }
.badge--p1 { color: var(--text-muted); }
.badge--p2 { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.badge--p3 { color: var(--alert); background: var(--alert-bg); border-color: transparent; font-weight: 600; }
.due--over { color: var(--alert); font-weight: 600; }
.list-tag { display: inline-flex; gap: 0.3rem; align-items: center; }
.tag { color: var(--accent); border: 1px solid var(--accent-light); border-radius: 4px; padding: 0 0.4rem; }
.has-note::before { content: "✎ "; }
.empty { color: var(--text-muted); padding: 2rem 0; text-align: center; }

/* ---------- 編集の画面 ---------- */

.sheet {
  /* 冒頭の * { margin: 0 } で中央寄せが消えるので、ここで戻します */
  margin: auto;
  border: 0;
  border-radius: 12px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.35); }
.sheet form { display: grid; gap: 1rem; padding: 1.25rem; }
.sheet__meta { font-size: 0.75rem; color: var(--text-muted); }
.sheet__actions { display: flex; gap: 0.5rem; align-items: center; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.segmented__item { position: relative; text-align: center; cursor: pointer; }
.segmented__item + .segmented__item { border-left: 1px solid var(--border-strong); }
.segmented__item input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented__item span { display: block; padding: 0.5rem 0; }
.segmented__item input:checked + span { background: var(--accent); color: #fff; font-weight: 600; }
.segmented__item input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }

.swatches { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.swatch { position: relative; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.swatch .dot { display: block; outline: 2px solid transparent; outline-offset: 2px; }
.swatch input:checked + .dot { outline-color: var(--text); }
.swatch input:focus-visible + .dot { outline-color: var(--focus); }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  max-width: calc(100vw - 32px);
  z-index: 20;
}

/* ---------- ドラッグで移す ---------- */

/* 長押しでつかむので、文字の選択やリンクのメニューが出ないようにします */
.todo__body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.todo--dragging { opacity: 0.4; }
body.is-dragging { cursor: grabbing; -webkit-user-select: none; user-select: none; }
.drag-ghost {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  transform: translate(-50%, -140%);
  max-width: min(70vw, 320px);
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--accent);
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.18);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9rem;
}
.drop-tray {
  position: fixed;
  z-index: 25;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100vw, 720px);
  max-height: 50dvh;
  overflow: auto;
  display: grid;
  gap: 0.6rem;
  padding: 0.9rem 16px max(0.9rem, env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -6px 24px rgb(0 0 0 / 0.12);
}
.drop-tray__heading { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.drop-tray__zones { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.drop {
  min-height: 2.6rem;
  min-width: 4.5rem;
  display: grid;
  place-items: center;
  padding: 0 0.9rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  font-size: 0.9rem;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drop--same { opacity: 0.35; }
.drop.is-over, .nav__item.is-over { background: var(--accent-light); outline: 2px solid var(--accent); outline-offset: -2px; border-color: transparent; }
.toast { display: flex; align-items: center; gap: 0.75rem; }
.toast__action { border: 0; background: transparent; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0.2rem; white-space: nowrap; }

/* ---------- スマホ ---------- */

@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; grid-template-areas: "top" "nav" "main"; }
  .nav {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 0.5rem 16px;
    gap: 0.25rem;
    scrollbar-width: none;
  }
  .nav ul { display: flex; gap: 0.25rem; }
  .nav__heading { display: none; }
  .nav__item { padding: 0.35rem 0.75rem; border: 1px solid var(--border); border-radius: 999px; white-space: nowrap; }
  .nav__label { overflow: visible; }
  .nav__add { margin: 0; flex: none; order: 1; } /* タグを先に、リストの追加は最後に */
  .nav__add input { width: 9rem; min-height: 2.2rem; border-radius: 999px; }
  .main { padding-inline: 16px; }
  .field-row { grid-template-columns: 1fr; }
  .sheet { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: 14px 14px 0 0; }
  .sheet form { padding-bottom: max(1.25rem, env(safe-area-inset-bottom)); }
  /* iPhone で入力欄を押したときに画面が拡大されないよう、16px 以上にします */
  input, select, textarea { font-size: 16px; }
}
