:root {
  --green: #06c755;
  --green-dark: #05a647;
  --bg: #8cabd9;
  --bg-grad: linear-gradient(180deg, #9db8e0 0%, #87a6d6 100%);
  --kitchen: #ff8a3d;
  --store: #3d8bff;
  --text: #1f2329;
  --muted: #6b7280;
  --bubble-me: #8de055;
  --bubble-other: #ffffff;
  --header-h: 60px;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--text);
  background: #f2f4f7;
  overscroll-behavior: none;
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Location screen ---------- */
.location-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #06c755 0%, #04a64a 55%, #038a3d 100%);
}
.location-card {
  width: 100%; max-width: 400px;
  background: #fff; border-radius: 28px;
  padding: 36px 24px 24px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: pop .35s ease;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
.brand-logo {
  width: 72px; height: 72px; margin: 0 auto 14px;
  border-radius: 22px; background: var(--green); color: #fff;
  font-weight: 800; font-size: 30px; display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(6,199,85,.35);
}
.location-title { margin: 0; font-size: 24px; font-weight: 800; }
.location-sub { margin: 6px 0 22px; color: var(--muted); font-size: 15px; }
.location-options { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.location-option {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 24px 10px; border-radius: 20px;
  border: 2px solid #e5e7eb; background: #fafafa;
  transition: transform .12s, border-color .15s, background .15s, box-shadow .15s;
}
.location-option:hover { border-color: var(--green); background: #f0fdf4; }
.location-option:active { transform: scale(.96); }
.location-option[data-location="kitchen"]:hover { border-color: var(--kitchen); background: #fff7ed; }
.location-option[data-location="store"]:hover { border-color: var(--store); background: #eff6ff; }
.location-emoji { font-size: 44px; line-height: 1; }
.location-name { font-size: 18px; font-weight: 700; }
.location-note { margin: 18px 0 0; font-size: 12px; color: #9ca3af; }

/* ---------- Chat layout ---------- */
.chat-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  max-width: 820px; margin: 0 auto;
  background: var(--bg-grad);
  box-shadow: 0 0 40px rgba(0,0,0,.12);
}
.chat-header {
  flex: none;
  height: calc(var(--header-h) + var(--safe-t));
  padding: var(--safe-t) 12px 0 14px;
  display: flex; align-items: center; justify-content: space-between;
  background: #263238; color: #fff;
  z-index: 5;
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-avatar {
  width: 38px; height: 38px; border-radius: 12px; background: var(--green);
  display: grid; place-items: center; font-weight: 800; font-size: 16px; flex: none;
}
.header-title { font-weight: 700; font-size: 17px; }
.connection-status { display: flex; align-items: center; gap: 5px; font-size: 11px; opacity: .85; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #fbbf24; }
.connection-status.online .status-dot { background: #34d399; }
.connection-status.offline .status-dot { background: #f87171; }
.header-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; font-size: 18px;
  background: rgba(255,255,255,.1);
}
.icon-btn:active { background: rgba(255,255,255,.2); }
.me-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  background: rgba(255,255,255,.14); font-size: 14px; font-weight: 700;
}
.me-chip:active { background: rgba(255,255,255,.25); }
.me-chip .chev { opacity: .7; font-size: 11px; }

/* ---------- Notification area (above timeline) ---------- */
.notify-area {
  flex: none; z-index: 4;
  display: flex; flex-direction: column; gap: 6px;
  padding: 0 10px;
  max-height: 40vh; overflow-y: auto;
}
.notify-area:not(:empty) { padding: 8px 10px; background: rgba(38,50,56,.06); }
.notify-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 12px;
  background: #fff; border-radius: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
  border-left: 5px solid var(--green);
  animation: slideDown .28s ease;
  cursor: pointer;
}
.notify-card.kitchen { border-left-color: var(--kitchen); }
.notify-card.store { border-left-color: var(--store); }
.notify-card.mention { background: #fffbeb; }
@keyframes slideDown { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
.notify-icon { font-size: 22px; flex: none; }
.notify-main { flex: 1; min-width: 0; }
.notify-head { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.notify-head b { color: var(--text); font-size: 13px; }
.notify-badge { background: #ef4444; color: #fff; border-radius: 6px; padding: 1px 6px; font-size: 10px; font-weight: 700; }
.notify-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.notify-close {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  color: #9ca3af; font-size: 15px;
}
.notify-close:hover { background: #f3f4f6; }
.notify-clear {
  align-self: flex-end; font-size: 12px; color: #374151;
  background: rgba(255,255,255,.75); padding: 4px 10px; border-radius: 999px;
}

/* ---------- Timeline ---------- */
.timeline {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 10px 10px 14px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.load-more-wrap { text-align: center; margin: 4px 0 10px; }
.load-more {
  font-size: 12px; padding: 6px 14px; border-radius: 999px;
  background: rgba(0,0,0,.18); color: #fff;
}
.date-sep { text-align: center; margin: 14px 0 10px; }
.date-sep span {
  display: inline-block; font-size: 12px; color: #fff;
  background: rgba(0,0,0,.2); padding: 3px 12px; border-radius: 999px;
}
.msg-row { display: flex; align-items: flex-end; gap: 6px; margin: 6px 0; position: relative; }
.msg-row.me { flex-direction: row-reverse; }
.msg-row.flash .bubble { animation: flash 1.4s ease; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 4px #facc15; } 100% { box-shadow: 0 0 0 0 transparent; } }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; align-self: flex-start;
  display: grid; place-items: center; font-size: 19px; color: #fff;
}
.avatar.kitchen { background: var(--kitchen); }
.avatar.store { background: var(--store); }
.msg-col { display: flex; flex-direction: column; max-width: min(76%, 520px); min-width: 0; }
.msg-row.me .msg-col { align-items: flex-end; }
.sender { font-size: 12px; color: #fff; margin: 0 0 3px 4px; text-shadow: 0 1px 2px rgba(0,0,0,.2); font-weight: 600; }
.bubble-line { display: flex; align-items: flex-end; gap: 5px; }
.msg-row.me .bubble-line { flex-direction: row-reverse; }
.bubble {
  position: relative;
  background: var(--bubble-other);
  padding: 9px 13px; border-radius: var(--radius);
  font-size: 15px; line-height: 1.5;
  word-break: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
  cursor: pointer; user-select: text;
  transition: transform .1s;
}
.msg-row:not(.me) .bubble { border-top-left-radius: 6px; }
.msg-row.me .bubble { background: var(--bubble-me); border-top-right-radius: 6px; }
.msg-row.to-me .bubble { box-shadow: 0 0 0 2px #facc15, 0 1px 1px rgba(0,0,0,.06); }
.bubble:active { transform: scale(.985); }
.meta { display: flex; flex-direction: column; font-size: 10.5px; color: rgba(255,255,255,.95); line-height: 1.3; flex: none; text-shadow: 0 1px 1px rgba(0,0,0,.15); padding-bottom: 2px; }
.msg-row.me .meta { align-items: flex-end; }
.meta .pending { color: #fef3c7; }
.meta .failed { color: #fecaca; font-weight: 700; }
.mention-tag {
  display: inline-block; font-weight: 700; font-size: 13px;
  padding: 0 6px; border-radius: 6px; margin-right: 4px;
  background: rgba(61,139,255,.12); color: #1d4ed8;
}
.mention-tag.kitchen { background: rgba(255,138,61,.15); color: #c2410c; }
.quote {
  display: block; margin: -2px -4px 6px; padding: 6px 9px;
  border-left: 3px solid rgba(0,0,0,.25);
  background: rgba(0,0,0,.05); border-radius: 8px;
  font-size: 12.5px; color: #4b5563; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
}
.quote b { color: #374151; margin-right: 4px; }
.reply-btn {
  flex: none; align-self: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,.85); color: #374151; font-size: 14px;
  display: grid; place-items: center;
  opacity: 0; transition: opacity .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.msg-row:hover .reply-btn, .msg-row.show-actions .reply-btn { opacity: 1; }
@media (hover: none) { .reply-btn { opacity: .75; } }
.retry-btn { font-size: 11px; color: #fff; background: #ef4444; border-radius: 999px; padding: 2px 8px; margin-top: 3px; }

.empty-state { text-align: center; color: #fff; margin-top: 18vh; text-shadow: 0 1px 2px rgba(0,0,0,.15); }
.empty-icon { font-size: 52px; margin-bottom: 8px; }

.jump-bottom {
  position: absolute; right: 16px; bottom: calc(150px + var(--safe-b));
  width: 44px; height: 44px; border-radius: 50%;
  background: #fff; color: #374151; font-size: 20px;
  box-shadow: 0 4px 14px rgba(0,0,0,.2); z-index: 6;
  display: grid; place-items: center;
}
.jump-count {
  position: absolute; top: -6px; right: -4px;
  background: var(--green); color: #fff; border-radius: 999px;
  font-size: 11px; font-weight: 700; padding: 1px 6px; min-width: 20px;
}

/* ---------- Composer ---------- */
.composer {
  flex: none; background: #fff;
  padding: 8px 10px calc(8px + var(--safe-b));
  border-top: 1px solid #e5e7eb; z-index: 5;
}
.reply-preview {
  display: flex; align-items: center; gap: 8px;
  background: #f3f4f6; border-radius: 12px; padding: 8px 8px 8px 0; margin-bottom: 8px;
  animation: slideDown .2s ease;
}
.reply-bar { width: 4px; align-self: stretch; background: var(--green); border-radius: 4px; margin-left: 8px; }
.reply-body { flex: 1; min-width: 0; }
.reply-label { font-size: 12px; color: var(--green-dark); font-weight: 700; }
.reply-text { font-size: 13px; color: #4b5563; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-cancel { width: 30px; height: 30px; border-radius: 50%; color: #6b7280; }
.reply-cancel:hover { background: #e5e7eb; }
.mention-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
.mention-row::-webkit-scrollbar { display: none; }
.mention-label { font-size: 12px; color: var(--muted); flex: none; margin-right: 2px; }
.mention-chip {
  flex: none; font-size: 13px; padding: 5px 12px; border-radius: 999px;
  background: #f3f4f6; color: #374151; border: 1.5px solid transparent;
  transition: background .12s, border-color .12s;
}
.mention-chip.active { background: #e8f9ef; border-color: var(--green); color: var(--green-dark); font-weight: 700; }
.mention-chip[data-mention="kitchen"].active { background: #fff3e8; border-color: var(--kitchen); color: #c2410c; }
.mention-chip[data-mention="store"].active { background: #e8f1ff; border-color: var(--store); color: #1d4ed8; }
.composer-form { display: flex; align-items: flex-end; gap: 8px; }
.message-input {
  flex: 1; resize: none; border: none; outline: none;
  background: #f3f4f6; border-radius: 22px;
  padding: 11px 16px; font: inherit; font-size: 16px; line-height: 1.4;
  max-height: 140px; min-height: 44px;
  transition: box-shadow .15s;
}
.message-input:focus { box-shadow: 0 0 0 2px rgba(6,199,85,.35); background: #fff; }
.send-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  background: var(--green); color: #fff;
  display: grid; place-items: center;
  transition: transform .1s, background .15s, opacity .15s;
}
.send-btn:disabled { background: #d1d5db; cursor: default; }
.send-btn:not(:disabled):active { transform: scale(.92); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(76px + var(--safe-t)); transform: translateX(-50%);
  background: rgba(17,24,39,.92); color: #fff; font-size: 14px;
  padding: 10px 16px; border-radius: 12px; z-index: 50; max-width: 90vw;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  animation: slideDown .2s ease;
}

@media (min-width: 821px) {
  body { background: #dfe5ec; }
}
