/* StaffChat - WhatsApp-inspired responsive UI (original styling) */
:root{
  --bg:#d1d7db; --panel:#ffffff; --head:#f0f2f5; --line:#e9edef; --text:#111b21; --muted:#667781;
  --accent:#00a884; --accent-d:#008069; --out:#d9fdd3; --in:#ffffff; --wall:#efeae2; --hover:#f5f6f6;
  --sel:#f0f2f5; --danger:#d93025; --badge:#25d366; --input:#ffffff; --shadow:0 1px .5px rgba(11,20,26,.13);
  --notice:#fff5c4; --notice-t:#54656f; --ok:#0a7d4f;
}
@media (prefers-color-scheme:dark){
  :root{
    --bg:#0b141a; --panel:#111b21; --head:#202c33; --line:#222d34; --text:#e9edef; --muted:#8696a0;
    --out:#005c4b; --in:#202c33; --wall:#0b141a; --hover:#182229; --sel:#2a3942; --input:#2a3942;
    --notice:#182229; --notice-t:#8696a0; --shadow:none; --ok:#4fd1a1;
  }
}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{font:15px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:var(--bg);color:var(--text);-webkit-text-size-adjust:100%}
[hidden]{display:none!important}
button{font:inherit;color:inherit;cursor:pointer;border:0;background:none;padding:0}
a{color:var(--accent-d)}
@media (prefers-color-scheme:dark){a{color:#53bdeb}}
.grow{flex:1;min-width:0}

/* ---------- layout ---------- */
#app{display:flex;height:100vh;height:100dvh;max-width:1700px;margin:0 auto;background:var(--panel);box-shadow:0 0 0 1px var(--line)}
#sidebar{width:min(420px,38%);min-width:300px;display:flex;flex-direction:column;border-right:1px solid var(--line);background:var(--panel)}
#conversation{flex:1;min-width:0;display:flex;flex-direction:column;background:var(--wall)}
#chatview{flex:1;min-height:0;display:flex;flex-direction:column}
.bar{display:flex;align-items:center;gap:10px;padding:10px 14px;background:var(--head);min-height:60px}
.me-name{font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.me-sub{font-size:12.5px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.icon-btn{width:42px;height:42px;border-radius:50%;display:grid;place-items:center;color:var(--muted);flex:none}
.icon-btn:hover{background:var(--sel)}
.fab{width:44px;height:44px;border-radius:50%;background:var(--accent);color:#fff;display:grid;place-items:center;flex:none}
.fab:hover{background:var(--accent-d)}
.avatar{width:40px;height:40px;border-radius:50%;color:#fff;font-weight:600;font-size:15px;display:grid;place-items:center;flex:none;user-select:none}
.back{display:none}
#chat-meta{cursor:default}
#chat-meta.clickable{cursor:pointer}

/* ---------- sidebar ---------- */
.searchbar{padding:8px 12px;border-bottom:1px solid var(--line)}
.searchbar input,.modal-search input{width:100%;border:0;outline:0;border-radius:10px;padding:9px 14px;background:var(--head);color:var(--text);font:inherit}
.chatlist{flex:1;overflow-y:auto}
.chat-row{display:flex;align-items:center;gap:12px;padding:10px 14px;cursor:pointer;border-bottom:1px solid var(--line)}
.chat-row:hover{background:var(--hover)}
.chat-row.active{background:var(--sel)}
.chat-mid{flex:1;min-width:0}
.chat-title{font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chat-preview{font-size:13.5px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chat-right{display:flex;flex-direction:column;align-items:flex-end;gap:4px;flex:none}
.chat-time{font-size:12px;color:var(--muted)}
.badge{background:var(--badge);color:#fff;font-size:12px;font-weight:600;min-width:20px;height:20px;padding:0 6px;border-radius:10px;display:grid;place-items:center}
.empty-list{padding:28px 18px;text-align:center;color:var(--muted)}
.offline{background:#c0392b;color:#fff;text-align:center;font-size:13px;padding:4px}

.menu-wrap{position:relative}
.menu{position:absolute;right:0;top:46px;z-index:20;min-width:190px;background:var(--panel);border-radius:8px;box-shadow:0 4px 18px rgba(0,0,0,.25);padding:6px 0}
.menu a,.menu button{display:block;width:100%;text-align:left;padding:10px 18px;color:var(--text);text-decoration:none;font-size:14.5px}
.menu a:hover,.menu button:hover{background:var(--hover)}
.menu form{margin:0}

/* ---------- empty pane ---------- */
.empty-pane{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;color:var(--muted);padding:24px;background:var(--head)}
.empty-pane .big{font-size:64px}
.empty-pane h2{margin:8px 0;color:var(--text);font-weight:500}

/* ---------- messages ---------- */
#messages{flex:1;min-height:0;overflow-y:auto;padding:12px 7%;background-color:var(--wall);background-image:radial-gradient(rgba(128,128,128,.13) 1px,transparent 1px);background-size:22px 22px;overscroll-behavior:contain}
.notice{max-width:520px;margin:6px auto 12px;padding:6px 12px;border-radius:8px;background:var(--notice);color:var(--notice-t);font-size:12.5px;text-align:center}
.msg{display:flex;margin:2px 0;transition:opacity .4s}
.msg.out{justify-content:flex-end}
.msg.gone{opacity:0}
.bubble{max-width:min(78%,560px);background:var(--in);padding:6px 9px 4px;border-radius:8px;box-shadow:var(--shadow);overflow-wrap:anywhere}
.msg.out .bubble{background:var(--out)}
.sender{font-size:12.5px;font-weight:600;margin-bottom:2px}
.text{white-space:pre-wrap}
.text a{word-break:break-all}
.meta{display:flex;gap:8px;justify-content:flex-end;font-size:11px;color:var(--muted);margin-top:2px}
.m-img{display:block;max-width:100%;max-height:340px;border-radius:6px;cursor:zoom-in;margin-bottom:4px}
.m-video{display:block;width:320px;max-width:100%;max-height:360px;border-radius:6px;background:#000;margin-bottom:4px}
.m-audio{display:block;width:280px;max-width:100%;margin-bottom:4px}

/* ---------- composer ---------- */
#composer{background:var(--head);padding:8px 10px calc(8px + env(safe-area-inset-bottom))}
.c-normal,.c-rec{display:flex;align-items:flex-end;gap:8px}
.c-rec{display:none;align-items:center}
#composer.recording .c-normal{display:none}
#composer.recording .c-rec{display:flex}
#input{flex:1;resize:none;border:0;outline:0;border-radius:22px;padding:11px 15px;background:var(--input);color:var(--text);font:inherit;max-height:140px;line-height:1.35}
.dot{width:10px;height:10px;border-radius:50%;background:#e53935;animation:blink 1s infinite}
@keyframes blink{50%{opacity:.25}}
.pending{display:flex;align-items:center;gap:10px;padding:8px 12px;background:var(--panel);border-top:1px solid var(--line)}
.pend-thumb{width:48px;height:48px;object-fit:cover;border-radius:6px}
.pend-icon{width:48px;height:48px;display:grid;place-items:center;font-size:26px;background:var(--head);border-radius:6px}
.pend-info{flex:1;min-width:0}
.pend-name{font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.pend-size{font-size:12.5px;color:var(--muted)}
.upload{padding:6px 12px;background:var(--panel);font-size:12.5px;color:var(--muted)}
.upload .track{height:4px;background:var(--line);border-radius:2px;overflow:hidden;margin-bottom:4px}
.upload i{display:block;height:100%;width:0;background:var(--accent);transition:width .15s}

/* ---------- modal / lightbox / toast ---------- */
.modal{position:fixed;inset:0;z-index:50;background:rgba(0,0,0,.5);display:grid;place-items:center;padding:12px}
.modal-card{width:min(460px,100%);max-height:88vh;display:flex;flex-direction:column;background:var(--panel);border-radius:12px;overflow:hidden;box-shadow:0 10px 40px rgba(0,0,0,.4)}
.modal-head{display:flex;align-items:center;justify-content:space-between;padding:6px 8px 6px 18px;background:var(--head)}
.modal-head h3{margin:0;font-size:16px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.modal-body{padding:12px 14px 16px;overflow-y:auto;display:flex;flex-direction:column;gap:10px}
.modal-search input{background:var(--head)}
.tabs{display:flex;gap:6px}
.tab{flex:1;padding:8px;border-radius:8px;background:var(--head);color:var(--muted);font-weight:600}
.tab.on{background:var(--accent);color:#fff}
.user-list{display:flex;flex-direction:column;max-height:44vh;overflow-y:auto;border:1px solid var(--line);border-radius:8px}
.user-row{display:flex;align-items:center;gap:12px;padding:8px 12px;cursor:pointer;border-bottom:1px solid var(--line)}
.user-row:last-child{border-bottom:0}
.user-row:hover{background:var(--hover)}
.user-row .u-name{font-weight:600}
.user-row .u-sub{font-size:12.5px;color:var(--muted)}
.user-row input[type=checkbox]{width:18px;height:18px;accent-color:var(--accent)}
.hint{font-size:13px;color:var(--muted)}
.text-input{width:100%;border:1px solid var(--line);border-radius:8px;padding:10px 12px;background:var(--panel);color:var(--text);font:inherit}
.btn{display:inline-block;padding:10px 16px;border-radius:8px;background:var(--head);color:var(--text);font-weight:600;text-decoration:none;text-align:center;border:0;cursor:pointer}
.btn.primary{background:var(--accent);color:#fff}
.btn.primary:hover{background:var(--accent-d)}
.btn.danger{color:var(--danger)}
.btn.small{padding:5px 10px;font-size:13px}
.btn.block{display:block;width:100%}
.media-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:10px}
.media-item{display:flex;flex-direction:column;gap:3px;font-size:12px}
.media-item img,.media-icon{width:100%;aspect-ratio:1;object-fit:cover;border-radius:8px;background:var(--head);cursor:zoom-in}
.media-icon{display:grid;place-items:center;font-size:34px;cursor:default}
.media-meta{color:var(--muted)}
.media-actions{display:flex;gap:10px}
.lightbox{position:fixed;inset:0;z-index:60;background:rgba(0,0,0,.92);display:grid;place-items:center;cursor:zoom-out}
.lightbox img{max-width:96vw;max-height:92vh;object-fit:contain}
.toast{position:fixed;left:50%;bottom:24px;transform:translate(-50%,20px);opacity:0;pointer-events:none;z-index:70;background:#233138;color:#fff;padding:10px 16px;border-radius:8px;max-width:90vw;transition:.25s}
.toast.show{opacity:1;transform:translate(-50%,0)}

/* ---------- emoji + stickers ---------- */
.emoji-panel{background:var(--panel);border-top:1px solid var(--line);padding:8px 10px 6px}
.emoji-panel .tabs{margin-bottom:6px}
.emoji-body{height:230px;overflow-y:auto}
.emoji-title{font-size:12px;font-weight:600;color:var(--muted);margin:8px 2px 4px}
.emoji-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(40px,1fr))}
.emoji-cell{font-size:26px;line-height:1;padding:6px 0;border-radius:8px;text-align:center;font-family:"Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif}
.emoji-cell:hover{background:var(--sel)}
.sticker-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(96px,1fr));gap:8px;padding-top:6px}
.sticker-cell{display:flex;flex-direction:column;align-items:center;gap:2px;padding:8px 4px;border-radius:12px;background:var(--head)}
.sticker-cell:hover{background:var(--sel)}
.stk-e{font-size:44px;line-height:1.1;font-family:"Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif}
.stk-c{font-size:11.5px;font-weight:700;text-align:center;color:var(--text)}
.bubble.sticker{background:transparent!important;box-shadow:none;padding:2px 4px}
.bubble.sticker .stk{display:flex;flex-direction:column;align-items:center;gap:2px;padding:6px 14px;border-radius:16px;background:var(--in);box-shadow:var(--shadow)}
.msg.out .bubble.sticker .stk{background:var(--out)}
.bubble.sticker .stk-e{font-size:76px}
.bubble.sticker .stk-c{font-size:13px}
.text.big-emoji{font-size:44px;line-height:1.2}

/* ---------- mobile ---------- */
@media (max-width:760px){
  #app{box-shadow:none}
  #sidebar{width:100%;min-width:0;border-right:0}
  #conversation{display:none}
  #app.chat-open #sidebar{display:none}
  #app.chat-open #conversation{display:flex}
  .back{display:grid}
  #messages{padding:10px 10px}
  .bubble{max-width:88%}
}

/* ---------- auth + admin pages ---------- */
body.auth{display:grid;place-items:center;min-height:100%;padding:18px;background:var(--head);height:auto}
.auth-card{width:min(400px,100%);background:var(--panel);padding:28px 24px;border-radius:14px;box-shadow:0 6px 28px rgba(0,0,0,.12)}
.auth-card.wide{width:min(560px,100%)}
.auth-card .logo{font-size:44px;text-align:center}
.auth-card h1{margin:4px 0 0;text-align:center;font-size:24px}
.auth-card h3{margin:20px 0 8px;font-size:15px}
.auth-card .sub{text-align:center;color:var(--muted);margin:2px 0 18px}
.field{display:block;margin-bottom:14px;font-size:13.5px;color:var(--muted);font-weight:600}
.field input[type=text],.field input[type=password],.field input[type=search],.field input[type=number]{display:block;width:100%;margin-top:5px;border:1px solid var(--line);border-radius:8px;padding:11px 12px;background:var(--panel);color:var(--text);font:inherit;font-weight:400}
.field input:focus,.text-input:focus{outline:2px solid var(--accent);outline-offset:-1px}
.field small{display:block;margin-top:4px;font-weight:400}
.alert{background:#fdecea;color:#8a1c14;border-radius:8px;padding:10px 12px;margin-bottom:14px;font-size:14px}
.alert.ok{background:#e6f6ee;color:#0b5a3a}
@media (prefers-color-scheme:dark){.alert{background:#3a1d1a;color:#ffb4ab}.alert.ok{background:#12301f;color:#9ae6b4}}
.fine{color:var(--muted);font-size:13px;text-align:center}
.checks{list-style:none;padding:0;margin:0 0 14px;font-size:14px}
.checks .ok{color:var(--ok)}.checks .bad{color:var(--danger)}
pre{background:var(--head);padding:10px;border-radius:8px;overflow:auto;font-size:12.5px}
code{background:var(--head);padding:1px 5px;border-radius:4px}

.admin-body{display:block;place-items:initial;padding:0;background:var(--head)}
.admin{max-width:1150px;margin:0 auto;padding:18px 14px 60px}
.admin header{display:flex;flex-wrap:wrap;gap:10px;align-items:center;justify-content:space-between;margin-bottom:16px}
.admin h1{margin:0;font-size:22px}
.card{background:var(--panel);border-radius:12px;padding:16px;margin-bottom:16px;box-shadow:var(--shadow)}
.card h2{margin:0 0 12px;font-size:17px}
.stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px}
.stat{background:var(--head);border-radius:10px;padding:10px 12px}
.stat b{display:block;font-size:20px}
.stat span{font-size:12.5px;color:var(--muted)}
.form-row{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:10px;align-items:end}
.form-row .field{margin:0}
.tbl-wrap{overflow-x:auto}
.tbl{width:100%;border-collapse:collapse}
.tbl th,.tbl td{padding:8px 10px;border-bottom:1px solid var(--line);text-align:left;vertical-align:middle;font-size:14px;white-space:nowrap}
.tbl th{color:var(--muted);font-size:12.5px;text-transform:uppercase;letter-spacing:.03em}
.inline{display:inline-flex;gap:6px;align-items:center;margin:2px 0}
.inline input[type=text]{width:130px;padding:6px 8px;border:1px solid var(--line);border-radius:6px;background:var(--panel);color:var(--text);font:inherit}
.pill{display:inline-block;padding:2px 8px;border-radius:10px;font-size:12px;background:var(--head)}
.pill.on{background:#e6f6ee;color:#0b5a3a}.pill.off{background:#fdecea;color:#8a1c14}
.created{background:#e6f6ee;color:#0b5a3a;border-radius:8px;padding:10px 12px;margin-bottom:12px}
@media (prefers-color-scheme:dark){.pill.on,.created{background:#12301f;color:#9ae6b4}.pill.off{background:#3a1d1a;color:#ffb4ab}}
