:root {
  --zalo: #0068ff;
  --zalo-dark: #0054d1;
  --bg: #f0f2f5;
  --chat-bg: #e8f3ff;
  --sent: #dbebff;
  --text: #081b33;
  --muted: #7589a3;
  --line: #e4e8ee;
  --danger: #e53935;
  --ok: #00b14f;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--text); background: #000; }
#app { max-width: 480px; margin: 0 auto; height: 100%; background: #fff; position: relative; overflow: hidden; display: flex; flex-direction: column; }
@media (min-width: 900px) {
  body { background: #0b1220; }
  #app { max-width: 980px; box-shadow: 0 0 0 1px #1e293b, 0 20px 60px rgba(0,0,0,.45); border-radius: 12px; height: calc(100% - 24px); margin-top: 12px; }
}

/* Login */
.login { flex: 1; display: flex; flex-direction: column; background: linear-gradient(#0068ff 0 42%, #fff 42%); }
.login-hero { padding: 36px 28px 16px; color: #fff; }
.brand-logo { display: block; height: 56px; width: auto; max-width: 240px; margin-bottom: 14px; background: #fff; padding: 8px 12px; border-radius: 12px; object-fit: contain; }
.login-hero h1 { font-size: 26px; letter-spacing: -0.3px; }
.login-hero p { opacity: .9; margin-top: 8px; font-size: 14px; line-height: 1.45; }
.login-card { margin: 8px 16px 0; background: #fff; border-radius: 16px; padding: 20px 18px; box-shadow: 0 10px 30px rgba(0,70,180,.12); }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.login-card input, .login-card select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px 12px; font-size: 16px; outline: none; background: #fff; }
.login-card input:focus, .login-card select:focus { border-color: var(--zalo); }
.btn { display: block; width: 100%; border: 0; border-radius: 10px; padding: 13px; font-size: 16px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--zalo); color: #fff; margin-top: 16px; }
.btn-secondary { background: #eaf2ff; color: var(--zalo); margin-top: 0; }
.btn-primary:disabled { opacity: .55; }
.hint { font-size: 12px; color: var(--muted); margin-top: 14px; line-height: 1.5; }
.btn-link { display: block; width: 100%; border: 0; background: transparent; color: var(--zalo); font-size: 13px; margin-top: 10px; cursor: pointer; }
.login-actions { display: flex; gap: 8px; }
.login-actions .btn-link { flex: 1; width: auto; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* Shell */
.shell { display: none; flex: 1; min-height: 0; }
.shell.on { display: flex; }
.col-list { width: 100%; display: flex; flex-direction: column; min-width: 0; background: #fff; }
.col-chat { display: none; flex: 1; flex-direction: column; min-width: 0; background: var(--chat-bg); }
@media (min-width: 900px) {
  .col-list { width: 360px; border-right: 1px solid var(--line); }
  .col-chat { display: flex; }
  .col-chat.empty .chat-placeholder { display: flex; }
}
.topbar { background: var(--zalo); color: #fff; padding: 12px 14px 10px; display: flex; align-items: center; gap: 10px; }
.topbar h2 { font-size: 20px; font-weight: 700; flex: 1; }
.iconbtn { background: transparent; border: 0; color: #fff; font-size: 20px; cursor: pointer; width: 44px; height: 44px; flex: 0 0 auto; touch-action: manipulation; }
.search { margin: -6px 12px 8px; }
.search input { width: 100%; border: 0; background: #fff; border-radius: 18px; padding: 8px 14px; font-size: 14px; }
.tabs { display: flex; border-top: 1px solid var(--line); background: #fff; }
.tabs button { flex: 1; border: 0; background: #fff; padding: 8px 0 10px; font-size: 11px; color: var(--muted); cursor: pointer; }
.tabs button.on { color: var(--zalo); font-weight: 600; }
.tabs .ico { display: block; font-size: 20px; margin-bottom: 2px; }

.list { flex: 1; overflow: auto; }
.row { display: flex; gap: 12px; padding: 12px 14px; align-items: center; cursor: pointer; border-bottom: 1px solid #f3f5f8; }
.row:hover { background: #f7faff; }
.row-action { border: 0; border-radius: 8px; padding: 7px 9px; color: var(--zalo); background: #eaf2ff; cursor: pointer; flex: 0 0 auto; }
.row-action.danger { color: #b42318; background: #fff0ef; }
.av { width: 48px; height: 48px; border-radius: 50%; background: #cfe3ff; color: var(--zalo-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.av.online { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ok); }
.meta { flex: 1; min-width: 0; }
.meta .n { font-weight: 600; font-size: 15px; }
.meta .s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.time { font-size: 11px; color: var(--muted); }
.unread { min-width: 21px; height: 21px; padding: 0 6px; border-radius: 12px; background: var(--zalo); color: #fff; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; }

.chat-head { background: var(--zalo); color: #fff; padding: 10px 4px 10px 8px; display: flex; align-items: center; gap: 2px; overflow-x: auto; }
.chat-head .who { flex: 1; }
.chat-head .who b { display: block; font-size: 16px; }
.chat-head .who span { font-size: 11px; opacity: .9; }
.msgs { flex: 1; overflow: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 14px; font-size: 15px; line-height: 1.4; word-wrap: break-word; }
.bubble.me { align-self: flex-end; background: var(--sent); border-bottom-right-radius: 4px; }
.bubble.them { align-self: flex-start; background: #fff; border-bottom-left-radius: 4px; box-shadow: 0 1px 1px rgba(0,0,0,.04); }
.bubble .t { display: block; font-size: 10px; color: var(--muted); margin-top: 4px; text-align: right; }
.bubble.sys { align-self: center; background: transparent; color: var(--muted); font-size: 12px; }
.bubble { -webkit-user-select: none; user-select: none; }
.bubble .msg-actions { display: none; }
.zone-pill { display: inline-block; margin-left: 6px; font-size: 10px; font-weight: 700; letter-spacing: .3px; padding: 1px 6px; border-radius: 8px; vertical-align: middle; }
.zone-pill.dmz { background: #fff3e0; color: #c05600; }
.zone-pill.lan { background: #e8f7e8; color: #1f7a3a; }
.sheet-action { display: block; width: 100%; border: 0; background: #f4f7fb; color: var(--text); text-align: left; padding: 14px 16px; border-radius: 12px; font-size: 16px; font-weight: 600; margin-bottom: 8px; cursor: pointer; }
.sheet-action.danger { background: #fff0ef; color: #b42318; }
.msg-sheet { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.bubble { position: relative; }
.msg-more { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border: 0; border-radius: 14px; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; }
.bubble.me .msg-more { right: auto; left: 4px; }
.msg-more:active, .msg-more:hover { background: rgba(0,0,0,.06); color: var(--text); }
.forwarded-label { color: #57708d; font-size: 11px; font-style: italic; margin-bottom: 4px; }
.quote { border-left: 3px solid var(--zalo); background: rgba(255,255,255,.5); border-radius: 5px; padding: 5px 7px; margin-bottom: 6px; display: flex; flex-direction: column; }
.quote b { font-size: 11px; color: var(--zalo-dark); }
.quote span { font-size: 12px; color: #5c6f84; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 230px; }
.msg-link { color: #0054d1; word-break: break-all; }
.composer { display: flex; gap: 8px; padding: 8px; background: #fff; border-top: 1px solid var(--line); align-items: center; }
.reply-bar { display: flex; align-items: center; gap: 8px; padding: 7px 12px; background: #fff; border-top: 1px solid var(--line); border-left: 3px solid var(--zalo); }
.reply-bar .meta { display: flex; flex-direction: column; min-width: 0; }
.reply-bar b { font-size: 12px; color: var(--zalo); }
.reply-bar span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar button { border: 0; background: #eef2f7; color: #456; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; }
.composer input[type=text] { flex: 1; border: 0; background: #f3f5f8; border-radius: 18px; padding: 10px 14px; font-size: 15px; outline: none; }
.composer button { border: 0; background: var(--zalo); color: #fff; width: 40px; height: 40px; border-radius: 50%; font-size: 18px; cursor: pointer; }
.bubble.selected { outline: 2px solid var(--zalo); box-shadow: 0 0 0 3px rgba(0,104,255,.18); }
.file-hint { font-size: 11px; color: #b42318; padding: 0 12px 8px; background: #fff; }
.filebtn:disabled { cursor: not-allowed; }
.filecard { display: flex; align-items: center; gap: 8px; }
.fileico { font-size: 20px; }
.filemeta { display: flex; flex-direction: column; min-width: 0; }
.filemeta b { font-size: 13px; }
.filemeta span { font-size: 11px; color: var(--muted); }
.preview { display: block; max-width: 220px; max-height: 180px; border-radius: 8px; margin: 6px 0; object-fit: cover; }
.dl { display: inline-block; margin-top: 6px; font-size: 13px; color: var(--zalo); font-weight: 600; text-decoration: none; }
.prog { font-size: 12px; color: var(--muted); margin-top: 4px; }
.recv { display: block; font-size: 11px; color: #2b6cb0; margin-top: 4px; line-height: 1.35; }
.poll-card { display: flex; flex-direction: column; gap: 7px; min-width: 250px; }
.poll-kicker { color: var(--zalo); font-size: 10px; font-weight: 800; letter-spacing: .7px; }
.poll-question { font-size: 15px; line-height: 1.35; margin-bottom: 2px; }
.poll-choice { position: relative; display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; text-align: left; border: 1px solid #cddff5; background: rgba(255,255,255,.8); border-radius: 9px; padding: 8px 9px; color: var(--text); cursor: pointer; overflow: hidden; }
.poll-choice.selected { border-color: var(--zalo); box-shadow: 0 0 0 1px var(--zalo); }
.poll-choice b { color: var(--zalo); }
.poll-choice small { grid-column: 1 / -1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poll-bar { grid-column: 1 / -1; height: 3px; border-radius: 3px; background: #e8edf4; overflow: hidden; }
.poll-bar i { display: block; height: 100%; background: var(--zalo); }
.poll-total { font-size: 11px; color: var(--muted); }
.chat-placeholder { display: none; flex: 1; align-items: center; justify-content: center; color: var(--muted); flex-direction: column; gap: 8px; }
.lock { font-size: 11px; color: #2e6b2e; background: #e8f7e8; display: inline-block; padding: 2px 8px; border-radius: 10px; margin-top: 4px; }

.panel { padding: 16px; overflow: auto; flex: 1; }
.card { background: #f7f9fc; border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.badge { display: inline-block; background: #e8f0ff; color: var(--zalo); font-size: 11px; padding: 2px 8px; border-radius: 8px; }
pre.audit { font-size: 11px; white-space: pre-wrap; max-height: 240px; overflow: auto; background: #0b1220; color: #d6e2ff; padding: 10px; border-radius: 8px; }
.warn { background: #fff6e5; color: #8a5a00; padding: 10px 12px; border-radius: 10px; font-size: 12px; line-height: 1.45; margin: 8px 12px; }

/* Dialogs and message tools */
.modal { position: absolute; inset: 0; z-index: 50; background: rgba(5,18,38,.48); display: flex; align-items: flex-end; justify-content: center; }
.modal-card { background: #fff; width: 100%; max-height: min(92dvh, 92%); overflow: auto; -webkit-overflow-scrolling: touch; border-radius: 18px 18px 0 0; padding: 18px 16px calc(28px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px rgba(0,0,0,.18); }
.modal-card input, .modal-card select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 16px; outline: none; background: #fff; }
.modal-tall { min-height: 62%; }
.modal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 18px; }
.modal-head b { flex: 1; }
.modal-close { border: 0; background: #eef2f7; color: #456; width: 34px; height: 34px; border-radius: 50%; font-size: 24px; cursor: pointer; }
.modal-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
.pick-list { margin-top: 8px; border: 1px solid var(--line); border-radius: 10px; max-height: 260px; overflow: auto; }
.pick-row { display: flex; align-items: center; gap: 10px; padding: 10px; border-bottom: 1px solid #f0f3f7; }
.pick-row:last-child { border-bottom: 0; }
.pick-row input { width: 20px; height: 20px; }
.pick-row .meta { cursor: pointer; }
.setting-row { background: #f7f9fc; border-radius: 12px; padding: 12px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; }
.setting-row .meta { flex: 1; }
.switch { position: relative; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #b8c2cf; border-radius: 20px; cursor: pointer; transition: .2s; }
.switch span:before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--zalo); }
.switch input:checked + span:before { transform: translateX(20px); }
.tool-tabs { display: flex; border-bottom: 1px solid var(--line); margin: 14px 0 8px; }
.tool-tabs button { flex: 1; border: 0; background: #fff; padding: 10px 4px; color: var(--muted); cursor: pointer; }
.tool-tabs button.on { color: var(--zalo); border-bottom: 2px solid var(--zalo); font-weight: 600; }
.tool-results { min-height: 160px; }
.tool-item { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid #f1f3f6; }
.tool-item .thumb { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; background: #eef2f7; }
.tool-item .meta { min-width: 0; }
.tool-item .meta a, .tool-item .meta b { display: block; overflow: hidden; text-overflow: ellipsis; color: #064eaa; text-decoration: none; }
.group-actions { margin: 12px 0; }
.group-actions h4 { margin-bottom: 8px; }
.mini-btn { border: 0; border-radius: 8px; padding: 8px 10px; color: var(--zalo); background: #eaf2ff; cursor: pointer; margin: 3px 4px 3px 0; }
.mini-btn.danger { color: #b42318; background: #fff0ef; }
.member-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid #f2f4f7; }
.member-line .meta { flex: 1; }
.admin-table { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.admin-create { display: grid; gap: 7px; margin-top: 10px; }
.admin-create input, .admin-create select { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #fff; }
.admin-user { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.admin-user .actions { display: flex; flex-wrap: wrap; margin-top: 8px; }
.poll-options-edit { display: flex; flex-direction: column; gap: 7px; }
.poll-option-edit { display: flex; gap: 7px; align-items: center; }
.poll-option-edit input { flex: 1; }
.poll-option-edit button { width: 38px; height: 38px; border: 0; border-radius: 9px; background: #fff0ef; color: #b42318; font-size: 20px; cursor: pointer; }
.mail-status { margin-top: 10px; padding: 10px; border-radius: 9px; background: #fff; border: 1px solid var(--line); }
.device-code { font-size: 26px; letter-spacing: 3px; font-weight: 800; color: var(--zalo); margin: 8px 0; }
.toast { position: absolute; z-index: 80; left: 16px; right: 16px; bottom: 82px; background: #10233d; color: #fff; padding: 11px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 13px; }

@media (min-width: 900px) {
  .modal { align-items: center; }
  .modal-card { max-width: 480px; border-radius: 18px; padding: 20px; }
}

.hidden { display: none !important; }
.mobile-only { display: inline-flex; }
@media (min-width: 900px) { .mobile-only { display: none !important; } .shell.chat-open .col-list { display: flex; } }
@media (max-width: 899px) {
  .shell.chat-open .col-list { display: none; }
  .shell.chat-open .col-chat { display: flex; }
}
.wall-grid { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.wall-swatch { width: 44px; height: 44px; border-radius: 10px; border: 2px solid #d7e1ee; cursor: pointer; background: #e8f3ff; }
.wall-swatch.w-blue { background: linear-gradient(#1a73e8, #0b3a7a); }
.wall-swatch.w-night { background: linear-gradient(#1b2430, #0b1220); }
.wall-swatch.w-green { background: linear-gradient(#d4edda, #7bc47f); }
.wall-swatch.w-paper { background: repeating-linear-gradient(45deg, #f7f3e8, #f7f3e8 8px, #efe6d0 8px, #efe6d0 16px); }
.chat-extra-settings { width: 100%; margin-top: 12px; }
#msgs { background-repeat: no-repeat; background-position: center; }
html[data-wall="blue"] #msgs { background: linear-gradient(#cfe4ff, #eaf3ff); }
html[data-wall="night"] #msgs { background: #121820; }
html[data-wall="green"] #msgs { background: #e7f6ea; }
html[data-wall="paper"] #msgs { background: #f4efe4; }
html[data-night="1"] { --bg: #0e141c; --text: #e8eef6; --muted: #8aa0b8; --chat-bg: #121820; --sent: #1d3a66; --line: #243044; }
html[data-night="1"] #app, html[data-night="1"] .login-card, html[data-night="1"] .modal-card, html[data-night="1"] .card { background: #151c26; color: var(--text); }
html[data-night="1"] .bubble.them { background: #1c2734; color: #e8eef6; }
html[data-night="1"] .composer, html[data-night="1"] .chat-head, html[data-night="1"] .topbar { background: #151c26; color: var(--text); }
html[data-night="1"] input, html[data-night="1"] select { background: #0e141c; color: var(--text); border-color: #2a3b50; }

.call-stage { position: absolute; inset: 0; z-index: 80; background: #081018; color: #fff; display: flex; flex-direction: column; }
.call-stage.hidden { display: none; }
.call-head { padding: 18px 16px 8px; text-align: center; }
.call-head b { display: block; font-size: 18px; }
.call-head span { font-size: 13px; opacity: .8; }
.call-grid { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; overflow: auto; align-content: start; }
.call-tile { position: relative; background: #122033; border-radius: 14px; overflow: hidden; min-height: 180px; }
.call-tile video { width: 100%; height: 100%; object-fit: cover; min-height: 180px; background: #000; }
.call-tile video.hidden { display: none; }
.call-tile audio { position: absolute; width: 0; height: 0; opacity: 0; }
.call-label, .call-state { position: absolute; left: 8px; font-size: 12px; }
.call-label { bottom: 8px; }
.call-state { top: 8px; opacity: .7; }
.call-local { position: absolute; right: 12px; bottom: 88px; width: 108px; height: 144px; object-fit: cover; border-radius: 12px; background: #000; z-index: 2; }
.call-bar { display: flex; justify-content: center; gap: 10px; padding: 14px 12px calc(16px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
.call-ctrl { border: 0; border-radius: 22px; padding: 12px 18px; font-weight: 700; cursor: pointer; background: #24344a; color: #fff; min-height: 44px; min-width: 44px; }
.call-ctrl.ok { background: #1f9d55; }
.call-ctrl.no { background: #e53935; }
.typing-line { font-size: 12px; color: var(--muted); padding: 0 14px 8px; }
.filebtn { touch-action: manipulation; min-width: 44px; min-height: 44px; }
#micBtn.rec { color: #e53935; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.voicecard { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
.voicecard audio { width: 220px; max-width: 100%; }

.net-banner { background: #fff3cd; color: #664d03; text-align: center; font-size: 12px; padding: 6px; }
.pin-bar { background: #e8f1ff; color: #003a8c; font-size: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.ticks { float: right; font-size: 12px; opacity: .75; margin-left: 8px; }
.edited { font-size: 11px; opacity: .6; margin-left: 6px; }
.rec-overlay { position: absolute; left: 12px; right: 12px; bottom: 72px; background: #e53935; color: #fff; text-align: center; padding: 12px; border-radius: 12px; z-index: 8; font-weight: 700; }
.lock-gate { position: absolute; inset: 0; z-index: 50; background: #0068FF; display: flex; align-items: center; justify-content: center; padding: 24px; }
.lock-gate.hidden { display: none; }
.lock-gate h2 { margin: 0 0 8px; }


