:root{
  --bg:#efeae2;
  --panel:#ffffff;
  --sidebar:#f7f9fa;
  --line:#e3e7e9;
  --text:#111b21;
  --muted:#667781;
  --accent:#00a884;
  --accent-dark:#008069;
  --mine:#d9fdd3;
  --incoming:#fff;
  --note:#fff6c9;
  --shadow:0 2px 8px rgba(11,20,26,.08);
}
*{box-sizing:border-box}
html,body{height:100%;margin:0;font-family:Inter,Segoe UI,Arial,sans-serif;color:var(--text);background:#d8dbd5}
body{overflow:hidden}
button,input,textarea,select{font:inherit}
button{cursor:pointer}
.hidden{display:none!important}
.muted{color:var(--muted)}
.small{font-size:12px}
.tiny{font-size:11px;color:var(--muted);line-height:1.45;margin-top:18px}

.app-shell{
  display:grid;grid-template-columns:390px 1fr;
  width:min(1600px,100%);height:100vh;margin:0 auto;background:var(--panel);
  box-shadow:0 0 22px rgba(0,0,0,.12)
}
.sidebar{min-width:0;border-right:1px solid var(--line);background:var(--sidebar);display:flex;flex-direction:column}
.topbar,.chat-header{height:64px;background:#f0f2f5;display:flex;align-items:center;padding:0 14px;gap:10px}
.brand-mini,.brand-mark,.empty-logo{
  display:grid;place-items:center;background:var(--accent);color:white;font-weight:800;border-radius:50%
}
.brand-mini{width:40px;height:40px;font-size:14px}
.brand-name{font-weight:700;font-size:15px}
.topbar .icon-btn{margin-left:auto}
.icon-btn{border:0;background:transparent;border-radius:50%;width:36px;height:36px;font-size:18px;color:#54656f}
.icon-btn:hover{background:#e4e7e9}
.icon-btn.large{width:42px;height:42px}
.search-row{display:flex;gap:8px;padding:9px 12px;background:white}
.search-row input{flex:1;background:#f0f2f5;border:0;border-radius:8px;padding:10px 12px;outline:none}
.filters{display:flex;gap:5px;padding:0 10px 9px;background:white;overflow:auto}
.filter{border:1px solid #dde2e5;background:white;color:#54656f;border-radius:16px;padding:5px 10px;font-size:12px;white-space:nowrap}
.filter.active{background:#e7fce9;color:#008069;border-color:#d2f2d5}
.mode-strip{font-size:10px;font-weight:800;letter-spacing:.08em;padding:5px 12px}
.mode-strip.demo{background:#fff4ce;color:#7a5b00}
.mode-strip.live{background:#dff8ef;color:#00745f}
.conversation-list{overflow:auto;flex:1;background:white}
.conv{
  min-height:72px;display:grid;grid-template-columns:48px 1fr auto;gap:11px;
  align-items:center;padding:10px 12px;border-bottom:1px solid #eef0f1;cursor:pointer
}
.conv:hover,.conv.active{background:#f0f2f5}
.avatar{width:42px;height:42px;border-radius:50%;background:#dfe5e7;display:grid;place-items:center;font-weight:700;color:#54656f;flex:0 0 auto}
.conv-main{min-width:0}
.conv-row{display:flex;justify-content:space-between;gap:8px;align-items:center}
.conv-name{font-size:15px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.conv-preview{font-size:13px;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:4px}
.conv-time{font-size:11px;color:var(--muted);white-space:nowrap}
.badge{background:var(--accent);color:white;border-radius:12px;min-width:20px;height:20px;padding:0 6px;display:grid;place-items:center;font-size:11px}
.tag{font-size:10px;background:#eef0f1;color:#54656f;padding:2px 6px;border-radius:10px;display:inline-block;margin-top:4px}
.assigned-dot{font-size:10px;color:#008069}

.chat-area{min-width:0;background:var(--bg);height:100vh}
.empty-state{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:40px;border-bottom:6px solid var(--accent)}
.empty-logo{width:84px;height:84px;font-size:28px;opacity:.85}
.empty-state h2{font-weight:400;font-size:30px;margin:25px 0 8px}
.empty-state p{max-width:560px;color:var(--muted);line-height:1.5}
.chat-panel{height:100%;display:flex;flex-direction:column}
.chat-header{border-bottom:1px solid var(--line)}
.chat-title-wrap{min-width:140px}
.chat-title{font-weight:650}
.header-controls{margin-left:auto;display:flex;gap:7px;align-items:center}
select,.tag-input{
  border:1px solid #d7dcdf;background:white;border-radius:7px;padding:7px 8px;color:#34434b;outline:none
}
.tag-input{width:145px}
.secondary,.primary{
  border:0;border-radius:7px;padding:9px 13px;font-weight:650
}
.secondary{background:#e7edef;color:#36464f}
.primary{background:var(--accent);color:white}
.primary:hover{background:var(--accent-dark)}
.wide{width:100%}

.chat-content{display:grid;grid-template-columns:1fr 270px;min-height:0;flex:1}
.message-list{
  overflow:auto;padding:22px 5vw;background-color:var(--bg);
  background-image:radial-gradient(rgba(0,0,0,.025) 1px,transparent 1px);
  background-size:15px 15px
}
.msg-row{display:flex;margin:5px 0}
.msg-row.out{justify-content:flex-end}
.bubble{max-width:min(690px,72%);padding:7px 10px 6px;border-radius:8px;background:var(--incoming);box-shadow:0 1px 1px rgba(0,0,0,.08)}
.msg-row.out .bubble{background:var(--mine)}
.bubble-body{white-space:pre-wrap;word-break:break-word;font-size:14px;line-height:1.4}
.bubble-meta{display:flex;justify-content:flex-end;gap:5px;margin-top:3px;color:#667781;font-size:10px}
.agent-label{font-size:10px;color:#008069;font-weight:700;margin-bottom:3px}
.media-link{display:inline-block;margin-top:5px;color:#027eb5;text-decoration:none;font-size:12px}
.day-sep{text-align:center;margin:12px 0;color:#54656f;font-size:11px}
.day-sep span{background:#e1f2fb;padding:5px 9px;border-radius:7px}

.notes-panel{border-left:1px solid rgba(0,0,0,.07);background:#fafafa;padding:15px;overflow:auto}
.notes-title{font-weight:700}
.notes-sub{font-size:11px;color:var(--muted);margin:3px 0 12px}
.note{background:var(--note);padding:9px;border-radius:7px;margin:8px 0;font-size:12px;line-height:1.35}
.note-meta{font-size:10px;color:#786f49;margin-top:4px}
.notes-panel textarea{width:100%;resize:vertical;border:1px solid #d5dadc;border-radius:7px;padding:8px;outline:none}

.composer{min-height:62px;background:#f0f2f5;display:flex;align-items:center;gap:8px;padding:9px 14px}
.composer textarea{flex:1;resize:none;max-height:120px;border:0;border-radius:9px;padding:11px 14px;outline:none}
.send-btn{width:42px;height:42px;border:0;border-radius:50%;background:var(--accent);color:white;font-size:18px}

.modal{position:fixed;inset:0;background:rgba(11,20,26,.45);display:grid;place-items:center;z-index:30;padding:20px}
.modal-card{background:white;width:min(760px,96vw);max-height:88vh;overflow:auto;border-radius:12px;box-shadow:0 20px 70px rgba(0,0,0,.3)}
.modal-head{display:flex;align-items:center;padding:14px 18px;border-bottom:1px solid var(--line)}
.modal-head h3{margin:0}
.modal-head button{margin-left:auto}
#modalBody{padding:18px}
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.form-grid label{font-size:12px;color:var(--muted);display:block;margin-bottom:5px}
.form-grid input,.form-grid select{width:100%;border:1px solid #d5dadc;border-radius:7px;padding:9px}
.form-actions{grid-column:1/-1;display:flex;justify-content:flex-end;gap:8px;margin-top:5px}
.user-table{width:100%;border-collapse:collapse;margin-top:20px;font-size:13px}
.user-table th,.user-table td{padding:8px;border-bottom:1px solid var(--line);text-align:left}
.alert{border-radius:7px;padding:9px 11px;margin:10px 0;font-size:13px}
.alert.error{background:#ffe3e3;color:#9c2424}
.alert.demo{background:#fff4ce;color:#715800}

.login-page{overflow:auto;background:linear-gradient(180deg,#00a884 0 220px,#e9edef 220px 100%)}
.login-shell{min-height:100vh;display:grid;grid-template-columns:1.1fr .9fr;align-items:center;gap:50px;max-width:980px;margin:auto;padding:50px}
.brand-panel{color:white}
.brand-mark{width:76px;height:76px;font-size:25px;border:3px solid rgba(255,255,255,.7)}
.brand-panel h1{font-size:45px;margin:20px 0 8px}
.brand-panel p{font-size:19px;opacity:.95}
.security-line{margin-top:30px;font-size:13px;opacity:.82}
.login-card{background:white;border-radius:12px;padding:30px;box-shadow:0 12px 40px rgba(0,0,0,.18)}
.login-card h2{margin-top:0}
.login-card label{font-size:12px;color:var(--muted);display:block;margin:15px 0 5px}
.login-card input{width:100%;padding:11px;border:1px solid #ccd3d7;border-radius:7px;outline:none}
.login-card .primary{margin-top:20px}

.toast{position:fixed;right:18px;bottom:18px;background:#263238;color:white;padding:11px 15px;border-radius:8px;z-index:99;box-shadow:var(--shadow);font-size:13px}
.toast.error{background:#a83232}

@media(max-width:1000px){
  .app-shell{grid-template-columns:330px 1fr}
  .chat-content{grid-template-columns:1fr}
  .notes-panel{display:none}
  .header-controls .tag-input{display:none}
}
@media(max-width:720px){
  .app-shell{display:block}
  .sidebar{width:100%;height:100vh}
  .chat-area{display:none}
  body.chat-open .sidebar{display:none}
  body.chat-open .chat-area{display:block}
  .chat-header{height:auto;min-height:64px;flex-wrap:wrap;padding:8px}
  .header-controls{width:100%;margin:0}
  .login-shell{grid-template-columns:1fr;padding:25px}
  .brand-panel{display:none}
}
