/* ============================================
   OPC AI — LINE-Style Clean White Theme
   ============================================ */

:root {
  --bg: #F7F8FA;
  --bg-raised: #FFFFFF;
  --bg-surface: #FFFFFF;
  --bg-input: #F0F2F5;
  --bg-chat: #7494A5;
  --border: #E5E5EA;
  --border-hover: rgba(6,199,85,0.35);
  --text: #1A1A1A;
  --text-strong: #000000;
  --muted: #8E8E93;
  --accent: #06C755;
  --accent-hover: #05A849;
  --accent-soft: rgba(6,199,85,0.08);
  --accent-glow: rgba(6,199,85,0.15);
  --ok: #06C755;
  --err: #FF3B30;
  --warn: #FF9500;
  --font: 'Inter', -apple-system, system-ui, 'Helvetica Neue', sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.1);
  --radius: 20px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* === App Layout === */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  margin: 0 auto;
  position: relative;
  background: var(--bg-chat);
}

/* === Header (LINE-style) === */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  background: var(--accent);
  border-bottom: none;
  flex-shrink: 0;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.header-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  color: white;
}

.header-info { flex: 1; min-width: 0; }
.header-name {
  font-size: 16px; font-weight: 700;
  color: #FFFFFF;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-status {
  font-size: 11px; color: rgba(255,255,255,0.75);
  display: flex; align-items: center; gap: 5px;
}
.header-status .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,0.5);
  transition: background 0.3s;
}
.header-status .dot.online { background: #FFFFFF; }

.header-actions { display: flex; gap: 2px; }
.header-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.85);
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.header-btn:hover, .header-btn:active {
  background: rgba(255,255,255,0.15);
  color: #FFFFFF;
}
.header-btn.active {
  background: rgba(255,255,255,0.25);
  color: white;
}

/* === Messages Area === */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-chat);
  background-image:
    radial-gradient(circle at 20% 50%, rgba(255,255,255,0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.04) 0%, transparent 40%);
}
.messages::-webkit-scrollbar { width: 0; }

/* === Message Row (avatar + bubble) === */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msgIn 0.2s ease-out;
}
.msg-row.assistant {
  align-self: flex-start;
  max-width: 82%;
  align-items: flex-end;
}
.msg-row.assistant .msg-avatar {
  align-self: flex-start;
}
.msg-row.user {
  align-self: flex-end;
  max-width: 82%;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  justify-content: flex-end;
  animation: msgIn 0.2s ease-out;
}
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: #E0E0E0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  margin-top: 2px;
}
.msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.msg-row .msg {
  max-width: 100%;
}

/* === Message Bubbles === */
.msg {
  max-width: 75%;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: msgIn 0.2s ease-out;
  position: relative;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  background: var(--accent);
  color: white;
  border-radius: 18px 4px 18px 18px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
  animation: none;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--bg-raised);
  color: var(--text);
  border-radius: 4px 18px 18px 18px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.msg.system {
  align-self: center;
  background: rgba(0,0,0,0.05);
  color: var(--muted);
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 14px;
  max-width: 85%;
}

.msg-time-ext {
  font-size: 10px;
  color: rgba(0,0,0,0.35);
  align-self: flex-end;
  flex-shrink: 0;
  white-space: nowrap;
  margin-bottom: 2px;
}
.msg-row.user .msg-time-ext { color: rgba(0,0,0,0.35); }
.msg.assistant .msg-time { display: none; }
.msg.user .msg-time { display: none; }

/* === Markdown inside messages === */
.msg pre {
  background: rgba(0,0,0,0.06);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 6px 0;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg.user pre { background: rgba(0,0,0,0.15); }
.msg code {
  font-family: var(--mono);
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}
.msg.user code { background: rgba(0,0,0,0.15); }
.msg pre code { background: none; padding: 0; }
.msg a { color: #0B84FF; text-decoration: underline; }
.msg.user a { color: rgba(255,255,255,0.9); }
.msg strong { font-weight: 600; }
.msg ul, .msg ol { padding-left: 18px; margin: 4px 0; }
.msg li { margin: 2px 0; }
.msg table { border-collapse: collapse; margin: 6px 0; width: 100%; font-size: 13px; }
.msg th, .msg td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.msg th { background: var(--bg); font-weight: 600; }
.msg.user th, .msg.user td { border-color: rgba(255,255,255,0.2); }
.msg.user th { background: rgba(0,0,0,0.1); }
.msg blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  margin: 6px 0;
  color: var(--muted);
}
.msg.user blockquote { border-left-color: rgba(255,255,255,0.5); color: rgba(255,255,255,0.8); }
.msg img { max-width: 100%; border-radius: 10px; margin: 6px 0; }

/* Image-only message — no bubble, like LINE */
.msg.img-msg {
  background: transparent !important;
  box-shadow: none !important;
  padding: 2px 0;
}
.msg.img-msg .msg-content img {
  max-width: 220px;
  border-radius: 14px;
  margin: 0;
  display: block;
}
.msg.img-msg .msg-sender { color: var(--muted); }
.msg.img-msg .msg-time { color: rgba(0,0,0,0.35); }
.msg h1, .msg h2, .msg h3 { font-size: 1em; font-weight: 700; margin: 8px 0 4px; color: var(--text-strong); }
.msg.user h1, .msg.user h2, .msg.user h3 { color: white; }
.msg hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.msg.user hr { border-top-color: rgba(255,255,255,0.2); }

/* === Typing Indicator === */
.typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 18px;
  background: var(--bg-raised);
  border-radius: 20px 20px 20px 4px;
  box-shadow: var(--shadow);
  animation: msgIn 0.2s ease-out;
}
.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* === Input Bar (LINE-style) === */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px 8px;
  padding-bottom: calc(6px + var(--safe-bottom));
  background: #F7F7F7;
  border-top: 1px solid #DCDCDC;
  flex-shrink: 0;
}

