/* ChatLoca Chat PWA — CSS v2 */
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;500;600;700&display=swap');

:root {
  --blue: #2E7CC9; --red: #E02020; --gold: #F5C518;
  --bg: #F7F8FA; --white: #FFFFFF; --text: #1A1A2E; --text-2: #4A4A68; --text-3: #8E8EA0;
  --border: #E8E8EF; --green: #22C55E;
  --radius: 16px; --radius-sm: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Sora', sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; overflow: hidden; height: 100dvh; }
#app { height: 100dvh; display: flex; flex-direction: column; }

/* ── Screen ── */
.screen { height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }

/* ── Topbar ── */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--white); border-bottom: 1px solid var(--border); flex-shrink: 0; padding-top: max(12px, env(safe-area-inset-top)); }
.topbar-title { font-size: 1.2rem; font-weight: 700; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn { background: none; border: none; font-size: 1.3rem; cursor: pointer; padding: 6px; border-radius: 50%; }
.icon-btn:active { background: var(--border); }
.back-btn { background: none; border: none; font-size: 1.4rem; cursor: pointer; padding: 6px 12px 6px 0; }

/* ── Bottombar ── */
.bottombar { display: flex; background: var(--white); border-top: 1px solid var(--border); flex-shrink: 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; border: none; background: none; font-size: .65rem; color: var(--text-3); cursor: pointer; font-family: inherit; }
.tab.active { color: var(--blue); }

/* ── Login ── */
.login-screen { justify-content: center; align-items: center; padding: 32px; text-align: center; }
.login-logo { font-size: 3.5rem; margin-bottom: 12px; }
.login-screen h1 { font-size: 1.8rem; font-weight: 700; margin-bottom: 8px; }
.login-sub { color: var(--text-3); font-size: .85rem; margin-bottom: 28px; line-height: 1.5; }
.login-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-form input { padding: 14px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: .95rem; font-family: inherit; background: var(--white); }
.login-form input:focus { outline: none; border-color: var(--blue); }
.login-msg { margin-top: 16px; font-size: .85rem; }
.msg-ok { color: var(--green); }
.msg-err { color: var(--red); }

/* ── Buttons ── */
.btn-primary { padding: 14px 24px; background: var(--blue); color: white; border: none; border-radius: var(--radius-sm); font-size: .95rem; font-weight: 600; cursor: pointer; font-family: inherit; transition: .2s; }
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .5; }
.btn-logout { padding: 12px 24px; background: none; border: 1px solid var(--red); color: var(--red); border-radius: var(--radius-sm); font-size: .85rem; cursor: pointer; margin-top: 20px; font-family: inherit; width: 100%; }

/* ── Onboarding ── */
.onboard-screen { justify-content: center; align-items: center; padding: 32px; text-align: center; }
.onboard-screen h2 { font-size: 1.4rem; margin-bottom: 6px; }
.onboard-screen p { color: var(--text-3); font-size: .85rem; margin-bottom: 24px; }
#onboard-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
#onboard-form input[type="text"] { padding: 14px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: .95rem; font-family: inherit; background: var(--white); }
.file-upload { padding: 14px 16px; border-radius: var(--radius-sm); border: 1px dashed var(--border); cursor: pointer; color: var(--text-3); font-size: .85rem; text-align: center; transition: .2s; }
.file-upload:hover { border-color: var(--blue); color: var(--blue); }

