* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", "Noto Sans TC", sans-serif; background: #f4f5f7; color: #1c1e21; }
a { color: #06c755; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top nav */
.topnav { display: flex; justify-content: center; align-items: center; background: #fff; border-bottom: 1px solid #e4e6eb; height: 52px; position: sticky; top: 0; z-index: 10; }
.nav-inner { display: flex; justify-content: space-between; align-items: center; width: 100%; max-width: 1200px; padding: 0 20px; }
.nav-left { display: flex; align-items: center; gap: 18px; }
.nav-left .brand { font-weight: 700; color: #06c755; font-size: 16px; }
.nav-left a { color: #444; font-size: 14px; }
.nav-right { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.nav-right .avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.role { font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.role-admin { background: #ffe3e3; color: #c92a2a; }
.role-member { background: #e7f5ff; color: #1971c2; }
.logout { color: #888; }

.content { padding: 20px; max-width: 1200px; margin: 0 auto; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { background: #fff; padding: 36px 32px; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.08); width: 320px; text-align: center; }
.login-card h1 { margin: 0 0 20px; font-size: 20px; color: #06c755; }
.login-card .step { color: #888; font-size: 13px; margin-bottom: 16px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 15px; margin-bottom: 12px; }
.btn, .btn-line { display: block; width: 100%; padding: 10px; border: none; border-radius: 8px; font-size: 15px; cursor: pointer; }
.btn { background: #06c755; color: #fff; }
.btn-line { background: #06c755; color: #fff; text-align: center; }
.btn-line:hover { text-decoration: none; opacity: .92; }
.alert { background: #fff0f0; color: #c92a2a; padding: 8px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }

/* Tables */
table.grid { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
table.grid th, table.grid td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #f0f0f0; font-size: 14px; }
table.grid th { background: #fafafa; color: #666; font-weight: 600; }
table.grid tr:hover td { background: #fafcff; }
.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; vertical-align: middle; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #eee; color: #555; }
.badge-bound { background: #e6fcf5; color: #099268; }
.badge-sup { background: #fff3bf; color: #e67700; }
.badge-off { background: #ffe3e3; color: #c92a2a; }

/* Search bar */
.search-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.search-bar input[type=text] { padding: 8px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; width: 260px; }
.search-bar label { font-size: 14px; color: #555; display: flex; align-items: center; gap: 4px; }
.btn-sm { padding: 5px 12px; border: none; border-radius: 6px; font-size: 13px; cursor: pointer; background: #06c755; color: #fff; }
.btn-sm.gray { background: #e4e6eb; color: #444; }
.btn-sm.red { background: #ffe3e3; color: #c92a2a; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-box { background: #fff; padding: 24px; border-radius: 12px; width: 340px; }
.modal-box h3 { margin: 0 0 16px; font-size: 17px; }
.modal-box input[type=text] { width: 100%; padding: 9px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; margin-bottom: 12px; }
.modal-box label { display: flex; align-items: center; gap: 6px; font-size: 14px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions button { padding: 8px 16px; border: none; border-radius: 8px; font-size: 14px; cursor: pointer; }
.modal-actions .cancel { background: #e4e6eb; color: #444; }
.modal-actions .save { background: #06c755; color: #fff; }
select.role-select { padding: 5px 8px; border: 1px solid #ddd; border-radius: 6px; font-size: 13px; }

/* Messages */
.chat-wrap { display: flex; height: calc(100vh - 92px); background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.chat-sidebar { width: 300px; border-right: 1px solid #eee; overflow-y: auto; flex-shrink: 0; }
.conv-item { display: flex; gap: 10px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid #f4f4f4; align-items: center; }
.conv-item:hover { background: #fafcff; }
.conv-item.active { background: #e7f9ef; }
.conv-item .avatar-ph { width: 40px; height: 40px; border-radius: 50%; background: #e4e6eb; flex-shrink: 0; }
.conv-item .avatar-sm { width: 40px; height: 40px; }
.conv-meta { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; }
.conv-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: #aaa; flex-shrink: 0; margin-left: 6px; }
.conv-last { font-size: 12px; color: #888; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header { padding: 14px 18px; border-bottom: 1px solid #eee; font-weight: 600; background: #fafafa; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background: #eef0f2; }
.msg { max-width: 66%; display: flex; flex-direction: column; }
.msg.other { align-self: flex-start; align-items: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .bubble { padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.5; word-break: break-word; }
.msg.other .bubble { background: #fff; border-top-left-radius: 4px; }
.msg.mine .bubble { background: #a0e6b8; border-top-right-radius: 4px; }
.msg .sender-name { font-size: 12px; color: #888; margin: 0 4px 2px; }
.msg .msg-time { font-size: 11px; color: #aaa; margin: 2px 4px 0; }
.msg-media { max-width: 220px; max-height: 260px; border-radius: 10px; display: block; }
.chat-input { display: flex; gap: 10px; padding: 12px; border-top: 1px solid #eee; background: #fff; }
.chat-input input { flex: 1; padding: 10px 14px; border: 1px solid #ddd; border-radius: 20px; font-size: 14px; }
.chat-input button { padding: 8px 20px; border: none; border-radius: 20px; background: #06c755; color: #fff; font-size: 14px; cursor: pointer; }

/* Events raw json */
details summary { cursor: pointer; color: #06c755; font-size: 13px; }
.rawjson { background: #1e1e1e; color: #d4d4d4; padding: 10px; border-radius: 6px; font-size: 12px; max-height: 320px; overflow: auto; max-width: 520px; margin: 6px 0 0; }

/* Toast */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #333; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .3s; box-shadow: 0 2px 10px rgba(0,0,0,.2); }
.toast.show { opacity: .95; }
.toast.err { background: #c92a2a; }
.modal-box p.confirm-msg { margin: 0 0 18px; font-size: 15px; }

/* Pager */
.pager { display: flex; justify-content: center; align-items: center; gap: 16px; margin: 18px 0; }
.pager a { padding: 6px 14px; border: 1px solid #ddd; border-radius: 6px; color: #444; background: #fff; }
.pager a:hover { text-decoration: none; border-color: #06c755; color: #06c755; }
.pager-info { color: #888; font-size: 14px; }
