/* =========================================================
   へやナビ スタイル
   ========================================================= */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #2b2a27;
  --muted: #77746c;
  --line: #e2ded4;
  --accent: #2f7a68;
  --accent-soft: #e3f1ec;
  --accent-text: #ffffff;
  --danger: #c0473b;
  --warn: #c98a1b;
  --radius: 12px;
  --tabbar-h: 64px;
  --font: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 1.05rem; }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: .85rem; }

/* ---------- 入力部品 ---------- */
label { display: block; font-size: .9rem; color: var(--muted); margin-top: 12px; }
input[type="email"], input[type="password"], input[type="text"],
input[type="number"], input[type="search"], select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px; /* iPhoneで勝手にズームしない最小サイズ */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
textarea { resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  font: inherit;
  font-size: .95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm { padding: 6px 12px; font-size: .85rem; }
.btn.block { width: 100%; margin-top: 16px; }

.form-msg { min-height: 1.2em; margin: 8px 0 0; font-size: .85rem; color: var(--accent); }
.form-msg.error { color: var(--danger); }

/* ---------- 認証画面 ---------- */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px;
}
.logo { font-size: 1.8rem; color: var(--accent); letter-spacing: .05em; }
.logo.small { font-size: 1.15rem; font-weight: 700; }
.auth-lead { color: var(--muted); font-size: .9rem; margin: 8px 0 20px; }
.seg { display: flex; background: var(--bg); border-radius: 8px; padding: 4px; }
.seg-btn {
  flex: 1; padding: 8px; font: inherit; font-size: .9rem;
  background: transparent; border: none; border-radius: 6px; cursor: pointer; color: var(--muted);
}
.seg-btn.active { background: var(--surface); color: var(--text); font-weight: 600; }

/* ---------- 共通レイアウト ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.main {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card.empty { text-align: center; color: var(--muted); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.head-actions { display: flex; gap: 6px; }
details.card summary { cursor: pointer; font-weight: 600; }

.room-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.room-bar select { margin-top: 0; flex: 1; min-width: 0; }

/* ---------- 見取り図 ---------- */
.plan { width: 100%; }
:is(.plan, .plan-snapshot) svg { width: 100%; height: auto; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
:is(.plan, .plan-snapshot) .room-floor { fill: #faf8f3; stroke: #8a857a; }
:is(.plan, .plan-snapshot) .grid { stroke: #ece8de; }
:is(.plan, .plan-snapshot) .furn rect { stroke: #2f7a68; cursor: grab; }
:is(.plan, .plan-snapshot) .furn.storage rect { fill: #d6ebe4; }
:is(.plan, .plan-snapshot) .furn.other rect { fill: #ece6da; stroke: #9a8f7a; }
:is(.plan, .plan-snapshot) .furn.selected rect { stroke: #c98a1b; }
:is(.plan, .plan-snapshot) .furn.dragging rect { cursor: grabbing; opacity: .85; }
:is(.plan, .plan-snapshot) text { fill: #2b2a27; pointer-events: none; }
:is(.plan, .plan-snapshot) .dim { fill: #77746c; }

/* ---------- 家具リスト ---------- */
.furn-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 10px; }
.furn-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.furn-name { font-weight: 600; }
.furn-size { color: var(--muted); font-size: .8rem; }
.meter { height: 6px; background: var(--bg); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); }
.meter.warn span { background: var(--warn); }
.meter.over span { background: var(--danger); }
.meter-label { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.item-list { list-style: none; padding: 0; margin: 8px 0 0; }
.item-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 0; border-top: 1px dashed var(--line); font-size: .92rem;
}
.item-list li:first-child { border-top: none; }
.item-meta { color: var(--muted); font-size: .78rem; }
.item-actions { display: flex; gap: 4px; flex-shrink: 0; }
.empty-line { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }

.search-results { list-style: none; padding: 0; margin: 8px 0 0; }
.search-results li { padding: 8px 0; border-top: 1px solid var(--line); }
.search-results li:first-child { border-top: none; }
.search-results .where { color: var(--accent); font-weight: 600; }
.simple-list { padding-left: 1.2em; margin: 8px 0 0; }
.simple-list li { margin: 4px 0; }

/* ---------- チャット ---------- */
.chat-log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: .95rem;
}
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.system { align-self: center; background: transparent; color: var(--muted); font-size: .85rem; }
.bubble img, .bubble .plan-snapshot { display: block; width: 100%; max-width: 420px; border-radius: 8px; margin-top: 8px; }
.bubble .caption { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  padding: 6px 12px; font: inherit; font-size: .82rem;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid transparent; border-radius: 999px; cursor: pointer;
}
.chat-form {
  position: sticky;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  background: var(--bg);
  padding: 8px 0;
}
.check { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; }
.chat-input-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-input-row textarea { margin-top: 0; flex: 1; }

/* ---------- カメラ ---------- */
.camera-buttons { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.camera-buttons .btn { flex: 1; }
.camera-preview { width: 100%; max-height: 360px; object-fit: contain; margin-top: 12px; border-radius: 8px; background: var(--bg); }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.result-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.result-actions .btn { flex: 1; }

/* ---------- タブバー ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font: inherit; font-size: .75rem; color: var(--muted);
  background: none; border: none; cursor: pointer;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.tab.active { color: var(--accent); font-weight: 600; }

/* ---------- ダイアログ ---------- */
dialog {
  width: min(92vw, 460px);
  max-height: 88vh;
  padding: 20px;
  border: none;
  border-radius: 16px;
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.spacer { flex: 1; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* ---------- 通知・読み込み ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: 90vw;
  padding: 10px 16px;
  background: #2b2a27; color: #fff;
  border-radius: 8px; font-size: .9rem;
}
.toast.error { background: var(--danger); }
.loading {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(246, 244, 239, .8);
}
.loading p { color: var(--muted); font-size: .9rem; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 720px) {
  .main { padding-top: 20px; }
  .bubble { max-width: 75%; }
}
