:root {
  --ink: #1c2421;
  --muted: #5e6a64;
  --paper: #f4efe6;
  --panel: #fffdf8;
  --line: #e3d9c8;
  --green: #0f5c4c;
  --green-deep: #143f36;
  --rust: #b42318;
  --gold: #f3d56a;
  --shadow: 0 10px 30px rgba(28, 36, 33, 0.06);
  font-family: "Yu Gothic UI", "Hiragino Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
/* hidden 属性は、display を指定したクラスより必ず優先する */
[hidden] { display: none !important; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.brand {
  margin: 0;
  font-family: "Palatino Linotype", "Yu Mincho", serif;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.brand span { color: #d7efe4; font-weight: 600; }

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--green-deep);
  color: #f7f3ea;
}
.tabs { display: flex; gap: 6px; }
.tab, .text-btn, .ghost, .primary {
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  padding: 6px 12px;
}
.tab.is-on { background: #f4efe6; color: var(--green-deep); }
.me { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.me form { margin: 0; }
.text-btn { border-color: rgba(255,255,255,.35); }

.demo-banner {
  margin: 0;
  padding: 8px 16px;
  background: var(--gold);
  color: #3d3208;
  font-weight: 700;
}
.flash {
  margin: 8px 16px 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: #e7f6ef;
}
.flash.is-error, .login-card .flash { background: #fde8e6; color: var(--rust); }

#app { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-height: 0; }
.view[hidden] { display: none; }

.line-view {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  min-height: 0;
}

.threads, #talk, #card, .customer-detail {
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
#card { border-right: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; }
#talk { display: flex; flex-direction: column; }
.threads { display: flex; flex-direction: column; }

.talk-bar h2, .card-bar h2, .detail-bar h2 {
  margin: 0;
  font-size: 16px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tools, .talk-bar, .card-bar, .detail-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}
.tools { flex-wrap: wrap; }
.tools input, .search {
  flex: 1;
  min-width: 140px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}
.check { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.thread-list, #bubbles, #card-body, .customer-detail, .table-wrap { overflow: auto; }
.thread-list { flex: 1; }

.thread {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 8px;
}
.thread.is-active { background: #e7f3ee; }
.thread.is-unread .title { font-weight: 700; }
.thread-main { min-width: 0; }
.title-row, .meta, .card-actions, .chips { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview, .muted, .meta, .note { color: var(--muted); font-size: 12px; }
.dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--rust); flex: none;
}
.badge {
  font-size: 11px;
  border-radius: 999px;
  padding: 1px 7px;
  background: #efe7d6;
}
.badge-blocked { background: #f3d6d2; color: var(--rust); }
.badge-registering { background: #d9ebff; color: #18456e; }
.badge-prospect { background: #efe7d6; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #d7ebe3;
}
.avatar-fallback {
  display: grid; place-items: center; font-weight: 700; color: var(--green-deep);
}

#bubbles { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: #f7f4ee; }
.bubble { max-width: min(78%, 460px); padding: 8px 10px; border-radius: 14px; background: #fff; box-shadow: var(--shadow); }
.bubble.out { margin-left: auto; background: #e5f4ee; }
.bubble.failed { outline: 2px solid var(--rust); }
.body { margin: 0; white-space: pre-wrap; word-break: break-word; }
.sticker, .photo { display: block; border-radius: 8px; }
.sticker { width: 120px; }
.photo { max-width: 220px; }
.photo-link { display: inline-block; max-width: 220px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; font-size: 12px; background: #fff; }
.read { margin: 4px 0 0; text-align: right; color: var(--green); font-size: 12px; }
.bad { color: var(--rust); font-weight: 700; }
.meta { margin: 6px 0 0; }

.reply { border-top: 1px solid var(--line); padding: 10px; background: var(--panel); }
.reply textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  resize: vertical;
  min-height: 72px;
}
.reply-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.reply-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  background: #fff;
}
.reply-preview .attach-size { font-size: 12px; color: var(--muted); white-space: nowrap; }
.file-link { color: var(--green-deep); font-weight: 700; word-break: break-word; }
.reply-preview .attach-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
}
.reply-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.attach-btn { padding: 8px 12px; }
.primary { background: var(--green); color: #fff; border-radius: 999px; padding: 8px 16px; }
.ghost { border-color: var(--line); background: #fff; border-radius: 999px; }
.note { margin: 6px 0 0; }
.warn { color: var(--rust); font-size: 13px; }

#card-body, .customer-detail { padding: 12px; }
.fact { margin: 0 0 8px; }
.fact b { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.card-actions { margin: 10px 0; }
.field { display: block; margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.history { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.link-hit { display: block; width: 100%; text-align: left; margin-top: 6px; }

.customer-view { display: grid; grid-template-columns: minmax(0, 1fr) 380px; min-height: 0; }
.table-wrap { min-height: 0; }
.toolbar { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 14px; }
th { font-size: 12px; color: var(--muted); background: #fbf8f2; position: sticky; top: 0; }
tr.is-active td { background: #e7f3ee; }
tbody tr { cursor: pointer; }
.customer-detail { border-right: 0; border-left: 1px solid var(--line); }

.login-page { display: grid; place-items: center; }
.login-card {
  width: min(420px, calc(100% - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.login-card .brand { color: var(--green-deep); font-size: 28px; }
.login-card .brand span { color: var(--green); }
.login-card h1 { font-size: 18px; margin: 8px 0 16px; }
.login-card label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.login-card input {
  display: block; width: 100%; margin-top: 4px; padding: 10px;
  border: 1px solid var(--line); border-radius: 8px;
}
.login-card button[type="submit"] {
  width: 100%; border: 0; border-radius: 999px; padding: 10px;
  background: var(--green); color: white;
}

.empty { color: var(--muted); padding: 16px; }

.reply textarea:disabled, .reply button:disabled { opacity: 0.55; cursor: not-allowed; }
.auto-view { overflow: auto; min-height: 0; }
.auto-form {
  margin: 12px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  max-width: 720px;
}
.auto-form textarea { min-height: 140px; }
.auto-preview { display: flex; flex-direction: column; gap: 8px; }
.auto-bubble {
  white-space: pre-wrap;
  background: #f7f3ea;
  border-radius: 8px;
  padding: 10px;
}
.auto-bubble .chips { margin-top: 8px; }
.auto-trigger { white-space: pre-wrap; color: var(--muted); }
.menu-view {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 0;
  overflow: auto;
}
.menu-list, .menu-main { min-height: 0; }
.menu-list {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.menu-item, .menu-pick {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 8px;
  color: inherit;
}
.menu-item.is-on, .menu-pick.is-on { outline: 2px solid var(--green); }
.menu-now {
  display: inline-block;
  background: var(--green);
  color: #fff;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
}
.menu-picker-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 12px 8px; align-items: flex-end; }
.menu-pick { width: 112px; }
.menu-shape { position: relative; width: 100%; background: #e7efe4; }
.menu-shape.is-large, .menu-canvas.is-large { aspect-ratio: 2500 / 1686; }
.menu-shape.is-small, .menu-canvas.is-small { aspect-ratio: 2500 / 843; }
.menu-bit, .menu-cell {
  position: absolute;
  box-sizing: border-box;
  border: 1px solid #1f3d32;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.menu-bit { font-size: 10px; background: rgba(255, 253, 248, 0.8); }
.menu-shape-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 8px;
}
.menu-toolbar { align-items: flex-end; }
.menu-toolbar .field { margin: 0; min-width: 180px; }
.menu-canvas-wrap { max-width: 720px; margin: 0 12px 12px; }
.menu-canvas {
  position: relative;
  width: 100%;
  background: #d5e4d8 center / cover no-repeat;
  border-radius: 12px;
  overflow: hidden;
}
.menu-cell-name { font-size: 12px; text-align: center; }
.menu-cell-actions { display: flex; gap: 8px; margin-top: 12px; }
.menu-cell-pop {
  position: fixed;
  z-index: 31;
  width: 420px;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(28, 36, 33, 0.18);
  overflow: hidden;
}
.menu-cell-pop[hidden] { display: none !important; }
.menu-cell-pop-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}
.menu-cell-pop-foot {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
}
.menu-cell-pop-foot .menu-cell-actions { margin: 0; }
@media (min-width: 861px) {
  #menu-editor-slot { display: none; }
}
.menu-cell {
  flex-direction: column;
  gap: 2px;
  background: rgba(255, 253, 248, 0.78);
  color: inherit;
  border-radius: 0;
  padding: 4px;
}
.menu-cell.is-on { outline: 3px solid var(--green); z-index: 1; }
.menu-yet, .menu-ok {
  position: absolute;
  top: 4px;
  right: 4px;
  font-style: normal;
  font-size: 11px;
  border-radius: 999px;
  padding: 1px 6px;
  color: #fff;
}
.menu-yet { background: var(--rust); }
.menu-ok { background: var(--green); }
.menu-yet-text { color: var(--rust); font-weight: 700; }
.menu-ok-text { color: var(--green); font-weight: 700; }
.menu-editor, .menu-image {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.menu-image { margin: 0 12px 16px; }
.menu-main h2 { margin: 8px 12px; font-size: 16px; }
.demo-view {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(280px, 420px);
  gap: 16px;
  padding: 16px;
  align-items: start;
  justify-content: center;
}
.demo-controls, .phone {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}
.phone {
  width: min(100%, 380px);
  min-height: 560px;
  display: flex;
  flex-direction: column;
  background: #6b8f71;
  border-color: #24362c;
  justify-self: center;
}
.phone-top {
  background: #1f3d32;
  color: #f7f3ea;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
}
.phone-log {
  flex: 1;
  overflow: auto;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 360px;
}
.phone-log .bubble.out { margin-left: 0; margin-right: auto; background: #fff; }
.phone-log .bubble.in { margin-left: auto; background: #d8f5c8; }
.chip-btn { background: #fff; cursor: pointer; }
#demo-replies { margin-top: 8px; }

@media (max-width: 860px) {
  .top { flex-wrap: wrap; }
  .me { width: 100%; justify-content: flex-end; }
  .line-view, .customer-view { display: block; }
  .line-view #talk, .line-view #card, .customer-view .customer-detail { display: none; }
  .line-view[data-mode="talk"] .threads, .line-view[data-mode="card"] .threads { display: none; }
  .line-view[data-mode="talk"] #talk { display: flex; min-height: calc(100dvh - 120px); }
  .line-view[data-mode="card"] #card { display: flex; min-height: calc(100dvh - 120px); }
  .customer-view[data-mode="detail"] .customer-list { display: none; }
  .customer-view[data-mode="detail"] .customer-detail { display: block; min-height: calc(100dvh - 120px); }
  .customer-view[data-mode="list"] .customer-detail { display: none; }
  .demo-view { display: block; }
  .menu-view, .menu-board { display: block; }
  .menu-editor { margin-top: 12px; }
  .phone { width: 100%; min-height: 480px; margin-top: 12px; }
  .back { display: inline-flex; }
  #card-toggle { display: none; }
}
@media (min-width: 861px) {
  .back, #open-card { display: none; }
  /* PCではページ全体をスクロールさせず、ヘッダーを固定して各パネルの中だけスクロールする */
  body:not(.login-page) { height: 100dvh; overflow: hidden; }
  .line-view, .customer-view { grid-template-rows: minmax(0, 1fr); }
  .customer-list { display: flex; flex-direction: column; min-height: 0; }
  .customer-list .table-wrap { flex: 1; }
  #card-body { flex: 1; min-height: 0; }
  .demo-view { overflow: auto; }
  /* 隠した時も「開く」ボタンが押せるよう、細い列として残す */
  .line-view.card-collapsed { grid-template-columns: 300px minmax(0, 1fr) 64px; }
  .line-view.card-collapsed #card-body,
  .line-view.card-collapsed .card-bar h2 { display: none; }
  .line-view.card-collapsed .card-bar { justify-content: center; padding: 10px 4px; }
}

/* 顧客一覧：電話番号と日付は途中で折り返さない */
#customer-table td:nth-child(4),
#customer-table td:nth-child(6),
#customer-table th:nth-child(6) { white-space: nowrap; }

/* 顧客タブ右側の詳細の折りたたみ（PC幅のみ） */
.detail-toggle-bar { display: flex; justify-content: flex-end; }
@media (min-width: 861px) {
  .customer-view.detail-collapsed { grid-template-columns: minmax(0, 1fr) 64px; }
  .customer-view.detail-collapsed #customer-detail-body { display: none; }
  .customer-view.detail-collapsed .detail-toggle-bar { justify-content: center; }
}
@media (max-width: 860px) {
  .detail-toggle-bar { display: none; }
  .chat-pop, .menu-cell-pop { display: none !important; }
}

.chat-pop {
  position: fixed;
  z-index: 30;
  width: 380px;
  height: 520px;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(28, 36, 33, 0.18);
  overflow: hidden;
}
.chat-pop[hidden] { display: none !important; }
.chat-pop-bar, .menu-cell-pop-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.chat-pop-bar:active, .menu-cell-pop-bar:active { cursor: grabbing; }
.chat-pop-bar h2, .menu-cell-pop-bar h2 {
  margin: 0;
  flex: 1 1 120px;
  min-width: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-pop-bar .ghost, .menu-cell-pop-bar .ghost {
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  touch-action: auto;
}
#chat-pop-bubbles {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f7f4ee;
}
.chat-pop .reply textarea { min-height: 64px; }
#customer-table th { white-space: nowrap; }
