:root{
  --bg:#ffffff;
  --bg-sidebar:#fbfbfa;
  --border:rgba(55,53,47,0.09);
  --border-strong:rgba(55,53,47,0.16);
  --text:#37352f;
  --text-dim:#787774;
  --text-faint:#9b9a97;
  --accent:#2383e2;
  --accent-tint:rgba(35,131,226,0.08);
  --hover:rgba(55,53,47,0.06);
  --cta-bg:#191919;
  --cta-text:#ffffff;
  --bubble-in:#f1f1ef;
  --bubble-out:#e7f3fc;
  --danger:#eb5757;
  --radius:6px;
}
*{box-sizing:border-box;margin:0;padding:0;}
html,body{height:100%;}
body{
  font-family:'Inter',ui-sans-serif,-apple-system,BlinkMacSystemFont,sans-serif;
  background:var(--bg);
  color:var(--text);
  -webkit-font-smoothing:antialiased;
  font-size:14px;
}

/* ---------- Login ---------- */
#login-screen{
  height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  background:var(--bg-sidebar);
}
.login-card{
  width:100%;
  max-width:340px;
  padding:36px 32px;
  background:#fff;
  border:1px solid var(--border);
  border-radius:8px;
  box-shadow:0 2px 8px rgba(15,15,15,0.04);
}
.login-brand{
  font-size:20px;
  font-weight:700;
  margin-bottom:2px;
  letter-spacing:-0.01em;
}
.login-title{
  font-size:13px;
  color:var(--text-dim);
  margin-bottom:26px;
}
label{
  display:block;
  font-size:12px;
  font-weight:500;
  color:var(--text-dim);
  margin-bottom:6px;
}
input[type=email],input[type=password]{
  width:100%;
  padding:9px 11px;
  background:#fff;
  border:1px solid var(--border-strong);
  border-radius:6px;
  color:var(--text);
  font-size:14px;
  font-family:inherit;
  margin-bottom:16px;
}
input:focus{outline:none;border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-tint);}
button{font-family:inherit;cursor:pointer;}
.btn-primary{
  width:100%;
  padding:10px;
  background:var(--cta-bg);
  color:var(--cta-text);
  border:none;
  border-radius:6px;
  font-weight:500;
  font-size:14px;
}
.btn-primary:hover{background:#000;}
.btn-primary:disabled{opacity:0.5;cursor:default;}
#login-error{
  color:var(--danger);
  font-size:13px;
  margin-top:12px;
  min-height:16px;
}

/* ---------- App shell ---------- */
#app{
  height:100vh;
  grid-template-columns:280px 1fr;
  display:none;
}
#app.active{display:grid;}

/* Sidebar */
#sidebar{
  background:var(--bg-sidebar);
  border-right:1px solid var(--border);
  display:flex;
  flex-direction:column;
  min-height:0;
}
#sidebar-header{
  padding:16px 14px 12px;
}
#sidebar-header .brand{
  font-size:14px;
  font-weight:600;
  padding:4px 6px;
}
#sidebar-header .user-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:6px 6px 0;
  margin-top:2px;
}
#sidebar-header .user-email{
  font-size:12px;
  color:var(--text-faint);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
#logout-btn{
  background:none;
  border:none;
  color:var(--text-faint);
  font-size:12px;
  flex-shrink:0;
}
#logout-btn:hover{color:var(--text);text-decoration:underline;}

.sidebar-label{
  padding:10px 20px 6px;
  font-size:11px;
  font-weight:600;
  color:var(--text-faint);
  text-transform:uppercase;
  letter-spacing:0.04em;
}

