
:root{
  --blue:#1253b9;--blue2:#0a3f91;--sky:#eef5ff;--line:#d9e5f5;--text:#10233f;
  --muted:#6b7c93;--green:#0f9d67;--red:#d84040;--amber:#d98a00;--card:#fff;
  --shadow:0 18px 55px rgba(17,60,120,.12);
}
*{box-sizing:border-box}
html,body{margin:0;min-height:100%;font-family:Inter,"Noto Sans Thai","Segoe UI",Tahoma,sans-serif;color:var(--text);background:#f4f7fb}
button,input,textarea,select{font:inherit}
button{cursor:pointer}
.hidden{display:none!important}
.topbar{height:64px;background:linear-gradient(120deg,var(--blue2),var(--blue));color:#fff;display:flex;align-items:center;padding:0 18px;gap:12px;box-shadow:0 6px 20px rgba(0,50,120,.18);position:sticky;top:0;z-index:20}
.brand{display:flex;align-items:center;gap:11px;font-weight:800;letter-spacing:.1px}
.brand img{width:38px;height:38px;border-radius:10px;background:#fff;padding:4px}
.brand small{display:block;font-weight:500;opacity:.82;font-size:11px}
.top-actions{margin-left:auto;display:flex;gap:8px;align-items:center}
.btn{border:1px solid var(--line);background:#fff;color:var(--text);border-radius:12px;padding:9px 13px;font-weight:700;box-shadow:0 2px 8px rgba(15,55,110,.04)}
.btn:hover{transform:translateY(-1px)}
.btn.primary{background:var(--blue);border-color:var(--blue);color:#fff}
.btn.green{background:var(--green);border-color:var(--green);color:#fff}
.btn.red{background:#fff2f2;border-color:#ffd1d1;color:#b92727}
.btn.sm{padding:7px 10px;border-radius:10px;font-size:13px}
.badge{padding:5px 9px;border-radius:999px;font-size:12px;font-weight:800;background:#eaf2ff;color:var(--blue)}
.badge.new,.badge.waiting_staff{background:#fff0d7;color:#9a6100}
.badge.waiting_customer{background:#e9f9f2;color:#06794d}
.badge.closed{background:#edf0f4;color:#667085}
.wrap{max-width:1100px;margin:0 auto;padding:22px}
.hero{background:linear-gradient(130deg,#fff,#f1f7ff);border:1px solid #dce8f7;border-radius:24px;padding:24px;box-shadow:var(--shadow);margin-bottom:18px}
.hero h1{margin:0 0 8px;font-size:26px}
.hero p{margin:0;color:var(--muted);line-height:1.7}
.card{background:var(--card);border:1px solid #e3eaf3;border-radius:20px;box-shadow:0 8px 25px rgba(18,63,124,.06)}
.form-card{max-width:650px;margin:0 auto;padding:22px}
.grid{display:grid;gap:14px}
.grid.g2{grid-template-columns:1fr 1fr}
label{font-size:13px;font-weight:800;color:#324762;display:block;margin:0 0 6px}
input,textarea,select{width:100%;border:1px solid #d5dfec;background:#fff;border-radius:12px;padding:11px 12px;outline:none;color:var(--text)}
input:focus,textarea:focus,select:focus{border-color:#77a9ee;box-shadow:0 0 0 3px rgba(18,83,185,.10)}
textarea{min-height:95px;resize:vertical}
.hint{font-size:12px;color:var(--muted);line-height:1.55}
.notice{background:#fff8e8;border:1px solid #ffe2a2;color:#755000;border-radius:13px;padding:10px 12px;font-size:13px;line-height:1.55}
.chat-shell{height:calc(100vh - 104px);max-height:880px;min-height:590px;display:grid;grid-template-rows:auto 1fr auto;background:#fff;border:1px solid #dfe8f3;border-radius:22px;overflow:hidden;box-shadow:var(--shadow)}
.chat-head{padding:14px 17px;border-bottom:1px solid #e7edf5;display:flex;align-items:center;gap:10px;background:#fff}
.avatar{width:42px;height:42px;border-radius:50%;display:grid;place-items:center;background:#eaf3ff;color:var(--blue);font-size:20px}
.chat-head .title{font-weight:850}
.chat-head .sub{font-size:12px;color:var(--muted);margin-top:2px}
.chat-messages{overflow:auto;padding:18px;background:linear-gradient(#f7faff,#f4f7fb)}
.msg-row{display:flex;margin:8px 0}
.msg-row.me{justify-content:flex-end}
.msg{max-width:min(75%,650px);padding:10px 12px;border-radius:16px;background:#fff;border:1px solid #e1e8f2;box-shadow:0 3px 10px rgba(20,55,95,.04);line-height:1.5;word-break:break-word}
.me .msg{background:#dcebff;border-color:#bdd7fb}
.msg .meta{font-size:10px;color:#78879a;margin-top:5px}
.msg img{display:block;max-width:100%;max-height:420px;border-radius:12px;margin-top:5px;cursor:zoom-in}
.expired{padding:18px;border:1px dashed #cbd6e4;background:#f7f9fc;color:#7c8999;border-radius:12px;text-align:center;font-size:13px}
.composer{padding:12px;border-top:1px solid #e5ecf4;display:grid;grid-template-columns:auto 1fr auto;gap:8px;align-items:end;background:#fff}
.composer textarea{min-height:45px;max-height:120px}
.file-btn{width:44px;height:44px;border-radius:12px;border:1px solid #d5dfec;background:#f8fbff;display:grid;place-items:center;font-size:20px}
.send-btn{height:44px;padding:0 16px}
.upload-preview{padding:8px 12px;border-top:1px solid #eef2f7;font-size:12px;color:var(--muted)}
.staff-layout{display:grid;grid-template-columns:330px minmax(0,1fr) 300px;gap:12px;height:calc(100vh - 84px);padding:10px}
.panel{background:#fff;border:1px solid #e1e8f1;border-radius:18px;overflow:hidden;min-height:0;box-shadow:0 6px 18px rgba(20,65,120,.05)}
.panel-head{padding:12px;border-bottom:1px solid #e7edf4;background:#fbfdff}
.thread-list{height:calc(100% - 118px);overflow:auto}
.thread{padding:12px;border-bottom:1px solid #edf1f5;cursor:pointer}
.thread:hover,.thread.active{background:#f0f6ff}
.thread-top{display:flex;justify-content:space-between;gap:8px}
.thread-name{font-weight:800}
.thread .phone{font-size:12px;color:#657890;margin-top:3px}
.thread .time{font-size:11px;color:#8a98aa;white-space:nowrap}
.unread-dot{width:9px;height:9px;border-radius:50%;background:#e94e4e;display:inline-block;margin-left:5px}
.staff-chat{height:100%;display:grid;grid-template-rows:auto 1fr auto}
.detail{padding:14px;overflow:auto;height:100%}
.detail h3{margin:4px 0 13px}
.kv{padding:9px 0;border-bottom:1px solid #edf1f5}
.kv .k{font-size:11px;color:#7b8a9d}
.kv .v{font-weight:700;margin-top:3px;word-break:break-word}
.login-shell{min-height:100vh;display:grid;place-items:center;padding:20px;background:linear-gradient(135deg,#eaf3ff,#f8fbff)}
.login-card{width:min(430px,100%);background:#fff;border:1px solid #dce7f4;border-radius:24px;padding:26px;box-shadow:var(--shadow)}
.login-logo{display:flex;align-items:center;gap:12px;margin-bottom:18px}
.login-logo img{width:54px;height:54px;border-radius:14px}
.login-logo h1{font-size:22px;margin:0}
.login-logo p{margin:3px 0 0;color:var(--muted);font-size:12px}
.error{background:#fff1f1;color:#b42318;border:1px solid #ffd4d4;border-radius:11px;padding:10px 12px;font-size:13px}
.empty{height:100%;display:grid;place-items:center;text-align:center;color:#8190a3;padding:25px}
.loader{display:inline-block;width:18px;height:18px;border:2px solid #d9e6f7;border-top-color:var(--blue);border-radius:50%;animation:spin .7s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
@media(max-width:980px){
  .staff-layout{grid-template-columns:300px minmax(0,1fr)}
  .staff-layout .detail-panel{display:none}
}
@media(max-width:720px){
  .wrap{padding:12px}.hero{padding:18px}.grid.g2{grid-template-columns:1fr}
  .topbar{height:58px;padding:0 10px}.brand small{display:none}
  .chat-shell{height:calc(100vh - 82px);min-height:0;border-radius:14px}
  .msg{max-width:88%}
  .staff-layout{display:block;height:calc(100vh - 58px);padding:0}
  .thread-panel{height:100%;border-radius:0}
  .chat-panel{display:none;height:100%;border-radius:0}
  body.thread-open .thread-panel{display:none}
  body.thread-open .chat-panel{display:block}
  .mobile-back{display:inline-flex!important}
}
.mobile-back{display:none}

.modal-backdrop{position:fixed;inset:0;background:rgba(10,25,50,.55);z-index:100;display:grid;place-items:center;padding:18px}
.modal-card{width:min(900px,100%);max-height:90vh;overflow:auto;background:#fff;border-radius:22px;box-shadow:0 28px 80px rgba(0,0,0,.28);border:1px solid #dfe7f2}
.modal-head{position:sticky;top:0;z-index:2;background:#fff;padding:16px 18px;border-bottom:1px solid #e7edf5;display:flex;align-items:center;gap:10px}
.modal-body{padding:18px}
.user-grid{display:grid;grid-template-columns:1.15fr 1.25fr .9fr .85fr 1fr;gap:8px;align-items:center;padding:10px 8px;border-bottom:1px solid #edf1f5}
.user-grid.head{font-size:11px;color:#728096;font-weight:800;background:#f8fbff;border-radius:10px}
.user-grid .email{font-size:12px;color:#64748b;word-break:break-all}
.user-status{font-size:12px;font-weight:800}
.user-status.on{color:#078454}.user-status.off{color:#b42318}
.admin-form{background:#f7faff;border:1px solid #dce8f7;border-radius:16px;padding:14px;margin-bottom:18px}
.admin-form h3{margin:0 0 12px}
@media(max-width:760px){
  .user-grid{grid-template-columns:1fr;gap:4px;padding:13px 8px}
  .user-grid.head{display:none}
  .modal-backdrop{padding:0}.modal-card{height:100vh;max-height:none;border-radius:0}
}