/* ── Conversations list ── */
.convs-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.conv-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: .15s; }
.conv-item:active { background: rgba(46,124,201,.04); }
.conv-avatar { font-size: 1.8rem; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.conv-info { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; }
.conv-name { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: .7rem; color: var(--text-3); flex-shrink: 0; margin-left: 8px; }
.conv-bottom { display: flex; justify-content: space-between; align-items: center; }
.conv-msg { font-size: .8rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-badge { background: var(--blue); color: white; font-size: .65rem; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: flex; align-items: center; justify-content: center; padding: 0 6px; flex-shrink: 0; margin-left: 8px; }

/* ── Empty state ── */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; text-align: center; color: var(--text-3); flex: 1; }
.empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty p { font-size: .9rem; margin-bottom: 8px; line-height: 1.5; }
.empty .btn-primary { margin-top: 16px; }
.loading { display: flex; align-items: center; justify-content: center; padding: 32px; color: var(--text-3); font-size: .85rem; flex: 1; }

/* ── Chat ── */
.chat-screen { background: #E8EDF2; }
.chat-header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--white); border-bottom: 1px solid var(--border); flex-shrink: 0; padding-top: max(10px, env(safe-area-inset-top)); }
.chat-header-info { display: flex; flex-direction: column; }
.chat-header-name { font-weight: 600; font-size: .95rem; }
.chat-header-sub { font-size: .7rem; color: var(--text-3); }
.messages { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 3px; -webkit-overflow-scrolling: touch; }
.msg { display: flex; max-width: 80%; }
.msg-mine { align-self: flex-end; }
.msg-other { align-self: flex-start; }
.msg-system { align-self: center; max-width: 90%; }
.msg-bubble { padding: 8px 12px; border-radius: 16px; font-size: .88rem; line-height: 1.45; word-break: break-word; position: relative; }
.msg-mine .msg-bubble { background: var(--blue); color: white; border-bottom-right-radius: 4px; }
.msg-other .msg-bubble { background: var(--white); color: var(--text); border-bottom-left-radius: 4px; }
.msg-system .msg-bubble { background: rgba(0,0,0,.06); color: var(--text-3); font-size: .78rem; text-align: center; border-radius: 12px; }
.msg-meta { font-size: .6rem; opacity: .6; margin-left: 8px; white-space: nowrap; }
.msg-form { display: flex; gap: 8px; padding: 8px 12px; background: var(--white); border-top: 1px solid var(--border); flex-shrink: 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.msg-form input { flex: 1; padding: 10px 14px; border-radius: 24px; border: 1px solid var(--border); font-size: .88rem; font-family: inherit; background: var(--bg); }
.msg-form input:focus { outline: none; border-color: var(--blue); }
.send-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--blue); color: white; border: none; font-size: 1.1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ── Typing indicator ── */
.typing-indicator { padding: 4px 16px; display: flex; gap: 4px; align-items: center; }
.typing-indicator span { width: 7px; height: 7px; background: var(--text-3); border-radius: 50%; animation: bounce .6s infinite alternate; }
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { to { transform: translateY(-5px); opacity: .3; } }

/* ── Scan ── */
.scan-content { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px; text-align: center; }
.scan-icon { font-size: 3rem; margin-bottom: 16px; }
.scan-content p { color: var(--text-3); font-size: .85rem; margin-bottom: 20px; }
#scan-form { width: 100%; max-width: 300px; display: flex; flex-direction: column; gap: 12px; }
#scan-form input { padding: 14px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: 1.1rem; text-align: center; letter-spacing: 2px; font-weight: 600; text-transform: uppercase; font-family: inherit; }
#scan-msg { margin-top: 12px; font-size: .85rem; }

/* ── Profile ── */
.profile-content { flex: 1; overflow-y: auto; padding: 24px 16px; display: flex; flex-direction: column; align-items: center; }
.profile-avatar { position: relative; margin-bottom: 20px; }
.avatar { border-radius: 50%; object-fit: cover; }
.avatar-init { background: var(--blue); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; }
.avatar-upload-btn { position: absolute; bottom: 0; right: 0; width: 28px; height: 28px; background: var(--white); border-radius: 50%; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.12); cursor: pointer; font-size: .75rem; }
#profile-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
#profile-form input { padding: 14px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: .95rem; font-family: inherit; background: var(--white); }
#p-msg { margin-top: 8px; font-size: .85rem; text-align: center; }