/* LIFF mode: LINE handles safe area, adjust padding */
.liff-mode .input-bar {
  padding-bottom: 10px;
}
.liff-mode .app {
  height: 100vh;
  height: 100dvh;
}

.input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: #FFFFFF;
  border: 1px solid #DCDCDC;
  border-radius: 20px;
  padding: 4px 12px;
  transition: border-color 0.2s;
  min-height: 38px;
}
.input-wrap:focus-within { border-color: var(--accent); }

.input-wrap textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  min-height: 22px;
  padding: 5px 0;
}
.input-wrap textarea::placeholder { color: #B0B0B0; }

.btn-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  opacity: 0;
  transform: scale(0);
  width: 0;
  overflow: hidden;
}
.btn-send.ready {
  opacity: 1;
  transform: scale(1);
  width: 36px;
  margin-left: 4px;
}
.btn-send:active { transform: scale(0.9); }
.btn-send:disabled { opacity: 0; transform: scale(0); width: 0; }

.btn-attach {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #8E8E93;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.25s;
}
.btn-attach svg {
  width: 24px; height: 24px;
  transition: transform 0.3s ease;
}
.btn-attach.active {
  color: var(--accent);
}
.btn-attach.active svg {
  transform: rotate(45deg);
}

.btn-voice {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #8E8E93;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.btn-voice:hover { color: var(--accent); }
.btn-voice.recording {
  color: var(--err);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,59,48,0.3); }
  50% { box-shadow: 0 0 0 8px rgba(255,59,48,0); }
}

/* === Attach Menu (LINE-style bottom drawer) === */
.attach-menu {
  max-height: 0;
  overflow: hidden;
  background: #F7F7F7;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}
.attach-menu.open {
  max-height: 200px;
}
.attach-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 16px 20px;
}
.attach-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 11px;
  color: #666;
  padding: 8px 4px;
  border-radius: 12px;
  transition: background 0.15s;
}
.attach-item:active {
  background: rgba(0,0,0,0.05);
}
.attach-icon {
  width: 52px; height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

/* === Session Drawer === */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.drawer-overlay.open { opacity: 1; visibility: visible; }

.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(300px, 80vw);
  background: var(--bg-raised);
  z-index: 101;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  box-shadow: var(--shadow-lg);
}
.drawer-overlay.open .drawer { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h3 {
  font-size: 16px; font-weight: 700;
  color: var(--text-strong);
}
.drawer-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s;
}
.drawer-close:hover { background: var(--bg-input); }

.drawer-new {
  margin: 12px 16px;
  padding: 10px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--accent);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: calc(100% - 32px);
}
.drawer-new:hover { background: var(--accent-soft); border-color: var(--accent); }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.session-list::-webkit-scrollbar { width: 0; }

