/* QOLiA チャット — LINE公式アプリ風モバイルUI */

:root {
  --green: #06c755;
  --green-dark: #05a847;
  --talk-bg: #8cabd9;
  --ink: #111318;
  --ink-2: #5b616e;
  --ink-3: #9aa0ab;
  --line: #e8eaee;
  --bg: #ffffff;
  --danger: #eb4d3d;
  --warn: #f0a020;
  --sab: env(safe-area-inset-bottom, 0px);
  --sat: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  color: var(--ink);
  background: #d7dde6;
  overscroll-behavior-y: none;
  font-size: 15px;
  line-height: 1.5;
}

#app { max-width: 560px; margin: 0 auto; height: 100%; background: var(--bg); box-shadow: 0 0 24px rgba(0,0,0,.08); }
@media (min-width: 561px) { #app { border-left: 1px solid #c9d0da; border-right: 1px solid #c9d0da; } }

.view { height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
[hidden] { display: none !important; }

/* ---------- 共通部品 ---------- */

.appbar {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  min-height: 52px;
  padding: calc(6px + var(--sat)) 12px 6px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 5;
}
.appbar-title { font-size: 19px; font-weight: 700; margin: 0; flex: 1; }
.appbar-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  border: 0; background: none; color: var(--ink);
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; flex: none;
}
.icon-btn:active { background: #f0f1f4; }

.seg { display: flex; background: #f0f1f4; border-radius: 999px; padding: 3px; }
.seg-btn {
  border: 0; background: none; border-radius: 999px;
  font-size: 13px; padding: 5px 12px; color: var(--ink-2);
  cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.seg-btn.is-active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg-badge {
  background: var(--green); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: 999px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center;
}

.net-banner {
  flex: none; background: #fff4e5; color: #8a5300;
  font-size: 12px; text-align: center; padding: 5px 8px;
  border-bottom: 1px solid #f5dcb8;
}

.avatar {
  position: relative;
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  background: #cfd6e2; color: #fff; font-weight: 700; font-size: 19px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; user-select: none;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-sm { width: 34px; height: 34px; font-size: 14px; }

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid #e3e6eb; border-top-color: var(--green);
  animation: spin .8s linear infinite; margin: 14px auto 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- スプラッシュ ---------- */
.splash { margin: auto; text-align: center; }
.splash-logo { width: 84px; height: 84px; border-radius: 22px; }

/* ---------- ログイン ---------- */
.login-wrap { margin: auto; width: min(320px, 84vw); text-align: center; padding-bottom: 12vh; }
.login-logo { width: 88px; height: 88px; border-radius: 24px; box-shadow: 0 6px 18px rgba(6,199,85,.28); }
.login-title { font-size: 22px; margin: 18px 0 2px; }
.login-sub { color: var(--ink-3); font-size: 13px; margin: 0 0 26px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-password {
  font-size: 16px; padding: 13px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: #f7f8fa; outline: none;
}
#login-password:focus { border-color: var(--green); background: #fff; }
.login-error { color: var(--danger); font-size: 13px; margin: 0; }
.btn-primary {
  border: 0; background: var(--green); color: #fff; font-size: 16px; font-weight: 700;
  padding: 13px; border-radius: 12px; cursor: pointer;
}
.btn-primary:active { background: var(--green-dark); }
.btn-primary:disabled { opacity: .55; }
.login-note { color: var(--ink-3); font-size: 12px; margin-top: 30px; }

/* ---------- 会話リスト ---------- */
.chat-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--sab); }
.chat-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; cursor: pointer; background: #fff;
}
.chat-row:active { background: #f4f5f7; }
.chat-row + .chat-row { border-top: 1px solid #f2f3f6; }
.chat-row-main { flex: 1; min-width: 0; }
.chat-row-name {
  font-size: 15.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-row.is-unread .chat-row-name { font-weight: 700; }
.chat-row-preview {
  color: var(--ink-3); font-size: 13px; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-row.is-unread .chat-row-preview { color: var(--ink-2); }
.chat-row-side { flex: none; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.chat-row-time { color: var(--ink-3); font-size: 11.5px; }
.unread-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--green); }
.status-tag { font-size: 10px; border-radius: 4px; padding: 1px 5px; color: #fff; }
.status-tag.st-in_progress { background: var(--warn); }
.chat-empty { text-align: center; color: var(--ink-3); padding: 64px 24px; font-size: 14px; }

/* ---------- トーク ---------- */
.talk-appbar { padding-left: 6px; gap: 6px; }
.talk-head-main { flex: 1; min-width: 0; }
.talk-name { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status-pill {
  flex: none; border: 0; cursor: pointer;
  font-size: 12px; font-weight: 700; color: #fff;
  padding: 5px 11px; border-radius: 999px;
}
.status-pill.st-unread { background: var(--danger); }
.status-pill.st-in_progress { background: var(--warn); }
.status-pill.st-resolved { background: #9aa0ab; }

.talk-scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--talk-bg);
  overflow-anchor: none; /* 追従スクロールは自前制御（ネイティブアンカリングと競合するため） */
}
.talk-messages { padding: 10px 12px 14px; display: flex; flex-direction: column; }

.date-sep { align-self: center; margin: 12px 0 8px; }
.date-sep span {
  background: rgba(20, 35, 70, .22); color: #fff; font-size: 11.5px;
  padding: 3px 12px; border-radius: 999px;
}

.msg-row { display: flex; align-items: flex-end; gap: 6px; margin-top: 3px; }
.msg-row.grp { margin-top: 10px; }
.msg-row.out { flex-direction: row-reverse; }
.msg-avatar-slot { width: 34px; flex: none; align-self: flex-start; }

.bubble {
  max-width: 74%; padding: 8px 12px; border-radius: 18px;
  font-size: 15px; line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
}
.msg-row.in .bubble { background: #fff; color: var(--ink); border-top-left-radius: 6px; }
.msg-row.out .bubble { background: var(--green); color: #fff; border-top-right-radius: 6px; }
.bubble a { color: #1465c8; text-decoration: underline; }
.msg-row.out .bubble a { color: #eaffe9; }

.bubble.media { padding: 0; background: none !important; border-radius: 14px; overflow: hidden; }
.bubble.media img { display: block; max-width: min(230px, 62vw); max-height: 280px; border-radius: 14px; }
.bubble.sticker { padding: 0; background: none !important; }
.bubble.sticker img { display: block; width: 130px; height: auto; }
.bubble.chip {
  background: rgba(255,255,255,.82); color: var(--ink-2); font-size: 13px;
}
.msg-row.out .bubble.chip { background: rgba(255,255,255,.82); color: var(--ink-2); }

.msg-meta {
  flex: none; font-size: 10px; color: rgba(255,255,255,.92);
  text-shadow: 0 1px 2px rgba(30,50,90,.25);
  display: flex; flex-direction: column; align-items: flex-start; line-height: 1.35;
}
.msg-row.out .msg-meta { align-items: flex-end; }
.msg-state { font-size: 9.5px; opacity: .95; }

.msg-row.pending .bubble { opacity: .62; }

/* ---------- 入力欄 ---------- */
.composer {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + var(--sab));
  background: #fff; border-top: 1px solid var(--line);
}
#composer-input {
  flex: 1; resize: none; border: 0; outline: none;
  background: #f2f3f6; border-radius: 18px;
  font: inherit; font-size: 16px; line-height: 1.4;
  padding: 9px 14px; max-height: 118px; overflow-y: hidden;
}
#send-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: var(--green); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
#send-btn:disabled { background: #cfd3da; }
#send-btn svg { margin-left: -2px; }

/* ---------- トースト / シート ---------- */
.toast {
  position: fixed; left: 50%; top: calc(14px + var(--sat)); transform: translateX(-50%);
  background: rgba(17, 19, 24, .92); color: #fff; font-size: 13.5px;
  padding: 10px 18px; border-radius: 999px; z-index: 60;
  max-width: 86vw; text-align: center;
}

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: min(560px, 100%); background: #f4f5f7;
  border-radius: 16px 16px 0 0; padding: 14px 12px calc(12px + var(--sab));
  animation: sheet-in .18s ease-out;
}
@keyframes sheet-in { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-title { text-align: center; color: var(--ink-2); font-size: 13px; padding: 2px 0 10px; }
.sheet-actions { display: flex; flex-direction: column; gap: 1px; border-radius: 12px; overflow: hidden; }
.sheet-btn {
  border: 0; background: #fff; font-size: 16px; padding: 14px; cursor: pointer; color: var(--ink);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.sheet-btn:active { background: #ececf0; }
.sheet-btn .dot { width: 10px; height: 10px; border-radius: 50%; }
.sheet-btn.is-current { font-weight: 700; }
.sheet-btn.danger { color: var(--danger); }
.sheet-note { text-align: center; color: var(--ink-3); font-size: 12px; padding-top: 10px; }
.sheet-cancel {
  width: 100%; margin-top: 10px; border: 0; background: #fff; border-radius: 12px;
  font-size: 16px; font-weight: 700; padding: 14px; cursor: pointer; color: var(--ink);
}