#conv-list{
  flex:1;
  overflow-y:auto;
  padding:0 8px 12px;
}
.conv-item{
  padding:8px 10px;
  border-radius:6px;
  cursor:pointer;
  display:flex;
  gap:10px;
  align-items:flex-start;
}
.conv-item:hover{background:var(--hover);}
.conv-item.active{background:var(--accent-tint);}
.avatar{
  width:26px;height:26px;
  border-radius:50%;
  background:#dfe1e6;
  color:#57606a;
  font-size:11px;
  font-weight:600;
  display:flex;
  align-items:center;
  justify-content:center;
  flex-shrink:0;
  margin-top:1px;
}
.conv-item .body{min-width:0;flex:1;}
.conv-item .row1{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:6px;
}
.row1-right{
  display:flex;
  align-items:center;
  gap:6px;
  flex-shrink:0;
}
.unread-badge{
  background:var(--accent);
  color:#fff;
  font-size:10px;
  font-weight:600;
  min-width:16px;
  height:16px;
  border-radius:8px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:0 4px;
}
.label-badge{
  display:inline-flex;
  align-items:center;
  gap:4px;
  margin-top:5px;
  padding:2px 7px;
  border-radius:10px;
  font-size:11px;
  font-weight:500;
  width:fit-content;
}
.label-badge--normal{background:#dbefe0;color:#2f9e58;}
.label-badge--medium{background:#fbf0da;color:#b8860b;}
.label-badge--high{background:#fbe4e4;color:#d9534f;}
#thread-header .header-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
}
#label-select{
  padding:5px 8px;
  border:1px solid var(--border-strong);
  border-radius:6px;
  font-size:12px;
  font-family:inherit;
  color:var(--text);
  background:#fff;
  cursor:pointer;
}
.label-field{
  display:flex;
  align-items:center;
  gap:8px;
}
.label-field-title{
  font-size:12px;
  color:var(--text-faint);
}
#label-select:focus{outline:none;border-color:var(--accent);}
#label-select.label-normal{background:#dbefe0;color:#2f9e58;border-color:transparent;font-weight:500;}
#label-select.label-medium{background:#fbf0da;color:#b8860b;border-color:transparent;font-weight:500;}
#label-select.label-high{background:#fbe4e4;color:#d9534f;border-color:transparent;font-weight:500;}
.conv-item .name{
  font-size:13px;
  font-weight:600;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.conv-item .time{
  font-size:11px;
  color:var(--text-faint);
  flex-shrink:0;
}
.conv-item .phone{
  font-size:12px;
  color:var(--text-dim);
  margin-top:1px;
}
#empty-conv, #loading-conv{
  padding:16px 18px;
  color:var(--text-faint);
  font-size:13px;
}

/* Main thread */
#thread{
  display:flex;
  flex-direction:column;
  min-height:0;
  background:#fff;
}
#thread-header{
  padding:14px 32px;
  border-bottom:1px solid var(--border);
  display:none;
}
#thread-header.active{display:block;}
#thread-header .name{font-size:15px;font-weight:600;}
#thread-header .meta{font-size:12px;color:var(--text-dim);margin-top:1px;}

#messages{
  flex:1;
  overflow-y:auto;
  padding:24px 32px;
  display:flex;
  flex-direction:column;
  gap:10px;
}
#thread-placeholder{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  color:var(--text-faint);
  font-size:14px;
}
.msg{
  max-width:56%;
  padding:9px 13px;
  border-radius:8px;
  font-size:14px;
  line-height:1.5;
  white-space:pre-wrap;
  word-wrap:break-word;
}
.msg.in{
  align-self:flex-start;
  background:var(--bubble-in);
}
.msg.out{
  align-self:flex-end;
  background:var(--bubble-out);
}
.msg .meta{
  display:block;
  font-size:10px;
  color:var(--text-faint);
  margin-top:4px;
}
.msg.out .meta{text-align:right;}

#reply-bar{
  padding:14px 32px 18px;
  border-top:1px solid var(--border);
}
#reply-form{
  display:flex;
  gap:8px;
  align-items:flex-end;
}
#reply-text{
  flex:1;
  resize:none;
  min-height:38px;
  max-height:120px;
  padding:9px 12px;
  border:1px solid var(--border-strong);
  border-radius:6px;
  font-family:inherit;
  font-size:14px;
  color:var(--text);
}
#reply-text:focus{outline:none;border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-tint);}
#reply-send-btn{
  padding:9px 16px;
  background:var(--cta-bg);
  color:var(--cta-text);
  border:none;
  border-radius:6px;
  font-weight:500;
  font-size:14px;
  flex-shrink:0;
}
#reply-send-btn:hover{background:#000;}
#reply-send-btn:disabled{opacity:0.5;cursor:default;}
#reply-error{
  color:var(--danger);
  font-size:12px;
  margin-top:6px;
  min-height:14px;
}

::-webkit-scrollbar{width:8px;}
::-webkit-scrollbar-thumb{background:var(--border-strong);border-radius:4px;}

.blink-underscore{
  color: var(--text-faint);
  animation: blink-cursor 2.8s ease-in-out infinite;
}
@keyframes blink-cursor{
  0%, 40%   { opacity: 1; }
  50%, 90%  { opacity: 0.15; }
  100%      { opacity: 1; }
}