.session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 2px;
}
.session-item:hover { background: var(--bg-input); }
.session-item.active { background: var(--accent-soft); }
.session-icon { font-size: 18px; flex-shrink: 0; }
.session-info { flex: 1; min-width: 0; }
.session-name {
  font-size: 13px; font-weight: 500;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-meta {
  font-size: 11px; color: var(--muted);
  margin-top: 1px;
}

/* === Settings Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.modal-overlay.open { opacity: 1; visibility: visible; }

.modal {
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  background: var(--bg-raised);
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  padding-bottom: var(--safe-bottom);
  box-shadow: var(--shadow-lg);
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 12px;
}
.modal-header h3 {
  font-size: 17px; font-weight: 700;
  color: var(--text-strong);
}
.modal-body { padding: 0 16px 20px; }

.setting-group { margin-bottom: 16px; }
.setting-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 6px;
}
.setting-item-info { flex: 1; }
.setting-item-title { font-size: 14px; color: var(--text); font-weight: 500; }
.setting-item-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Toggle switch */
.toggle {
  width: 44px; height: 24px;
  background: var(--border);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
  flex-shrink: 0;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: '';
  width: 18px; height: 18px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 3px; left: 3px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle.on::after { transform: translateX(20px); }

/* === Welcome Screen === */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  gap: 14px;
  animation: fadeUp 0.5s ease-out;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.welcome-logo {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  color: white;
  box-shadow: 0 6px 24px var(--accent-glow);
}
.welcome h2 {
  font-size: 20px; font-weight: 700;
  color: var(--text-strong);
}
.welcome p {
  font-size: 14px; color: var(--muted);
  max-width: 260px; line-height: 1.5;
}
.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}
.welcome-chip {
  padding: 8px 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  box-shadow: var(--shadow-sm);
}
.welcome-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* === Connection Banner === */
.conn-banner {
  padding: 6px 16px;
  background: var(--err);
  color: white;
  font-size: 12px;
  text-align: center;
  font-weight: 500;
  display: none;
  flex-shrink: 0;
}
.conn-banner.show { display: block; }

/* === Image Viewer === */
.img-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.img-viewer.open { display: flex; }
.img-viewer img { max-width: 95vw; max-height: 95vh; object-fit: contain; border-radius: 8px; }

/* === Login Screen === */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-raised);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s;
}
.login-overlay.hidden { opacity: 0; pointer-events: none; }
.login-card {
  text-align: center;
  padding: 40px 28px;
  max-width: 360px;
  width: 90%;
  animation: fadeUp 0.5s ease-out;
}
.login-logo {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  color: white;
  margin: 0 auto 20px;
  box-shadow: 0 6px 24px var(--accent-glow);
}
.login-card h2 {
  font-size: 22px; font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 4px;
}
.login-card p {
  color: var(--muted); font-size: 14px;
  margin-bottom: 28px;
}
.login-card input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--accent); }
.login-btn {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: white;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.login-btn:hover { background: var(--accent-hover); }
.login-btn:active { transform: scale(0.98); }
.login-error {
  color: var(--err);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
}
.login-hint {
  color: var(--muted);
  font-size: 11px;
  margin-top: 16px;
}

/* === Name Entry Screen === */
.name-entry h2 {
  font-size: 20px;
  margin-bottom: 6px;
}
.name-entry p {
  margin-bottom: 24px;
}
.name-avatar-picker {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.name-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: white;
  box-shadow: 0 6px 24px var(--accent-glow);
}
.name-entry input {
  text-align: center;
  font-size: 18px !important;
  font-weight: 500;
  letter-spacing: 0.3px;
}
.name-entry input::placeholder {
  font-weight: 400;
  font-size: 16px;
}

/* === User name label on messages === */
.msg-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 3px;
  display: block;
}
.msg.user .msg-sender {
  text-align: right;
  color: rgba(255,255,255,0.7);
}

/* === Toast notification === */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%; transform: translateX(-50%);
  background: var(--text-strong);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  z-index: 400;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; }

/* === Desktop === */
@media (min-width: 640px) {
  .app {
    max-width: 640px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
  }
  .chatlist-view {
    max-width: 640px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* ═══════════════════════════════════════════
   Chat List View (LINE-style)
   ═══════════════════════════════════════════ */
.chatlist-view {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #FFFFFF;
  z-index: 500;
  display: none;
  flex-direction: column;
  max-width: 100%;
  margin: 0 auto;
}
.chatlist-view.open {
  display: flex;
}
@media (min-width: 640px) {
  .chatlist-view { max-width: 640px; left: 50%; transform: translateX(-50%); }
}

/* Chat List Header */
.cl-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: #FFFFFF;
  border-bottom: 1px solid #F0F0F0;
}
.cl-title {
  font-size: 22px;
  font-weight: 700;
  color: #1A1A1A;
}
.cl-header-actions { display: flex; gap: 8px; }
.cl-header-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: #F0F2F5;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.cl-header-btn:active { background: #E0E2E5; }

/* Search */
.cl-search {
  padding: 0 16px 10px;
  background: #FFF;
}
.cl-search.hidden { display: none; }
.cl-search input {
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: 20px;
  background: #F0F2F5;
  font-size: 14px;
  outline: none;
  font-family: var(--font);
}

/* Tabs */
.cl-tabs {
  display: flex;
  background: #FFF;
  border-bottom: 1px solid #F0F0F0;
  padding: 0 12px;
}
.cl-tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: #999;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  font-family: var(--font);
}
.cl-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Tab Content */
.cl-tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 64px;
}
.cl-tab-content.active { display: block; }

/* Chat Item */
.cl-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid #F7F7F7;
}
.cl-item:active { background: #F5F5F5; }
.cl-item.pinned { background: #FAFFFE; }

/* Avatar */
.cl-avatar {
  width: 50px; height: 50px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #E0E0E0;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.cl-avatar.ai { background: var(--accent); }
.cl-avatar.group { background: #6C63FF; border-radius: 14px; }
.cl-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Info */
.cl-info { flex: 1; min-width: 0; }
.cl-name {
  font-size: 15px;
  font-weight: 600;
  color: #1A1A1A;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cl-badge-official {
  font-size: 9px;
  background: var(--accent);
  color: white;
  padding: 1px 5px;
  border-radius: 8px;
  font-weight: 700;
}
.cl-last-msg {
  font-size: 13px;
  color: #999;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* Meta (time + badge) */
.cl-meta { text-align: right; flex-shrink: 0; }
.cl-time { font-size: 11px; color: #BBB; }
.cl-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px; height: 20px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  margin-top: 4px;
  padding: 0 6px;
}

/* Section Header */
.cl-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  font-size: 13px;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
}
.cl-add-btn {
  font-size: 12px;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-family: var(--font);
}

/* Empty State */
.cl-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}
.cl-empty-icon { font-size: 48px; margin-bottom: 12px; }
.cl-empty-text { font-size: 16px; font-weight: 600; color: #333; }
.cl-empty-sub { font-size: 13px; color: #999; margin-top: 6px; }
.cl-action-btn {
  margin-top: 20px;
  padding: 10px 24px;
  border: none;
  border-radius: 24px;
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.2s;
}
.cl-action-btn:active { background: var(--accent-hover); }

/* Bottom Tab Bar */
.cl-bottom-tabs {
  display: flex;
  background: #FFF;
  border-top: 1px solid #E5E5E5;
  padding: 4px 0;
  padding-bottom: calc(4px + var(--safe-bottom));
  flex-shrink: 0;
}
.cl-btab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  border: none;
  background: none;
  cursor: pointer;
  color: #999;
  font-family: var(--font);
  transition: color 0.2s;
}
.cl-btab span { font-size: 20px; }
.cl-btab small { font-size: 10px; font-weight: 600; }
.cl-btab.active { color: var(--accent); }

/* ═══ Add Friend / Create Group Modals ═══ */
.af-section { padding: 16px 20px; }
.af-label { font-size: 14px; font-weight: 700; color: #333; margin-bottom: 6px; }
.af-desc { font-size: 12px; color: #999; margin-bottom: 10px; }
.af-link-box {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.af-link-box input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #E0E0E0;
  border-radius: 10px;
  font-size: 12px;
  background: #F9F9F9;
  color: #555;
  font-family: var(--mono);
  outline: none;
}
.af-copy {
  width: 42px;
  border: 1px solid #E0E0E0;
  border-radius: 10px;
  background: #FFF;
  cursor: pointer;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.af-copy:active { background: #F0F0F0; }
.af-share-btns { display: flex; gap: 8px; }
.af-share-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.2s;
}
.af-share-btn:active { opacity: 0.8; }
.af-share-btn.line { background: var(--accent); color: white; }
.af-share-btn.copy { background: #F0F2F5; color: #333; }
.af-divider {
  text-align: center;
  color: #CCC;
  font-size: 12px;
  padding: 4px 0;
  position: relative;
}
.af-divider::before, .af-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 35%;
  height: 1px;
  background: #E0E0E0;
}
.af-divider::before { left: 5%; }
.af-divider::after { right: 5%; }
.af-submit {
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  margin-left: 8px;
}
#afAddByIdForm, #cgCreateForm {
  display: flex;
  gap: 8px;
}
#afAddByIdForm input, #cgCreateForm input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #E0E0E0;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  font-family: var(--font);
}
#afAddByIdForm input:focus, #cgCreateForm input:focus {
  border-color: var(--accent);
}

/* === LIFF Mode (inside LINE app) === */
body.liff-mode .app {
  max-width: 100%;
}
body.liff-mode .header {
  padding-top: 10px; /* No extra safe area needed in LINE */
}
body.liff-mode .cl-header {
  padding-top: 10px;
}
body.liff-mode .cl-bottom-tabs {
  padding-bottom: 10px;
}

/* === Header avatar with profile picture === */
.header-avatar[style*="background-image"] {
  font-size: 0;
  border: 2px solid rgba(255,255,255,0.4);
}

/* === File preview === */
.file-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #F7F7F7;
  border-top: 1px solid #DCDCDC;
  flex-shrink: 0;
}
.file-preview-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-preview-remove {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.08);
  color: #666;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
